diff --git "a/partition_80.json" "b/partition_80.json" new file mode 100644--- /dev/null +++ "b/partition_80.json" @@ -0,0 +1,84260 @@ +[ + { + "hash": "94291389d72f38b2a1641fd7b82d14e2fd691f1f", + "msg": "Merged unicode changes back into main branch.", + "author": { + "name": "Travis Oliphant", + "email": "oliphant@enthought.com" + }, + "committer": { + "name": "Travis Oliphant", + "email": "oliphant@enthought.com" + }, + "author_date": "2006-02-09T05:31:53+00:00", + "author_timezone": 0, + "committer_date": "2006-02-09T05:31:53+00:00", + "committer_timezone": 0, + "branches": [ + "main" + ], + "in_main_branch": true, + "merge": true, + "parents": [ + "094c14dfe3bb2f19979bde0978cff9a9f96ab321", + "fc7ac38dec262117bbc30698e0696e9911369207" + ], + "project_name": "repo_copy", + "project_path": "/tmp/tmpdjwupkfu/repo_copy", + "deletions": 91, + "insertions": 254, + "lines": 345, + "files": 8, + "dmm_unit_size": null, + "dmm_unit_complexity": null, + "dmm_unit_interfacing": null + }, + { + "hash": "e4df04ac07a6442d711a34cfa64d64c033f4f1a8", + "msg": "Speed up fill a little.", + "author": { + "name": "Travis Oliphant", + "email": "oliphant@enthought.com" + }, + "committer": { + "name": "Travis Oliphant", + "email": "oliphant@enthought.com" + }, + "author_date": "2006-02-09T05:54:19+00:00", + "author_timezone": 0, + "committer_date": "2006-02-09T05:54:19+00:00", + "committer_timezone": 0, + "branches": [ + "main" + ], + "in_main_branch": true, + "merge": false, + "parents": [ + "94291389d72f38b2a1641fd7b82d14e2fd691f1f" + ], + "project_name": "repo_copy", + "project_path": "/tmp/tmpdjwupkfu/repo_copy", + "deletions": 4, + "insertions": 8, + "lines": 12, + "files": 1, + "dmm_unit_size": null, + "dmm_unit_complexity": null, + "dmm_unit_interfacing": null, + "modified_files": [ + { + "old_path": "numpy/core/src/arraytypes.inc.src", + "new_path": "numpy/core/src/arraytypes.inc.src", + "filename": "arraytypes.inc.src", + "extension": "src", + "change_type": "MODIFY", + "diff": "@@ -1648,15 +1648,17 @@ OBJECT_fill(PyObject **buffer, intp length, void *ignored)\n static void\n @NAME@_fill(@typ@ *buffer, intp length, void *ignored)\n {\n-\tintp i;\t\n+\t@typ@ *buffermax;\n \t@typ@ start = buffer[0];\n \t@typ@ delta = buffer[1];\n \tdelta -= start;\n \tstart += (delta + delta);\n+\tbuffermax = buffer + length;\n \tbuffer += 2;\n-\tfor (i=2; ireal;\n \tstart.imag = buffer->imag;\n@@ -1680,12 +1682,14 @@ static void\n \tdelta.imag -= start.imag;\n \tstart.real += (delta.real + delta.real);\n \tstart.imag += (delta.imag + delta.imag);\n+\tbuffermax = buffer + length;\n \tbuffer += 2;\n-\tfor (i=2; ireal = start.real;\n \t\tbuffer->imag = start.imag; \n \t\tstart.real += delta.real;\n \t\tstart.imag += delta.imag;\n+\t\tbuffer++;\n \t}\n }\n /**end repeat**/\n", + "added_lines": 8, + "deleted_lines": 4, + "source_code": "/* -*- c -*- */\n\n/**begin repeat\n#name=UnsignedLong,UnsignedLongLong,LongLong#\n#type=ulong,ulonglong,longlong#\n */\nstatic @type@\nMyPyLong_As@name@(PyObject *vv)\n{\n\t@type@ ret;\n\n\tif (!PyLong_Check(vv)) {\n\t\tPyObject *mylong;\n\t\tmylong = PyNumber_Long(vv);\n\t\tif (mylong == NULL) return (@type@) -1;\n\t\tvv = mylong;\n\t}\n\telse Py_INCREF(vv);\n\n\tret = PyLong_As@name@(vv);\n\tPy_DECREF(vv);\n\treturn ret;\n}\n/**end repeat**/\n\n\nstatic double \n_getNAN(void) {\n#ifdef NAN\n return NAN;\n#else\n static double nan=0;\n \n if (nan == 0) {\n\t\tdouble mul = 1e100;\n\t\tdouble tmp = 0.0;\n\t\tdouble pinf=0;\n pinf = mul;\n for (;;) {\n pinf *= mul;\n if (pinf == tmp) break;\n tmp = pinf;\n }\n nan = pinf / pinf;\n }\n return nan;\n#endif\n}\n\nstatic double\nMyPyFloat_AsDouble(PyObject *obj)\n{\n if (obj == Py_None) return _getNAN();\n return PyFloat_AsDouble(obj); \n}\n\n\n/****************** getitem and setitem **********************/\n\n/**begin repeat\n\n#TYP=BOOL,BYTE,UBYTE,SHORT,USHORT,INT,LONG,UINT,ULONG,LONGLONG,ULONGLONG,FLOAT,DOUBLE#\n#func1=PyBool_FromLong, PyInt_FromLong*6, PyLong_FromUnsignedLong*2, PyLong_FromLongLong, PyLong_FromUnsignedLongLong, PyFloat_FromDouble*2#\n#func2=PyObject_IsTrue, PyInt_AsLong*6, MyPyLong_AsUnsignedLong*2, MyPyLong_AsLongLong, MyPyLong_AsUnsignedLongLong, MyPyFloat_AsDouble*2#\n#typ=Bool, byte, ubyte, short, ushort, int, long, uint, ulong, longlong, ulonglong, float, double#\n#typ1=long*7, ulong*2, longlong, ulonglong, float, double#\n#kind=Bool, Byte, UByte, Short, UShort, Int, Long, UInt, ULong, LongLong, ULongLong, Float, Double#\n*/\n\nstatic PyObject * \n@TYP@_getitem(char *ip, PyArrayObject *ap) {\n @typ@ t1;\n\n\tif ((ap==NULL) || PyArray_ISBEHAVED_RO(ap)) {\n t1 = *((@typ@ *)ip);\n return @func1@((@typ1@)t1);\n\t}\n\telse {\n ap->descr->f->copyswap(&t1, ip, !PyArray_ISNOTSWAPPED(ap),\n\t\t\t\t ap->descr->elsize);\n return @func1@((@typ1@)t1);\n\t}\n}\n\nstatic int \n@TYP@_setitem(PyObject *op, char *ov, PyArrayObject *ap) {\n @typ@ temp; /* ensures alignment */\n\n if (PyArray_IsScalar(op, @kind@)) {\n temp = ((Py@kind@ScalarObject *)op)->obval;\n }\n else {\n temp = (@typ@)@func2@(op);\n }\n if (PyErr_Occurred()) return -1;\n if (ap == NULL || PyArray_ISBEHAVED(ap)) \n *((@typ@ *)ov)=temp;\n else {\n ap->descr->f->copyswap(ov, &temp, !PyArray_ISNOTSWAPPED(ap), \n\t\t\t\t ap->descr->elsize);\n }\n \n return 0;\n}\n\n/**end repeat**/\n\n\n/**begin repeat \n\n#TYP=CFLOAT,CDOUBLE#\n#typ=float, double#\n*/\n\nstatic PyObject * \n@TYP@_getitem(char *ip, PyArrayObject *ap) {\n @typ@ t1, t2;\n\n if ((ap==NULL) || PyArray_ISBEHAVED_RO(ap)) { \n return PyComplex_FromDoubles((double)((@typ@ *)ip)[0], \n (double)((@typ@ *)ip)[1]);\n }\n else {\n\t\tint size = sizeof(@typ@);\n\t\tBool swap = !PyArray_ISNOTSWAPPED(ap);\n copy_and_swap(&t1, ip, size, 1, 0, swap);\n copy_and_swap(&t2, ip+size, size, 1, 0, swap);\n return PyComplex_FromDoubles((double)t1, (double)t2);\n }\n}\n/**end repeat**/\n\n/**begin repeat \n\n#TYP=CFLOAT, CDOUBLE, CLONGDOUBLE#\n#typ=float, double, longdouble#\n#kind=CFloat, CDouble, CLongDouble#\n*/\nstatic int \n@TYP@_setitem(PyObject *op, char *ov, PyArrayObject *ap) \n{\n Py_complex oop;\n PyObject *op2;\n c@typ@ temp;\n\tint rsize;\n \n if (!(PyArray_IsScalar(op, @kind@))) {\n if (PyArray_Check(op) && (PyArray_NDIM(op)==0)) {\n op2 = ((PyArrayObject *)op)->descr->f->getitem \\\n (((PyArrayObject *)op)->data, \n (PyArrayObject *)op);\n\t\t}\n\t\telse { \n op2 = op; Py_INCREF(op);\n }\n if (op2 == Py_None) {\n oop.real = oop.imag = _getNAN();\n }\n else {\n oop = PyComplex_AsCComplex (op2);\n }\n Py_DECREF(op2);\n if (PyErr_Occurred()) return -1;\n temp.real = (@typ@) oop.real;\n temp.imag = (@typ@) oop.imag; \n }\n\telse {\n temp = ((Py@kind@ScalarObject *)op)->obval;\n }\n\t\n memcpy(ov, &temp, ap->descr->elsize);\n if (!PyArray_ISNOTSWAPPED(ap))\n byte_swap_vector(ov, 2, sizeof(@typ@));\n\t\n\trsize = sizeof(@typ@);\n\tcopy_and_swap(ov, &temp, rsize, 2, rsize, !PyArray_ISNOTSWAPPED(ap));\n return 0;\n}\n/**end repeat**/\n\nstatic PyObject * \nLONGDOUBLE_getitem(char *ip, PyArrayObject *ap) \n{\n return PyArray_Scalar(ip, ap->descr, NULL);\n}\n\nstatic int \nLONGDOUBLE_setitem(PyObject *op, char *ov, PyArrayObject *ap) {\n longdouble temp; /* ensures alignment */\n\n if (PyArray_IsScalar(op, LongDouble)) {\n temp = ((PyLongDoubleScalarObject *)op)->obval;\n }\n else {\n if (op == Py_None) temp = (longdouble)_getNAN();\n else temp = (longdouble)PyFloat_AsDouble(op);\n }\n if (PyErr_Occurred()) return -1;\n if (ap == NULL || PyArray_ISBEHAVED(ap)) \n *((longdouble *)ov)=temp;\n else {\n copy_and_swap(ov, &temp, ap->descr->elsize, 1, 0,\n !PyArray_ISNOTSWAPPED(ap));\n }\n \n return 0;\n}\n\nstatic PyObject * \nCLONGDOUBLE_getitem(char *ip, PyArrayObject *ap) \n{\n return PyArray_Scalar(ip, ap->descr, NULL);\n}\n\n\n/* UNICODE */\nstatic PyObject * \nUNICODE_getitem(char *ip, PyArrayObject *ap) \n{\n\tPyObject *obj;\n\tint mysize;\n\tPyArray_UCS4 *dptr;\n\n\tmysize = ap->descr->elsize >> 2;\n\tdptr = (PyArray_UCS4 *)ip + mysize-1;\n\twhile(mysize > 0 && *dptr-- == 0) mysize--;\n\tif (!PyArray_ISNOTSWAPPED(ap) && (obj != NULL)) {\n\t\tbyte_swap_vector(PyArray_BYTES(ap), mysize, 4);\n\t}\n#ifdef Py_UNICODE_WIDE\n\tobj = PyUnicode_FromUnicode((const PyArray_UCS4 *)ip, mysize);\n#else\n\t/* create new empty unicode object of length mysize*2 */\n\tobj = MyPyUnicode_New(mysize*2);\n\tif (obj == NULL) return obj;\n\tmysize = PyUCS2Buffer_FromUCS4(((PyUnicodeObject *)obj)->str, \n\t\t\t\t (PyArray_UCS4 *)ip, mysize);\n\t/* reset length of unicode object to ucs2size */\n\tif (MyPyUnicode_Resize((PyUnicodeObject *)obj, mysize) < 0) {\n\t\tPy_DECREF(obj);\n\t\treturn NULL;\n\t}\n#endif\n\n\treturn obj;\n}\n\nstatic int \nUNICODE_setitem(PyObject *op, char *ov, PyArrayObject *ap) \n{\n PyObject *temp;\n\tPy_UNICODE *ptr;\n\tint datalen;\n\n\tif ((temp=PyObject_Unicode(op)) == NULL) return -1;\n\tptr = PyUnicode_AS_UNICODE(temp);\n\tif ((ptr == NULL) || (PyErr_Occurred())) {\n\t\tPy_DECREF(temp);\n\t\treturn -1;\n\t}\n\tdatalen = PyUnicode_GET_DATA_SIZE(temp);\n\n#ifdef Py_UNICODE_WIDE\n\tmemcpy(ov, ptr, MIN(ap->descr->elsize, datalen));\n#else\n datalen = PyUCS2Buffer_AsUCS4(ptr, (PyArray_UCS4 *)ov, datalen >> 1,\n\t\t\t\t ap->descr->elsize >> 2);\n\tdatalen <<= 2;\n#endif\n\t/* Fill in the rest of the space with 0 */\n\tif (ap->descr->elsize > datalen) {\n\t\tmemset(ov + datalen, 0, (ap->descr->elsize - datalen));\n\t}\n\t\n\tif (!PyArray_ISNOTSWAPPED(ap)) \n\t\tbyte_swap_vector(ov, ap->descr->elsize >> 2, 4);\n\tPy_DECREF(temp);\n\treturn 0;\n}\n\n/* STRING -- can handle both NULL-terminated and not NULL-terminated cases */\nstatic PyObject * \nSTRING_getitem(char *ip, PyArrayObject *ap) \n{\n\tif (ip[ap->descr->elsize-1])\n\t\treturn PyString_FromStringAndSize(ip,ap->descr->elsize);\n\telse\n\t\treturn PyString_FromString(ip);\n}\n\nstatic int \nSTRING_setitem(PyObject *op, char *ov, PyArrayObject *ap) \n{\n\tchar *ptr;\n\tint len;\n\tPyObject *temp=PyObject_Str(op);\n\t\n\tif (temp == NULL) return -1;\n\t\n\tif (PyString_AsStringAndSize(temp, &ptr, &len) == -1) {\n\t\tPy_DECREF(temp);\n\t\treturn -1;\n\t}\n\tmemcpy(ov, ptr, MIN(ap->descr->elsize,len));\n\tif (ap->descr->elsize > len) {\n\t\tmemset(ov + len, 0, (ap->descr->elsize - len));\n\t}\n\tPy_DECREF(temp);\n\treturn 0;\n}\n\n/* OBJECT */\n\nstatic PyObject * \nOBJECT_getitem(char *ip, PyArrayObject *ap) \n{\n\tPy_INCREF(*(PyObject **)ip);\n\treturn *(PyObject **)ip;\n}\n\nstatic int \nOBJECT_setitem(PyObject *op, char *ov, PyArrayObject *ap) \n{\n\tPy_XDECREF(*(PyObject **)ov);\n\tPy_INCREF(op);\n\t*(PyObject **)ov = op;\n\treturn PyErr_Occurred() ? -1:0;\n}\n\n/* VOID */\n\nstatic PyObject *\nVOID_getitem(char *ip, PyArrayObject *ap)\n{\n PyObject *u=NULL;\n\tPyArray_Descr* descr;\n int itemsize;\n\n\tdescr = ap->descr;\n\tif (descr->fields && descr->fields != Py_None) {\n\t\tPyObject *key;\n\t\tPyObject *names;\n\t\tint i, n;\n\t\tPyObject *ret;\n\t\tPyObject *tup, *title;\n\t\tPyArray_Descr *new;\n\t\tint offset;\n\t\tint savedflags;\n\n\t\t/* get the names from the fields dictionary*/\n\t\tkey = PyInt_FromLong(-1);\n\t\tnames = PyDict_GetItem(descr->fields, key);\n\t\tPy_DECREF(key);\n\t\tif (!names) goto finish;\n\t\tn = PyList_GET_SIZE(names);\n\t\tret = PyTuple_New(n);\n\t\tsavedflags = ap->flags;\n\t\tfor (i=0; ifields, key);\n\t\t\tif (!PyArg_ParseTuple(tup, \"Oi|O\", &new, &offset, \n\t\t\t\t\t &title)) {\n\t\t\t\tPy_DECREF(ret); \n\t\t\t\tap->descr = descr;\n\t\t\t\treturn NULL;\n\t\t\t}\n\t\t\tap->descr = new;\n\t\t\t/* update alignment based on offset */\n\t\t\tif ((new->alignment > 1) &&\t\t\t\\\n\t\t\t ((((intp)(ip+offset)) % new->alignment) != 0))\n\t\t\t\tap->flags &= ~ALIGNED;\n\t\t\telse\n\t\t\t\tap->flags |= ALIGNED;\n\n\t\t\tPyTuple_SET_ITEM(ret, i,\t\t\t\\\n\t\t\t\t\t new->f->getitem(ip+offset, ap));\n\t\t\tap->flags = savedflags;\n\t\t}\n\t\tap->descr = descr;\n\t\treturn ret;\n\t}\n\n\tif (descr->subarray) {\n\t\t/* return an array of the basic type */\n\t\tPyArray_Dims shape={NULL,-1};\n\t\tPyObject *ret;\n\t\tif (!(PyArray_IntpConverter(descr->subarray->shape, \n\t\t\t\t\t &shape))) {\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\treturn NULL;\n\t\t}\n Py_INCREF(descr->subarray->base);\n\t\tret = PyArray_NewFromDescr(&PyArray_Type,\n\t\t\t\t\t descr->subarray->base,\n\t\t\t\t\t shape.len, shape.ptr,\n\t\t\t\t\t NULL, ip, ap->flags, NULL);\n\t\tPyDimMem_FREE(shape.ptr);\n\t\tif (!ret) return NULL;\n\t\tPyArray_BASE(ret) = (PyObject *)ap;\n\t\tPy_INCREF(ap);\n\t\tPyArray_UpdateFlags((PyArrayObject *)ret, UPDATE_ALL_FLAGS);\n\t\treturn ret;\n\t}\n\n finish:\n\titemsize=ap->descr->elsize;\n\tif (PyArray_ISWRITEABLE(ap))\n\t\tu = PyBuffer_FromReadWriteMemory(ip, itemsize);\n\telse\n\t\tu = PyBuffer_FromMemory(ip, itemsize);\n\tif (u==NULL) goto fail;\n\n\t/* default is to return buffer object pointing to current item */\n\t/* a view of it */\n\treturn u; \n\t\n fail:\n return NULL;\n}\n\n\n\nstatic int PyArray_CopyObject(PyArrayObject *, PyObject *);\n\nstatic int\nVOID_setitem(PyObject *op, char *ip, PyArrayObject *ap)\n{\n\tPyArray_Descr* descr;\n int itemsize=ap->descr->elsize;\n\tint res;\n\n\tdescr = ap->descr;\n\tif (descr->fields && (descr->fields != Py_None) && \\\n\t PyTuple_Check(op)) {\n\t\tPyObject *key;\n\t\tPyObject *names;\n\t\tint i, n;\n\t\tPyObject *tup, *title;\n\t\tPyArray_Descr *new;\n\t\tint offset;\n\t\tint savedflags;\n\t\tres = -1;\n\t\t/* get the names from the fields dictionary*/\n\t\tkey = PyInt_FromLong(-1);\n\t\tnames = PyDict_GetItem(descr->fields, key);\n\t\tPy_DECREF(key);\n\t\tif (!names) goto finish;\n\t\tn = PyList_GET_SIZE(names);\n\t\tif (PyTuple_GET_SIZE(op) != n) {\n\t\t\tPyErr_SetString(PyExc_ValueError, \n\t\t\t\t\t\"size of tuple must match\"\\\n\t\t\t\t\t\"number of fields.\");\n\t\t\treturn -1;\n\t\t}\n\t\tsavedflags = ap->flags;\n\t\tfor (i=0; ifields, key);\n\t\t\tif (!PyArg_ParseTuple(tup, \"Oi|O\", &new, &offset, \n\t\t\t\t\t &title)) {\n\t\t\t\tap->descr = descr;\n\t\t\t\treturn -1;\n\t\t\t}\n\t\t\tap->descr = new;\n\t\t\t/* remember to update alignment flags */\n\t\t\tif ((new->alignment > 1) &&\t\t\t\\\n\t\t\t ((((intp)(ip+offset)) % new->alignment) != 0))\n\t\t\t\tap->flags &= ~ALIGNED;\n\t\t\telse\n\t\t\t\tap->flags |= ALIGNED;\n\n\t\t\tres = new->f->setitem(PyTuple_GET_ITEM(op, i),\n\t\t\t\t\t ip+offset, ap);\n\t\t\tap->flags = savedflags;\n\t\t\tif (res < 0) break;\n\t\t}\n\t\tap->descr = descr;\n\t\treturn res;\n\t}\n\n\tif (descr->subarray) {\n\t\t/* copy into an array of the same basic type */\n\t\tPyArray_Dims shape={NULL,-1};\n\t\tPyObject *ret;\n\t\tif (!(PyArray_IntpConverter(descr->subarray->shape, \n\t\t\t\t\t &shape))) {\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\treturn -1;\n\t\t}\n Py_INCREF(descr->subarray->base);\n\t\tret = PyArray_NewFromDescr(&PyArray_Type,\n\t\t\t\t\t descr->subarray->base,\n\t\t\t\t\t shape.len, shape.ptr,\n\t\t\t\t\t NULL, ip, ap->flags, NULL);\n\t\tPyDimMem_FREE(shape.ptr);\n\t\tif (!ret) return -1;\n\t\tPyArray_BASE(ret) = (PyObject *)ap;\n\t\tPy_INCREF(ap);\n\t\tPyArray_UpdateFlags((PyArrayObject *)ret, UPDATE_ALL_FLAGS);\n\t\tres = PyArray_CopyObject((PyArrayObject *)ret, op);\n\t\tPy_DECREF(ret);\n\t\treturn res;\n\t}\n\n finish:\n\t/* Default is to use buffer interface to set item */\n\t{\n\t\tconst void *buffer;\n\t\tint buflen;\n\t\tres = PyObject_AsReadBuffer(op, &buffer, &buflen);\n\t\tif (res == -1) goto fail;\n\t\tmemcpy(ip, buffer, MIN(buflen, itemsize));\n }\n\treturn 0;\n\n fail:\n return -1; \n}\n\n\n/****************** XXX_to_YYY *******************************/ \n\n/* Assumes contiguous, and aligned, from and to */\n\n\n/**begin repeat\n#to=(BYTE,UBYTE,SHORT,USHORT,INT,UINT,LONG,ULONG,LONGLONG,ULONGLONG,FLOAT,DOUBLE,LONGDOUBLE)*16#\n#from=BYTE*13,UBYTE*13,SHORT*13,USHORT*13,INT*13,UINT*13,LONG*13,ULONG*13,LONGLONG*13,ULONGLONG*13,FLOAT*13,DOUBLE*13,LONGDOUBLE*13,CFLOAT*13,CDOUBLE*13,CLONGDOUBLE*13#\n#totyp=(byte, ubyte, short, ushort, int, uint, long, ulong, longlong, ulonglong, float, double, longdouble)*16#\n#fromtyp=byte*13, ubyte*13, short*13, ushort*13, int*13, uint*13, long*13, ulong*13, longlong*13, ulonglong*13, float*13, double*13, longdouble*13, float*13, double*13, longdouble*13#\n#incr= ip++*169,ip+=2*39#\n*/\nstatic void \n@from@_to_@to@(@fromtyp@ *ip, @totyp@ *op, intp n, PyArrayObject *aip, \n\t PyArrayObject *aop) {\n\tregister intp i; \n\tfor(i=0;idescr->elsize*3, 1#\n*/\nstatic void \n@from@_to_OBJECT(@fromtyp@ *ip, PyObject **op, intp n, PyArrayObject *aip,\n\t\t PyArrayObject *aop)\n{\n\tregister intp i; \n\tint skip=@skip@;\n\tfor(i=0;idescr->elsize*3#\n*/\nstatic void \nOBJECT_to_@to@(PyObject **ip, @totyp@ *op, intp n, PyArrayObject *aip,\n\t\t PyArrayObject *aop)\n{\n\tregister intp i; \n\tint skip=@skip@;\n\tfor(i=0;idescr->elsize*3)*3#\n#convert=1*17,0*3,1*17,0*3,0*20#\n#convstr=(Int*9,Long*2,Float*3,Complex*3,Tuple*3)*3#\n*/\nstatic void\n@from@_to_@to@(@fromtyp@ *ip, @totyp@ *op, intp n, PyArrayObject *aip, \n\t PyArrayObject *aop)\n{\n\tregister intp i;\n\tPyObject *temp=NULL;\n\tint skip=aip->descr->elsize;\n\tint oskip=@oskip@;\n\tfor(i=0; idescr->elsize;\n\tfor(i=0; i= 0x02040000) || defined(PyOS_ascii_strtod)\nstatic int\n@fname@_fromstr(char *str, @type@ *ip, char **endptr, void *ignore)\n{\n\tdouble result;\n\n\tresult = PyOS_ascii_strtod(str, endptr);\n\t*ip = (@type@) result;\n\treturn 0;\n}\n#else\n#define @fname@_fromstr NULL\n#endif\n/**end repeat**/\n\n\n\n/**begin repeat\n#fname=BOOL,CFLOAT,CDOUBLE,CLONGDOUBLE,OBJECT,STRING,UNICODE,VOID#\n*/\n#define @fname@_fromstr NULL\n/**end repeat**/\n\n\n/****************** copyswapn *************************************/\n\n/**begin repeat\n\n#fname=SHORT,USHORT,INT,UINT,LONG,ULONG,LONGLONG,ULONGLONG,FLOAT,DOUBLE,LONGDOUBLE#\n#fsize=SHORT,SHORT,INT,INT,LONG,LONG,LONGLONG,LONGLONG,FLOAT,DOUBLE,LONGDOUBLE#\n#type=short,ushort,int,uint,long,ulong,longlong,ulonglong,float,double,longdouble#\n*/\nstatic void\n@fname@_copyswapn (void *dst, void *src, intp n, int swap, int itemsize)\n{\n\tif (src != NULL) /* copy first if needed */\n\t\tmemcpy(dst, src, n*sizeof(@type@));\n\n\tif (swap) {\n\t\tregister char *a, *b, c;\n\t\tfor (a = (char *)dst; n>0; n--) {\n#if SIZEOF_@fsize@ == 2\n\t\t\tb = a + 1;\n\t\t\tc = *a; *a++ = *b; *b = c;\n\t\t\ta += 1;\n#elif SIZEOF_@fsize@ == 4\n\t\t\tb = a + 3;\n c = *a; *a++ = *b; *b-- = c;\n c = *a; *a++ = *b; *b = c;\n\t\t\ta += 2;\n#elif SIZEOF_@fsize@ == 8\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\t\t\ta += 4;\n#elif SIZEOF_@fsize@ == 10\n b = a + 9;\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 c = *a; *a++ = *b; *b = c;\n\t\t\ta += 5;\n#elif SIZEOF_@fsize@ == 12\n b = a + 11;\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 c = *a; *a++ = *b; *b-- = c;\n c = *a; *a++ = *b; *b = c;\n\t\t\ta += 6;\n#elif SIZEOF_@fsize@ == 16\n b = a + 15;\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 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\t\t\ta += 8;\n#else\n\t\t\tregister int i, nn;\n b = a + (SIZEOF_@fsize@-1);\n\t\t\tnn = SIZEOF_@fsize@ / 2;\n for (i=0; i0; nn--) {\n#if SIZEOF_@fsize@ == 4\n\t\t\tb = a + 3;\n c = *a; *a++ = *b; *b-- = c;\n c = *a; *a++ = *b; *b = c;\n\t\t\ta += 2;\n#elif SIZEOF_@fsize@ == 8\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\t\t\ta += 4;\n#elif SIZEOF_@fsize@ == 10\n b = a + 9;\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 c = *a; *a++ = *b; *b = c;\n\t\t\ta += 5;\n#elif SIZEOF_@fsize@ == 12\n b = a + 11;\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 c = *a; *a++ = *b; *b-- = c;\n c = *a; *a++ = *b; *b = c;\n\t\t\ta += 6;\n#elif SIZEOF_@fsize@ == 16\n b = a + 15;\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 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\t\t\ta += 8;\n#else\n\t\t\tregister int i, kn;\n\n b = a + (SIZEOF_@fsize@-1);\n\t\t\tkn = SIZEOF_@fsize@ / 2;\n for (i=0; i0; n--) {\n\t\t\tb = a + 3;\n\t\t\tc=*a; *a++ = *b; *b-- = c;\n\t\t\tc=*a; *a++ = *b; *b-- = c;\n\t\t\ta += 1;\n\t\t}\n\t}\n}\n\n\nstatic void\nOBJECT_copyswap (PyObject **dst, PyObject **src, int swap, int itemsize)\n{\n OBJECT_copyswapn(dst, src, 1, swap, itemsize);\n}\n\nstatic void\nSTRING_copyswap (char *dst, char *src, int swap, int itemsize)\n{\n\tif (src != NULL) \n\t\tmemcpy(dst, src, itemsize);\n\t\n}\n\n/* ignore swap */\nstatic void\nVOID_copyswap (char *dst, char *src, int swap, int itemsize)\n{\n\tif (src != NULL) \n\t\tmemcpy(dst, src, itemsize);\t\n\treturn;\n}\n\nstatic void\nUNICODE_copyswap (char *dst, char *src, int swap, int itemsize)\n{\n\n\tif (src != NULL) \n\t\tmemcpy(dst, src, itemsize);\n\t\n\tif (swap) {\n\t\tregister char *a, *b, c;\n a = (char *)dst;\n b = a + 3;\n\t\tc=*a; *a++ = *b; *b-- = c;\n\t\tc=*a; *a++ = *b; *b-- = c;\n\t}\n}\n\n\n/****************** nonzero **********************************/\n\n/**begin repeat\n#fname=BOOL,BYTE,UBYTE,SHORT,USHORT,INT,UINT,LONG,ULONG,LONGLONG,ULONGLONG,FLOAT,DOUBLE,LONGDOUBLE#\n#type=Bool, byte, ubyte, short, ushort, int, uint, long, ulong, longlong, ulonglong, float, double, longdouble#\n*/\nstatic Bool \n@fname@_nonzero (@type@ *ip, PyArrayObject *ap)\n{\n\t@type@ t1;\n\tif (ap==NULL || PyArray_ISBEHAVED_RO(ap))\n\t\treturn (Bool) (*ip != 0);\n\telse {\n\t\t/* don't worry about swap, since we are just testing\n\t\t whether or not equal to 0 */\n\t\tmemcpy(&t1, ip, sizeof(@type@));\n\t\treturn (Bool) (t1 != 0);\n\t}\n}\n/**end repeat**/\n\n/**begin repeat\n#fname=CFLOAT,CDOUBLE,CLONGDOUBLE#\n#type=cfloat, cdouble, clongdouble#\n*/\nstatic Bool \n@fname@_nonzero (@type@ *ip, PyArrayObject *ap)\n{\n\t@type@ t1;\n\tif (ap==NULL || PyArray_ISBEHAVED_RO(ap))\n\t\treturn (Bool) ((ip->real != 0) || (ip->imag != 0));\n\telse {\n\t\t/* don't worry about swap, since we are just testing\n\t\t whether or not equal to 0 */\n\t\tmemcpy(&t1, ip, sizeof(@type@));\n\t\treturn (Bool) ((t1.real != 0) || (t1.imag != 0));\n\t}\n}\n/**end repeat**/\n\n\n\n#define WHITESPACE \" \\t\\n\\r\\v\\f\"\n#define WHITELEN 6\n\nstatic Bool\nPy_STRING_ISSPACE(char ch) \n{\n\tchar white[] = WHITESPACE;\n\tint j;\n\tBool space=FALSE;\n\tfor (j=0; jdescr->elsize;\n\tint i;\n\tBool nonz = FALSE;\n\n\tfor (i=0; idescr->elsize >> 2;\n\tint i;\n\tBool nonz = FALSE;\n\tchar *buffer=NULL;\t\n\n\tif ((!PyArray_ISNOTSWAPPED(ap)) || \\\n\t (!PyArray_ISALIGNED(ap))) {\n\t\tbuffer = _pya_malloc(ap->descr->elsize);\n\t\tif (buffer == NULL) {\n\t\t\treturn nonz;\n\t\t}\n\t\tmemcpy(buffer, ip, ap->descr->elsize);\n\t\tif (!PyArray_ISNOTSWAPPED(ap)) {\n\t\t\tbyte_swap_vector(buffer, len, 4);\n\t\t}\n\t\tip = (PyArray_UCS4 *)buffer;\n\t}\n\n\tfor (i=0; idescr->elsize;\n\tBool nonz = FALSE;\n\t\n\tfor (i=0; idescr->elsize);\n}\n\n/* taken from Python */\nstatic int \nUNICODE_compare(register PyArray_UCS4 *ip1, register PyArray_UCS4 *ip2, \n\t\tPyArrayObject *ap)\n{\n register int itemsize=ap->descr->elsize;\n\tregister PyArray_UCS4 c1, c2;\n\n\tif (itemsize < 0) return 0;\n\t\n\twhile(itemsize-- > 0) {\n\t\tc1 = *ip1++;\n\t\tc2 = *ip2++;\n\t\t\n\t\tif (c1 != c2) \n\t\t\treturn (c1 < c2) ? -1 : 1;\n\t}\n\treturn 0;\n}\n\n/* possibly redefine compare in terms of fields and subarrays if any */\n\n/* as it is, it compares raw-bytes as it they were strings */\n#define VOID_compare STRING_compare\n\n/****************** argfunc **********************************/\n\n/**begin repeat\n\n#fname= BOOL,BYTE, UBYTE, SHORT, USHORT, INT, UINT, LONG, ULONG, LONGLONG, ULONGLONG, FLOAT, DOUBLE, LONGDOUBLE, CFLOAT, CDOUBLE, CLONGDOUBLE#\n#type= Bool, byte, ubyte, short, ushort, int, uint, long, ulong, longlong, ulonglong, float, double, longdouble, float, double, longdouble#\n#incr= ip++*14, ip+=2*3#\n*/\n\nstatic int\n@fname@_argmax(@type@ *ip, intp n, intp *max_ind, PyArrayObject *aip)\n{\n\tregister intp i;\n\t@type@ mp=*ip;\n\t*max_ind=0;\n\tfor (i=1; i mp) {\n\t\t\tmp = *ip;\n\t\t\t*max_ind = i;\n\t\t}\n\t}\n\treturn 0;\n}\n\n/**end repeat**/\n\nstatic int \nOBJECT_argmax(PyObject **ip, intp n, intp *max_ind, PyArrayObject *aip) \n{\n\tregister intp i; \n\tPyObject *mp=ip[0]; *max_ind=0;\n\tfor(i=1; i 0) { \n\t\t\tmp = *ip; \n\t\t\t*max_ind=i;\n\t\t} \n\t} \n\treturn 0;\n}\n\n/**begin repeat\n\n#fname= STRING, UNICODE#\n#type= char, PyArray_UCS4#\n\n*/\nstatic int \n@fname@_argmax(@type@ *ip, intp n, intp *max_ind, PyArrayObject *aip) \n{\n\tregister intp i; \n\tint elsize = aip->descr->elsize;\n\t@type@ *mp = (@type@ *)_pya_malloc(elsize);\n\t\n\tif (mp==NULL) return 0;\n\tmemcpy(mp, ip, elsize);\n\t*max_ind = 0;\n\tfor(i=1; i 0) { \n\t\t\tmemcpy(mp, ip, elsize);\n\t\t\t*max_ind=i;\n\t\t} \n\t} \n\t_pya_free(mp);\n\treturn 0;\n}\n\n/**end repeat**/\n\n#define VOID_argmax NULL\n\nstatic void\nBOOL_dot(char *ip1, intp is1, char *ip2, intp is2, char *op, intp n, \n void *ignore)\n{\n\tregister Bool tmp=FALSE;\n\tregister intp i;\n\tfor(i=0;ireal;\n\tstart.imag = buffer->imag;\n\tdelta.real = buffer[1].real;\n\tdelta.imag = buffer[1].imag;\n\tdelta.real -= start.real;\n\tdelta.imag -= start.imag;\n\tstart.real += (delta.real + delta.real);\n\tstart.imag += (delta.imag + delta.imag);\n\tbuffermax = buffer + length;\n\tbuffer += 2;\n\twhile (buffer < buffermax) {\n\t\tbuffer->real = start.real;\n\t\tbuffer->imag = start.imag; \n\t\tstart.real += delta.real;\n\t\tstart.imag += delta.imag;\n\t\tbuffer++;\n\t}\n}\n/**end repeat**/\n\n\n#define _ALIGN(type) offsetof(struct {char c; type v;},v)\n\n/**begin repeat\n\n#from= VOID, STRING, UNICODE#\n#align= char, char, PyArray_UCS4#\n#NAME= Void, String, Unicode#\n#endian= |, |, =#\n*/\n\nstatic PyArray_ArrFuncs _Py@NAME@_ArrFuncs = {\n\t{\n\t\t(PyArray_VectorUnaryFunc*)@from@_to_BOOL, \n\t\t(PyArray_VectorUnaryFunc*)@from@_to_BYTE, \n\t\t(PyArray_VectorUnaryFunc*)@from@_to_UBYTE, \n\t\t(PyArray_VectorUnaryFunc*)@from@_to_SHORT, \n\t\t(PyArray_VectorUnaryFunc*)@from@_to_USHORT, \n\t\t(PyArray_VectorUnaryFunc*)@from@_to_INT, \n\t\t(PyArray_VectorUnaryFunc*)@from@_to_UINT, \n\t\t(PyArray_VectorUnaryFunc*)@from@_to_LONG,\n\t\t(PyArray_VectorUnaryFunc*)@from@_to_ULONG, \n\t\t(PyArray_VectorUnaryFunc*)@from@_to_LONGLONG, \n\t\t(PyArray_VectorUnaryFunc*)@from@_to_ULONGLONG, \n\t\t(PyArray_VectorUnaryFunc*)@from@_to_FLOAT, \n\t\t(PyArray_VectorUnaryFunc*)@from@_to_DOUBLE, \n\t\t(PyArray_VectorUnaryFunc*)@from@_to_LONGDOUBLE, \n\t\t(PyArray_VectorUnaryFunc*)@from@_to_CFLOAT, \n\t\t(PyArray_VectorUnaryFunc*)@from@_to_CDOUBLE, \n\t\t(PyArray_VectorUnaryFunc*)@from@_to_CLONGDOUBLE, \n\t\t(PyArray_VectorUnaryFunc*)@from@_to_OBJECT, \n\t\t(PyArray_VectorUnaryFunc*)@from@_to_STRING, \n\t\t(PyArray_VectorUnaryFunc*)@from@_to_UNICODE, \n\t\t(PyArray_VectorUnaryFunc*)@from@_to_VOID\n\t},\n\t(PyArray_GetItemFunc*)@from@_getitem, \n\t(PyArray_SetItemFunc*)@from@_setitem,\n\t(PyArray_CopySwapNFunc*)@from@_copyswapn,\n\t(PyArray_CopySwapFunc*)@from@_copyswap,\n\t(PyArray_CompareFunc*)@from@_compare, \n\t(PyArray_ArgFunc*)@from@_argmax,\n\t(PyArray_DotFunc*)NULL, \n\t(PyArray_ScanFunc*)@from@_scan,\n\t(PyArray_FromStrFunc*)@from@_fromstr,\n\t(PyArray_NonzeroFunc*)@from@_nonzero,\n\t(PyArray_FillFunc*)NULL,\n\t{\n\t\tNULL, NULL, NULL, NULL\n\t},\n\t{\n\t\tNULL, NULL, NULL, NULL\n\t}\n};\n\nstatic PyArray_Descr @from@_Descr = { \n\tPyObject_HEAD_INIT(&PyArrayDescr_Type)\n\t&Py@NAME@ArrType_Type,\n\tPyArray_@from@LTR,\n\tPyArray_@from@LTR,\n\t'@endian@', 0,\n\tPyArray_@from@, 0,\n\t_ALIGN(@align@),\n\tNULL,\n\tNULL,\n\t&_Py@NAME@_ArrFuncs,\n};\n\n/**end repeat**/\n\n\n/**begin repeat\n\n#from= BOOL,BYTE,UBYTE,SHORT,USHORT,INT,UINT,LONG,ULONG,LONGLONG,ULONGLONG,FLOAT,DOUBLE,LONGDOUBLE,CFLOAT,CDOUBLE,CLONGDOUBLE,OBJECT#\n#num= 1*14,2*3,1#\n#fromtyp= Bool, byte, ubyte, short, ushort, int, uint, long, ulong, longlong, ulonglong, float, double, longdouble, float, double, longdouble, PyObject *#\n#NAME= Bool, Byte, UByte, Short, UShort, Int, UInt, Long, ULong, LongLong, ULongLong, Float, Double, LongDouble, CFloat, CDouble, CLongDouble, Object#\n#kind= GENBOOL, SIGNED, UNSIGNED, SIGNED, UNSIGNED, SIGNED, UNSIGNED, SIGNED, UNSIGNED, SIGNED, UNSIGNED, FLOATING, FLOATING, FLOATING, COMPLEX, COMPLEX, COMPLEX, OBJECT#\n#endian= |*3, =*14, |#\n#isobject= 0*17,1#\n*/\n\nstatic PyArray_ArrFuncs _Py@NAME@_ArrFuncs = {\n\t{\n\t\t(PyArray_VectorUnaryFunc*)@from@_to_BOOL, \n\t\t(PyArray_VectorUnaryFunc*)@from@_to_BYTE,\n\t\t(PyArray_VectorUnaryFunc*)@from@_to_UBYTE, \n\t\t(PyArray_VectorUnaryFunc*)@from@_to_SHORT, \n\t\t(PyArray_VectorUnaryFunc*)@from@_to_USHORT, \n\t\t(PyArray_VectorUnaryFunc*)@from@_to_INT, \n\t\t(PyArray_VectorUnaryFunc*)@from@_to_UINT, \n\t\t(PyArray_VectorUnaryFunc*)@from@_to_LONG,\n\t\t(PyArray_VectorUnaryFunc*)@from@_to_ULONG, \n\t\t(PyArray_VectorUnaryFunc*)@from@_to_LONGLONG, \n\t\t(PyArray_VectorUnaryFunc*)@from@_to_ULONGLONG, \n\t\t(PyArray_VectorUnaryFunc*)@from@_to_FLOAT, \n\t\t(PyArray_VectorUnaryFunc*)@from@_to_DOUBLE, \n\t\t(PyArray_VectorUnaryFunc*)@from@_to_LONGDOUBLE, \n\t\t(PyArray_VectorUnaryFunc*)@from@_to_CFLOAT, \n\t\t(PyArray_VectorUnaryFunc*)@from@_to_CDOUBLE, \n\t\t(PyArray_VectorUnaryFunc*)@from@_to_CLONGDOUBLE, \n\t\t(PyArray_VectorUnaryFunc*)@from@_to_OBJECT, \n\t\t(PyArray_VectorUnaryFunc*)@from@_to_STRING, \n\t\t(PyArray_VectorUnaryFunc*)@from@_to_UNICODE, \n\t\t(PyArray_VectorUnaryFunc*)@from@_to_VOID\n\t},\n\t(PyArray_GetItemFunc*)@from@_getitem, \n\t(PyArray_SetItemFunc*)@from@_setitem,\n\t(PyArray_CopySwapNFunc*)@from@_copyswapn,\n\t(PyArray_CopySwapFunc*)@from@_copyswap,\n\t(PyArray_CompareFunc*)@from@_compare, \n\t(PyArray_ArgFunc*)@from@_argmax,\n\t(PyArray_DotFunc*)@from@_dot, \n\t(PyArray_ScanFunc*)@from@_scan,\n\t(PyArray_FromStrFunc*)@from@_fromstr,\n\t(PyArray_NonzeroFunc*)@from@_nonzero,\n\t(PyArray_FillFunc*)@from@_fill,\n\t{\n\t\tNULL, NULL, NULL, NULL\n\t},\n\t{\n\t\tNULL, NULL, NULL, NULL\n\t}\n};\n\nstatic PyArray_Descr @from@_Descr = { \n\tPyObject_HEAD_INIT(&PyArrayDescr_Type)\n\t&Py@NAME@ArrType_Type,\n\tPyArray_@kind@LTR,\n\tPyArray_@from@LTR,\n\t'@endian@', @isobject@,\n\tPyArray_@from@, \n\t@num@*sizeof(@fromtyp@), \n\t_ALIGN(@fromtyp@),\n\tNULL,\n\tNULL,\n\t&_Py@NAME@_ArrFuncs,\n};\n\n/**end repeat**/\n\n#define _MAX_LETTER 128\nstatic char _letter_to_num[_MAX_LETTER];\n\nstatic PyArray_Descr *_builtin_descrs[] = {\n\t&BOOL_Descr,\n\t&BYTE_Descr,\n\t&UBYTE_Descr,\n\t&SHORT_Descr, \n\t&USHORT_Descr, \n\t&INT_Descr, \n\t&UINT_Descr, \n\t&LONG_Descr, \n\t&ULONG_Descr,\n\t&LONGLONG_Descr,\n\t&ULONGLONG_Descr,\n\t&FLOAT_Descr, \n\t&DOUBLE_Descr,\n\t&LONGDOUBLE_Descr,\n\t&CFLOAT_Descr, \n\t&CDOUBLE_Descr, \n\t&CLONGDOUBLE_Descr,\n\t&OBJECT_Descr, \n\t&STRING_Descr, \n\t&UNICODE_Descr,\n\t&VOID_Descr,\n};\n\n/*OBJECT_API\n Get the PyArray_Descr structure for a type.\n*/\nstatic PyArray_Descr *\nPyArray_DescrFromType(int type)\n{\n\tPyArray_Descr *ret=NULL;\n\n\tif (type < PyArray_NTYPES) {\n\t\tret = _builtin_descrs[type];\n\t}\n\telse if (type == PyArray_NOTYPE) {\n\t\t/* This needs to not raise an error so\n\t\t that PyArray_DescrFromType(PyArray_NOTYPE)\n\t\t works for backwards-compatible C-API \n\t\t*/\t\t\n\t\treturn NULL;\n\t}\n\telse if PyTypeNum_ISUSERDEF(type) {\n\t\tret = userdescrs[type-PyArray_USERDEF];\n\t} \n\telse {\n\t\tint num=PyArray_NTYPES;\n\t\tif (type < _MAX_LETTER) \n\t\t\tnum = (int) _letter_to_num[type];\n\t\tif (num >= PyArray_NTYPES)\n\t\t\tret = NULL;\n\t\telse\n\t\t\tret = _builtin_descrs[num];\n\t}\n\tif (ret==NULL) {\n\t\tPyErr_SetString(PyExc_ValueError, \n\t\t\t\t\"Invalid data-type for array\"); \n\t}\n\telse Py_INCREF(ret);\n\treturn ret;\n}\n\n\nstatic int\nset_typeinfo(PyObject *dict)\n{\n\tPyObject *infodict, *s;\n\tint i;\n\n\tfor (i=0; i<_MAX_LETTER; i++) {\n\t\t_letter_to_num[i] = PyArray_NTYPES;\n\t}\n\n/**begin repeat\n#name=BOOL,BYTE,UBYTE,SHORT,USHORT,INT,UINT,INTP,UINTP,LONG,ULONG,LONGLONG,ULONGLONG,FLOAT,DOUBLE,LONGDOUBLE,CFLOAT,CDOUBLE,CLONGDOUBLE,OBJECT,STRING,UNICODE,VOID#\n*/\n\t_letter_to_num[PyArray_@name@LTR] = PyArray_@name@;\n/**end repeat**/\n\t_letter_to_num[PyArray_STRINGLTR2] = PyArray_STRING;\n\n/**begin repeat\n#name=BOOL,BYTE,UBYTE,SHORT,USHORT,INT,UINT,LONG,ULONG,LONGLONG,ULONGLONG,FLOAT,DOUBLE,LONGDOUBLE,CFLOAT,CDOUBLE,CLONGDOUBLE,OBJECT,STRING,UNICODE,VOID#\n*/\n\t@name@_Descr.fields = Py_None;\n/**end repeat**/\n\t\n\t/* Set a dictionary with type information */\n\tinfodict = PyDict_New();\n\tif (infodict == NULL) return -1;\n\n#define BITSOF_INTP CHAR_BIT*SIZEOF_PY_INTPTR_T\n#define BITSOF_BYTE CHAR_BIT\n\n/**begin repeat \n\n#name=BOOL,BYTE,UBYTE,SHORT,USHORT,INT,UINT,INTP,UINTP,LONG,ULONG,LONGLONG,ULONGLONG#\n#uname=BOOL,BYTE*2,SHORT*2,INT*2,INTP*2,LONG*2,LONGLONG*2#\n#Name=Bool,Byte,UByte,Short,UShort,Int,UInt,Intp,UIntp,Long,ULong,LongLong,ULongLong#\n#type=Bool,byte,ubyte,short,ushort,int,uint,intp,uintp,long,ulong,longlong,ulonglong#\n#max=1,MAX_BYTE,MAX_UBYTE,MAX_SHORT,MAX_USHORT,MAX_INT,PyLong_FromUnsignedLong(MAX_UINT),PyLong_FromLongLong((longlong) MAX_INTP),PyLong_FromUnsignedLongLong((ulonglong) MAX_UINTP),MAX_LONG,PyLong_FromUnsignedLong((unsigned long) MAX_ULONG),PyLong_FromLongLong((longlong) MAX_LONGLONG), PyLong_FromUnsignedLongLong((ulonglong) MAX_ULONGLONG)#\n#min=0,MIN_BYTE,0,MIN_SHORT,0,MIN_INT,0,PyLong_FromLongLong((longlong) MIN_INTP),0,MIN_LONG,0,PyLong_FromLongLong((longlong) MIN_LONGLONG),0#\n#cx=i*6,N,N,N,l,N,N,N#\n#cn=i*7,N,i,l,i,N,i#\n*/\n \tPyDict_SetItemString(infodict, \"@name@\", \n\t\t\t s=Py_BuildValue(\"ciii@cx@@cn@O\", \n\t\t\t\t\t PyArray_@name@LTR, \n\t\t\t\t\t PyArray_@name@,\n\t\t\t\t\t BITSOF_@uname@,\n\t\t\t\t\t _ALIGN(@type@),\n\t\t\t\t\t @max@, @min@,\n\t\t\t\t (PyObject *)&Py@Name@ArrType_Type));\n\tPy_DECREF(s); \n/**end repeat**/\n\n#define BITSOF_CFLOAT 2*BITSOF_FLOAT\n#define BITSOF_CDOUBLE 2*BITSOF_DOUBLE\n#define BITSOF_CLONGDOUBLE 2*BITSOF_LONGDOUBLE\n\n/**begin repeat\n\n#type=float,double,longdouble,cfloat,cdouble,clongdouble#\n#name=FLOAT, DOUBLE, LONGDOUBLE, CFLOAT, CDOUBLE, CLONGDOUBLE#\n#Name=Float,Double,LongDouble,CFloat,CDouble,CLongDouble#\n*/\n \tPyDict_SetItemString(infodict, \"@name@\", \n\t\t\t s=Py_BuildValue(\"ciiiO\", PyArray_@name@LTR, \n\t\t\t\t\t PyArray_@name@, BITSOF_@name@,\n\t\t\t\t\t _ALIGN(@type@),\n (PyObject *)\\\n &Py@Name@ArrType_Type));\n\tPy_DECREF(s);\n/**end repeat**/\n\t\n\tPyDict_SetItemString(infodict, \"OBJECT\", \n\t\t\t s=Py_BuildValue(\"ciiiO\", PyArray_OBJECTLTR, \n\t\t\t\t\t PyArray_OBJECT, \n\t\t\t\t\t sizeof(PyObject *)*CHAR_BIT,\n\t\t\t\t\t _ALIGN(PyObject *),\n (PyObject *)\\\n &PyObjectArrType_Type));\n\tPy_DECREF(s);\n\tPyDict_SetItemString(infodict, \"STRING\", \n\t\t\t s=Py_BuildValue(\"ciiiO\", PyArray_STRINGLTR, \n\t\t\t\t\t PyArray_STRING, 0,\n\t\t\t\t\t _ALIGN(char),\n (PyObject *)\\\n &PyStringArrType_Type));\n\tPy_DECREF(s);\n\tPyDict_SetItemString(infodict, \"UNICODE\", \n\t\t\t s=Py_BuildValue(\"ciiiO\", PyArray_UNICODELTR, \n\t\t\t\t\t PyArray_UNICODE, 0,\n\t\t\t\t\t _ALIGN(PyArray_UCS4),\n (PyObject *)\\\n &PyUnicodeArrType_Type));\t\n\tPy_DECREF(s);\n\tPyDict_SetItemString(infodict, \"VOID\", \n\t\t\t s=Py_BuildValue(\"ciiiO\", PyArray_VOIDLTR, \n\t\t\t\t\t PyArray_VOID, 0,\n\t\t\t\t\t _ALIGN(char),\n (PyObject *)\\\n &PyVoidArrType_Type));\t\n\tPy_DECREF(s);\n\n#define SETTYPE(name) \\\n Py_INCREF(&Py##name##ArrType_Type); \\\n PyDict_SetItemString(infodict, #name, \\\n (PyObject *)&Py##name##ArrType_Type);\n\n SETTYPE(Generic)\n SETTYPE(Number)\n SETTYPE(Integer)\n\tSETTYPE(Inexact)\n SETTYPE(SignedInteger)\n SETTYPE(UnsignedInteger)\n SETTYPE(Floating)\n SETTYPE(ComplexFloating)\n SETTYPE(Flexible)\n SETTYPE(Character)\n\n#undef SETTYPE \t\n\n\tPyDict_SetItemString(dict, \"typeinfo\", infodict);\n\tPy_DECREF(infodict);\n\treturn 0;\n}\n\n#undef _MAX_LETTER\n\n", + "source_code_before": "/* -*- c -*- */\n\n/**begin repeat\n#name=UnsignedLong,UnsignedLongLong,LongLong#\n#type=ulong,ulonglong,longlong#\n */\nstatic @type@\nMyPyLong_As@name@(PyObject *vv)\n{\n\t@type@ ret;\n\n\tif (!PyLong_Check(vv)) {\n\t\tPyObject *mylong;\n\t\tmylong = PyNumber_Long(vv);\n\t\tif (mylong == NULL) return (@type@) -1;\n\t\tvv = mylong;\n\t}\n\telse Py_INCREF(vv);\n\n\tret = PyLong_As@name@(vv);\n\tPy_DECREF(vv);\n\treturn ret;\n}\n/**end repeat**/\n\n\nstatic double \n_getNAN(void) {\n#ifdef NAN\n return NAN;\n#else\n static double nan=0;\n \n if (nan == 0) {\n\t\tdouble mul = 1e100;\n\t\tdouble tmp = 0.0;\n\t\tdouble pinf=0;\n pinf = mul;\n for (;;) {\n pinf *= mul;\n if (pinf == tmp) break;\n tmp = pinf;\n }\n nan = pinf / pinf;\n }\n return nan;\n#endif\n}\n\nstatic double\nMyPyFloat_AsDouble(PyObject *obj)\n{\n if (obj == Py_None) return _getNAN();\n return PyFloat_AsDouble(obj); \n}\n\n\n/****************** getitem and setitem **********************/\n\n/**begin repeat\n\n#TYP=BOOL,BYTE,UBYTE,SHORT,USHORT,INT,LONG,UINT,ULONG,LONGLONG,ULONGLONG,FLOAT,DOUBLE#\n#func1=PyBool_FromLong, PyInt_FromLong*6, PyLong_FromUnsignedLong*2, PyLong_FromLongLong, PyLong_FromUnsignedLongLong, PyFloat_FromDouble*2#\n#func2=PyObject_IsTrue, PyInt_AsLong*6, MyPyLong_AsUnsignedLong*2, MyPyLong_AsLongLong, MyPyLong_AsUnsignedLongLong, MyPyFloat_AsDouble*2#\n#typ=Bool, byte, ubyte, short, ushort, int, long, uint, ulong, longlong, ulonglong, float, double#\n#typ1=long*7, ulong*2, longlong, ulonglong, float, double#\n#kind=Bool, Byte, UByte, Short, UShort, Int, Long, UInt, ULong, LongLong, ULongLong, Float, Double#\n*/\n\nstatic PyObject * \n@TYP@_getitem(char *ip, PyArrayObject *ap) {\n @typ@ t1;\n\n\tif ((ap==NULL) || PyArray_ISBEHAVED_RO(ap)) {\n t1 = *((@typ@ *)ip);\n return @func1@((@typ1@)t1);\n\t}\n\telse {\n ap->descr->f->copyswap(&t1, ip, !PyArray_ISNOTSWAPPED(ap),\n\t\t\t\t ap->descr->elsize);\n return @func1@((@typ1@)t1);\n\t}\n}\n\nstatic int \n@TYP@_setitem(PyObject *op, char *ov, PyArrayObject *ap) {\n @typ@ temp; /* ensures alignment */\n\n if (PyArray_IsScalar(op, @kind@)) {\n temp = ((Py@kind@ScalarObject *)op)->obval;\n }\n else {\n temp = (@typ@)@func2@(op);\n }\n if (PyErr_Occurred()) return -1;\n if (ap == NULL || PyArray_ISBEHAVED(ap)) \n *((@typ@ *)ov)=temp;\n else {\n ap->descr->f->copyswap(ov, &temp, !PyArray_ISNOTSWAPPED(ap), \n\t\t\t\t ap->descr->elsize);\n }\n \n return 0;\n}\n\n/**end repeat**/\n\n\n/**begin repeat \n\n#TYP=CFLOAT,CDOUBLE#\n#typ=float, double#\n*/\n\nstatic PyObject * \n@TYP@_getitem(char *ip, PyArrayObject *ap) {\n @typ@ t1, t2;\n\n if ((ap==NULL) || PyArray_ISBEHAVED_RO(ap)) { \n return PyComplex_FromDoubles((double)((@typ@ *)ip)[0], \n (double)((@typ@ *)ip)[1]);\n }\n else {\n\t\tint size = sizeof(@typ@);\n\t\tBool swap = !PyArray_ISNOTSWAPPED(ap);\n copy_and_swap(&t1, ip, size, 1, 0, swap);\n copy_and_swap(&t2, ip+size, size, 1, 0, swap);\n return PyComplex_FromDoubles((double)t1, (double)t2);\n }\n}\n/**end repeat**/\n\n/**begin repeat \n\n#TYP=CFLOAT, CDOUBLE, CLONGDOUBLE#\n#typ=float, double, longdouble#\n#kind=CFloat, CDouble, CLongDouble#\n*/\nstatic int \n@TYP@_setitem(PyObject *op, char *ov, PyArrayObject *ap) \n{\n Py_complex oop;\n PyObject *op2;\n c@typ@ temp;\n\tint rsize;\n \n if (!(PyArray_IsScalar(op, @kind@))) {\n if (PyArray_Check(op) && (PyArray_NDIM(op)==0)) {\n op2 = ((PyArrayObject *)op)->descr->f->getitem \\\n (((PyArrayObject *)op)->data, \n (PyArrayObject *)op);\n\t\t}\n\t\telse { \n op2 = op; Py_INCREF(op);\n }\n if (op2 == Py_None) {\n oop.real = oop.imag = _getNAN();\n }\n else {\n oop = PyComplex_AsCComplex (op2);\n }\n Py_DECREF(op2);\n if (PyErr_Occurred()) return -1;\n temp.real = (@typ@) oop.real;\n temp.imag = (@typ@) oop.imag; \n }\n\telse {\n temp = ((Py@kind@ScalarObject *)op)->obval;\n }\n\t\n memcpy(ov, &temp, ap->descr->elsize);\n if (!PyArray_ISNOTSWAPPED(ap))\n byte_swap_vector(ov, 2, sizeof(@typ@));\n\t\n\trsize = sizeof(@typ@);\n\tcopy_and_swap(ov, &temp, rsize, 2, rsize, !PyArray_ISNOTSWAPPED(ap));\n return 0;\n}\n/**end repeat**/\n\nstatic PyObject * \nLONGDOUBLE_getitem(char *ip, PyArrayObject *ap) \n{\n return PyArray_Scalar(ip, ap->descr, NULL);\n}\n\nstatic int \nLONGDOUBLE_setitem(PyObject *op, char *ov, PyArrayObject *ap) {\n longdouble temp; /* ensures alignment */\n\n if (PyArray_IsScalar(op, LongDouble)) {\n temp = ((PyLongDoubleScalarObject *)op)->obval;\n }\n else {\n if (op == Py_None) temp = (longdouble)_getNAN();\n else temp = (longdouble)PyFloat_AsDouble(op);\n }\n if (PyErr_Occurred()) return -1;\n if (ap == NULL || PyArray_ISBEHAVED(ap)) \n *((longdouble *)ov)=temp;\n else {\n copy_and_swap(ov, &temp, ap->descr->elsize, 1, 0,\n !PyArray_ISNOTSWAPPED(ap));\n }\n \n return 0;\n}\n\nstatic PyObject * \nCLONGDOUBLE_getitem(char *ip, PyArrayObject *ap) \n{\n return PyArray_Scalar(ip, ap->descr, NULL);\n}\n\n\n/* UNICODE */\nstatic PyObject * \nUNICODE_getitem(char *ip, PyArrayObject *ap) \n{\n\tPyObject *obj;\n\tint mysize;\n\tPyArray_UCS4 *dptr;\n\n\tmysize = ap->descr->elsize >> 2;\n\tdptr = (PyArray_UCS4 *)ip + mysize-1;\n\twhile(mysize > 0 && *dptr-- == 0) mysize--;\n\tif (!PyArray_ISNOTSWAPPED(ap) && (obj != NULL)) {\n\t\tbyte_swap_vector(PyArray_BYTES(ap), mysize, 4);\n\t}\n#ifdef Py_UNICODE_WIDE\n\tobj = PyUnicode_FromUnicode((const PyArray_UCS4 *)ip, mysize);\n#else\n\t/* create new empty unicode object of length mysize*2 */\n\tobj = MyPyUnicode_New(mysize*2);\n\tif (obj == NULL) return obj;\n\tmysize = PyUCS2Buffer_FromUCS4(((PyUnicodeObject *)obj)->str, \n\t\t\t\t (PyArray_UCS4 *)ip, mysize);\n\t/* reset length of unicode object to ucs2size */\n\tif (MyPyUnicode_Resize((PyUnicodeObject *)obj, mysize) < 0) {\n\t\tPy_DECREF(obj);\n\t\treturn NULL;\n\t}\n#endif\n\n\treturn obj;\n}\n\nstatic int \nUNICODE_setitem(PyObject *op, char *ov, PyArrayObject *ap) \n{\n PyObject *temp;\n\tPy_UNICODE *ptr;\n\tint datalen;\n\n\tif ((temp=PyObject_Unicode(op)) == NULL) return -1;\n\tptr = PyUnicode_AS_UNICODE(temp);\n\tif ((ptr == NULL) || (PyErr_Occurred())) {\n\t\tPy_DECREF(temp);\n\t\treturn -1;\n\t}\n\tdatalen = PyUnicode_GET_DATA_SIZE(temp);\n\n#ifdef Py_UNICODE_WIDE\n\tmemcpy(ov, ptr, MIN(ap->descr->elsize, datalen));\n#else\n datalen = PyUCS2Buffer_AsUCS4(ptr, (PyArray_UCS4 *)ov, datalen >> 1,\n\t\t\t\t ap->descr->elsize >> 2);\n\tdatalen <<= 2;\n#endif\n\t/* Fill in the rest of the space with 0 */\n\tif (ap->descr->elsize > datalen) {\n\t\tmemset(ov + datalen, 0, (ap->descr->elsize - datalen));\n\t}\n\t\n\tif (!PyArray_ISNOTSWAPPED(ap)) \n\t\tbyte_swap_vector(ov, ap->descr->elsize >> 2, 4);\n\tPy_DECREF(temp);\n\treturn 0;\n}\n\n/* STRING -- can handle both NULL-terminated and not NULL-terminated cases */\nstatic PyObject * \nSTRING_getitem(char *ip, PyArrayObject *ap) \n{\n\tif (ip[ap->descr->elsize-1])\n\t\treturn PyString_FromStringAndSize(ip,ap->descr->elsize);\n\telse\n\t\treturn PyString_FromString(ip);\n}\n\nstatic int \nSTRING_setitem(PyObject *op, char *ov, PyArrayObject *ap) \n{\n\tchar *ptr;\n\tint len;\n\tPyObject *temp=PyObject_Str(op);\n\t\n\tif (temp == NULL) return -1;\n\t\n\tif (PyString_AsStringAndSize(temp, &ptr, &len) == -1) {\n\t\tPy_DECREF(temp);\n\t\treturn -1;\n\t}\n\tmemcpy(ov, ptr, MIN(ap->descr->elsize,len));\n\tif (ap->descr->elsize > len) {\n\t\tmemset(ov + len, 0, (ap->descr->elsize - len));\n\t}\n\tPy_DECREF(temp);\n\treturn 0;\n}\n\n/* OBJECT */\n\nstatic PyObject * \nOBJECT_getitem(char *ip, PyArrayObject *ap) \n{\n\tPy_INCREF(*(PyObject **)ip);\n\treturn *(PyObject **)ip;\n}\n\nstatic int \nOBJECT_setitem(PyObject *op, char *ov, PyArrayObject *ap) \n{\n\tPy_XDECREF(*(PyObject **)ov);\n\tPy_INCREF(op);\n\t*(PyObject **)ov = op;\n\treturn PyErr_Occurred() ? -1:0;\n}\n\n/* VOID */\n\nstatic PyObject *\nVOID_getitem(char *ip, PyArrayObject *ap)\n{\n PyObject *u=NULL;\n\tPyArray_Descr* descr;\n int itemsize;\n\n\tdescr = ap->descr;\n\tif (descr->fields && descr->fields != Py_None) {\n\t\tPyObject *key;\n\t\tPyObject *names;\n\t\tint i, n;\n\t\tPyObject *ret;\n\t\tPyObject *tup, *title;\n\t\tPyArray_Descr *new;\n\t\tint offset;\n\t\tint savedflags;\n\n\t\t/* get the names from the fields dictionary*/\n\t\tkey = PyInt_FromLong(-1);\n\t\tnames = PyDict_GetItem(descr->fields, key);\n\t\tPy_DECREF(key);\n\t\tif (!names) goto finish;\n\t\tn = PyList_GET_SIZE(names);\n\t\tret = PyTuple_New(n);\n\t\tsavedflags = ap->flags;\n\t\tfor (i=0; ifields, key);\n\t\t\tif (!PyArg_ParseTuple(tup, \"Oi|O\", &new, &offset, \n\t\t\t\t\t &title)) {\n\t\t\t\tPy_DECREF(ret); \n\t\t\t\tap->descr = descr;\n\t\t\t\treturn NULL;\n\t\t\t}\n\t\t\tap->descr = new;\n\t\t\t/* update alignment based on offset */\n\t\t\tif ((new->alignment > 1) &&\t\t\t\\\n\t\t\t ((((intp)(ip+offset)) % new->alignment) != 0))\n\t\t\t\tap->flags &= ~ALIGNED;\n\t\t\telse\n\t\t\t\tap->flags |= ALIGNED;\n\n\t\t\tPyTuple_SET_ITEM(ret, i,\t\t\t\\\n\t\t\t\t\t new->f->getitem(ip+offset, ap));\n\t\t\tap->flags = savedflags;\n\t\t}\n\t\tap->descr = descr;\n\t\treturn ret;\n\t}\n\n\tif (descr->subarray) {\n\t\t/* return an array of the basic type */\n\t\tPyArray_Dims shape={NULL,-1};\n\t\tPyObject *ret;\n\t\tif (!(PyArray_IntpConverter(descr->subarray->shape, \n\t\t\t\t\t &shape))) {\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\treturn NULL;\n\t\t}\n Py_INCREF(descr->subarray->base);\n\t\tret = PyArray_NewFromDescr(&PyArray_Type,\n\t\t\t\t\t descr->subarray->base,\n\t\t\t\t\t shape.len, shape.ptr,\n\t\t\t\t\t NULL, ip, ap->flags, NULL);\n\t\tPyDimMem_FREE(shape.ptr);\n\t\tif (!ret) return NULL;\n\t\tPyArray_BASE(ret) = (PyObject *)ap;\n\t\tPy_INCREF(ap);\n\t\tPyArray_UpdateFlags((PyArrayObject *)ret, UPDATE_ALL_FLAGS);\n\t\treturn ret;\n\t}\n\n finish:\n\titemsize=ap->descr->elsize;\n\tif (PyArray_ISWRITEABLE(ap))\n\t\tu = PyBuffer_FromReadWriteMemory(ip, itemsize);\n\telse\n\t\tu = PyBuffer_FromMemory(ip, itemsize);\n\tif (u==NULL) goto fail;\n\n\t/* default is to return buffer object pointing to current item */\n\t/* a view of it */\n\treturn u; \n\t\n fail:\n return NULL;\n}\n\n\n\nstatic int PyArray_CopyObject(PyArrayObject *, PyObject *);\n\nstatic int\nVOID_setitem(PyObject *op, char *ip, PyArrayObject *ap)\n{\n\tPyArray_Descr* descr;\n int itemsize=ap->descr->elsize;\n\tint res;\n\n\tdescr = ap->descr;\n\tif (descr->fields && (descr->fields != Py_None) && \\\n\t PyTuple_Check(op)) {\n\t\tPyObject *key;\n\t\tPyObject *names;\n\t\tint i, n;\n\t\tPyObject *tup, *title;\n\t\tPyArray_Descr *new;\n\t\tint offset;\n\t\tint savedflags;\n\t\tres = -1;\n\t\t/* get the names from the fields dictionary*/\n\t\tkey = PyInt_FromLong(-1);\n\t\tnames = PyDict_GetItem(descr->fields, key);\n\t\tPy_DECREF(key);\n\t\tif (!names) goto finish;\n\t\tn = PyList_GET_SIZE(names);\n\t\tif (PyTuple_GET_SIZE(op) != n) {\n\t\t\tPyErr_SetString(PyExc_ValueError, \n\t\t\t\t\t\"size of tuple must match\"\\\n\t\t\t\t\t\"number of fields.\");\n\t\t\treturn -1;\n\t\t}\n\t\tsavedflags = ap->flags;\n\t\tfor (i=0; ifields, key);\n\t\t\tif (!PyArg_ParseTuple(tup, \"Oi|O\", &new, &offset, \n\t\t\t\t\t &title)) {\n\t\t\t\tap->descr = descr;\n\t\t\t\treturn -1;\n\t\t\t}\n\t\t\tap->descr = new;\n\t\t\t/* remember to update alignment flags */\n\t\t\tif ((new->alignment > 1) &&\t\t\t\\\n\t\t\t ((((intp)(ip+offset)) % new->alignment) != 0))\n\t\t\t\tap->flags &= ~ALIGNED;\n\t\t\telse\n\t\t\t\tap->flags |= ALIGNED;\n\n\t\t\tres = new->f->setitem(PyTuple_GET_ITEM(op, i),\n\t\t\t\t\t ip+offset, ap);\n\t\t\tap->flags = savedflags;\n\t\t\tif (res < 0) break;\n\t\t}\n\t\tap->descr = descr;\n\t\treturn res;\n\t}\n\n\tif (descr->subarray) {\n\t\t/* copy into an array of the same basic type */\n\t\tPyArray_Dims shape={NULL,-1};\n\t\tPyObject *ret;\n\t\tif (!(PyArray_IntpConverter(descr->subarray->shape, \n\t\t\t\t\t &shape))) {\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\treturn -1;\n\t\t}\n Py_INCREF(descr->subarray->base);\n\t\tret = PyArray_NewFromDescr(&PyArray_Type,\n\t\t\t\t\t descr->subarray->base,\n\t\t\t\t\t shape.len, shape.ptr,\n\t\t\t\t\t NULL, ip, ap->flags, NULL);\n\t\tPyDimMem_FREE(shape.ptr);\n\t\tif (!ret) return -1;\n\t\tPyArray_BASE(ret) = (PyObject *)ap;\n\t\tPy_INCREF(ap);\n\t\tPyArray_UpdateFlags((PyArrayObject *)ret, UPDATE_ALL_FLAGS);\n\t\tres = PyArray_CopyObject((PyArrayObject *)ret, op);\n\t\tPy_DECREF(ret);\n\t\treturn res;\n\t}\n\n finish:\n\t/* Default is to use buffer interface to set item */\n\t{\n\t\tconst void *buffer;\n\t\tint buflen;\n\t\tres = PyObject_AsReadBuffer(op, &buffer, &buflen);\n\t\tif (res == -1) goto fail;\n\t\tmemcpy(ip, buffer, MIN(buflen, itemsize));\n }\n\treturn 0;\n\n fail:\n return -1; \n}\n\n\n/****************** XXX_to_YYY *******************************/ \n\n/* Assumes contiguous, and aligned, from and to */\n\n\n/**begin repeat\n#to=(BYTE,UBYTE,SHORT,USHORT,INT,UINT,LONG,ULONG,LONGLONG,ULONGLONG,FLOAT,DOUBLE,LONGDOUBLE)*16#\n#from=BYTE*13,UBYTE*13,SHORT*13,USHORT*13,INT*13,UINT*13,LONG*13,ULONG*13,LONGLONG*13,ULONGLONG*13,FLOAT*13,DOUBLE*13,LONGDOUBLE*13,CFLOAT*13,CDOUBLE*13,CLONGDOUBLE*13#\n#totyp=(byte, ubyte, short, ushort, int, uint, long, ulong, longlong, ulonglong, float, double, longdouble)*16#\n#fromtyp=byte*13, ubyte*13, short*13, ushort*13, int*13, uint*13, long*13, ulong*13, longlong*13, ulonglong*13, float*13, double*13, longdouble*13, float*13, double*13, longdouble*13#\n#incr= ip++*169,ip+=2*39#\n*/\nstatic void \n@from@_to_@to@(@fromtyp@ *ip, @totyp@ *op, intp n, PyArrayObject *aip, \n\t PyArrayObject *aop) {\n\tregister intp i; \n\tfor(i=0;idescr->elsize*3, 1#\n*/\nstatic void \n@from@_to_OBJECT(@fromtyp@ *ip, PyObject **op, intp n, PyArrayObject *aip,\n\t\t PyArrayObject *aop)\n{\n\tregister intp i; \n\tint skip=@skip@;\n\tfor(i=0;idescr->elsize*3#\n*/\nstatic void \nOBJECT_to_@to@(PyObject **ip, @totyp@ *op, intp n, PyArrayObject *aip,\n\t\t PyArrayObject *aop)\n{\n\tregister intp i; \n\tint skip=@skip@;\n\tfor(i=0;idescr->elsize*3)*3#\n#convert=1*17,0*3,1*17,0*3,0*20#\n#convstr=(Int*9,Long*2,Float*3,Complex*3,Tuple*3)*3#\n*/\nstatic void\n@from@_to_@to@(@fromtyp@ *ip, @totyp@ *op, intp n, PyArrayObject *aip, \n\t PyArrayObject *aop)\n{\n\tregister intp i;\n\tPyObject *temp=NULL;\n\tint skip=aip->descr->elsize;\n\tint oskip=@oskip@;\n\tfor(i=0; idescr->elsize;\n\tfor(i=0; i= 0x02040000) || defined(PyOS_ascii_strtod)\nstatic int\n@fname@_fromstr(char *str, @type@ *ip, char **endptr, void *ignore)\n{\n\tdouble result;\n\n\tresult = PyOS_ascii_strtod(str, endptr);\n\t*ip = (@type@) result;\n\treturn 0;\n}\n#else\n#define @fname@_fromstr NULL\n#endif\n/**end repeat**/\n\n\n\n/**begin repeat\n#fname=BOOL,CFLOAT,CDOUBLE,CLONGDOUBLE,OBJECT,STRING,UNICODE,VOID#\n*/\n#define @fname@_fromstr NULL\n/**end repeat**/\n\n\n/****************** copyswapn *************************************/\n\n/**begin repeat\n\n#fname=SHORT,USHORT,INT,UINT,LONG,ULONG,LONGLONG,ULONGLONG,FLOAT,DOUBLE,LONGDOUBLE#\n#fsize=SHORT,SHORT,INT,INT,LONG,LONG,LONGLONG,LONGLONG,FLOAT,DOUBLE,LONGDOUBLE#\n#type=short,ushort,int,uint,long,ulong,longlong,ulonglong,float,double,longdouble#\n*/\nstatic void\n@fname@_copyswapn (void *dst, void *src, intp n, int swap, int itemsize)\n{\n\tif (src != NULL) /* copy first if needed */\n\t\tmemcpy(dst, src, n*sizeof(@type@));\n\n\tif (swap) {\n\t\tregister char *a, *b, c;\n\t\tfor (a = (char *)dst; n>0; n--) {\n#if SIZEOF_@fsize@ == 2\n\t\t\tb = a + 1;\n\t\t\tc = *a; *a++ = *b; *b = c;\n\t\t\ta += 1;\n#elif SIZEOF_@fsize@ == 4\n\t\t\tb = a + 3;\n c = *a; *a++ = *b; *b-- = c;\n c = *a; *a++ = *b; *b = c;\n\t\t\ta += 2;\n#elif SIZEOF_@fsize@ == 8\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\t\t\ta += 4;\n#elif SIZEOF_@fsize@ == 10\n b = a + 9;\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 c = *a; *a++ = *b; *b = c;\n\t\t\ta += 5;\n#elif SIZEOF_@fsize@ == 12\n b = a + 11;\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 c = *a; *a++ = *b; *b-- = c;\n c = *a; *a++ = *b; *b = c;\n\t\t\ta += 6;\n#elif SIZEOF_@fsize@ == 16\n b = a + 15;\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 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\t\t\ta += 8;\n#else\n\t\t\tregister int i, nn;\n b = a + (SIZEOF_@fsize@-1);\n\t\t\tnn = SIZEOF_@fsize@ / 2;\n for (i=0; i0; nn--) {\n#if SIZEOF_@fsize@ == 4\n\t\t\tb = a + 3;\n c = *a; *a++ = *b; *b-- = c;\n c = *a; *a++ = *b; *b = c;\n\t\t\ta += 2;\n#elif SIZEOF_@fsize@ == 8\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\t\t\ta += 4;\n#elif SIZEOF_@fsize@ == 10\n b = a + 9;\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 c = *a; *a++ = *b; *b = c;\n\t\t\ta += 5;\n#elif SIZEOF_@fsize@ == 12\n b = a + 11;\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 c = *a; *a++ = *b; *b-- = c;\n c = *a; *a++ = *b; *b = c;\n\t\t\ta += 6;\n#elif SIZEOF_@fsize@ == 16\n b = a + 15;\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 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\t\t\ta += 8;\n#else\n\t\t\tregister int i, kn;\n\n b = a + (SIZEOF_@fsize@-1);\n\t\t\tkn = SIZEOF_@fsize@ / 2;\n for (i=0; i0; n--) {\n\t\t\tb = a + 3;\n\t\t\tc=*a; *a++ = *b; *b-- = c;\n\t\t\tc=*a; *a++ = *b; *b-- = c;\n\t\t\ta += 1;\n\t\t}\n\t}\n}\n\n\nstatic void\nOBJECT_copyswap (PyObject **dst, PyObject **src, int swap, int itemsize)\n{\n OBJECT_copyswapn(dst, src, 1, swap, itemsize);\n}\n\nstatic void\nSTRING_copyswap (char *dst, char *src, int swap, int itemsize)\n{\n\tif (src != NULL) \n\t\tmemcpy(dst, src, itemsize);\n\t\n}\n\n/* ignore swap */\nstatic void\nVOID_copyswap (char *dst, char *src, int swap, int itemsize)\n{\n\tif (src != NULL) \n\t\tmemcpy(dst, src, itemsize);\t\n\treturn;\n}\n\nstatic void\nUNICODE_copyswap (char *dst, char *src, int swap, int itemsize)\n{\n\n\tif (src != NULL) \n\t\tmemcpy(dst, src, itemsize);\n\t\n\tif (swap) {\n\t\tregister char *a, *b, c;\n a = (char *)dst;\n b = a + 3;\n\t\tc=*a; *a++ = *b; *b-- = c;\n\t\tc=*a; *a++ = *b; *b-- = c;\n\t}\n}\n\n\n/****************** nonzero **********************************/\n\n/**begin repeat\n#fname=BOOL,BYTE,UBYTE,SHORT,USHORT,INT,UINT,LONG,ULONG,LONGLONG,ULONGLONG,FLOAT,DOUBLE,LONGDOUBLE#\n#type=Bool, byte, ubyte, short, ushort, int, uint, long, ulong, longlong, ulonglong, float, double, longdouble#\n*/\nstatic Bool \n@fname@_nonzero (@type@ *ip, PyArrayObject *ap)\n{\n\t@type@ t1;\n\tif (ap==NULL || PyArray_ISBEHAVED_RO(ap))\n\t\treturn (Bool) (*ip != 0);\n\telse {\n\t\t/* don't worry about swap, since we are just testing\n\t\t whether or not equal to 0 */\n\t\tmemcpy(&t1, ip, sizeof(@type@));\n\t\treturn (Bool) (t1 != 0);\n\t}\n}\n/**end repeat**/\n\n/**begin repeat\n#fname=CFLOAT,CDOUBLE,CLONGDOUBLE#\n#type=cfloat, cdouble, clongdouble#\n*/\nstatic Bool \n@fname@_nonzero (@type@ *ip, PyArrayObject *ap)\n{\n\t@type@ t1;\n\tif (ap==NULL || PyArray_ISBEHAVED_RO(ap))\n\t\treturn (Bool) ((ip->real != 0) || (ip->imag != 0));\n\telse {\n\t\t/* don't worry about swap, since we are just testing\n\t\t whether or not equal to 0 */\n\t\tmemcpy(&t1, ip, sizeof(@type@));\n\t\treturn (Bool) ((t1.real != 0) || (t1.imag != 0));\n\t}\n}\n/**end repeat**/\n\n\n\n#define WHITESPACE \" \\t\\n\\r\\v\\f\"\n#define WHITELEN 6\n\nstatic Bool\nPy_STRING_ISSPACE(char ch) \n{\n\tchar white[] = WHITESPACE;\n\tint j;\n\tBool space=FALSE;\n\tfor (j=0; jdescr->elsize;\n\tint i;\n\tBool nonz = FALSE;\n\n\tfor (i=0; idescr->elsize >> 2;\n\tint i;\n\tBool nonz = FALSE;\n\tchar *buffer=NULL;\t\n\n\tif ((!PyArray_ISNOTSWAPPED(ap)) || \\\n\t (!PyArray_ISALIGNED(ap))) {\n\t\tbuffer = _pya_malloc(ap->descr->elsize);\n\t\tif (buffer == NULL) {\n\t\t\treturn nonz;\n\t\t}\n\t\tmemcpy(buffer, ip, ap->descr->elsize);\n\t\tif (!PyArray_ISNOTSWAPPED(ap)) {\n\t\t\tbyte_swap_vector(buffer, len, 4);\n\t\t}\n\t\tip = (PyArray_UCS4 *)buffer;\n\t}\n\n\tfor (i=0; idescr->elsize;\n\tBool nonz = FALSE;\n\t\n\tfor (i=0; idescr->elsize);\n}\n\n/* taken from Python */\nstatic int \nUNICODE_compare(register PyArray_UCS4 *ip1, register PyArray_UCS4 *ip2, \n\t\tPyArrayObject *ap)\n{\n register int itemsize=ap->descr->elsize;\n\tregister PyArray_UCS4 c1, c2;\n\n\tif (itemsize < 0) return 0;\n\t\n\twhile(itemsize-- > 0) {\n\t\tc1 = *ip1++;\n\t\tc2 = *ip2++;\n\t\t\n\t\tif (c1 != c2) \n\t\t\treturn (c1 < c2) ? -1 : 1;\n\t}\n\treturn 0;\n}\n\n/* possibly redefine compare in terms of fields and subarrays if any */\n\n/* as it is, it compares raw-bytes as it they were strings */\n#define VOID_compare STRING_compare\n\n/****************** argfunc **********************************/\n\n/**begin repeat\n\n#fname= BOOL,BYTE, UBYTE, SHORT, USHORT, INT, UINT, LONG, ULONG, LONGLONG, ULONGLONG, FLOAT, DOUBLE, LONGDOUBLE, CFLOAT, CDOUBLE, CLONGDOUBLE#\n#type= Bool, byte, ubyte, short, ushort, int, uint, long, ulong, longlong, ulonglong, float, double, longdouble, float, double, longdouble#\n#incr= ip++*14, ip+=2*3#\n*/\n\nstatic int\n@fname@_argmax(@type@ *ip, intp n, intp *max_ind, PyArrayObject *aip)\n{\n\tregister intp i;\n\t@type@ mp=*ip;\n\t*max_ind=0;\n\tfor (i=1; i mp) {\n\t\t\tmp = *ip;\n\t\t\t*max_ind = i;\n\t\t}\n\t}\n\treturn 0;\n}\n\n/**end repeat**/\n\nstatic int \nOBJECT_argmax(PyObject **ip, intp n, intp *max_ind, PyArrayObject *aip) \n{\n\tregister intp i; \n\tPyObject *mp=ip[0]; *max_ind=0;\n\tfor(i=1; i 0) { \n\t\t\tmp = *ip; \n\t\t\t*max_ind=i;\n\t\t} \n\t} \n\treturn 0;\n}\n\n/**begin repeat\n\n#fname= STRING, UNICODE#\n#type= char, PyArray_UCS4#\n\n*/\nstatic int \n@fname@_argmax(@type@ *ip, intp n, intp *max_ind, PyArrayObject *aip) \n{\n\tregister intp i; \n\tint elsize = aip->descr->elsize;\n\t@type@ *mp = (@type@ *)_pya_malloc(elsize);\n\t\n\tif (mp==NULL) return 0;\n\tmemcpy(mp, ip, elsize);\n\t*max_ind = 0;\n\tfor(i=1; i 0) { \n\t\t\tmemcpy(mp, ip, elsize);\n\t\t\t*max_ind=i;\n\t\t} \n\t} \n\t_pya_free(mp);\n\treturn 0;\n}\n\n/**end repeat**/\n\n#define VOID_argmax NULL\n\nstatic void\nBOOL_dot(char *ip1, intp is1, char *ip2, intp is2, char *op, intp n, \n void *ignore)\n{\n\tregister Bool tmp=FALSE;\n\tregister intp i;\n\tfor(i=0;ireal;\n\tstart.imag = buffer->imag;\n\tdelta.real = buffer[1].real;\n\tdelta.imag = buffer[1].imag;\n\tdelta.real -= start.real;\n\tdelta.imag -= start.imag;\n\tstart.real += (delta.real + delta.real);\n\tstart.imag += (delta.imag + delta.imag);\n\tbuffer += 2;\n\tfor (i=2; ireal = start.real;\n\t\tbuffer->imag = start.imag; \n\t\tstart.real += delta.real;\n\t\tstart.imag += delta.imag;\n\t}\n}\n/**end repeat**/\n\n\n#define _ALIGN(type) offsetof(struct {char c; type v;},v)\n\n/**begin repeat\n\n#from= VOID, STRING, UNICODE#\n#align= char, char, PyArray_UCS4#\n#NAME= Void, String, Unicode#\n#endian= |, |, =#\n*/\n\nstatic PyArray_ArrFuncs _Py@NAME@_ArrFuncs = {\n\t{\n\t\t(PyArray_VectorUnaryFunc*)@from@_to_BOOL, \n\t\t(PyArray_VectorUnaryFunc*)@from@_to_BYTE, \n\t\t(PyArray_VectorUnaryFunc*)@from@_to_UBYTE, \n\t\t(PyArray_VectorUnaryFunc*)@from@_to_SHORT, \n\t\t(PyArray_VectorUnaryFunc*)@from@_to_USHORT, \n\t\t(PyArray_VectorUnaryFunc*)@from@_to_INT, \n\t\t(PyArray_VectorUnaryFunc*)@from@_to_UINT, \n\t\t(PyArray_VectorUnaryFunc*)@from@_to_LONG,\n\t\t(PyArray_VectorUnaryFunc*)@from@_to_ULONG, \n\t\t(PyArray_VectorUnaryFunc*)@from@_to_LONGLONG, \n\t\t(PyArray_VectorUnaryFunc*)@from@_to_ULONGLONG, \n\t\t(PyArray_VectorUnaryFunc*)@from@_to_FLOAT, \n\t\t(PyArray_VectorUnaryFunc*)@from@_to_DOUBLE, \n\t\t(PyArray_VectorUnaryFunc*)@from@_to_LONGDOUBLE, \n\t\t(PyArray_VectorUnaryFunc*)@from@_to_CFLOAT, \n\t\t(PyArray_VectorUnaryFunc*)@from@_to_CDOUBLE, \n\t\t(PyArray_VectorUnaryFunc*)@from@_to_CLONGDOUBLE, \n\t\t(PyArray_VectorUnaryFunc*)@from@_to_OBJECT, \n\t\t(PyArray_VectorUnaryFunc*)@from@_to_STRING, \n\t\t(PyArray_VectorUnaryFunc*)@from@_to_UNICODE, \n\t\t(PyArray_VectorUnaryFunc*)@from@_to_VOID\n\t},\n\t(PyArray_GetItemFunc*)@from@_getitem, \n\t(PyArray_SetItemFunc*)@from@_setitem,\n\t(PyArray_CopySwapNFunc*)@from@_copyswapn,\n\t(PyArray_CopySwapFunc*)@from@_copyswap,\n\t(PyArray_CompareFunc*)@from@_compare, \n\t(PyArray_ArgFunc*)@from@_argmax,\n\t(PyArray_DotFunc*)NULL, \n\t(PyArray_ScanFunc*)@from@_scan,\n\t(PyArray_FromStrFunc*)@from@_fromstr,\n\t(PyArray_NonzeroFunc*)@from@_nonzero,\n\t(PyArray_FillFunc*)NULL,\n\t{\n\t\tNULL, NULL, NULL, NULL\n\t},\n\t{\n\t\tNULL, NULL, NULL, NULL\n\t}\n};\n\nstatic PyArray_Descr @from@_Descr = { \n\tPyObject_HEAD_INIT(&PyArrayDescr_Type)\n\t&Py@NAME@ArrType_Type,\n\tPyArray_@from@LTR,\n\tPyArray_@from@LTR,\n\t'@endian@', 0,\n\tPyArray_@from@, 0,\n\t_ALIGN(@align@),\n\tNULL,\n\tNULL,\n\t&_Py@NAME@_ArrFuncs,\n};\n\n/**end repeat**/\n\n\n/**begin repeat\n\n#from= BOOL,BYTE,UBYTE,SHORT,USHORT,INT,UINT,LONG,ULONG,LONGLONG,ULONGLONG,FLOAT,DOUBLE,LONGDOUBLE,CFLOAT,CDOUBLE,CLONGDOUBLE,OBJECT#\n#num= 1*14,2*3,1#\n#fromtyp= Bool, byte, ubyte, short, ushort, int, uint, long, ulong, longlong, ulonglong, float, double, longdouble, float, double, longdouble, PyObject *#\n#NAME= Bool, Byte, UByte, Short, UShort, Int, UInt, Long, ULong, LongLong, ULongLong, Float, Double, LongDouble, CFloat, CDouble, CLongDouble, Object#\n#kind= GENBOOL, SIGNED, UNSIGNED, SIGNED, UNSIGNED, SIGNED, UNSIGNED, SIGNED, UNSIGNED, SIGNED, UNSIGNED, FLOATING, FLOATING, FLOATING, COMPLEX, COMPLEX, COMPLEX, OBJECT#\n#endian= |*3, =*14, |#\n#isobject= 0*17,1#\n*/\n\nstatic PyArray_ArrFuncs _Py@NAME@_ArrFuncs = {\n\t{\n\t\t(PyArray_VectorUnaryFunc*)@from@_to_BOOL, \n\t\t(PyArray_VectorUnaryFunc*)@from@_to_BYTE,\n\t\t(PyArray_VectorUnaryFunc*)@from@_to_UBYTE, \n\t\t(PyArray_VectorUnaryFunc*)@from@_to_SHORT, \n\t\t(PyArray_VectorUnaryFunc*)@from@_to_USHORT, \n\t\t(PyArray_VectorUnaryFunc*)@from@_to_INT, \n\t\t(PyArray_VectorUnaryFunc*)@from@_to_UINT, \n\t\t(PyArray_VectorUnaryFunc*)@from@_to_LONG,\n\t\t(PyArray_VectorUnaryFunc*)@from@_to_ULONG, \n\t\t(PyArray_VectorUnaryFunc*)@from@_to_LONGLONG, \n\t\t(PyArray_VectorUnaryFunc*)@from@_to_ULONGLONG, \n\t\t(PyArray_VectorUnaryFunc*)@from@_to_FLOAT, \n\t\t(PyArray_VectorUnaryFunc*)@from@_to_DOUBLE, \n\t\t(PyArray_VectorUnaryFunc*)@from@_to_LONGDOUBLE, \n\t\t(PyArray_VectorUnaryFunc*)@from@_to_CFLOAT, \n\t\t(PyArray_VectorUnaryFunc*)@from@_to_CDOUBLE, \n\t\t(PyArray_VectorUnaryFunc*)@from@_to_CLONGDOUBLE, \n\t\t(PyArray_VectorUnaryFunc*)@from@_to_OBJECT, \n\t\t(PyArray_VectorUnaryFunc*)@from@_to_STRING, \n\t\t(PyArray_VectorUnaryFunc*)@from@_to_UNICODE, \n\t\t(PyArray_VectorUnaryFunc*)@from@_to_VOID\n\t},\n\t(PyArray_GetItemFunc*)@from@_getitem, \n\t(PyArray_SetItemFunc*)@from@_setitem,\n\t(PyArray_CopySwapNFunc*)@from@_copyswapn,\n\t(PyArray_CopySwapFunc*)@from@_copyswap,\n\t(PyArray_CompareFunc*)@from@_compare, \n\t(PyArray_ArgFunc*)@from@_argmax,\n\t(PyArray_DotFunc*)@from@_dot, \n\t(PyArray_ScanFunc*)@from@_scan,\n\t(PyArray_FromStrFunc*)@from@_fromstr,\n\t(PyArray_NonzeroFunc*)@from@_nonzero,\n\t(PyArray_FillFunc*)@from@_fill,\n\t{\n\t\tNULL, NULL, NULL, NULL\n\t},\n\t{\n\t\tNULL, NULL, NULL, NULL\n\t}\n};\n\nstatic PyArray_Descr @from@_Descr = { \n\tPyObject_HEAD_INIT(&PyArrayDescr_Type)\n\t&Py@NAME@ArrType_Type,\n\tPyArray_@kind@LTR,\n\tPyArray_@from@LTR,\n\t'@endian@', @isobject@,\n\tPyArray_@from@, \n\t@num@*sizeof(@fromtyp@), \n\t_ALIGN(@fromtyp@),\n\tNULL,\n\tNULL,\n\t&_Py@NAME@_ArrFuncs,\n};\n\n/**end repeat**/\n\n#define _MAX_LETTER 128\nstatic char _letter_to_num[_MAX_LETTER];\n\nstatic PyArray_Descr *_builtin_descrs[] = {\n\t&BOOL_Descr,\n\t&BYTE_Descr,\n\t&UBYTE_Descr,\n\t&SHORT_Descr, \n\t&USHORT_Descr, \n\t&INT_Descr, \n\t&UINT_Descr, \n\t&LONG_Descr, \n\t&ULONG_Descr,\n\t&LONGLONG_Descr,\n\t&ULONGLONG_Descr,\n\t&FLOAT_Descr, \n\t&DOUBLE_Descr,\n\t&LONGDOUBLE_Descr,\n\t&CFLOAT_Descr, \n\t&CDOUBLE_Descr, \n\t&CLONGDOUBLE_Descr,\n\t&OBJECT_Descr, \n\t&STRING_Descr, \n\t&UNICODE_Descr,\n\t&VOID_Descr,\n};\n\n/*OBJECT_API\n Get the PyArray_Descr structure for a type.\n*/\nstatic PyArray_Descr *\nPyArray_DescrFromType(int type)\n{\n\tPyArray_Descr *ret=NULL;\n\n\tif (type < PyArray_NTYPES) {\n\t\tret = _builtin_descrs[type];\n\t}\n\telse if (type == PyArray_NOTYPE) {\n\t\t/* This needs to not raise an error so\n\t\t that PyArray_DescrFromType(PyArray_NOTYPE)\n\t\t works for backwards-compatible C-API \n\t\t*/\t\t\n\t\treturn NULL;\n\t}\n\telse if PyTypeNum_ISUSERDEF(type) {\n\t\tret = userdescrs[type-PyArray_USERDEF];\n\t} \n\telse {\n\t\tint num=PyArray_NTYPES;\n\t\tif (type < _MAX_LETTER) \n\t\t\tnum = (int) _letter_to_num[type];\n\t\tif (num >= PyArray_NTYPES)\n\t\t\tret = NULL;\n\t\telse\n\t\t\tret = _builtin_descrs[num];\n\t}\n\tif (ret==NULL) {\n\t\tPyErr_SetString(PyExc_ValueError, \n\t\t\t\t\"Invalid data-type for array\"); \n\t}\n\telse Py_INCREF(ret);\n\treturn ret;\n}\n\n\nstatic int\nset_typeinfo(PyObject *dict)\n{\n\tPyObject *infodict, *s;\n\tint i;\n\n\tfor (i=0; i<_MAX_LETTER; i++) {\n\t\t_letter_to_num[i] = PyArray_NTYPES;\n\t}\n\n/**begin repeat\n#name=BOOL,BYTE,UBYTE,SHORT,USHORT,INT,UINT,INTP,UINTP,LONG,ULONG,LONGLONG,ULONGLONG,FLOAT,DOUBLE,LONGDOUBLE,CFLOAT,CDOUBLE,CLONGDOUBLE,OBJECT,STRING,UNICODE,VOID#\n*/\n\t_letter_to_num[PyArray_@name@LTR] = PyArray_@name@;\n/**end repeat**/\n\t_letter_to_num[PyArray_STRINGLTR2] = PyArray_STRING;\n\n/**begin repeat\n#name=BOOL,BYTE,UBYTE,SHORT,USHORT,INT,UINT,LONG,ULONG,LONGLONG,ULONGLONG,FLOAT,DOUBLE,LONGDOUBLE,CFLOAT,CDOUBLE,CLONGDOUBLE,OBJECT,STRING,UNICODE,VOID#\n*/\n\t@name@_Descr.fields = Py_None;\n/**end repeat**/\n\t\n\t/* Set a dictionary with type information */\n\tinfodict = PyDict_New();\n\tif (infodict == NULL) return -1;\n\n#define BITSOF_INTP CHAR_BIT*SIZEOF_PY_INTPTR_T\n#define BITSOF_BYTE CHAR_BIT\n\n/**begin repeat \n\n#name=BOOL,BYTE,UBYTE,SHORT,USHORT,INT,UINT,INTP,UINTP,LONG,ULONG,LONGLONG,ULONGLONG#\n#uname=BOOL,BYTE*2,SHORT*2,INT*2,INTP*2,LONG*2,LONGLONG*2#\n#Name=Bool,Byte,UByte,Short,UShort,Int,UInt,Intp,UIntp,Long,ULong,LongLong,ULongLong#\n#type=Bool,byte,ubyte,short,ushort,int,uint,intp,uintp,long,ulong,longlong,ulonglong#\n#max=1,MAX_BYTE,MAX_UBYTE,MAX_SHORT,MAX_USHORT,MAX_INT,PyLong_FromUnsignedLong(MAX_UINT),PyLong_FromLongLong((longlong) MAX_INTP),PyLong_FromUnsignedLongLong((ulonglong) MAX_UINTP),MAX_LONG,PyLong_FromUnsignedLong((unsigned long) MAX_ULONG),PyLong_FromLongLong((longlong) MAX_LONGLONG), PyLong_FromUnsignedLongLong((ulonglong) MAX_ULONGLONG)#\n#min=0,MIN_BYTE,0,MIN_SHORT,0,MIN_INT,0,PyLong_FromLongLong((longlong) MIN_INTP),0,MIN_LONG,0,PyLong_FromLongLong((longlong) MIN_LONGLONG),0#\n#cx=i*6,N,N,N,l,N,N,N#\n#cn=i*7,N,i,l,i,N,i#\n*/\n \tPyDict_SetItemString(infodict, \"@name@\", \n\t\t\t s=Py_BuildValue(\"ciii@cx@@cn@O\", \n\t\t\t\t\t PyArray_@name@LTR, \n\t\t\t\t\t PyArray_@name@,\n\t\t\t\t\t BITSOF_@uname@,\n\t\t\t\t\t _ALIGN(@type@),\n\t\t\t\t\t @max@, @min@,\n\t\t\t\t (PyObject *)&Py@Name@ArrType_Type));\n\tPy_DECREF(s); \n/**end repeat**/\n\n#define BITSOF_CFLOAT 2*BITSOF_FLOAT\n#define BITSOF_CDOUBLE 2*BITSOF_DOUBLE\n#define BITSOF_CLONGDOUBLE 2*BITSOF_LONGDOUBLE\n\n/**begin repeat\n\n#type=float,double,longdouble,cfloat,cdouble,clongdouble#\n#name=FLOAT, DOUBLE, LONGDOUBLE, CFLOAT, CDOUBLE, CLONGDOUBLE#\n#Name=Float,Double,LongDouble,CFloat,CDouble,CLongDouble#\n*/\n \tPyDict_SetItemString(infodict, \"@name@\", \n\t\t\t s=Py_BuildValue(\"ciiiO\", PyArray_@name@LTR, \n\t\t\t\t\t PyArray_@name@, BITSOF_@name@,\n\t\t\t\t\t _ALIGN(@type@),\n (PyObject *)\\\n &Py@Name@ArrType_Type));\n\tPy_DECREF(s);\n/**end repeat**/\n\t\n\tPyDict_SetItemString(infodict, \"OBJECT\", \n\t\t\t s=Py_BuildValue(\"ciiiO\", PyArray_OBJECTLTR, \n\t\t\t\t\t PyArray_OBJECT, \n\t\t\t\t\t sizeof(PyObject *)*CHAR_BIT,\n\t\t\t\t\t _ALIGN(PyObject *),\n (PyObject *)\\\n &PyObjectArrType_Type));\n\tPy_DECREF(s);\n\tPyDict_SetItemString(infodict, \"STRING\", \n\t\t\t s=Py_BuildValue(\"ciiiO\", PyArray_STRINGLTR, \n\t\t\t\t\t PyArray_STRING, 0,\n\t\t\t\t\t _ALIGN(char),\n (PyObject *)\\\n &PyStringArrType_Type));\n\tPy_DECREF(s);\n\tPyDict_SetItemString(infodict, \"UNICODE\", \n\t\t\t s=Py_BuildValue(\"ciiiO\", PyArray_UNICODELTR, \n\t\t\t\t\t PyArray_UNICODE, 0,\n\t\t\t\t\t _ALIGN(PyArray_UCS4),\n (PyObject *)\\\n &PyUnicodeArrType_Type));\t\n\tPy_DECREF(s);\n\tPyDict_SetItemString(infodict, \"VOID\", \n\t\t\t s=Py_BuildValue(\"ciiiO\", PyArray_VOIDLTR, \n\t\t\t\t\t PyArray_VOID, 0,\n\t\t\t\t\t _ALIGN(char),\n (PyObject *)\\\n &PyVoidArrType_Type));\t\n\tPy_DECREF(s);\n\n#define SETTYPE(name) \\\n Py_INCREF(&Py##name##ArrType_Type); \\\n PyDict_SetItemString(infodict, #name, \\\n (PyObject *)&Py##name##ArrType_Type);\n\n SETTYPE(Generic)\n SETTYPE(Number)\n SETTYPE(Integer)\n\tSETTYPE(Inexact)\n SETTYPE(SignedInteger)\n SETTYPE(UnsignedInteger)\n SETTYPE(Floating)\n SETTYPE(ComplexFloating)\n SETTYPE(Flexible)\n SETTYPE(Character)\n\n#undef SETTYPE \t\n\n\tPyDict_SetItemString(dict, \"typeinfo\", infodict);\n\tPy_DECREF(infodict);\n\treturn 0;\n}\n\n#undef _MAX_LETTER\n\n", + "methods": [], + "methods_before": [], + "changed_methods": [], + "nloc": null, + "complexity": null, + "token_count": null, + "diff_parsed": { + "added": [ + "\t@typ@ *buffermax;", + "\tbuffermax = buffer + length;", + "\twhile(buffer < buffermax) {", + "\t\tbuffer++;", + "\t@typ@ *buffermax;", + "\tbuffermax = buffer + length;", + "\twhile (buffer < buffermax) {", + "\t\tbuffer++;" + ], + "deleted": [ + "\tintp i;", + "\tfor (i=2; i\n# last revision: 1996-3-13\n# modified by Jim Hugunin 1997-3-3 for repr's and str's (and other details)\n# and by Perry Greenfield 2000-4-1 for numarray\n# and by Travis Oliphant 2005-8-22 for numpy\n\nimport sys\nimport numeric as _gen\nimport numerictypes as _nt\nimport umath as _uf\n_nc = _gen\n\n# The following functions are emergency substitutes for numeric functions\n# which sometimes get broken during development.\n\ndef product(x, y): return x*y\n\ndef _maximum_reduce(arr):\n maximum = arr[0]\n for i in xrange(1, arr.nelements()):\n if arr[i] > maximum: maximum = arr[i]\n return maximum\n\ndef _minimum_reduce(arr):\n minimum = arr[0]\n for i in xrange(1, arr.nelements()):\n if arr[i] < minimum: minimum = arr[i]\n return minimum\n\ndef _numeric_compress(arr):\n nonzero = 0\n for i in xrange(arr.nelements()):\n if arr[i] != 0: nonzero += 1\n retarr = _nc.zeros((nonzero,))\n nonzero = 0\n for i in xrange(arr.nelements()):\n if arr[i] != 0:\n retarr[nonzero] = abs(arr[i])\n nonzero += 1\n return retarr\n\n_failsafe = 0\nif _failsafe:\n max_reduce = _maximum_reduce\n min_reduce = _minimum_reduce\nelse:\n max_reduce = _uf.maximum.reduce\n min_reduce = _uf.minimum.reduce\n\n_summaryEdgeItems = 3 # repr N leading and trailing items of each dimension\n_summaryThreshhold = 1000 # total items > triggers array summarization\n\n_float_output_precision = 8\n_float_output_suppress_small = False\n_line_width = 75\n\n\ndef set_printoptions(precision=None, threshold=None, edgeitems=None, \n linewidth=None, suppress=None):\n \"\"\"Set options associated with printing.\n\n precision the default number of digits of precision for floating\n point output\n (default 8)\n threshold total number of array elements which trigger summarization\n rather than full repr.\n (default 1000)\n edgeitems number of array items in summary at beginning and end of\n each dimension.\n (default 3)\n linewidth the number of characters per line for the purpose of inserting\n line breaks.\n (default 75)\n supress Boolean value indicating whether or not suppress printing\n of small floating point values using scientific notation\n (default False)\n \"\"\" \n \n global _summaryThreshhold, _summaryEdgeItems, _float_output_precision, \\\n _line_width, _float_output_suppress_small\n if (linewidth is not None):\n _line_width = linewidth\n if (threshold is not None):\n _summaryThreshhold = threshold\n if (edgeitems is not None):\n _summaryEdgeItems = edgeitems\n if (precision is not None):\n _float_output_precision = precision\n if (suppress is not None):\n _float_output_supress_small = not not suppress\n return\n\ndef get_printoptions():\n return _float_output_precision, _summaryThreshhold, _summaryEdgeItems, \\\n _line_width, _float_output_suppress_small\n\n\ndef _leading_trailing(a):\n if a.ndim == 1:\n if len(a) > 2*_summaryEdgeItems:\n b = _gen.concatenate((a[:_summaryEdgeItems],\n a[-_summaryEdgeItems:]))\n else:\n b = a\n else:\n if len(a) > 2*_summaryEdgeItems:\n l = [_leading_trailing(a[i]) for i in range(\n min(len(a), _summaryEdgeItems))]\n l.extend([_leading_trailing(a[-i]) for i in range(\n min(len(a), _summaryEdgeItems),0,-1)])\n else:\n l = [_leading_trailing(a[i]) for i in range(0, len(a))]\n b = _gen.concatenate(tuple(l))\n return b\n\ndef _array2string(a, max_line_width, precision, suppress_small, separator=' ',\n prefix=\"\"):\n\n if max_line_width is None:\n max_line_width = _line_width\n \n if precision is None:\n precision = _float_output_precision\n\n if suppress_small is None:\n suppress_small = _float_output_suppress_small\n\n if a.size > _summaryThreshhold:\n summary_insert = \"..., \"\n data = _leading_trailing(a)\n else:\n summary_insert = \"\"\n data = a.ravel()\n\n items_per_line = a.shape[-1]\n \n try:\n format_function = a._format\n except AttributeError:\n dtype = a.dtype.type\n if issubclass(dtype, _nt.bool):\n format = \"%s\"\n format_function = lambda x, f = format: format % x\n if issubclass(dtype, _nt.integer):\n max_str_len = max(len(str(max_reduce(data))),\n len(str(min_reduce(data))))\n format = '%' + str(max_str_len) + 'd'\n format_function = lambda x, f = format: _formatInteger(x, f)\n elif issubclass(dtype, _nt.floating):\n format = _floatFormat(data, precision, suppress_small)\n format_function = lambda x, f = format: _formatFloat(x, f)\n elif issubclass(dtype, _nt.complexfloating):\n real_format = _floatFormat(\n data.real, precision, suppress_small, sign=0)\n imag_format = _floatFormat(\n data.imag, precision, suppress_small, sign=1)\n format_function = lambda x, f1 = real_format, f2 = imag_format: \\\n _formatComplex(x, f1, f2)\n elif issubclass(dtype, _nt.unicode_):\n format = \"%s\"\n format_function = lambda x, f = format: repr(x)\n else:\n\t format = '%s'\n\t format_function = lambda x, f = format: format % str(x)\n\t \n next_line_prefix = \" \" # skip over \"[\"\n next_line_prefix += \" \"*len(prefix) # skip over array(\n\n\n lst = _formatArray(a, format_function, len(a.shape), max_line_width,\n next_line_prefix, separator,\n _summaryEdgeItems, summary_insert)[:-1]\n\n return lst\n\ndef array2string(a, max_line_width = None, precision = None,\n suppress_small = None, separator=' ', prefix=\"\",\n style=repr):\n\n if a.shape == ():\n x = a.item()\n try:\n lst = a._format(x)\n except AttributeError:\n lst = style(x)\n elif reduce(product, a.shape) == 0:\n # treat as a null array if any of shape elements == 0\n lst = \"[]\"\n else:\n lst = _array2string(a, max_line_width, precision, suppress_small,\n separator, prefix)\n return lst\n\ndef _extendLine(s, line, word, max_line_len, next_line_prefix):\n if len(line.rstrip()) + len(word.rstrip()) >= max_line_len:\n s += line.rstrip() + \"\\n\"\n line = next_line_prefix\n line += word\n return s, line\n\ndef _formatArray(a, format_function, rank, max_line_len,\n next_line_prefix, separator, edge_items, summary_insert):\n \"\"\"formatArray is designed for two modes of operation:\n\n 1. Full output\n\n 2. Summarized output\n \n \"\"\"\n if rank == 0:\n return str(a.item())\n \n if summary_insert and 2*edge_items < len(a):\n leading_items, trailing_items, summary_insert1 = \\\n edge_items, edge_items, summary_insert\n else:\n leading_items, trailing_items, summary_insert1 = 0, len(a), \"\"\n\n if rank == 1:\n \n s = \"\"\n line = next_line_prefix\n for i in xrange(leading_items):\n word = format_function(a[i]) + separator\n s, line = _extendLine(s, line, word, max_line_len, next_line_prefix)\n \n if summary_insert1:\n s, line = _extendLine(s, line, summary_insert1, max_line_len, next_line_prefix)\n\n for i in xrange(trailing_items, 1, -1):\n word = format_function(a[-i]) + separator \n s, line = _extendLine(s, line, word, max_line_len, next_line_prefix)\n \n word = format_function(a[-1])\n s, line = _extendLine(s, line, word, max_line_len, next_line_prefix)\n s += line + \"]\\n\"\n s = '[' + s[len(next_line_prefix):]\n else:\n s = '['\n sep = separator.rstrip()\n for i in xrange(leading_items):\n if i > 0:\n s += next_line_prefix\n s += _formatArray(a[i], format_function, rank-1, max_line_len,\n \" \" + next_line_prefix, separator, edge_items,\n summary_insert)\n s = s.rstrip()+ sep.rstrip() + '\\n'*max(rank-1,1)\n \n if summary_insert1:\n s += next_line_prefix + summary_insert1 + \"\\n\"\n \n for i in xrange(trailing_items, 1, -1):\n if leading_items or i != trailing_items:\n s += next_line_prefix\n s += _formatArray(a[-i], format_function, rank-1, max_line_len,\n \" \" + next_line_prefix, separator, edge_items,\n summary_insert)\n s = s.rstrip() + sep.rstrip() + '\\n'*max(rank-1,1)\n if leading_items or trailing_items > 1:\n s += next_line_prefix\n s += _formatArray(a[-1], format_function, rank-1, max_line_len,\n \" \" + next_line_prefix, separator, edge_items,\n summary_insert).rstrip()+']\\n'\n return s\n\ndef _floatFormat(data, precision, suppress_small, sign = 0):\n exp_format = 0\n non_zero = _uf.absolute(data.compress(_uf.not_equal(data, 0)))\n ##non_zero = _numeric_compress(data) ##\n if len(non_zero) == 0:\n max_val = 0.\n min_val = 0.\n else:\n max_val = max_reduce(non_zero)\n min_val = min_reduce(non_zero)\n if max_val >= 1.e8:\n exp_format = 1\n if not suppress_small and (min_val < 0.0001\n or max_val/min_val > 1000.):\n exp_format = 1\n if exp_format:\n large_exponent = 0 < min_val < 1e-99 or max_val >= 1e100\n max_str_len = 8 + precision + large_exponent\n if sign: format = '%+'\n else: format = '%'\n format = format + str(max_str_len) + '.' + str(precision) + 'e'\n if large_exponent: format = format + '3'\n else:\n format = '%.' + str(precision) + 'f'\n precision = min(precision, max(tuple(map(lambda x, p=precision,\n f=format: _digits(x,p,f),\n data))))\n max_str_len = len(str(int(max_val))) + precision + 2\n if sign: format = '%#+'\n else: format = '%#'\n format = format + str(max_str_len) + '.' + str(precision) + 'f'\n return format\n\ndef _digits(x, precision, format):\n s = format % x\n zeros = len(s)\n while s[zeros-1] == '0': zeros = zeros-1\n return precision-len(s)+zeros\n\n\n_MAXINT = sys.maxint\n_MININT = -sys.maxint-1\ndef _formatInteger(x, format):\n if (x < _MAXINT) and (x > _MININT):\n return format % x\n else:\n return \"%s\" % x\n\ndef _formatFloat(x, format, strip_zeros = 1):\n if format[-1] == '3':\n # 3-digit exponent\n format = format[:-1]\n s = format % x\n third = s[-3]\n if third == '+' or third == '-':\n s = s[1:-2] + '0' + s[-2:]\n elif format[-1] == 'e':\n # 2-digit exponent\n s = format % x\n if s[-3] == '0':\n s = ' ' + s[:-3] + s[-2:]\n elif format[-1] == 'f':\n s = format % x\n if strip_zeros:\n zeros = len(s)\n while s[zeros-1] == '0': zeros = zeros-1\n s = s[:zeros] + (len(s)-zeros)*' '\n else:\n s = format % x\n return s\n\ndef _formatComplex(x, real_format, imag_format):\n r = _formatFloat(x.real, real_format)\n i = _formatFloat(x.imag, imag_format, 0)\n if imag_format[-1] == 'f':\n zeros = len(i)\n while zeros > 2 and i[zeros-1] == '0': zeros = zeros-1\n i = i[:zeros] + 'j' + (len(i)-zeros)*' '\n else:\n i = i + 'j'\n return r + i\n\ndef _formatGeneral(x):\n return str(x) + ' '\n\nif __name__ == '__main__':\n a = _nc.arange(10)\n print array2string(a)\n print array2string(_nc.array([[],[]]))\n", + "source_code_before": "\"\"\"Array printing function\n\n$Id: arrayprint.py,v 1.9 2005/09/13 13:58:44 teoliphant Exp $\n\"\"\"\n__all__ = [\"set_summary\", \"summary_off\", \"set_precision\", \"set_line_width\",\n \"array2string\"]\n \n#\n# Written by Konrad Hinsen \n# last revision: 1996-3-13\n# modified by Jim Hugunin 1997-3-3 for repr's and str's (and other details)\n# and by Perry Greenfield 2000-4-1 for numarray\n# and by Travis Oliphant 2005-8-22 for numpy\n\nimport sys\nimport numeric as _gen\nimport numerictypes as _nt\nimport umath as _uf\n_nc = _gen\n\n# The following functions are emergency substitutes for numeric functions\n# which sometimes get broken during development.\n\ndef product(x, y): return x*y\n\ndef _maximum_reduce(arr):\n maximum = arr[0]\n for i in xrange(1, arr.nelements()):\n if arr[i] > maximum: maximum = arr[i]\n return maximum\n\ndef _minimum_reduce(arr):\n minimum = arr[0]\n for i in xrange(1, arr.nelements()):\n if arr[i] < minimum: minimum = arr[i]\n return minimum\n\ndef _numeric_compress(arr):\n nonzero = 0\n for i in xrange(arr.nelements()):\n if arr[i] != 0: nonzero += 1\n retarr = _nc.zeros((nonzero,))\n nonzero = 0\n for i in xrange(arr.nelements()):\n if arr[i] != 0:\n retarr[nonzero] = abs(arr[i])\n nonzero += 1\n return retarr\n\n_failsafe = 0\nif _failsafe:\n max_reduce = _maximum_reduce\n min_reduce = _minimum_reduce\nelse:\n max_reduce = _uf.maximum.reduce\n min_reduce = _uf.minimum.reduce\n\n_summaryEdgeItems = 3 # repr N leading and trailing items of each dimension\n_summaryThreshhold = 1000 # total items > triggers array summarization\n\n_float_output_precision = 8\n_float_output_suppress_small = False\n_line_width = 75\n\n\ndef set_printoptions(precision=None, threshold=None, edgeitems=None, \n linewidth=None, suppress=None):\n \"\"\"Set options associated with printing.\n\n precision the default number of digits of precision for floating\n point output\n (default 8)\n threshold total number of array elements which trigger summarization\n rather than full repr.\n (default 1000)\n edgeitems number of array items in summary at beginning and end of\n each dimension.\n (default 3)\n linewidth the number of characters per line for the purpose of inserting\n line breaks.\n (default 75)\n supress Boolean value indicating whether or not suppress printing\n of small floating point values using scientific notation\n (default False)\n \"\"\" \n \n global _summaryThreshhold, _summaryEdgeItems, _float_output_precision, \\\n _line_width, _float_output_suppress_small\n if (linewidth is not None):\n _line_width = linewidth\n if (threshold is not None):\n _summaryThreshhold = threshold\n if (edgeitems is not None):\n _summaryEdgeItems = edgeitems\n if (precision is not None):\n _float_output_precision = precision\n if (suppress is not None):\n _float_output_supress_small = not not suppress\n return\n\ndef get_printoptions():\n return _float_output_precision, _summaryThreshhold, _summaryEdgeItems, \\\n _line_width, _float_output_suppress_small\n\n\ndef _leading_trailing(a):\n if a.ndim == 1:\n if len(a) > 2*_summaryEdgeItems:\n b = _gen.concatenate((a[:_summaryEdgeItems],\n a[-_summaryEdgeItems:]))\n else:\n b = a\n else:\n if len(a) > 2*_summaryEdgeItems:\n l = [_leading_trailing(a[i]) for i in range(\n min(len(a), _summaryEdgeItems))]\n l.extend([_leading_trailing(a[-i]) for i in range(\n min(len(a), _summaryEdgeItems),0,-1)])\n else:\n l = [_leading_trailing(a[i]) for i in range(0, len(a))]\n b = _gen.concatenate(tuple(l))\n return b\n\ndef _array2string(a, max_line_width, precision, suppress_small, separator=' ',\n prefix=\"\"):\n\n if max_line_width is None:\n max_line_width = _line_width\n \n if precision is None:\n precision = _float_output_precision\n\n if suppress_small is None:\n suppress_small = _float_output_suppress_small\n\n if a.size > _summaryThreshhold:\n summary_insert = \"..., \"\n data = _leading_trailing(a)\n else:\n summary_insert = \"\"\n data = a.ravel()\n\n items_per_line = a.shape[-1]\n \n try:\n format_function = a._format\n except AttributeError:\n dtype = a.dtype.type\n if issubclass(dtype, _nt.bool):\n format = \"%s\"\n format_function = lambda x, f = format: format % x\n if issubclass(dtype, _nt.integer):\n max_str_len = max(len(str(max_reduce(data))),\n len(str(min_reduce(data))))\n format = '%' + str(max_str_len) + 'd'\n format_function = lambda x, f = format: _formatInteger(x, f)\n elif issubclass(dtype, _nt.floating):\n format = _floatFormat(data, precision, suppress_small)\n format_function = lambda x, f = format: _formatFloat(x, f)\n elif issubclass(dtype, _nt.complexfloating):\n real_format = _floatFormat(\n data.real, precision, suppress_small, sign=0)\n imag_format = _floatFormat(\n data.imag, precision, suppress_small, sign=1)\n format_function = lambda x, f1 = real_format, f2 = imag_format: \\\n _formatComplex(x, f1, f2)\n else:\n\t format = '%s'\n\t format_function = lambda x, f = format: format % str(x)\n\t \n next_line_prefix = \" \" # skip over \"[\"\n next_line_prefix += \" \"*len(prefix) # skip over array(\n\n\n lst = _formatArray(a, format_function, len(a.shape), max_line_width,\n next_line_prefix, separator,\n _summaryEdgeItems, summary_insert)[:-1]\n\n return lst\n\ndef array2string(a, max_line_width = None, precision = None,\n suppress_small = None, separator=' ', prefix=\"\",\n style=repr):\n\n if a.shape == ():\n x = a.item()\n try:\n lst = a._format(x)\n except AttributeError:\n lst = style(x)\n elif reduce(product, a.shape) == 0:\n # treat as a null array if any of shape elements == 0\n lst = \"[]\"\n else:\n lst = _array2string(a, max_line_width, precision, suppress_small,\n separator, prefix)\n return lst\n\ndef _extendLine(s, line, word, max_line_len, next_line_prefix):\n if len(line.rstrip()) + len(word.rstrip()) >= max_line_len:\n s += line.rstrip() + \"\\n\"\n line = next_line_prefix\n line += word\n return s, line\n\ndef _formatArray(a, format_function, rank, max_line_len,\n next_line_prefix, separator, edge_items, summary_insert):\n \"\"\"formatArray is designed for two modes of operation:\n\n 1. Full output\n\n 2. Summarized output\n \n \"\"\"\n if rank == 0:\n return str(a.item())\n \n if summary_insert and 2*edge_items < len(a):\n leading_items, trailing_items, summary_insert1 = \\\n edge_items, edge_items, summary_insert\n else:\n leading_items, trailing_items, summary_insert1 = 0, len(a), \"\"\n\n if rank == 1:\n \n s = \"\"\n line = next_line_prefix\n for i in xrange(leading_items):\n word = format_function(a[i]) + separator\n s, line = _extendLine(s, line, word, max_line_len, next_line_prefix)\n \n if summary_insert1:\n s, line = _extendLine(s, line, summary_insert1, max_line_len, next_line_prefix)\n\n for i in xrange(trailing_items, 1, -1):\n word = format_function(a[-i]) + separator \n s, line = _extendLine(s, line, word, max_line_len, next_line_prefix)\n \n word = format_function(a[-1])\n s, line = _extendLine(s, line, word, max_line_len, next_line_prefix)\n s += line + \"]\\n\"\n s = '[' + s[len(next_line_prefix):]\n else:\n s = '['\n sep = separator.rstrip()\n for i in xrange(leading_items):\n if i > 0:\n s += next_line_prefix\n s += _formatArray(a[i], format_function, rank-1, max_line_len,\n \" \" + next_line_prefix, separator, edge_items,\n summary_insert)\n s = s.rstrip()+ sep.rstrip() + '\\n'*max(rank-1,1)\n \n if summary_insert1:\n s += next_line_prefix + summary_insert1 + \"\\n\"\n \n for i in xrange(trailing_items, 1, -1):\n if leading_items or i != trailing_items:\n s += next_line_prefix\n s += _formatArray(a[-i], format_function, rank-1, max_line_len,\n \" \" + next_line_prefix, separator, edge_items,\n summary_insert)\n s = s.rstrip() + sep.rstrip() + '\\n'*max(rank-1,1)\n if leading_items or trailing_items > 1:\n s += next_line_prefix\n s += _formatArray(a[-1], format_function, rank-1, max_line_len,\n \" \" + next_line_prefix, separator, edge_items,\n summary_insert).rstrip()+']\\n'\n return s\n\ndef _floatFormat(data, precision, suppress_small, sign = 0):\n exp_format = 0\n non_zero = _uf.absolute(data.compress(_uf.not_equal(data, 0)))\n ##non_zero = _numeric_compress(data) ##\n if len(non_zero) == 0:\n max_val = 0.\n min_val = 0.\n else:\n max_val = max_reduce(non_zero)\n min_val = min_reduce(non_zero)\n if max_val >= 1.e8:\n exp_format = 1\n if not suppress_small and (min_val < 0.0001\n or max_val/min_val > 1000.):\n exp_format = 1\n if exp_format:\n large_exponent = 0 < min_val < 1e-99 or max_val >= 1e100\n max_str_len = 8 + precision + large_exponent\n if sign: format = '%+'\n else: format = '%'\n format = format + str(max_str_len) + '.' + str(precision) + 'e'\n if large_exponent: format = format + '3'\n else:\n format = '%.' + str(precision) + 'f'\n precision = min(precision, max(tuple(map(lambda x, p=precision,\n f=format: _digits(x,p,f),\n data))))\n max_str_len = len(str(int(max_val))) + precision + 2\n if sign: format = '%#+'\n else: format = '%#'\n format = format + str(max_str_len) + '.' + str(precision) + 'f'\n return format\n\ndef _digits(x, precision, format):\n s = format % x\n zeros = len(s)\n while s[zeros-1] == '0': zeros = zeros-1\n return precision-len(s)+zeros\n\n\n_MAXINT = sys.maxint\n_MININT = -sys.maxint-1\ndef _formatInteger(x, format):\n if (x < _MAXINT) and (x > _MININT):\n return format % x\n else:\n return \"%s\" % x\n\ndef _formatFloat(x, format, strip_zeros = 1):\n if format[-1] == '3':\n # 3-digit exponent\n format = format[:-1]\n s = format % x\n third = s[-3]\n if third == '+' or third == '-':\n s = s[1:-2] + '0' + s[-2:]\n elif format[-1] == 'e':\n # 2-digit exponent\n s = format % x\n if s[-3] == '0':\n s = ' ' + s[:-3] + s[-2:]\n elif format[-1] == 'f':\n s = format % x\n if strip_zeros:\n zeros = len(s)\n while s[zeros-1] == '0': zeros = zeros-1\n s = s[:zeros] + (len(s)-zeros)*' '\n else:\n s = format % x\n return s\n\ndef _formatComplex(x, real_format, imag_format):\n r = _formatFloat(x.real, real_format)\n i = _formatFloat(x.imag, imag_format, 0)\n if imag_format[-1] == 'f':\n zeros = len(i)\n while zeros > 2 and i[zeros-1] == '0': zeros = zeros-1\n i = i[:zeros] + 'j' + (len(i)-zeros)*' '\n else:\n i = i + 'j'\n return r + i\n\ndef _formatGeneral(x):\n return str(x) + ' '\n\nif __name__ == '__main__':\n a = _nc.arange(10)\n print array2string(a)\n print array2string(_nc.array([[],[]]))\n", + "methods": [ + { + "name": "_maximum_reduce", + "long_name": "_maximum_reduce( arr )", + "filename": "arrayprint.py", + "nloc": 5, + "complexity": 3, + "token_count": 41, + "parameters": [ + "arr" + ], + "start_line": 26, + "end_line": 30, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 5, + "top_nesting_level": 0 + }, + { + "name": "_minimum_reduce", + "long_name": "_minimum_reduce( arr )", + "filename": "arrayprint.py", + "nloc": 5, + "complexity": 3, + "token_count": 41, + "parameters": [ + "arr" + ], + "start_line": 32, + "end_line": 36, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 5, + "top_nesting_level": 0 + }, + { + "name": "_numeric_compress", + "long_name": "_numeric_compress( arr )", + "filename": "arrayprint.py", + "nloc": 11, + "complexity": 5, + "token_count": 82, + "parameters": [ + "arr" + ], + "start_line": 38, + "end_line": 48, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 11, + "top_nesting_level": 0 + }, + { + "name": "set_printoptions", + "long_name": "set_printoptions( precision = None , threshold = None , edgeitems = None , linewidth = None , suppress = None )", + "filename": "arrayprint.py", + "nloc": 15, + "complexity": 6, + "token_count": 93, + "parameters": [ + "precision", + "threshold", + "edgeitems", + "linewidth", + "suppress" + ], + "start_line": 66, + "end_line": 99, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 34, + "top_nesting_level": 0 + }, + { + "name": "get_printoptions", + "long_name": "get_printoptions( )", + "filename": "arrayprint.py", + "nloc": 3, + "complexity": 1, + "token_count": 15, + "parameters": [], + "start_line": 101, + "end_line": 103, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 0 + }, + { + "name": "_leading_trailing", + "long_name": "_leading_trailing( a )", + "filename": "arrayprint.py", + "nloc": 17, + "complexity": 7, + "token_count": 159, + "parameters": [ + "a" + ], + "start_line": 106, + "end_line": 122, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 17, + "top_nesting_level": 0 + }, + { + "name": "_array2string", + "long_name": "_array2string( a , max_line_width , precision , suppress_small , separator = ' ' , prefix = \"\" )", + "filename": "arrayprint.py", + "nloc": 49, + "complexity": 11, + "token_count": 371, + "parameters": [ + "a", + "max_line_width", + "precision", + "suppress_small", + "separator", + "prefix" + ], + "start_line": 124, + "end_line": 182, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 59, + "top_nesting_level": 0 + }, + { + "name": "array2string", + "long_name": "array2string( a , max_line_width = None , precision = None , suppress_small = None , separator = ' ' , prefix = \"\" , style = repr )", + "filename": "arrayprint.py", + "nloc": 15, + "complexity": 4, + "token_count": 98, + "parameters": [ + "a", + "max_line_width", + "precision", + "suppress_small", + "separator", + "prefix", + "style" + ], + "start_line": 184, + "end_line": 200, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 17, + "top_nesting_level": 0 + }, + { + "name": "_extendLine", + "long_name": "_extendLine( s , line , word , max_line_len , next_line_prefix )", + "filename": "arrayprint.py", + "nloc": 6, + "complexity": 2, + "token_count": 53, + "parameters": [ + "s", + "line", + "word", + "max_line_len", + "next_line_prefix" + ], + "start_line": 202, + "end_line": 207, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 6, + "top_nesting_level": 0 + }, + { + "name": "_formatArray", + "long_name": "_formatArray( a , format_function , rank , max_line_len , next_line_prefix , separator , edge_items , summary_insert )", + "filename": "arrayprint.py", + "nloc": 49, + "complexity": 16, + "token_count": 433, + "parameters": [ + "a", + "format_function", + "rank", + "max_line_len", + "next_line_prefix", + "separator", + "edge_items", + "summary_insert" + ], + "start_line": 209, + "end_line": 272, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 64, + "top_nesting_level": 0 + }, + { + "name": "_floatFormat", + "long_name": "_floatFormat( data , precision , suppress_small , sign = 0 )", + "filename": "arrayprint.py", + "nloc": 31, + "complexity": 11, + "token_count": 252, + "parameters": [ + "data", + "precision", + "suppress_small", + "sign" + ], + "start_line": 274, + "end_line": 305, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 32, + "top_nesting_level": 0 + }, + { + "name": "_digits", + "long_name": "_digits( x , precision , format )", + "filename": "arrayprint.py", + "nloc": 5, + "complexity": 2, + "token_count": 44, + "parameters": [ + "x", + "precision", + "format" + ], + "start_line": 307, + "end_line": 311, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 5, + "top_nesting_level": 0 + }, + { + "name": "_formatInteger", + "long_name": "_formatInteger( x , format )", + "filename": "arrayprint.py", + "nloc": 5, + "complexity": 3, + "token_count": 30, + "parameters": [ + "x", + "format" + ], + "start_line": 316, + "end_line": 320, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 5, + "top_nesting_level": 0 + }, + { + "name": "_formatFloat", + "long_name": "_formatFloat( x , format , strip_zeros = 1 )", + "filename": "arrayprint.py", + "nloc": 20, + "complexity": 9, + "token_count": 172, + "parameters": [ + "x", + "format", + "strip_zeros" + ], + "start_line": 322, + "end_line": 343, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 22, + "top_nesting_level": 0 + }, + { + "name": "_formatComplex", + "long_name": "_formatComplex( x , real_format , imag_format )", + "filename": "arrayprint.py", + "nloc": 10, + "complexity": 4, + "token_count": 96, + "parameters": [ + "x", + "real_format", + "imag_format" + ], + "start_line": 345, + "end_line": 354, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 10, + "top_nesting_level": 0 + }, + { + "name": "_formatGeneral", + "long_name": "_formatGeneral( x )", + "filename": "arrayprint.py", + "nloc": 2, + "complexity": 1, + "token_count": 12, + "parameters": [ + "x" + ], + "start_line": 356, + "end_line": 357, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 0 + } + ], + "methods_before": [ + { + "name": "_maximum_reduce", + "long_name": "_maximum_reduce( arr )", + "filename": "arrayprint.py", + "nloc": 5, + "complexity": 3, + "token_count": 41, + "parameters": [ + "arr" + ], + "start_line": 26, + "end_line": 30, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 5, + "top_nesting_level": 0 + }, + { + "name": "_minimum_reduce", + "long_name": "_minimum_reduce( arr )", + "filename": "arrayprint.py", + "nloc": 5, + "complexity": 3, + "token_count": 41, + "parameters": [ + "arr" + ], + "start_line": 32, + "end_line": 36, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 5, + "top_nesting_level": 0 + }, + { + "name": "_numeric_compress", + "long_name": "_numeric_compress( arr )", + "filename": "arrayprint.py", + "nloc": 11, + "complexity": 5, + "token_count": 82, + "parameters": [ + "arr" + ], + "start_line": 38, + "end_line": 48, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 11, + "top_nesting_level": 0 + }, + { + "name": "set_printoptions", + "long_name": "set_printoptions( precision = None , threshold = None , edgeitems = None , linewidth = None , suppress = None )", + "filename": "arrayprint.py", + "nloc": 15, + "complexity": 6, + "token_count": 93, + "parameters": [ + "precision", + "threshold", + "edgeitems", + "linewidth", + "suppress" + ], + "start_line": 66, + "end_line": 99, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 34, + "top_nesting_level": 0 + }, + { + "name": "get_printoptions", + "long_name": "get_printoptions( )", + "filename": "arrayprint.py", + "nloc": 3, + "complexity": 1, + "token_count": 15, + "parameters": [], + "start_line": 101, + "end_line": 103, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 0 + }, + { + "name": "_leading_trailing", + "long_name": "_leading_trailing( a )", + "filename": "arrayprint.py", + "nloc": 17, + "complexity": 7, + "token_count": 159, + "parameters": [ + "a" + ], + "start_line": 106, + "end_line": 122, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 17, + "top_nesting_level": 0 + }, + { + "name": "_array2string", + "long_name": "_array2string( a , max_line_width , precision , suppress_small , separator = ' ' , prefix = \"\" )", + "filename": "arrayprint.py", + "nloc": 46, + "complexity": 10, + "token_count": 345, + "parameters": [ + "a", + "max_line_width", + "precision", + "suppress_small", + "separator", + "prefix" + ], + "start_line": 124, + "end_line": 179, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 56, + "top_nesting_level": 0 + }, + { + "name": "array2string", + "long_name": "array2string( a , max_line_width = None , precision = None , suppress_small = None , separator = ' ' , prefix = \"\" , style = repr )", + "filename": "arrayprint.py", + "nloc": 15, + "complexity": 4, + "token_count": 98, + "parameters": [ + "a", + "max_line_width", + "precision", + "suppress_small", + "separator", + "prefix", + "style" + ], + "start_line": 181, + "end_line": 197, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 17, + "top_nesting_level": 0 + }, + { + "name": "_extendLine", + "long_name": "_extendLine( s , line , word , max_line_len , next_line_prefix )", + "filename": "arrayprint.py", + "nloc": 6, + "complexity": 2, + "token_count": 53, + "parameters": [ + "s", + "line", + "word", + "max_line_len", + "next_line_prefix" + ], + "start_line": 199, + "end_line": 204, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 6, + "top_nesting_level": 0 + }, + { + "name": "_formatArray", + "long_name": "_formatArray( a , format_function , rank , max_line_len , next_line_prefix , separator , edge_items , summary_insert )", + "filename": "arrayprint.py", + "nloc": 49, + "complexity": 16, + "token_count": 433, + "parameters": [ + "a", + "format_function", + "rank", + "max_line_len", + "next_line_prefix", + "separator", + "edge_items", + "summary_insert" + ], + "start_line": 206, + "end_line": 269, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 64, + "top_nesting_level": 0 + }, + { + "name": "_floatFormat", + "long_name": "_floatFormat( data , precision , suppress_small , sign = 0 )", + "filename": "arrayprint.py", + "nloc": 31, + "complexity": 11, + "token_count": 252, + "parameters": [ + "data", + "precision", + "suppress_small", + "sign" + ], + "start_line": 271, + "end_line": 302, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 32, + "top_nesting_level": 0 + }, + { + "name": "_digits", + "long_name": "_digits( x , precision , format )", + "filename": "arrayprint.py", + "nloc": 5, + "complexity": 2, + "token_count": 44, + "parameters": [ + "x", + "precision", + "format" + ], + "start_line": 304, + "end_line": 308, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 5, + "top_nesting_level": 0 + }, + { + "name": "_formatInteger", + "long_name": "_formatInteger( x , format )", + "filename": "arrayprint.py", + "nloc": 5, + "complexity": 3, + "token_count": 30, + "parameters": [ + "x", + "format" + ], + "start_line": 313, + "end_line": 317, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 5, + "top_nesting_level": 0 + }, + { + "name": "_formatFloat", + "long_name": "_formatFloat( x , format , strip_zeros = 1 )", + "filename": "arrayprint.py", + "nloc": 20, + "complexity": 9, + "token_count": 172, + "parameters": [ + "x", + "format", + "strip_zeros" + ], + "start_line": 319, + "end_line": 340, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 22, + "top_nesting_level": 0 + }, + { + "name": "_formatComplex", + "long_name": "_formatComplex( x , real_format , imag_format )", + "filename": "arrayprint.py", + "nloc": 10, + "complexity": 4, + "token_count": 96, + "parameters": [ + "x", + "real_format", + "imag_format" + ], + "start_line": 342, + "end_line": 351, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 10, + "top_nesting_level": 0 + }, + { + "name": "_formatGeneral", + "long_name": "_formatGeneral( x )", + "filename": "arrayprint.py", + "nloc": 2, + "complexity": 1, + "token_count": 12, + "parameters": [ + "x" + ], + "start_line": 353, + "end_line": 354, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 0 + } + ], + "changed_methods": [ + { + "name": "_array2string", + "long_name": "_array2string( a , max_line_width , precision , suppress_small , separator = ' ' , prefix = \"\" )", + "filename": "arrayprint.py", + "nloc": 49, + "complexity": 11, + "token_count": 371, + "parameters": [ + "a", + "max_line_width", + "precision", + "suppress_small", + "separator", + "prefix" + ], + "start_line": 124, + "end_line": 182, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 59, + "top_nesting_level": 0 + } + ], + "nloc": 278, + "complexity": 88, + "token_count": 2141, + "diff_parsed": { + "added": [ + " elif issubclass(dtype, _nt.unicode_):", + " format = \"%s\"", + " format_function = lambda x, f = format: repr(x)" + ], + "deleted": [] + } + }, + { + "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": "@@ -2390,8 +2390,12 @@ PyArray_DescrFromScalar(PyObject *sc)\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\telse if (type_num == PyArray_UNICODE) {\n \t\t\tdescr->elsize = PyUnicode_GET_DATA_SIZE(sc);\n+#ifndef Py_UNICODE_WIDE\n+\t\t\tdescr->elsize <<= 1;\n+#endif\t\t\n+\t\t}\n \t\telse {\n \t\t\tdescr->elsize =\t\t\t\t\t\\\n \t\t\t\t((PyVoidScalarObject *)sc)->ob_size;\n", + "added_lines": 5, + "deleted_lines": 1, + "source_code": "/* -*- c -*- */\n\nstatic int PyArrayScalar_Offset[PyArray_NTYPES+1];\n/* to be exposed in C-API */\n#define PyArrayScalar_False ((PyObject *)&_PyArrayScalar_BoolValues[0])\n#define PyArrayScalar_True ((PyObject *)&_PyArrayScalar_BoolValues[1])\n#define PyArrayScalar_RETURN_BOOL_FROM_LONG(i)\t\t\t\\\n\treturn Py_INCREF(&_PyArrayScalar_BoolValues[((i)!=0)]),\t\\\n\t\t(PyObject *)&_PyArrayScalar_BoolValues[((i)!=0)]\n#define PyArrayScalar_RETURN_FALSE\t\t\\\n\treturn Py_INCREF(PyArrayScalar_False),\t\\\n\t\tPyArrayScalar_False\n#define PyArrayScalar_RETURN_TRUE\t\t\\\n\treturn Py_INCREF(PyArrayScalar_True),\t\\\n\t\tPyArrayScalar_True\n/* end to be exposed in C-API */\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\nstatic PyBoolScalarObject _PyArrayScalar_BoolValues[] = {\n\t{PyObject_HEAD_INIT(&PyBoolArrType_Type) 0},\n\t{PyObject_HEAD_INIT(&PyBoolArrType_Type) 1},\n};\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@scalar\",\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 break;\n\t\tcase PyArray_UNICODE:\n\t\t\t*newptr = (void *)PyUnicode_AS_DATA(scalar);\n break;\n\t\tdefault:\n\t\t\t*newptr = ((PyVoidScalarObject *)scalar)->obval;\n break;\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#ifdef Py_UNICODE_WIDE\n\t\tbreak;\n#else\n\t\tPyUCS2Buffer_AsUCS4((Py_UNICODE *)memptr, \n\t\t\t\t (PyArray_UCS4 *)PyArray_DATA(r),\n\t\t\t\t PyUnicode_GET_SIZE(scalar),\n\t\t\t\t PyArray_ITEMSIZE(r) >> 2);\n goto finish;\n#endif\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\n finish:\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, NULL);\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, NULL);\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, NULL);\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, NULL);\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/* over-ride repr and str of array-scalar strings and unicode to \n remove NULL bytes and then call the corresponding functions \n of string and unicode. \n */\n\n/**begin repeat\n#name=string*2,unicode*2#\n#form=(repr,str)*2#\n#Name=String*2,Unicode*2#\n#NAME=STRING*2,UNICODE*2#\n#extra=AndSize*2,,#\n#type=char*2, Py_UNICODE*2#\n*/\nstatic PyObject *\n@name@type_@form@(PyObject *self)\n{\n\tconst @type@ *dptr, *ip;\n\tint len;\n\tPyObject *new;\n\tPyObject *ret;\n\n\tip = dptr = Py@Name@_AS_@NAME@(self);\n\tlen = Py@Name@_GET_SIZE(self);\n\tdptr += len-1;\n\twhile(len > 0 && *dptr-- == 0) len--;\n\tnew = Py@Name@_From@Name@@extra@(ip, len);\n\tif (new == NULL) return PyString_FromString(\"\");\n\tret = Py@Name@_Type.tp_@form@(new);\n\tPy_DECREF(new);\n\treturn ret;\n}\n/**end repeat**/\n\n\n\n#if SIZEOF_LONGDOUBLE == SIZEOF_DOUBLE\n#define PREC_REPR 17\n#define PREC_STR 17\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\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->descr, \"str\");\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_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\t{\"dtype\",\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};/* XXX ? */\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, NULL);\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, \"dtype\");\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{\"dtype\",\n\t (getter)voidtype_dtypedescr_get,\n\t (setter)0,\n\t \"dtype 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 \"genericscalar\",\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, NULL);\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\tif (obj == Py_False)\n\t\tPyArrayScalar_RETURN_FALSE;\n\tif (obj == Py_True)\n\t\tPyArrayScalar_RETURN_TRUE;\n\tarr = PyArray_FROM_OTF(obj, PyArray_BOOL, FORCECAST);\n\tif (arr && 0 == PyArray_NDIM(arr)) {\n\t\tPyArrayScalar_RETURN_BOOL_FROM_LONG(*(Bool*)PyArray_DATA(arr));\n\t}\n\treturn PyArray_Return((PyArrayObject *)arr);\n}\n\nstatic PyObject *\nbool_arrtype_and(PyObject *a, PyObject *b)\n{\n\tif (PyArray_IsScalar(a, Bool) && PyArray_IsScalar(b, Bool)) \n\t\tPyArrayScalar_RETURN_BOOL_FROM_LONG\n\t\t\t((a == PyArrayScalar_True)&(b == PyArrayScalar_True));\n\treturn PyGenericArrType_Type.tp_as_number->nb_and(a, b);\n}\n\nstatic PyObject *\nbool_arrtype_or(PyObject *a, PyObject *b)\n{\n\tif (PyArray_IsScalar(a, Bool) && PyArray_IsScalar(b, Bool)) \n\t\tPyArrayScalar_RETURN_BOOL_FROM_LONG\n\t\t\t((a == PyArrayScalar_True)|(b == PyArrayScalar_True));\n\treturn PyGenericArrType_Type.tp_as_number->nb_or(a, b);\n}\n\nstatic PyObject *\nbool_arrtype_xor(PyObject *a, PyObject *b)\n{\n\tif (PyArray_IsScalar(a, Bool) && PyArray_IsScalar(b, Bool)) \n\t\tPyArrayScalar_RETURN_BOOL_FROM_LONG\n\t\t\t((a == PyArrayScalar_True)^(b == PyArrayScalar_True));\n\treturn PyGenericArrType_Type.tp_as_number->nb_xor(a, b);\n}\n\nstatic int\nbool_arrtype_nonzero(PyObject *a)\n{\n\treturn a == PyArrayScalar_True;\n}\n\n/* Arithmetic methods -- only so we can override &, |, ^. */\nstatic PyNumberMethods bool_arrtype_as_number = {\n\t0,\t\t\t\t\t/* nb_add */\n\t0,\t\t\t\t\t/* nb_subtract */\n\t0,\t\t\t\t\t/* nb_multiply */\n\t0,\t\t\t\t\t/* nb_divide */\n\t0,\t\t\t\t\t/* nb_remainder */\n\t0,\t\t\t\t\t/* nb_divmod */\n\t0,\t\t\t\t\t/* nb_power */\n\t0,\t\t\t\t\t/* nb_negative */\n\t0,\t\t\t\t\t/* nb_positive */\n\t0,\t\t\t\t\t/* nb_absolute */\n\t(inquiry)bool_arrtype_nonzero,\t\t/* nb_nonzero */\n\t0,\t\t\t\t\t/* nb_invert */\n\t0,\t\t\t\t\t/* nb_lshift */\n\t0,\t\t\t\t\t/* nb_rshift */\n\t(binaryfunc)bool_arrtype_and,\t\t/* nb_and */\n\t(binaryfunc)bool_arrtype_xor,\t\t/* nb_xor */\n\t(binaryfunc)bool_arrtype_or,\t\t/* nb_or */\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 \"objectscalar\",\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@scalar\",\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@ \"scalar\",\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\tPyBoolArrType_Type.tp_as_number = &bool_arrtype_as_number;\n\n\tPyStringArrType_Type.tp_alloc = NULL;\n\tPyStringArrType_Type.tp_free = NULL;\n\t\n\tPyStringArrType_Type.tp_repr = stringtype_repr;\n\tPyStringArrType_Type.tp_str = stringtype_str;\n\n\tPyUnicodeArrType_Type.tp_repr = unicodetype_repr;\n\tPyUnicodeArrType_Type.tp_str = unicodetype_str;\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#ifndef Py_UNICODE_WIDE\n\t\t\tdescr->elsize <<= 1;\n#endif\t\t\n\t\t}\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/* to be exposed in C-API */\n#define PyArrayScalar_False ((PyObject *)&_PyArrayScalar_BoolValues[0])\n#define PyArrayScalar_True ((PyObject *)&_PyArrayScalar_BoolValues[1])\n#define PyArrayScalar_RETURN_BOOL_FROM_LONG(i)\t\t\t\\\n\treturn Py_INCREF(&_PyArrayScalar_BoolValues[((i)!=0)]),\t\\\n\t\t(PyObject *)&_PyArrayScalar_BoolValues[((i)!=0)]\n#define PyArrayScalar_RETURN_FALSE\t\t\\\n\treturn Py_INCREF(PyArrayScalar_False),\t\\\n\t\tPyArrayScalar_False\n#define PyArrayScalar_RETURN_TRUE\t\t\\\n\treturn Py_INCREF(PyArrayScalar_True),\t\\\n\t\tPyArrayScalar_True\n/* end to be exposed in C-API */\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\nstatic PyBoolScalarObject _PyArrayScalar_BoolValues[] = {\n\t{PyObject_HEAD_INIT(&PyBoolArrType_Type) 0},\n\t{PyObject_HEAD_INIT(&PyBoolArrType_Type) 1},\n};\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@scalar\",\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 break;\n\t\tcase PyArray_UNICODE:\n\t\t\t*newptr = (void *)PyUnicode_AS_DATA(scalar);\n break;\n\t\tdefault:\n\t\t\t*newptr = ((PyVoidScalarObject *)scalar)->obval;\n break;\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#ifdef Py_UNICODE_WIDE\n\t\tbreak;\n#else\n\t\tPyUCS2Buffer_AsUCS4((Py_UNICODE *)memptr, \n\t\t\t\t (PyArray_UCS4 *)PyArray_DATA(r),\n\t\t\t\t PyUnicode_GET_SIZE(scalar),\n\t\t\t\t PyArray_ITEMSIZE(r) >> 2);\n goto finish;\n#endif\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\n finish:\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, NULL);\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, NULL);\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, NULL);\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, NULL);\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/* over-ride repr and str of array-scalar strings and unicode to \n remove NULL bytes and then call the corresponding functions \n of string and unicode. \n */\n\n/**begin repeat\n#name=string*2,unicode*2#\n#form=(repr,str)*2#\n#Name=String*2,Unicode*2#\n#NAME=STRING*2,UNICODE*2#\n#extra=AndSize*2,,#\n#type=char*2, Py_UNICODE*2#\n*/\nstatic PyObject *\n@name@type_@form@(PyObject *self)\n{\n\tconst @type@ *dptr, *ip;\n\tint len;\n\tPyObject *new;\n\tPyObject *ret;\n\n\tip = dptr = Py@Name@_AS_@NAME@(self);\n\tlen = Py@Name@_GET_SIZE(self);\n\tdptr += len-1;\n\twhile(len > 0 && *dptr-- == 0) len--;\n\tnew = Py@Name@_From@Name@@extra@(ip, len);\n\tif (new == NULL) return PyString_FromString(\"\");\n\tret = Py@Name@_Type.tp_@form@(new);\n\tPy_DECREF(new);\n\treturn ret;\n}\n/**end repeat**/\n\n\n\n#if SIZEOF_LONGDOUBLE == SIZEOF_DOUBLE\n#define PREC_REPR 17\n#define PREC_STR 17\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\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->descr, \"str\");\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_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\t{\"dtype\",\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};/* XXX ? */\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, NULL);\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, \"dtype\");\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{\"dtype\",\n\t (getter)voidtype_dtypedescr_get,\n\t (setter)0,\n\t \"dtype 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 \"genericscalar\",\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, NULL);\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\tif (obj == Py_False)\n\t\tPyArrayScalar_RETURN_FALSE;\n\tif (obj == Py_True)\n\t\tPyArrayScalar_RETURN_TRUE;\n\tarr = PyArray_FROM_OTF(obj, PyArray_BOOL, FORCECAST);\n\tif (arr && 0 == PyArray_NDIM(arr)) {\n\t\tPyArrayScalar_RETURN_BOOL_FROM_LONG(*(Bool*)PyArray_DATA(arr));\n\t}\n\treturn PyArray_Return((PyArrayObject *)arr);\n}\n\nstatic PyObject *\nbool_arrtype_and(PyObject *a, PyObject *b)\n{\n\tif (PyArray_IsScalar(a, Bool) && PyArray_IsScalar(b, Bool)) \n\t\tPyArrayScalar_RETURN_BOOL_FROM_LONG\n\t\t\t((a == PyArrayScalar_True)&(b == PyArrayScalar_True));\n\treturn PyGenericArrType_Type.tp_as_number->nb_and(a, b);\n}\n\nstatic PyObject *\nbool_arrtype_or(PyObject *a, PyObject *b)\n{\n\tif (PyArray_IsScalar(a, Bool) && PyArray_IsScalar(b, Bool)) \n\t\tPyArrayScalar_RETURN_BOOL_FROM_LONG\n\t\t\t((a == PyArrayScalar_True)|(b == PyArrayScalar_True));\n\treturn PyGenericArrType_Type.tp_as_number->nb_or(a, b);\n}\n\nstatic PyObject *\nbool_arrtype_xor(PyObject *a, PyObject *b)\n{\n\tif (PyArray_IsScalar(a, Bool) && PyArray_IsScalar(b, Bool)) \n\t\tPyArrayScalar_RETURN_BOOL_FROM_LONG\n\t\t\t((a == PyArrayScalar_True)^(b == PyArrayScalar_True));\n\treturn PyGenericArrType_Type.tp_as_number->nb_xor(a, b);\n}\n\nstatic int\nbool_arrtype_nonzero(PyObject *a)\n{\n\treturn a == PyArrayScalar_True;\n}\n\n/* Arithmetic methods -- only so we can override &, |, ^. */\nstatic PyNumberMethods bool_arrtype_as_number = {\n\t0,\t\t\t\t\t/* nb_add */\n\t0,\t\t\t\t\t/* nb_subtract */\n\t0,\t\t\t\t\t/* nb_multiply */\n\t0,\t\t\t\t\t/* nb_divide */\n\t0,\t\t\t\t\t/* nb_remainder */\n\t0,\t\t\t\t\t/* nb_divmod */\n\t0,\t\t\t\t\t/* nb_power */\n\t0,\t\t\t\t\t/* nb_negative */\n\t0,\t\t\t\t\t/* nb_positive */\n\t0,\t\t\t\t\t/* nb_absolute */\n\t(inquiry)bool_arrtype_nonzero,\t\t/* nb_nonzero */\n\t0,\t\t\t\t\t/* nb_invert */\n\t0,\t\t\t\t\t/* nb_lshift */\n\t0,\t\t\t\t\t/* nb_rshift */\n\t(binaryfunc)bool_arrtype_and,\t\t/* nb_and */\n\t(binaryfunc)bool_arrtype_xor,\t\t/* nb_xor */\n\t(binaryfunc)bool_arrtype_or,\t\t/* nb_or */\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 \"objectscalar\",\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@scalar\",\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@ \"scalar\",\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\tPyBoolArrType_Type.tp_as_number = &bool_arrtype_as_number;\n\n\tPyStringArrType_Type.tp_alloc = NULL;\n\tPyStringArrType_Type.tp_free = NULL;\n\t\n\tPyStringArrType_Type.tp_repr = stringtype_repr;\n\tPyStringArrType_Type.tp_str = stringtype_str;\n\n\tPyUnicodeArrType_Type.tp_repr = unicodetype_repr;\n\tPyUnicodeArrType_Type.tp_str = unicodetype_str;\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\telse if (type_num == PyArray_UNICODE) {", + "#ifndef Py_UNICODE_WIDE", + "\t\t\tdescr->elsize <<= 1;", + "#endif", + "\t\t}" + ], + "deleted": [ + "\t\telse if (type_num == PyArray_UNICODE)" + ] + } + }, + { + "old_path": "numpy/core/src/ucsnarrow.c", + "new_path": "numpy/core/src/ucsnarrow.c", + "filename": "ucsnarrow.c", + "extension": "c", + "change_type": "MODIFY", + "diff": "@@ -15,12 +15,12 @@ static int\n PyUCS2Buffer_FromUCS4(Py_UNICODE *ucs2, PyArray_UCS4 *ucs4, int ucs4length)\n {\n register int i;\n- int surrpairs = 0;\n+ int numucs2 = 0;\n PyArray_UCS4 chr;\n for (i=0; i 0xffff) {\n- surrpairs++;\n+\t\t\tnumucs2++;\n chr -= 0x10000L;\n *ucs2++ = 0xD800 + (Py_UNICODE) (chr >> 10);\n *ucs2++ = 0xDC00 + (Py_UNICODE) (chr & 0x03FF);\n@@ -28,8 +28,9 @@ PyUCS2Buffer_FromUCS4(Py_UNICODE *ucs2, PyArray_UCS4 *ucs4, int ucs4length)\n else {\n *ucs2++ = (Py_UNICODE) chr;\n }\n+\t\tnumucs2++;\n }\n- return ucs4length + surrpairs;\n+ return numucs2;\n }\n \n \n", + "added_lines": 4, + "deleted_lines": 3, + "source_code": "/* Functions only needed on narrow builds of Python \n for converting back and forth between the NumPy Unicode data-type (always 4-byte)\n and the Python Unicode scalar (2-bytes on a narrow build). \n */\n\n/* the ucs2 buffer must be large enough to hold 2*ucs4length characters\n due to the use of surrogate pairs. \n\n The return value is the number of ucs2 bytes used-up which\n is ucs4length + number of surrogate pairs found. \n\n values above 0xffff are converted to surrogate pairs. \n */\nstatic int\nPyUCS2Buffer_FromUCS4(Py_UNICODE *ucs2, PyArray_UCS4 *ucs4, int ucs4length)\n{\n register int i;\n int numucs2 = 0;\n PyArray_UCS4 chr;\n for (i=0; i 0xffff) {\n\t\t\tnumucs2++;\n chr -= 0x10000L;\n *ucs2++ = 0xD800 + (Py_UNICODE) (chr >> 10);\n *ucs2++ = 0xDC00 + (Py_UNICODE) (chr & 0x03FF);\n }\n else {\n *ucs2++ = (Py_UNICODE) chr;\n }\n\t\tnumucs2++;\n }\n return numucs2;\n}\n\n\n/* This converts a UCS2 buffer of the given length to UCS4 buffer.\n It converts up to ucs4len characters of UCS2\n\n It returns the number of characters converted which can\n be less than ucslen if there are surrogate pairs in ucs2.\n\n The return value is the actual size of the used part of the ucs4 buffer. \n*/\n\nstatic int\nPyUCS2Buffer_AsUCS4(Py_UNICODE *ucs2, PyArray_UCS4 *ucs4, int ucs2len, int ucs4len)\n{\n\tregister int i;\n\tregister PyArray_UCS4 chr;\n\tregister Py_UNICODE ch;\n\tregister int numchars=0;\n\n\tfor (i=0; (i < ucs2len) && (numchars < ucs4len); i++) {\n\t\tch = *ucs2++;\n\t\tif (ch >= 0xd800 && ch <= 0xdfff) {\n\t\t\t/* surrogate pair */\n\t\t\tchr = ((PyArray_UCS4)(ch-0xd800)) << 10;\n\t\t\tchr += *ucs2++ + 0x2400; /* -0xdc00 + 0x10000 */\n\t\t\ti++;\n\t\t}\n\t\telse {\n\t\t\tchr = (PyArray_UCS4) ch;\n\t\t}\n\t\t*ucs4++ = chr;\n\t\tnumchars++;\n\t}\n\treturn numchars;\n}\n\n\nstatic PyObject *\nMyPyUnicode_New(int length)\n{\n\tPyUnicodeObject *unicode;\n\tunicode = PyObject_New(PyUnicodeObject, &PyUnicode_Type);\n\tif (unicode == NULL) return NULL;\n\tunicode->str = PyMem_NEW(Py_UNICODE, length+1);\n\tif (!unicode->str) {\n\t\t_Py_ForgetReference((PyObject *)unicode);\n\t\tPyObject_Del(unicode);\n\t\treturn PyErr_NoMemory();\n\t}\n\tunicode->str[0] = 0;\n\tunicode->str[length] = 0;\n\tunicode->length = length;\n\tunicode->hash = -1;\n\tunicode->defenc = NULL;\n\treturn (PyObject *)unicode;\n}\n\nstatic int\nMyPyUnicode_Resize(PyUnicodeObject *uni, int length)\n{\t\n\tvoid *oldstr;\n\t\n\toldstr = uni->str;\n\tPyMem_RESIZE(uni->str, Py_UNICODE, length+1);\n\tif (!uni->str) {\n\t\tuni->str = oldstr;\n\t\tPyErr_NoMemory();\n\t\treturn -1;\n\t}\n\tuni->str[length] = 0;\n\tuni->length = length;\n\treturn 0;\n}\n", + "source_code_before": "/* Functions only needed on narrow builds of Python \n for converting back and forth between the NumPy Unicode data-type (always 4-byte)\n and the Python Unicode scalar (2-bytes on a narrow build). \n */\n\n/* the ucs2 buffer must be large enough to hold 2*ucs4length characters\n due to the use of surrogate pairs. \n\n The return value is the number of ucs2 bytes used-up which\n is ucs4length + number of surrogate pairs found. \n\n values above 0xffff are converted to surrogate pairs. \n */\nstatic int\nPyUCS2Buffer_FromUCS4(Py_UNICODE *ucs2, PyArray_UCS4 *ucs4, int ucs4length)\n{\n register int i;\n int surrpairs = 0;\n PyArray_UCS4 chr;\n for (i=0; i 0xffff) {\n surrpairs++;\n chr -= 0x10000L;\n *ucs2++ = 0xD800 + (Py_UNICODE) (chr >> 10);\n *ucs2++ = 0xDC00 + (Py_UNICODE) (chr & 0x03FF);\n }\n else {\n *ucs2++ = (Py_UNICODE) chr;\n }\n }\n return ucs4length + surrpairs;\n}\n\n\n/* This converts a UCS2 buffer of the given length to UCS4 buffer.\n It converts up to ucs4len characters of UCS2\n\n It returns the number of characters converted which can\n be less than ucslen if there are surrogate pairs in ucs2.\n\n The return value is the actual size of the used part of the ucs4 buffer. \n*/\n\nstatic int\nPyUCS2Buffer_AsUCS4(Py_UNICODE *ucs2, PyArray_UCS4 *ucs4, int ucs2len, int ucs4len)\n{\n\tregister int i;\n\tregister PyArray_UCS4 chr;\n\tregister Py_UNICODE ch;\n\tregister int numchars=0;\n\n\tfor (i=0; (i < ucs2len) && (numchars < ucs4len); i++) {\n\t\tch = *ucs2++;\n\t\tif (ch >= 0xd800 && ch <= 0xdfff) {\n\t\t\t/* surrogate pair */\n\t\t\tchr = ((PyArray_UCS4)(ch-0xd800)) << 10;\n\t\t\tchr += *ucs2++ + 0x2400; /* -0xdc00 + 0x10000 */\n\t\t\ti++;\n\t\t}\n\t\telse {\n\t\t\tchr = (PyArray_UCS4) ch;\n\t\t}\n\t\t*ucs4++ = chr;\n\t\tnumchars++;\n\t}\n\treturn numchars;\n}\n\n\nstatic PyObject *\nMyPyUnicode_New(int length)\n{\n\tPyUnicodeObject *unicode;\n\tunicode = PyObject_New(PyUnicodeObject, &PyUnicode_Type);\n\tif (unicode == NULL) return NULL;\n\tunicode->str = PyMem_NEW(Py_UNICODE, length+1);\n\tif (!unicode->str) {\n\t\t_Py_ForgetReference((PyObject *)unicode);\n\t\tPyObject_Del(unicode);\n\t\treturn PyErr_NoMemory();\n\t}\n\tunicode->str[0] = 0;\n\tunicode->str[length] = 0;\n\tunicode->length = length;\n\tunicode->hash = -1;\n\tunicode->defenc = NULL;\n\treturn (PyObject *)unicode;\n}\n\nstatic int\nMyPyUnicode_Resize(PyUnicodeObject *uni, int length)\n{\t\n\tvoid *oldstr;\n\t\n\toldstr = uni->str;\n\tPyMem_RESIZE(uni->str, Py_UNICODE, length+1);\n\tif (!uni->str) {\n\t\tuni->str = oldstr;\n\t\tPyErr_NoMemory();\n\t\treturn -1;\n\t}\n\tuni->str[length] = 0;\n\tuni->length = length;\n\treturn 0;\n}\n", + "methods": [ + { + "name": "PyUCS2Buffer_FromUCS4", + "long_name": "PyUCS2Buffer_FromUCS4( Py_UNICODE * ucs2 , PyArray_UCS4 * ucs4 , int ucs4length)", + "filename": "ucsnarrow.c", + "nloc": 20, + "complexity": 3, + "token_count": 112, + "parameters": [ + "ucs2", + "ucs4", + "ucs4length" + ], + "start_line": 15, + "end_line": 34, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 20, + "top_nesting_level": 0 + }, + { + "name": "PyUCS2Buffer_AsUCS4", + "long_name": "PyUCS2Buffer_AsUCS4( Py_UNICODE * ucs2 , PyArray_UCS4 * ucs4 , int ucs2len , int ucs4len)", + "filename": "ucsnarrow.c", + "nloc": 21, + "complexity": 5, + "token_count": 126, + "parameters": [ + "ucs2", + "ucs4", + "ucs2len", + "ucs4len" + ], + "start_line": 47, + "end_line": 69, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 23, + "top_nesting_level": 0 + }, + { + "name": "MyPyUnicode_New", + "long_name": "MyPyUnicode_New( int length)", + "filename": "ucsnarrow.c", + "nloc": 18, + "complexity": 3, + "token_count": 115, + "parameters": [ + "length" + ], + "start_line": 73, + "end_line": 90, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 18, + "top_nesting_level": 0 + }, + { + "name": "MyPyUnicode_Resize", + "long_name": "MyPyUnicode_Resize( PyUnicodeObject * uni , int length)", + "filename": "ucsnarrow.c", + "nloc": 14, + "complexity": 2, + "token_count": 75, + "parameters": [ + "uni", + "length" + ], + "start_line": 93, + "end_line": 107, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 15, + "top_nesting_level": 0 + } + ], + "methods_before": [ + { + "name": "PyUCS2Buffer_FromUCS4", + "long_name": "PyUCS2Buffer_FromUCS4( Py_UNICODE * ucs2 , PyArray_UCS4 * ucs4 , int ucs4length)", + "filename": "ucsnarrow.c", + "nloc": 19, + "complexity": 3, + "token_count": 111, + "parameters": [ + "ucs2", + "ucs4", + "ucs4length" + ], + "start_line": 15, + "end_line": 33, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 19, + "top_nesting_level": 0 + }, + { + "name": "PyUCS2Buffer_AsUCS4", + "long_name": "PyUCS2Buffer_AsUCS4( Py_UNICODE * ucs2 , PyArray_UCS4 * ucs4 , int ucs2len , int ucs4len)", + "filename": "ucsnarrow.c", + "nloc": 21, + "complexity": 5, + "token_count": 126, + "parameters": [ + "ucs2", + "ucs4", + "ucs2len", + "ucs4len" + ], + "start_line": 46, + "end_line": 68, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 23, + "top_nesting_level": 0 + }, + { + "name": "MyPyUnicode_New", + "long_name": "MyPyUnicode_New( int length)", + "filename": "ucsnarrow.c", + "nloc": 18, + "complexity": 3, + "token_count": 115, + "parameters": [ + "length" + ], + "start_line": 72, + "end_line": 89, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 18, + "top_nesting_level": 0 + }, + { + "name": "MyPyUnicode_Resize", + "long_name": "MyPyUnicode_Resize( PyUnicodeObject * uni , int length)", + "filename": "ucsnarrow.c", + "nloc": 14, + "complexity": 2, + "token_count": 75, + "parameters": [ + "uni", + "length" + ], + "start_line": 92, + "end_line": 106, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 15, + "top_nesting_level": 0 + } + ], + "changed_methods": [ + { + "name": "PyUCS2Buffer_FromUCS4", + "long_name": "PyUCS2Buffer_FromUCS4( Py_UNICODE * ucs2 , PyArray_UCS4 * ucs4 , int ucs4length)", + "filename": "ucsnarrow.c", + "nloc": 20, + "complexity": 3, + "token_count": 112, + "parameters": [ + "ucs2", + "ucs4", + "ucs4length" + ], + "start_line": 15, + "end_line": 34, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 20, + "top_nesting_level": 0 + } + ], + "nloc": 77, + "complexity": 13, + "token_count": 437, + "diff_parsed": { + "added": [ + " int numucs2 = 0;", + "\t\t\tnumucs2++;", + "\t\tnumucs2++;", + " return numucs2;" + ], + "deleted": [ + " int surrpairs = 0;", + " surrpairs++;", + " return ucs4length + surrpairs;" + ] + } + } + ] + }, + { + "hash": "2eb3a4b6e293a96465229ce18109b2ccae97ca70", + "msg": "Impl. rename() method for NumpyTest class that allows redefining mapping between module name and test_.py file name. Fixed bug with output_exception argument.", + "author": { + "name": "Pearu Peterson", + "email": "pearu.peterson@gmail.com" + }, + "committer": { + "name": "Pearu Peterson", + "email": "pearu.peterson@gmail.com" + }, + "author_date": "2006-02-09T12:38:13+00:00", + "author_timezone": 0, + "committer_date": "2006-02-09T12:38:13+00:00", + "committer_timezone": 0, + "branches": [ + "main" + ], + "in_main_branch": true, + "merge": false, + "parents": [ + "622e6867a9b500d30333d157eaffdf44d3c52fe1" + ], + "project_name": "repo_copy", + "project_path": "/tmp/tmpdjwupkfu/repo_copy", + "deletions": 3, + "insertions": 20, + "lines": 23, + "files": 1, + "dmm_unit_size": 0.6666666666666666, + "dmm_unit_complexity": 0.6666666666666666, + "dmm_unit_interfacing": 0.6666666666666666, + "modified_files": [ + { + "old_path": "numpy/testing/numpytest.py", + "new_path": "numpy/testing/numpytest.py", + "filename": "numpytest.py", + "extension": "py", + "change_type": "MODIFY", + "diff": "@@ -206,6 +206,8 @@ class NumpyTest:\n \n Package is supposed to contain a directory tests/\n with test_*.py files where * refers to the names of submodules.\n+ See .rename() method to redefine name mapping between test_*.py files\n+ and names of submodules.\n \n test_*.py files are supposed to define a classes, derived\n from NumpyTestCase or unittest.TestCase, with methods having\n@@ -221,8 +223,19 @@ def __init__(self, package=None):\n if package is None:\n from numpy.distutils.misc_util import get_frame\n f = get_frame(1)\n- package = f.f_locals['__name__']\n+ package = f.f_locals.get('__name__',f.f_globals.get('__name__',None))\n+ assert package is not None\n self.package = package\n+ self._rename_map = {}\n+\n+ def rename(self, **kws):\n+ \"\"\" Apply renaming submodule test file test_.py to test_.py.\n+ Usage: self.rename(name='newname') before calling self.test() method.\n+ If 'newname' is None, then no tests will be executed for a given module.\n+ \"\"\"\n+ for k,v in kws.items():\n+ self._rename_map[k] = v\n+ return\n \n def _module_str(self, module):\n filename = module.__file__[-30:]\n@@ -261,6 +274,10 @@ def _get_module_tests(self,module,level,verbosity):\n if short_module_name=='__init__':\n short_module_name = module.__name__.split('.')[-1]\n \n+ short_module_name = self._rename_map.get(short_module_name,short_module_name)\n+ if short_module_name is None:\n+ return []\n+\n test_dir = os.path.join(d,'tests')\n test_file = os.path.join(test_dir,'test_'+short_module_name+'.py')\n \n@@ -306,7 +323,7 @@ def _get_module_tests(self,module,level,verbosity):\n os.remove(test_file+pref+'c')\n except:\n self.warn(' !! FAILURE importing tests for %s' % mstr(module))\n- output_exception(self.warn)\n+ output_exception(sys.stderr)\n return []\n \n self.test_files.append(test_file)\n@@ -322,7 +339,7 @@ def _get_suite_list(self, test_module, level, module_name='__main__'):\n return total_suite._tests\n except:\n self.warn(' !! FAILURE building tests for %s' % mstr(test_module))\n- output_exception(self.warn)\n+ output_exception(sys.stderr)\n return []\n suite_list = []\n for name in dir(test_module):\n", + "added_lines": 20, + "deleted_lines": 3, + "source_code": "\nimport os\nimport sys\nimport imp\nimport types\nimport unittest\nimport traceback\n\n__all__ = ['set_package_path', 'set_local_path', 'restore_path',\n 'IgnoreException', 'NumpyTestCase', 'NumpyTest',\n 'ScipyTestCase', 'ScipyTest', # for backward compatibility\n ]\n\nDEBUG=0\nget_frame = sys._getframe\nfrom utils import jiffies\n\n\nclass IgnoreException(Exception):\n \"Ignoring this exception due to disabled feature\"\n\n\ndef set_package_path(level=1):\n \"\"\" Prepend package directory to sys.path.\n\n set_package_path should be called from a test_file.py that\n satisfies the following tree structure:\n\n //test_file.py\n\n Then the first existing path name from the following list\n\n /build/lib.-\n /..\n\n is prepended to sys.path.\n The caller is responsible for removing this path by using\n\n restore_path()\n \"\"\"\n from distutils.util import get_platform\n f = get_frame(level)\n if f.f_locals['__name__']=='__main__':\n testfile = sys.argv[0]\n else:\n testfile = f.f_locals['__file__']\n d = os.path.dirname(os.path.dirname(os.path.abspath(testfile)))\n d1 = os.path.join(d,'build','lib.%s-%s'%(get_platform(),sys.version[:3]))\n if not os.path.isdir(d1):\n d1 = os.path.dirname(d)\n if DEBUG:\n print 'Inserting %r to sys.path' % (d1)\n sys.path.insert(0,d1)\n return\n\n\ndef set_local_path(reldir='', level=1):\n \"\"\" Prepend local directory to sys.path.\n\n The caller is responsible for removing this path by using\n\n restore_path()\n \"\"\"\n f = get_frame(level)\n if f.f_locals['__name__']=='__main__':\n testfile = sys.argv[0]\n else:\n testfile = f.f_locals['__file__']\n local_path = os.path.join(os.path.dirname(os.path.abspath(testfile)),reldir)\n if DEBUG:\n print 'Inserting %r to sys.path' % (local_path)\n sys.path.insert(0,local_path)\n return\n\n\ndef restore_path():\n if DEBUG:\n print 'Removing %r from sys.path' % (sys.path[0])\n del sys.path[0]\n return\n\n\ndef output_exception(printstream = sys.stdout):\n try:\n type, value, tb = sys.exc_info()\n info = traceback.extract_tb(tb)\n #this is more verbose\n #traceback.print_exc()\n filename, lineno, function, text = info[-1] # last line only\n print>>printstream, \"%s:%d: %s: %s (in %s)\" %\\\n (filename, lineno, type.__name__, str(value), function)\n finally:\n type = value = tb = None # clean up\n return\n\n\nclass _dummy_stream:\n def __init__(self,stream):\n self.data = []\n self.stream = stream\n def write(self,message):\n if not self.data and not message.startswith('E'):\n self.stream.write(message)\n self.stream.flush()\n message = ''\n self.data.append(message)\n def writeln(self,message):\n self.write(message+'\\n')\n\n\nclass NumpyTestCase (unittest.TestCase):\n\n def measure(self,code_str,times=1):\n \"\"\" Return elapsed time for executing code_str in the\n namespace of the caller for given times.\n \"\"\"\n frame = get_frame(1)\n locs,globs = frame.f_locals,frame.f_globals\n code = compile(code_str,\n 'NumpyTestCase runner for '+self.__class__.__name__,\n 'exec')\n i = 0\n elapsed = jiffies()\n while i>sys.stderr,'Warning: %s' % (message)\n sys.stderr.flush()\n def info(self, message):\n print>>sys.stdout, message\n sys.stdout.flush()\n\nScipyTestCase = NumpyTestCase\n\ndef _get_all_method_names(cls):\n names = dir(cls)\n if sys.version[:3]<='2.1':\n for b in cls.__bases__:\n for n in dir(b)+_get_all_method_names(b):\n if n not in names:\n names.append(n)\n return names\n\n\n# for debug build--check for memory leaks during the test.\nclass _SciPyTextTestResult(unittest._TextTestResult):\n def startTest(self, test):\n unittest._TextTestResult.startTest(self, test)\n if self.showAll:\n N = len(sys.getobjects(0))\n self._totnumobj = N\n self._totrefcnt = sys.gettotalrefcount()\n return\n\n def stopTest(self, test):\n if self.showAll:\n N = len(sys.getobjects(0))\n self.stream.write(\"objects: %d ===> %d; \" % (self._totnumobj, N))\n self.stream.write(\"refcnts: %d ===> %d\\n\" % (self._totrefcnt,\n sys.gettotalrefcount()))\n return\n\nclass SciPyTextTestRunner(unittest.TextTestRunner):\n def _makeResult(self):\n return _SciPyTextTestResult(self.stream, self.descriptions, self.verbosity)\n \n\nclass NumpyTest:\n \"\"\" Numpy tests site manager.\n\n Usage:\n >>> NumpyTest().test(level=1,verbosity=1)\n\n is package name or its module object.\n\n Package is supposed to contain a directory tests/\n with test_*.py files where * refers to the names of submodules.\n See .rename() method to redefine name mapping between test_*.py files\n and names of submodules.\n\n test_*.py files are supposed to define a classes, derived\n from NumpyTestCase or unittest.TestCase, with methods having\n names starting with test or bench or check.\n\n And that is it! No need to implement test or test_suite functions\n in each .py file.\n\n Also old styled test_suite(level=1) hooks are supported but\n soon to be removed.\n \"\"\"\n def __init__(self, package=None):\n if package is None:\n from numpy.distutils.misc_util import get_frame\n f = get_frame(1)\n package = f.f_locals.get('__name__',f.f_globals.get('__name__',None))\n assert package is not None\n self.package = package\n self._rename_map = {}\n\n def rename(self, **kws):\n \"\"\" Apply renaming submodule test file test_.py to test_.py.\n Usage: self.rename(name='newname') before calling self.test() method.\n If 'newname' is None, then no tests will be executed for a given module.\n \"\"\"\n for k,v in kws.items():\n self._rename_map[k] = v\n return\n\n def _module_str(self, module):\n filename = module.__file__[-30:]\n if filename!=module.__file__:\n filename = '...'+filename\n return '' % (`module.__name__`, `filename`)\n\n def _get_method_names(self,clsobj,level):\n names = []\n for mthname in _get_all_method_names(clsobj):\n if mthname[:5] not in ['bench','check'] \\\n and mthname[:4] not in ['test']:\n continue\n mth = getattr(clsobj, mthname)\n if type(mth) is not types.MethodType:\n continue\n d = mth.im_func.func_defaults\n if d is not None:\n mthlevel = d[0]\n else:\n mthlevel = 1\n if level>=mthlevel:\n if mthname not in names:\n names.append(mthname)\n for base in clsobj.__bases__:\n for n in self._get_method_names(base,level):\n if n not in names:\n names.append(n) \n return names\n\n def _get_module_tests(self,module,level,verbosity):\n mstr = self._module_str\n d,f = os.path.split(module.__file__)\n\n short_module_name = os.path.splitext(os.path.basename(f))[0]\n if short_module_name=='__init__':\n short_module_name = module.__name__.split('.')[-1]\n\n short_module_name = self._rename_map.get(short_module_name,short_module_name)\n if short_module_name is None:\n return []\n\n test_dir = os.path.join(d,'tests')\n test_file = os.path.join(test_dir,'test_'+short_module_name+'.py')\n\n local_test_dir = os.path.join(os.getcwd(),'tests')\n local_test_file = os.path.join(local_test_dir,\n 'test_'+short_module_name+'.py')\n if os.path.basename(os.path.dirname(local_test_dir)) \\\n == os.path.basename(os.path.dirname(test_dir)) \\\n and os.path.isfile(local_test_file):\n test_file = local_test_file\n\n if not os.path.isfile(test_file):\n if short_module_name[:5]=='info_' \\\n and short_module_name[5:]==module.__name__.split('.')[-2]:\n return []\n if short_module_name in ['__cvs_version__','__svn_version__']:\n return []\n if short_module_name[-8:]=='_version' \\\n and short_module_name[:-8]==module.__name__.split('.')[-2]:\n return []\n if verbosity>1:\n self.warn(test_file)\n self.warn(' !! No test file %r found for %s' \\\n % (os.path.basename(test_file), mstr(module)))\n return []\n\n if test_file in self.test_files:\n return []\n \n try:\n if sys.version[:3]=='2.1':\n # Workaround for Python 2.1 .pyc file generator bug\n import random\n pref = '-nopyc'+`random.randint(1,100)`\n else:\n pref = ''\n f = open(test_file,'r')\n test_module = imp.load_module(\\\n module.__name__+'.test_'+short_module_name+pref,\n f, test_file+pref,('.py', 'r', 1))\n f.close()\n if sys.version[:3]=='2.1' and os.path.isfile(test_file+pref+'c'):\n os.remove(test_file+pref+'c')\n except:\n self.warn(' !! FAILURE importing tests for %s' % mstr(module))\n output_exception(sys.stderr)\n return []\n\n self.test_files.append(test_file)\n\n return self._get_suite_list(test_module, level, module.__name__)\n\n def _get_suite_list(self, test_module, level, module_name='__main__'):\n mstr = self._module_str\n if hasattr(test_module,'test_suite'):\n # Using old styled test suite\n try:\n total_suite = test_module.test_suite(level)\n return total_suite._tests\n except:\n self.warn(' !! FAILURE building tests for %s' % mstr(test_module))\n output_exception(sys.stderr)\n return []\n suite_list = []\n for name in dir(test_module):\n obj = getattr(test_module, name)\n if type(obj) is not type(unittest.TestCase) \\\n or not issubclass(obj, unittest.TestCase) \\\n or obj.__name__[:4] != 'test':\n continue\n for mthname in self._get_method_names(obj,level):\n suite = obj(mthname)\n if getattr(suite,'isrunnable',lambda mthname:1)(mthname):\n suite_list.append(suite)\n self.info(' Found %s tests for %s' % (len(suite_list),module_name))\n return suite_list\n\n def test(self,level=1,verbosity=1):\n \"\"\" Run Numpy module test suite with level and verbosity.\n \"\"\"\n if type(self.package) is type(''):\n exec 'import %s as this_package' % (self.package)\n else:\n this_package = self.package\n\n package_name = this_package.__name__\n\n modules = []\n for name, module in sys.modules.items():\n if package_name != name[:len(package_name)] \\\n or module is None:\n continue\n if os.path.basename(os.path.dirname(module.__file__))=='tests':\n continue\n modules.append(module)\n\n self.test_files = []\n suites = []\n for module in modules:\n suites.extend(self._get_module_tests(module, level, verbosity))\n\n suites.extend(self._get_suite_list(sys.modules[package_name], level))\n\n all_tests = unittest.TestSuite(suites)\n #if hasattr(sys,'getobjects'):\n # runner = SciPyTextTestRunner(verbosity=verbosity)\n #else:\n runner = unittest.TextTestRunner(verbosity=verbosity)\n # Use the builtin displayhook. If the tests are being run\n # under IPython (for instance), any doctest test suites will\n # fail otherwise.\n old_displayhook = sys.displayhook\n sys.displayhook = sys.__displayhook__\n try:\n runner.run(all_tests)\n finally:\n sys.displayhook = old_displayhook\n return runner\n\n def run(self):\n \"\"\" Run Numpy module test suite with level and verbosity\n taken from sys.argv. Requires optparse module.\n \"\"\"\n try:\n from optparse import OptionParser\n except ImportError:\n self.warn('Failed to import optparse module, ignoring.')\n return self.test()\n usage = r'usage: %prog [-v ] [-l ]'\n parser = OptionParser(usage)\n parser.add_option(\"-v\", \"--verbosity\",\n action=\"store\",\n dest=\"verbosity\",\n default=1,\n type='int')\n parser.add_option(\"-l\", \"--level\",\n action=\"store\",\n dest=\"level\",\n default=1,\n type='int')\n (options, args) = parser.parse_args()\n self.test(options.level,options.verbosity)\n return\n\n def warn(self, message):\n print>>sys.stderr,'Warning: %s' % (message)\n sys.stderr.flush()\n def info(self, message):\n print>>sys.stdout, message\n sys.stdout.flush()\n\nScipyTest = NumpyTest\n", + "source_code_before": "\nimport os\nimport sys\nimport imp\nimport types\nimport unittest\nimport traceback\n\n__all__ = ['set_package_path', 'set_local_path', 'restore_path',\n 'IgnoreException', 'NumpyTestCase', 'NumpyTest',\n 'ScipyTestCase', 'ScipyTest', # for backward compatibility\n ]\n\nDEBUG=0\nget_frame = sys._getframe\nfrom utils import jiffies\n\n\nclass IgnoreException(Exception):\n \"Ignoring this exception due to disabled feature\"\n\n\ndef set_package_path(level=1):\n \"\"\" Prepend package directory to sys.path.\n\n set_package_path should be called from a test_file.py that\n satisfies the following tree structure:\n\n //test_file.py\n\n Then the first existing path name from the following list\n\n /build/lib.-\n /..\n\n is prepended to sys.path.\n The caller is responsible for removing this path by using\n\n restore_path()\n \"\"\"\n from distutils.util import get_platform\n f = get_frame(level)\n if f.f_locals['__name__']=='__main__':\n testfile = sys.argv[0]\n else:\n testfile = f.f_locals['__file__']\n d = os.path.dirname(os.path.dirname(os.path.abspath(testfile)))\n d1 = os.path.join(d,'build','lib.%s-%s'%(get_platform(),sys.version[:3]))\n if not os.path.isdir(d1):\n d1 = os.path.dirname(d)\n if DEBUG:\n print 'Inserting %r to sys.path' % (d1)\n sys.path.insert(0,d1)\n return\n\n\ndef set_local_path(reldir='', level=1):\n \"\"\" Prepend local directory to sys.path.\n\n The caller is responsible for removing this path by using\n\n restore_path()\n \"\"\"\n f = get_frame(level)\n if f.f_locals['__name__']=='__main__':\n testfile = sys.argv[0]\n else:\n testfile = f.f_locals['__file__']\n local_path = os.path.join(os.path.dirname(os.path.abspath(testfile)),reldir)\n if DEBUG:\n print 'Inserting %r to sys.path' % (local_path)\n sys.path.insert(0,local_path)\n return\n\n\ndef restore_path():\n if DEBUG:\n print 'Removing %r from sys.path' % (sys.path[0])\n del sys.path[0]\n return\n\n\ndef output_exception(printstream = sys.stdout):\n try:\n type, value, tb = sys.exc_info()\n info = traceback.extract_tb(tb)\n #this is more verbose\n #traceback.print_exc()\n filename, lineno, function, text = info[-1] # last line only\n print>>printstream, \"%s:%d: %s: %s (in %s)\" %\\\n (filename, lineno, type.__name__, str(value), function)\n finally:\n type = value = tb = None # clean up\n return\n\n\nclass _dummy_stream:\n def __init__(self,stream):\n self.data = []\n self.stream = stream\n def write(self,message):\n if not self.data and not message.startswith('E'):\n self.stream.write(message)\n self.stream.flush()\n message = ''\n self.data.append(message)\n def writeln(self,message):\n self.write(message+'\\n')\n\n\nclass NumpyTestCase (unittest.TestCase):\n\n def measure(self,code_str,times=1):\n \"\"\" Return elapsed time for executing code_str in the\n namespace of the caller for given times.\n \"\"\"\n frame = get_frame(1)\n locs,globs = frame.f_locals,frame.f_globals\n code = compile(code_str,\n 'NumpyTestCase runner for '+self.__class__.__name__,\n 'exec')\n i = 0\n elapsed = jiffies()\n while i>sys.stderr,'Warning: %s' % (message)\n sys.stderr.flush()\n def info(self, message):\n print>>sys.stdout, message\n sys.stdout.flush()\n\nScipyTestCase = NumpyTestCase\n\ndef _get_all_method_names(cls):\n names = dir(cls)\n if sys.version[:3]<='2.1':\n for b in cls.__bases__:\n for n in dir(b)+_get_all_method_names(b):\n if n not in names:\n names.append(n)\n return names\n\n\n# for debug build--check for memory leaks during the test.\nclass _SciPyTextTestResult(unittest._TextTestResult):\n def startTest(self, test):\n unittest._TextTestResult.startTest(self, test)\n if self.showAll:\n N = len(sys.getobjects(0))\n self._totnumobj = N\n self._totrefcnt = sys.gettotalrefcount()\n return\n\n def stopTest(self, test):\n if self.showAll:\n N = len(sys.getobjects(0))\n self.stream.write(\"objects: %d ===> %d; \" % (self._totnumobj, N))\n self.stream.write(\"refcnts: %d ===> %d\\n\" % (self._totrefcnt,\n sys.gettotalrefcount()))\n return\n\nclass SciPyTextTestRunner(unittest.TextTestRunner):\n def _makeResult(self):\n return _SciPyTextTestResult(self.stream, self.descriptions, self.verbosity)\n \n\nclass NumpyTest:\n \"\"\" Numpy tests site manager.\n\n Usage:\n >>> NumpyTest().test(level=1,verbosity=1)\n\n is package name or its module object.\n\n Package is supposed to contain a directory tests/\n with test_*.py files where * refers to the names of submodules.\n\n test_*.py files are supposed to define a classes, derived\n from NumpyTestCase or unittest.TestCase, with methods having\n names starting with test or bench or check.\n\n And that is it! No need to implement test or test_suite functions\n in each .py file.\n\n Also old styled test_suite(level=1) hooks are supported but\n soon to be removed.\n \"\"\"\n def __init__(self, package=None):\n if package is None:\n from numpy.distutils.misc_util import get_frame\n f = get_frame(1)\n package = f.f_locals['__name__']\n self.package = package\n\n def _module_str(self, module):\n filename = module.__file__[-30:]\n if filename!=module.__file__:\n filename = '...'+filename\n return '' % (`module.__name__`, `filename`)\n\n def _get_method_names(self,clsobj,level):\n names = []\n for mthname in _get_all_method_names(clsobj):\n if mthname[:5] not in ['bench','check'] \\\n and mthname[:4] not in ['test']:\n continue\n mth = getattr(clsobj, mthname)\n if type(mth) is not types.MethodType:\n continue\n d = mth.im_func.func_defaults\n if d is not None:\n mthlevel = d[0]\n else:\n mthlevel = 1\n if level>=mthlevel:\n if mthname not in names:\n names.append(mthname)\n for base in clsobj.__bases__:\n for n in self._get_method_names(base,level):\n if n not in names:\n names.append(n) \n return names\n\n def _get_module_tests(self,module,level,verbosity):\n mstr = self._module_str\n d,f = os.path.split(module.__file__)\n\n short_module_name = os.path.splitext(os.path.basename(f))[0]\n if short_module_name=='__init__':\n short_module_name = module.__name__.split('.')[-1]\n\n test_dir = os.path.join(d,'tests')\n test_file = os.path.join(test_dir,'test_'+short_module_name+'.py')\n\n local_test_dir = os.path.join(os.getcwd(),'tests')\n local_test_file = os.path.join(local_test_dir,\n 'test_'+short_module_name+'.py')\n if os.path.basename(os.path.dirname(local_test_dir)) \\\n == os.path.basename(os.path.dirname(test_dir)) \\\n and os.path.isfile(local_test_file):\n test_file = local_test_file\n\n if not os.path.isfile(test_file):\n if short_module_name[:5]=='info_' \\\n and short_module_name[5:]==module.__name__.split('.')[-2]:\n return []\n if short_module_name in ['__cvs_version__','__svn_version__']:\n return []\n if short_module_name[-8:]=='_version' \\\n and short_module_name[:-8]==module.__name__.split('.')[-2]:\n return []\n if verbosity>1:\n self.warn(test_file)\n self.warn(' !! No test file %r found for %s' \\\n % (os.path.basename(test_file), mstr(module)))\n return []\n\n if test_file in self.test_files:\n return []\n \n try:\n if sys.version[:3]=='2.1':\n # Workaround for Python 2.1 .pyc file generator bug\n import random\n pref = '-nopyc'+`random.randint(1,100)`\n else:\n pref = ''\n f = open(test_file,'r')\n test_module = imp.load_module(\\\n module.__name__+'.test_'+short_module_name+pref,\n f, test_file+pref,('.py', 'r', 1))\n f.close()\n if sys.version[:3]=='2.1' and os.path.isfile(test_file+pref+'c'):\n os.remove(test_file+pref+'c')\n except:\n self.warn(' !! FAILURE importing tests for %s' % mstr(module))\n output_exception(self.warn)\n return []\n\n self.test_files.append(test_file)\n\n return self._get_suite_list(test_module, level, module.__name__)\n\n def _get_suite_list(self, test_module, level, module_name='__main__'):\n mstr = self._module_str\n if hasattr(test_module,'test_suite'):\n # Using old styled test suite\n try:\n total_suite = test_module.test_suite(level)\n return total_suite._tests\n except:\n self.warn(' !! FAILURE building tests for %s' % mstr(test_module))\n output_exception(self.warn)\n return []\n suite_list = []\n for name in dir(test_module):\n obj = getattr(test_module, name)\n if type(obj) is not type(unittest.TestCase) \\\n or not issubclass(obj, unittest.TestCase) \\\n or obj.__name__[:4] != 'test':\n continue\n for mthname in self._get_method_names(obj,level):\n suite = obj(mthname)\n if getattr(suite,'isrunnable',lambda mthname:1)(mthname):\n suite_list.append(suite)\n self.info(' Found %s tests for %s' % (len(suite_list),module_name))\n return suite_list\n\n def test(self,level=1,verbosity=1):\n \"\"\" Run Numpy module test suite with level and verbosity.\n \"\"\"\n if type(self.package) is type(''):\n exec 'import %s as this_package' % (self.package)\n else:\n this_package = self.package\n\n package_name = this_package.__name__\n\n modules = []\n for name, module in sys.modules.items():\n if package_name != name[:len(package_name)] \\\n or module is None:\n continue\n if os.path.basename(os.path.dirname(module.__file__))=='tests':\n continue\n modules.append(module)\n\n self.test_files = []\n suites = []\n for module in modules:\n suites.extend(self._get_module_tests(module, level, verbosity))\n\n suites.extend(self._get_suite_list(sys.modules[package_name], level))\n\n all_tests = unittest.TestSuite(suites)\n #if hasattr(sys,'getobjects'):\n # runner = SciPyTextTestRunner(verbosity=verbosity)\n #else:\n runner = unittest.TextTestRunner(verbosity=verbosity)\n # Use the builtin displayhook. If the tests are being run\n # under IPython (for instance), any doctest test suites will\n # fail otherwise.\n old_displayhook = sys.displayhook\n sys.displayhook = sys.__displayhook__\n try:\n runner.run(all_tests)\n finally:\n sys.displayhook = old_displayhook\n return runner\n\n def run(self):\n \"\"\" Run Numpy module test suite with level and verbosity\n taken from sys.argv. Requires optparse module.\n \"\"\"\n try:\n from optparse import OptionParser\n except ImportError:\n self.warn('Failed to import optparse module, ignoring.')\n return self.test()\n usage = r'usage: %prog [-v ] [-l ]'\n parser = OptionParser(usage)\n parser.add_option(\"-v\", \"--verbosity\",\n action=\"store\",\n dest=\"verbosity\",\n default=1,\n type='int')\n parser.add_option(\"-l\", \"--level\",\n action=\"store\",\n dest=\"level\",\n default=1,\n type='int')\n (options, args) = parser.parse_args()\n self.test(options.level,options.verbosity)\n return\n\n def warn(self, message):\n print>>sys.stderr,'Warning: %s' % (message)\n sys.stderr.flush()\n def info(self, message):\n print>>sys.stdout, message\n sys.stdout.flush()\n\nScipyTest = NumpyTest\n", + "methods": [ + { + "name": "set_package_path", + "long_name": "set_package_path( level = 1 )", + "filename": "numpytest.py", + "nloc": 15, + "complexity": 4, + "token_count": 141, + "parameters": [ + "level" + ], + "start_line": 23, + "end_line": 54, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 32, + "top_nesting_level": 0 + }, + { + "name": "set_local_path", + "long_name": "set_local_path( reldir = '' , level = 1 )", + "filename": "numpytest.py", + "nloc": 11, + "complexity": 3, + "token_count": 92, + "parameters": [ + "reldir", + "level" + ], + "start_line": 57, + "end_line": 73, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 17, + "top_nesting_level": 0 + }, + { + "name": "restore_path", + "long_name": "restore_path( )", + "filename": "numpytest.py", + "nloc": 5, + "complexity": 2, + "token_count": 26, + "parameters": [], + "start_line": 76, + "end_line": 80, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 5, + "top_nesting_level": 0 + }, + { + "name": "output_exception", + "long_name": "output_exception( printstream = sys . stdout )", + "filename": "numpytest.py", + "nloc": 10, + "complexity": 2, + "token_count": 77, + "parameters": [ + "printstream" + ], + "start_line": 83, + "end_line": 94, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 12, + "top_nesting_level": 0 + }, + { + "name": "__init__", + "long_name": "__init__( self , stream )", + "filename": "numpytest.py", + "nloc": 3, + "complexity": 1, + "token_count": 18, + "parameters": [ + "self", + "stream" + ], + "start_line": 98, + "end_line": 100, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "write", + "long_name": "write( self , message )", + "filename": "numpytest.py", + "nloc": 6, + "complexity": 3, + "token_count": 47, + "parameters": [ + "self", + "message" + ], + "start_line": 101, + "end_line": 106, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 6, + "top_nesting_level": 1 + }, + { + "name": "writeln", + "long_name": "writeln( self , message )", + "filename": "numpytest.py", + "nloc": 2, + "complexity": 1, + "token_count": 15, + "parameters": [ + "self", + "message" + ], + "start_line": 107, + "end_line": 108, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 1 + }, + { + "name": "measure", + "long_name": "measure( self , code_str , times = 1 )", + "filename": "numpytest.py", + "nloc": 13, + "complexity": 2, + "token_count": 80, + "parameters": [ + "self", + "code_str", + "times" + ], + "start_line": 113, + "end_line": 128, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 16, + "top_nesting_level": 1 + }, + { + "name": "__call__", + "long_name": "__call__( self , result = None )", + "filename": "numpytest.py", + "nloc": 25, + "complexity": 6, + "token_count": 229, + "parameters": [ + "self", + "result" + ], + "start_line": 130, + "end_line": 155, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 26, + "top_nesting_level": 1 + }, + { + "name": "warn", + "long_name": "warn( self , message )", + "filename": "numpytest.py", + "nloc": 3, + "complexity": 1, + "token_count": 26, + "parameters": [ + "self", + "message" + ], + "start_line": 157, + "end_line": 159, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "info", + "long_name": "info( self , message )", + "filename": "numpytest.py", + "nloc": 3, + "complexity": 1, + "token_count": 22, + "parameters": [ + "self", + "message" + ], + "start_line": 160, + "end_line": 162, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "_get_all_method_names", + "long_name": "_get_all_method_names( cls )", + "filename": "numpytest.py", + "nloc": 8, + "complexity": 5, + "token_count": 56, + "parameters": [ + "cls" + ], + "start_line": 166, + "end_line": 173, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 8, + "top_nesting_level": 0 + }, + { + "name": "startTest", + "long_name": "startTest( self , test )", + "filename": "numpytest.py", + "nloc": 7, + "complexity": 2, + "token_count": 48, + "parameters": [ + "self", + "test" + ], + "start_line": 178, + "end_line": 184, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 7, + "top_nesting_level": 1 + }, + { + "name": "stopTest", + "long_name": "stopTest( self , test )", + "filename": "numpytest.py", + "nloc": 7, + "complexity": 2, + "token_count": 60, + "parameters": [ + "self", + "test" + ], + "start_line": 186, + "end_line": 192, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 7, + "top_nesting_level": 1 + }, + { + "name": "_makeResult", + "long_name": "_makeResult( self )", + "filename": "numpytest.py", + "nloc": 2, + "complexity": 1, + "token_count": 20, + "parameters": [ + "self" + ], + "start_line": 195, + "end_line": 196, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 1 + }, + { + "name": "__init__", + "long_name": "__init__( self , package = None )", + "filename": "numpytest.py", + "nloc": 8, + "complexity": 2, + "token_count": 65, + "parameters": [ + "self", + "package" + ], + "start_line": 222, + "end_line": 229, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 8, + "top_nesting_level": 1 + }, + { + "name": "rename", + "long_name": "rename( self , ** kws )", + "filename": "numpytest.py", + "nloc": 4, + "complexity": 2, + "token_count": 29, + "parameters": [ + "self", + "kws" + ], + "start_line": 231, + "end_line": 238, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 8, + "top_nesting_level": 1 + }, + { + "name": "_module_str", + "long_name": "_module_str( self , module )", + "filename": "numpytest.py", + "nloc": 5, + "complexity": 2, + "token_count": 43, + "parameters": [ + "self", + "module" + ], + "start_line": 240, + "end_line": 244, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 5, + "top_nesting_level": 1 + }, + { + "name": "_get_method_names", + "long_name": "_get_method_names( self , clsobj , level )", + "filename": "numpytest.py", + "nloc": 22, + "complexity": 11, + "token_count": 142, + "parameters": [ + "self", + "clsobj", + "level" + ], + "start_line": 246, + "end_line": 267, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 22, + "top_nesting_level": 1 + }, + { + "name": "_get_module_tests", + "long_name": "_get_module_tests( self , module , level , verbosity )", + "filename": "numpytest.py", + "nloc": 53, + "complexity": 17, + "token_count": 487, + "parameters": [ + "self", + "module", + "level", + "verbosity" + ], + "start_line": 269, + "end_line": 331, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 63, + "top_nesting_level": 1 + }, + { + "name": "_get_suite_list", + "long_name": "_get_suite_list( self , test_module , level , module_name = '__main__' )", + "filename": "numpytest.py", + "nloc": 23, + "complexity": 9, + "token_count": 176, + "parameters": [ + "self", + "test_module", + "level", + "module_name" + ], + "start_line": 333, + "end_line": 356, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 24, + "top_nesting_level": 1 + }, + { + "name": "test", + "long_name": "test( self , level = 1 , verbosity = 1 )", + "filename": "numpytest.py", + "nloc": 28, + "complexity": 8, + "token_count": 205, + "parameters": [ + "self", + "level", + "verbosity" + ], + "start_line": 358, + "end_line": 398, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 41, + "top_nesting_level": 1 + }, + { + "name": "run", + "long_name": "run( self )", + "filename": "numpytest.py", + "nloc": 21, + "complexity": 2, + "token_count": 109, + "parameters": [ + "self" + ], + "start_line": 400, + "end_line": 423, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 24, + "top_nesting_level": 1 + }, + { + "name": "warn", + "long_name": "warn( self , message )", + "filename": "numpytest.py", + "nloc": 3, + "complexity": 1, + "token_count": 26, + "parameters": [ + "self", + "message" + ], + "start_line": 425, + "end_line": 427, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "info", + "long_name": "info( self , message )", + "filename": "numpytest.py", + "nloc": 3, + "complexity": 1, + "token_count": 22, + "parameters": [ + "self", + "message" + ], + "start_line": 428, + "end_line": 430, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + } + ], + "methods_before": [ + { + "name": "set_package_path", + "long_name": "set_package_path( level = 1 )", + "filename": "numpytest.py", + "nloc": 15, + "complexity": 4, + "token_count": 141, + "parameters": [ + "level" + ], + "start_line": 23, + "end_line": 54, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 32, + "top_nesting_level": 0 + }, + { + "name": "set_local_path", + "long_name": "set_local_path( reldir = '' , level = 1 )", + "filename": "numpytest.py", + "nloc": 11, + "complexity": 3, + "token_count": 92, + "parameters": [ + "reldir", + "level" + ], + "start_line": 57, + "end_line": 73, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 17, + "top_nesting_level": 0 + }, + { + "name": "restore_path", + "long_name": "restore_path( )", + "filename": "numpytest.py", + "nloc": 5, + "complexity": 2, + "token_count": 26, + "parameters": [], + "start_line": 76, + "end_line": 80, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 5, + "top_nesting_level": 0 + }, + { + "name": "output_exception", + "long_name": "output_exception( printstream = sys . stdout )", + "filename": "numpytest.py", + "nloc": 10, + "complexity": 2, + "token_count": 77, + "parameters": [ + "printstream" + ], + "start_line": 83, + "end_line": 94, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 12, + "top_nesting_level": 0 + }, + { + "name": "__init__", + "long_name": "__init__( self , stream )", + "filename": "numpytest.py", + "nloc": 3, + "complexity": 1, + "token_count": 18, + "parameters": [ + "self", + "stream" + ], + "start_line": 98, + "end_line": 100, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "write", + "long_name": "write( self , message )", + "filename": "numpytest.py", + "nloc": 6, + "complexity": 3, + "token_count": 47, + "parameters": [ + "self", + "message" + ], + "start_line": 101, + "end_line": 106, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 6, + "top_nesting_level": 1 + }, + { + "name": "writeln", + "long_name": "writeln( self , message )", + "filename": "numpytest.py", + "nloc": 2, + "complexity": 1, + "token_count": 15, + "parameters": [ + "self", + "message" + ], + "start_line": 107, + "end_line": 108, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 1 + }, + { + "name": "measure", + "long_name": "measure( self , code_str , times = 1 )", + "filename": "numpytest.py", + "nloc": 13, + "complexity": 2, + "token_count": 80, + "parameters": [ + "self", + "code_str", + "times" + ], + "start_line": 113, + "end_line": 128, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 16, + "top_nesting_level": 1 + }, + { + "name": "__call__", + "long_name": "__call__( self , result = None )", + "filename": "numpytest.py", + "nloc": 25, + "complexity": 6, + "token_count": 229, + "parameters": [ + "self", + "result" + ], + "start_line": 130, + "end_line": 155, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 26, + "top_nesting_level": 1 + }, + { + "name": "warn", + "long_name": "warn( self , message )", + "filename": "numpytest.py", + "nloc": 3, + "complexity": 1, + "token_count": 26, + "parameters": [ + "self", + "message" + ], + "start_line": 157, + "end_line": 159, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "info", + "long_name": "info( self , message )", + "filename": "numpytest.py", + "nloc": 3, + "complexity": 1, + "token_count": 22, + "parameters": [ + "self", + "message" + ], + "start_line": 160, + "end_line": 162, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "_get_all_method_names", + "long_name": "_get_all_method_names( cls )", + "filename": "numpytest.py", + "nloc": 8, + "complexity": 5, + "token_count": 56, + "parameters": [ + "cls" + ], + "start_line": 166, + "end_line": 173, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 8, + "top_nesting_level": 0 + }, + { + "name": "startTest", + "long_name": "startTest( self , test )", + "filename": "numpytest.py", + "nloc": 7, + "complexity": 2, + "token_count": 48, + "parameters": [ + "self", + "test" + ], + "start_line": 178, + "end_line": 184, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 7, + "top_nesting_level": 1 + }, + { + "name": "stopTest", + "long_name": "stopTest( self , test )", + "filename": "numpytest.py", + "nloc": 7, + "complexity": 2, + "token_count": 60, + "parameters": [ + "self", + "test" + ], + "start_line": 186, + "end_line": 192, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 7, + "top_nesting_level": 1 + }, + { + "name": "_makeResult", + "long_name": "_makeResult( self )", + "filename": "numpytest.py", + "nloc": 2, + "complexity": 1, + "token_count": 20, + "parameters": [ + "self" + ], + "start_line": 195, + "end_line": 196, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 1 + }, + { + "name": "__init__", + "long_name": "__init__( self , package = None )", + "filename": "numpytest.py", + "nloc": 6, + "complexity": 2, + "token_count": 41, + "parameters": [ + "self", + "package" + ], + "start_line": 220, + "end_line": 225, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 6, + "top_nesting_level": 1 + }, + { + "name": "_module_str", + "long_name": "_module_str( self , module )", + "filename": "numpytest.py", + "nloc": 5, + "complexity": 2, + "token_count": 43, + "parameters": [ + "self", + "module" + ], + "start_line": 227, + "end_line": 231, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 5, + "top_nesting_level": 1 + }, + { + "name": "_get_method_names", + "long_name": "_get_method_names( self , clsobj , level )", + "filename": "numpytest.py", + "nloc": 22, + "complexity": 11, + "token_count": 142, + "parameters": [ + "self", + "clsobj", + "level" + ], + "start_line": 233, + "end_line": 254, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 22, + "top_nesting_level": 1 + }, + { + "name": "_get_module_tests", + "long_name": "_get_module_tests( self , module , level , verbosity )", + "filename": "numpytest.py", + "nloc": 50, + "complexity": 16, + "token_count": 467, + "parameters": [ + "self", + "module", + "level", + "verbosity" + ], + "start_line": 256, + "end_line": 314, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 59, + "top_nesting_level": 1 + }, + { + "name": "_get_suite_list", + "long_name": "_get_suite_list( self , test_module , level , module_name = '__main__' )", + "filename": "numpytest.py", + "nloc": 23, + "complexity": 9, + "token_count": 176, + "parameters": [ + "self", + "test_module", + "level", + "module_name" + ], + "start_line": 316, + "end_line": 339, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 24, + "top_nesting_level": 1 + }, + { + "name": "test", + "long_name": "test( self , level = 1 , verbosity = 1 )", + "filename": "numpytest.py", + "nloc": 28, + "complexity": 8, + "token_count": 205, + "parameters": [ + "self", + "level", + "verbosity" + ], + "start_line": 341, + "end_line": 381, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 41, + "top_nesting_level": 1 + }, + { + "name": "run", + "long_name": "run( self )", + "filename": "numpytest.py", + "nloc": 21, + "complexity": 2, + "token_count": 109, + "parameters": [ + "self" + ], + "start_line": 383, + "end_line": 406, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 24, + "top_nesting_level": 1 + }, + { + "name": "warn", + "long_name": "warn( self , message )", + "filename": "numpytest.py", + "nloc": 3, + "complexity": 1, + "token_count": 26, + "parameters": [ + "self", + "message" + ], + "start_line": 408, + "end_line": 410, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "info", + "long_name": "info( self , message )", + "filename": "numpytest.py", + "nloc": 3, + "complexity": 1, + "token_count": 22, + "parameters": [ + "self", + "message" + ], + "start_line": 411, + "end_line": 413, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + } + ], + "changed_methods": [ + { + "name": "__init__", + "long_name": "__init__( self , package = None )", + "filename": "numpytest.py", + "nloc": 8, + "complexity": 2, + "token_count": 65, + "parameters": [ + "self", + "package" + ], + "start_line": 222, + "end_line": 229, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 8, + "top_nesting_level": 1 + }, + { + "name": "_get_module_tests", + "long_name": "_get_module_tests( self , module , level , verbosity )", + "filename": "numpytest.py", + "nloc": 53, + "complexity": 17, + "token_count": 487, + "parameters": [ + "self", + "module", + "level", + "verbosity" + ], + "start_line": 269, + "end_line": 331, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 63, + "top_nesting_level": 1 + }, + { + "name": "rename", + "long_name": "rename( self , ** kws )", + "filename": "numpytest.py", + "nloc": 4, + "complexity": 2, + "token_count": 29, + "parameters": [ + "self", + "kws" + ], + "start_line": 231, + "end_line": 238, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 8, + "top_nesting_level": 1 + }, + { + "name": "_get_suite_list", + "long_name": "_get_suite_list( self , test_module , level , module_name = '__main__' )", + "filename": "numpytest.py", + "nloc": 23, + "complexity": 9, + "token_count": 176, + "parameters": [ + "self", + "test_module", + "level", + "module_name" + ], + "start_line": 333, + "end_line": 356, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 24, + "top_nesting_level": 1 + } + ], + "nloc": 334, + "complexity": 91, + "token_count": 2374, + "diff_parsed": { + "added": [ + " See .rename() method to redefine name mapping between test_*.py files", + " and names of submodules.", + " package = f.f_locals.get('__name__',f.f_globals.get('__name__',None))", + " assert package is not None", + " self._rename_map = {}", + "", + " def rename(self, **kws):", + " \"\"\" Apply renaming submodule test file test_.py to test_.py.", + " Usage: self.rename(name='newname') before calling self.test() method.", + " If 'newname' is None, then no tests will be executed for a given module.", + " \"\"\"", + " for k,v in kws.items():", + " self._rename_map[k] = v", + " return", + " short_module_name = self._rename_map.get(short_module_name,short_module_name)", + " if short_module_name is None:", + " return []", + "", + " output_exception(sys.stderr)", + " output_exception(sys.stderr)" + ], + "deleted": [ + " package = f.f_locals['__name__']", + " output_exception(self.warn)", + " output_exception(self.warn)" + ] + } + } + ] + }, + { + "hash": "44f0e40eed3cc04292f1295ae524a1d5aedb382c", + "msg": "Fixed get_path bug fix.", + "author": { + "name": "Pearu Peterson", + "email": "pearu.peterson@gmail.com" + }, + "committer": { + "name": "Pearu Peterson", + "email": "pearu.peterson@gmail.com" + }, + "author_date": "2006-02-09T12:50:30+00:00", + "author_timezone": 0, + "committer_date": "2006-02-09T12:50:30+00:00", + "committer_timezone": 0, + "branches": [ + "main" + ], + "in_main_branch": true, + "merge": false, + "parents": [ + "2eb3a4b6e293a96465229ce18109b2ccae97ca70" + ], + "project_name": "repo_copy", + "project_path": "/tmp/tmpdjwupkfu/repo_copy", + "deletions": 7, + "insertions": 10, + "lines": 17, + "files": 1, + "dmm_unit_size": 0.0, + "dmm_unit_complexity": 0.0, + "dmm_unit_interfacing": 1.0, + "modified_files": [ + { + "old_path": "numpy/distutils/misc_util.py", + "new_path": "numpy/distutils/misc_util.py", + "filename": "misc_util.py", + "extension": "py", + "change_type": "MODIFY", + "diff": "@@ -27,18 +27,21 @@ def get_path(mod_name, parent_path=None):\n Returned path is relative to parent_path when given,\n otherwise it is absolute path.\n \"\"\"\n- if mod_name == '__main__' and not hasattr('__main__', '__file__'):\n- # we're probably running setup.py as execfile(\"setup.py\")\n- # (likely we're building an egg)\n- d = os.path.abspath('.')\n- elif mod_name == '__builtin__':\n+ if mod_name == '__builtin__':\n #builtin if/then added by Pearu for use in core.run_setup.\n d = os.path.dirname(os.path.abspath(sys.argv[0]))\n else:\n __import__(mod_name)\n mod = sys.modules[mod_name]\n- filename = mod.__file__\n- d = os.path.dirname(os.path.abspath(filename))\n+ if hasattr(mod,'__file__'):\n+ filename = mod.__file__\n+ d = os.path.dirname(os.path.abspath(mod.__file__))\n+ else:\n+ # we're probably running setup.py as execfile(\"setup.py\")\n+ # (likely we're building an egg) \n+ d = os.path.abspath('.')\n+ # hmm, should we use sys.argv[0] like in __builtin__ case?\n+\n if parent_path is not None:\n pd = os.path.abspath(parent_path)\n if pd == d[:len(pd)]:\n", + "added_lines": 10, + "deleted_lines": 7, + "source_code": "import os\nimport re\nimport sys\nimport imp\nimport copy\nimport glob\n\n__all__ = ['Configuration', 'get_numpy_include_dirs', 'default_config_dict',\n 'dict_append', 'appendpath', 'generate_config_py',\n 'get_cmd', 'allpath',\n 'terminal_has_colors', 'red_text', 'green_text', 'yellow_text',\n 'blue_text', 'cyan_text', 'cyg2win32', 'all_strings',\n 'has_f_sources', 'has_cxx_sources', 'filter_sources',\n 'get_dependencies', 'is_local_src_dir', 'get_ext_source_files',\n 'get_script_files', 'get_lib_source_files', 'get_data_files',\n 'dot_join', 'get_frame', 'minrelpath','njoin',\n 'is_sequence', 'is_string', 'as_list']\n\ndef allpath(name):\n \"Convert a /-separated pathname to one using the OS's path separator.\"\n splitted = name.split('/')\n return os.path.join(*splitted)\n\ndef get_path(mod_name, parent_path=None):\n \"\"\" Return path of the module.\n\n Returned path is relative to parent_path when given,\n otherwise it is absolute path.\n \"\"\"\n if mod_name == '__builtin__':\n #builtin if/then added by Pearu for use in core.run_setup.\n d = os.path.dirname(os.path.abspath(sys.argv[0]))\n else:\n __import__(mod_name)\n mod = sys.modules[mod_name]\n if hasattr(mod,'__file__'):\n filename = mod.__file__\n d = os.path.dirname(os.path.abspath(mod.__file__))\n else:\n # we're probably running setup.py as execfile(\"setup.py\")\n # (likely we're building an egg) \n d = os.path.abspath('.')\n # hmm, should we use sys.argv[0] like in __builtin__ case?\n\n if parent_path is not None:\n pd = os.path.abspath(parent_path)\n if pd == d[:len(pd)]:\n d = d[len(pd)+1:]\n return d or '.'\n\ndef njoin(*path):\n \"\"\" Join two or more pathname components +\n - convert a /-separated pathname to one using the OS's path separator.\n - resolve `..` from path.\n\n Either passing n arguments as in njoin('a','b'), or a sequence\n of n names as in njoin(['a','b']) is handled.\n \"\"\"\n if not path:\n # njoin()\n joined = ''\n elif is_sequence(path[0]) and len(path) == 1:\n # njoin(['a', 'b'])\n joined = os.path.join(*path[0])\n else:\n # njoin('a', 'b')\n joined = os.path.join(*path)\n if os.path.sep != '/':\n joined = joined.replace('/',os.path.sep)\n return minrelpath(joined)\n\ndef minrelpath(path):\n \"\"\" Resolve `..` from path.\n \"\"\"\n if not is_string(path):\n return path\n if '..' not in path:\n return path\n l = path.split(os.sep)\n j = 1\n while l:\n try:\n i = l.index('..',j)\n except ValueError:\n break\n if l[i-1]=='..':\n j += 1\n else:\n del l[i],l[i-1]\n j = 1\n if not l:\n return ''\n return os.path.join(*l)\n\n# Hooks for colored terminal output.\n# See also http://www.livinglogic.de/Python/ansistyle\ndef terminal_has_colors():\n if sys.platform=='cygwin' and not os.environ.has_key('USE_COLOR'):\n # Avoid importing curses that causes illegal operation\n # with a message:\n # PYTHON2 caused an invalid page fault in\n # module CYGNURSES7.DLL as 015f:18bbfc28\n # Details: Python 2.3.3 [GCC 3.3.1 (cygming special)]\n # ssh to Win32 machine from debian\n # curses.version is 2.2\n # CYGWIN_98-4.10, release 1.5.7(0.109/3/2))\n return 0\n if hasattr(sys.stdout,'isatty') and sys.stdout.isatty():\n try:\n import curses\n curses.setupterm()\n if (curses.tigetnum(\"colors\") >= 0\n and curses.tigetnum(\"pairs\") >= 0\n and ((curses.tigetstr(\"setf\") is not None\n and curses.tigetstr(\"setb\") is not None)\n or (curses.tigetstr(\"setaf\") is not None\n and curses.tigetstr(\"setab\") is not None)\n or curses.tigetstr(\"scp\") is not None)):\n return 1\n except Exception,msg:\n pass\n return 0\n\nif terminal_has_colors():\n def red_text(s): return '\\x1b[31m%s\\x1b[0m'%s\n def green_text(s): return '\\x1b[32m%s\\x1b[0m'%s\n def yellow_text(s): return '\\x1b[33m%s\\x1b[0m'%s\n def blue_text(s): return '\\x1b[34m%s\\x1b[0m'%s\n def cyan_text(s): return '\\x1b[35m%s\\x1b[0m'%s\nelse:\n def red_text(s): return s\n def green_text(s): return s\n def yellow_text(s): return s\n def cyan_text(s): return s\n def blue_text(s): return s\n\n#########################\n\ndef cyg2win32(path):\n if sys.platform=='cygwin' and path.startswith('/cygdrive'):\n path = path[10] + ':' + os.path.normcase(path[11:])\n return path\n\n#########################\n\n#XXX need support for .C that is also C++\ncxx_ext_match = re.compile(r'.*[.](cpp|cxx|cc)\\Z',re.I).match\nfortran_ext_match = re.compile(r'.*[.](f90|f95|f77|for|ftn|f)\\Z',re.I).match\nf90_ext_match = re.compile(r'.*[.](f90|f95)\\Z',re.I).match\nf90_module_name_match = re.compile(r'\\s*module\\s*(?P[\\w_]+)',re.I).match\ndef _get_f90_modules(source):\n \"\"\" Return a list of Fortran f90 module names that\n given source file defines.\n \"\"\"\n if not f90_ext_match(source):\n return []\n modules = []\n f = open(source,'r')\n f_readlines = getattr(f,'xreadlines',f.readlines)\n for line in f_readlines():\n m = f90_module_name_match(line)\n if m:\n name = m.group('name')\n modules.append(name)\n # break # XXX can we assume that there is one module per file?\n f.close()\n return modules\n\ndef is_string(s):\n return isinstance(s, str)\n\ndef all_strings(lst):\n \"\"\" Return True if all items in lst are string objects. \"\"\"\n for item in lst:\n if not is_string(item):\n return False\n return True\n\ndef is_sequence(seq):\n if is_string(seq):\n return False\n try:\n len(seq)\n except:\n return False\n return True\n\ndef as_list(seq):\n if is_sequence(seq):\n return list(seq)\n else:\n return [seq]\n\ndef has_f_sources(sources):\n \"\"\" Return True if sources contains Fortran files \"\"\"\n for source in sources:\n if fortran_ext_match(source):\n return True\n return False\n\ndef has_cxx_sources(sources):\n \"\"\" Return True if sources contains C++ files \"\"\"\n for source in sources:\n if cxx_ext_match(source):\n return True\n return False\n\ndef filter_sources(sources):\n \"\"\" Return four lists of filenames containing\n C, C++, Fortran, and Fortran 90 module sources,\n respectively.\n \"\"\"\n c_sources = []\n cxx_sources = []\n f_sources = []\n fmodule_sources = []\n for source in sources:\n if fortran_ext_match(source):\n modules = _get_f90_modules(source)\n if modules:\n fmodule_sources.append(source)\n else:\n f_sources.append(source)\n elif cxx_ext_match(source):\n cxx_sources.append(source)\n else:\n c_sources.append(source)\n return c_sources, cxx_sources, f_sources, fmodule_sources\n\n\ndef _get_headers(directory_list):\n # get *.h files from list of directories\n headers = []\n for d in directory_list:\n head = glob.glob(os.path.join(d,\"*.h\")) #XXX: *.hpp files??\n headers.extend(head)\n return headers\n\ndef _get_directories(list_of_sources):\n # get unique directories from list of sources.\n direcs = []\n for f in list_of_sources:\n d = os.path.split(f)\n if d[0] != '' and not d[0] in direcs:\n direcs.append(d[0])\n return direcs\n\ndef get_dependencies(sources):\n #XXX scan sources for include statements\n return _get_headers(_get_directories(sources))\n\ndef is_local_src_dir(directory):\n \"\"\" Return true if directory is local directory.\n \"\"\"\n if not is_string(directory):\n return False\n abs_dir = os.path.abspath(directory)\n c = os.path.commonprefix([os.getcwd(),abs_dir])\n new_dir = abs_dir[len(c):].split(os.sep)\n if new_dir and not new_dir[0]:\n new_dir = new_dir[1:]\n if new_dir and new_dir[0]=='build':\n return False\n new_dir = os.sep.join(new_dir)\n return os.path.isdir(new_dir)\n\ndef general_source_files(top_path):\n pruned_directories = {'CVS':1, '.svn':1, 'build':1}\n prune_file_pat = re.compile(r'(?:[~#]|\\.py[co]|\\.o)$')\n for dirpath, dirnames, filenames in os.walk(top_path, topdown=True):\n pruned = [ d for d in dirnames if d not in pruned_directories ]\n dirnames[:] = pruned\n for f in filenames:\n if not prune_file_pat.search(f):\n yield os.path.join(dirpath, f)\n\ndef get_ext_source_files(ext):\n # Get sources and any include files in the same directory.\n filenames = []\n sources = filter(is_string, ext.sources)\n filenames.extend(sources)\n filenames.extend(get_dependencies(sources))\n for d in ext.depends:\n if is_local_src_dir(d):\n filenames.extend(list(general_source_files(d)))\n elif os.path.isfile(d):\n filenames.append(d)\n return filenames\n\ndef get_script_files(scripts):\n scripts = filter(is_string, scripts)\n return scripts\n\ndef get_lib_source_files(lib):\n filenames = []\n sources = lib[1].get('sources',[])\n sources = filter(is_string, sources)\n filenames.extend(sources)\n filenames.extend(get_dependencies(sources))\n depends = lib[1].get('depends',[])\n for d in depends:\n if is_local_src_dir(d):\n filenames.extend(list(general_source_files(d)))\n elif os.path.isfile(d):\n filenames.append(d)\n return filenames\n\ndef get_data_files(data):\n if is_string(data):\n return [data]\n sources = data[1]\n filenames = []\n for s in sources:\n if callable(s):\n continue\n if is_local_src_dir(s):\n filenames.extend(list(general_source_files(s)))\n elif is_string(s):\n if os.path.isfile(s):\n filenames.append(s)\n else:\n print 'Not existing data file:',s\n else:\n raise TypeError,repr(s)\n return filenames\n\ndef dot_join(*args):\n return '.'.join([a for a in args if a])\n\ndef get_frame(level=0):\n try:\n return sys._getframe(level+1)\n except AttributeError:\n frame = sys.exc_info()[2].tb_frame\n for _ in range(level+1):\n frame = frame.f_back\n return frame\n\n######################\n\nclass Configuration(object):\n\n _list_keys = ['packages', 'ext_modules', 'data_files', 'include_dirs',\n 'libraries', 'headers', 'scripts', 'py_modules']\n _dict_keys = ['package_dir']\n\n numpy_include_dirs = []\n\n def __init__(self,\n package_name=None,\n parent_name=None,\n top_path=None,\n package_path=None,\n **attrs):\n \"\"\" Construct configuration instance of a package.\n\n package_name -- name of the package\n Ex.: 'distutils'\n parent_name -- name of the parent package\n Ex.: 'numpy'\n top_path -- directory of the toplevel package\n Ex.: the directory where the numpy package source sits\n package_path -- directory of package. Will be computed by magic from the\n directory of the caller module if not specified\n Ex.: the directory where numpy.distutils is\n \"\"\"\n self.name = dot_join(parent_name, package_name)\n\n caller_frame = get_frame(1)\n caller_name = eval('__name__',caller_frame.f_globals,caller_frame.f_locals)\n\n self.local_path = get_path(caller_name, top_path)\n if top_path is None:\n top_path = self.local_path\n if package_path is None:\n package_path = self.local_path\n elif os.path.isdir(njoin(self.local_path,package_path)):\n package_path = njoin(self.local_path,package_path)\n if not os.path.isdir(package_path):\n raise ValueError(\"%r is not a directory\" % (package_path,))\n self.top_path = top_path\n self.package_path = package_path\n # this is the relative path in the installed package\n self.path_in_package = os.path.join(*self.name.split('.'))\n\n self.list_keys = self._list_keys[:]\n self.dict_keys = self._dict_keys[:]\n\n for n in self.list_keys:\n v = copy.copy(attrs.get(n, []))\n setattr(self, n, as_list(v))\n\n for n in self.dict_keys:\n v = copy.copy(attrs.get(n, {}))\n setattr(self, n, v)\n\n known_keys = self.list_keys + self.dict_keys\n self.extra_keys = []\n for n in attrs.keys():\n if n in known_keys:\n continue\n a = attrs[n]\n setattr(self,n,a)\n if isinstance(a, list):\n self.list_keys.append(n)\n elif isinstance(a, dict):\n self.dict_keys.append(n)\n else:\n self.extra_keys.append(n)\n\n if os.path.exists(njoin(package_path,'__init__.py')):\n self.packages.append(self.name)\n self.package_dir[self.name] = package_path\n\n self.options = dict(\n ignore_setup_xxx_py = False,\n assume_default_configuration = False,\n delegate_options_to_subpackages = False,\n quiet = False,\n )\n\n for i in range(1,3):\n f = get_frame(i)\n try:\n caller_instance = eval('self',f.f_globals,f.f_locals)\n break\n except NameError:\n caller_instance = None\n if isinstance(caller_instance, self.__class__):\n if caller_instance.options['delegate_options_to_subpackages']:\n self.set_options(**caller_instance.options)\n\n def todict(self):\n \"\"\" Return configuration distionary suitable for passing\n to distutils.core.setup() function.\n \"\"\"\n d = {}\n for n in self.list_keys + self.dict_keys + self.extra_keys:\n a = getattr(self,n)\n if a:\n d[n] = a\n if self.name:\n d['name'] = self.name\n return d\n\n def info(self, message):\n if not self.options['quiet']:\n print message\n\n def warn(self, message):\n print>>sys.stderr, 'Warning:',message\n\n\n def set_options(self, **options):\n \"\"\" Configure Configuration instance.\n\n The following options are available:\n - ignore_setup_xxx_py\n - assume_default_configuration\n - delegate_options_to_subpackages\n - quiet\n \"\"\"\n for key, value in options.items():\n if self.options.has_key(key):\n self.options[key] = value\n else:\n raise ValueError,'Unknown option: '+key\n\n def get_distribution(self):\n import distutils.core\n dist = distutils.core._setup_distribution\n return dist\n\n def _wildcard_get_subpackage(self, subpackage_name):\n l = subpackage_name.split('.')\n subpackage_path = njoin([self.local_path]+l)\n dirs = filter(os.path.isdir,glob.glob(subpackage_path))\n config_list = []\n for d in dirs:\n if not os.path.isfile(njoin(d,'__init__.py')):\n continue\n if 'build' in d.split(os.sep):\n continue\n n = '.'.join(d.split(os.sep)[-len(l):])\n c = self.get_subpackage(n)\n config_list.extend(c)\n return config_list\n\n def _get_configuration_from_setup_py(self, setup_py,\n subpackage_name, subpackage_path):\n # In case setup_py imports local modules:\n sys.path.insert(0,os.path.dirname(setup_py))\n try:\n fo_setup_py = open(setup_py, 'U')\n setup_name = os.path.splitext(os.path.basename(setup_py))[0]\n n = dot_join(self.name,setup_name)\n setup_module = imp.load_module('_'.join(n.split('.')),\n fo_setup_py,\n setup_py,\n ('.py', 'U', 1))\n if not hasattr(setup_module,'configuration'):\n if not self.options['assume_default_configuration']:\n self.warn('Assuming default configuration '\\\n '(%s does not define configuration())'\\\n % (setup_module))\n config = Configuration(subpackage_name, self.name,\n self.top_path, subpackage_path)\n else:\n args = (self.name,)\n if setup_module.configuration.func_code.co_argcount > 1:\n args = args + (self.top_path,)\n config = setup_module.configuration(*args)\n finally:\n del sys.path[0]\n return config\n\n def get_subpackage(self,subpackage_name,subpackage_path=None):\n \"\"\" Return list of subpackage configurations.\n\n '*' in subpackage_name is handled as a wildcard.\n \"\"\"\n if subpackage_name is None:\n if subpackage_path is None:\n raise ValueError(\n \"either subpackage_name or subpackage_path must be specified\")\n subpackage_name = os.path.basename(subpackage_path)\n\n # handle wildcards\n l = subpackage_name.split('.')\n if subpackage_path is None and '*' in subpackage_name:\n return self._wildcard_get_subpackage(subpackage_name)\n\n if subpackage_path is None:\n subpackage_path = njoin([self.local_path] + l)\n else:\n subpackage_path = njoin([subpackage_path] + l[:-1])\n subpackage_path = self._fix_paths([subpackage_path])[0]\n\n setup_py = njoin(subpackage_path, 'setup.py')\n if not self.options['ignore_setup_xxx_py']:\n if not os.path.isfile(setup_py):\n setup_py = njoin(subpackage_path,\n 'setup_%s.py' % (subpackage_name))\n\n if not os.path.isfile(setup_py):\n if not self.options['assume_default_configuration']:\n self.warn('Assuming default configuration '\\\n '(%s/{setup_%s,setup}.py was not found)' \\\n % (os.path.dirname(setup_py), subpackage_name))\n config = Configuration(subpackage_name, self.name,\n self.top_path, subpackage_path)\n else:\n config = self._get_configuration_from_setup_py(setup_py,\n subpackage_name,\n subpackage_path)\n\n if config:\n return [config]\n else:\n return []\n\n def add_subpackage(self,subpackage_name,subpackage_path=None):\n \"\"\" Add subpackage to configuration.\n \"\"\"\n config_list = self.get_subpackage(subpackage_name,subpackage_path)\n if not config_list:\n self.warn('No configuration returned, assuming unavailable.')\n for config in config_list:\n try:\n d = config.todict()\n except AttributeError:\n d = config\n self.info('Appending %s configuration to %s' \\\n % (d.get('name'), self.name))\n self.dict_append(**d)\n\n dist = self.get_distribution()\n if dist is not None:\n self.warn('distutils distribution has been initialized,'\\\n ' it may be too late to add a subpackage '+ subpackage_name)\n return\n\n def add_data_dir(self,data_path):\n \"\"\" Recursively add files under data_path to data_files list.\n Argument can be either\n - 2-sequence (,)\n - path to data directory where python datadir suffix defaults\n to package dir.\n If path is not absolute then it's datadir suffix is\n package dir + subdirname of the path.\n \"\"\"\n if is_sequence(data_path):\n d, data_path = data_path\n else:\n d = None\n if not is_string(data_path):\n raise TypeError(\"not a string: %r\" % (data_path,))\n for path in self.paths(data_path):\n if not os.path.exists(path):\n continue\n filenames = list(general_source_files(path))\n if not os.path.isabs(path):\n npath = data_path\n if '*' in npath:\n npath = os.path.join(*(path.split(os.sep)[-len(npath.split(os.sep)):]))\n if d is None:\n d = self.path_in_package\n ds = os.path.join(d, npath)\n self.add_data_files((ds,filenames))\n else:\n if d is None:\n self.add_data_files(*filenames)\n else:\n self.add_data_files((d,filenames))\n return\n\n def add_data_files(self,*files):\n \"\"\" Add data files to configuration data_files.\n Argument(s) can be either\n - 2-sequence (,)\n - paths to data files where python datadir prefix defaults\n to package dir.\n If path is not absolute then it's datadir prefix is\n package dir + dirname of the path.\n \"\"\"\n data_dict = {}\n new_files = []\n for p in files:\n if not is_sequence(p):\n d = self.path_in_package\n if is_string(p) and not os.path.isabs(p):\n pd = os.path.dirname(p)\n if '*' in pd:\n pn = os.path.basename(p)\n n = len(pd.split(os.sep))\n for d1 in filter(os.path.isdir,self.paths(pd)):\n p = os.path.join(d1,pn)\n d1 = os.sep.join(d1.split(os.sep)[-n:])\n new_files.append((appendpath(d,d1),p))\n continue\n d = appendpath(d,pd)\n p = (d,p)\n new_files.append(p)\n\n files = []\n for prefix,filepattern in new_files:\n assert '*' not in prefix, repr((prefix,filepattern))\n if is_string(filepattern):\n file_list = self.paths(filepattern,include_non_existing=False)\n elif callable(filepattern):\n file_list = [filepattern]\n else:\n file_list = self.paths(*filepattern)\n\n nof_path_components = [len(f.split(os.sep))\n for f in file_list if is_string(f)]\n if nof_path_components:\n min_path_components = min(nof_path_components)-1\n else:\n min_path_components = 0\n\n for f in file_list:\n if is_string(f):\n extra_path_components = f.split(os.sep)[min_path_components:-1]\n p = njoin([prefix]+extra_path_components)\n else:\n p = prefix\n if not data_dict.has_key(p):\n data_dict[p] = [f]\n else:\n data_dict[p].append(f)\n\n dist = self.get_distribution()\n if dist is not None:\n dist.data_files.extend(data_dict.items())\n else:\n self.data_files.extend(data_dict.items())\n\n ### XXX Implement add_py_modules\n\n def add_include_dirs(self,*paths):\n \"\"\" Add paths to configuration include directories.\n \"\"\"\n include_dirs = self._fix_paths(paths)\n dist = self.get_distribution()\n if dist is not None:\n dist.include_dirs.extend(include_dirs)\n else:\n self.include_dirs.extend(include_dirs)\n return\n\n def add_headers(self,*files):\n \"\"\" Add installable headers to configuration.\n Argument(s) can be either\n - 2-sequence (,)\n - path(s) to header file(s) where python includedir suffix will default\n to package name.\n \"\"\"\n headers = []\n for path in files:\n if is_string(path):\n [headers.append((self.name,p)) for p in self.paths(path)]\n else:\n if not isinstance(path, (tuple, list)) or len(path) != 2:\n raise TypeError(repr(path))\n [headers.append((path[0],p)) for p in self.paths(path[1])]\n dist = self.get_distribution()\n if dist is not None:\n dist.headers.extend(headers)\n else:\n self.headers.extend(headers)\n return\n\n def _fix_paths(self,paths,include_non_existing=True):\n assert is_sequence(paths), repr(type(paths))\n new_paths = []\n for n in paths:\n if isinstance(n,str):\n if '*' in n or '?' in n:\n p = glob.glob(n)\n p2 = glob.glob(njoin(self.local_path,n))\n if p2:\n new_paths.extend(p2)\n elif p:\n new_paths.extend(p)\n else:\n if include_non_existing:\n new_paths.append(n)\n self.warn('could not resolve pattern in %s: %r' \\\n % (self.local_path,n))\n else:\n n2 = njoin(self.local_path,n)\n if os.path.exists(n2):\n new_paths.append(n2)\n else:\n if os.path.exists(n):\n new_paths.append(n)\n elif include_non_existing:\n new_paths.append(n)\n if not os.path.exists(n):\n self.warn('not existing path in %s: %s' \\\n % (self.local_path,n))\n else:\n new_paths.append(n)\n return map(minrelpath,new_paths)\n\n def paths(self,*paths,**kws):\n \"\"\" Apply glob to paths and prepend local_path if needed.\n \"\"\"\n include_non_existing = kws.get('include_non_existing',True)\n return self._fix_paths(paths,\n include_non_existing=include_non_existing)\n\n def _fix_paths_dict(self,kw):\n for k in kw.keys():\n v = kw[k]\n if k in ['sources','depends','include_dirs','library_dirs',\n 'module_dirs','extra_objects']:\n new_v = self._fix_paths(v)\n kw[k] = new_v\n return\n\n def add_extension(self,name,sources,**kw):\n \"\"\" Add extension to configuration.\n\n Keywords:\n include_dirs, define_macros, undef_macros,\n library_dirs, libraries, runtime_library_dirs,\n extra_objects, extra_compile_args, extra_link_args,\n export_symbols, swig_opts, depends, language,\n f2py_options, module_dirs\n extra_info - dict or list of dict of keywords to be\n appended to keywords.\n \"\"\"\n ext_args = copy.copy(kw)\n ext_args['name'] = dot_join(self.name,name)\n ext_args['sources'] = sources\n\n if ext_args.has_key('extra_info'):\n extra_info = ext_args['extra_info']\n del ext_args['extra_info']\n if isinstance(extra_info, dict):\n extra_info = [extra_info]\n for info in extra_info:\n assert isinstance(info, dict), repr(info)\n dict_append(ext_args,**info)\n\n self._fix_paths_dict(ext_args)\n\n # Resolve out-of-tree dependencies\n libraries = ext_args.get('libraries',[])\n libnames = []\n ext_args['libraries'] = []\n for libname in libraries:\n if isinstance(libname,tuple):\n self._fix_paths_dict(libname[1])\n\n # Handle library names of the form libname@relative/path/to/library\n if '@' in libname:\n lname,lpath = libname.split('@',1)\n lpath = os.path.abspath(njoin(self.local_path,lpath))\n if os.path.isdir(lpath):\n c = self.get_subpackage(None,lpath)\n if isinstance(c,Configuration):\n c = c.todict()\n for l in [l[0] for l in c.get('libraries',[])]:\n llname = l.split('__OF__',1)[0]\n if llname == lname:\n c.pop('name',None)\n dict_append(ext_args,**c)\n break\n continue\n libnames.append(libname)\n\n ext_args['libraries'] = libnames + ext_args['libraries']\n\n from numpy.distutils.core import Extension\n ext = Extension(**ext_args)\n self.ext_modules.append(ext)\n\n dist = self.get_distribution()\n if dist is not None:\n self.warn('distutils distribution has been initialized,'\\\n ' it may be too late to add an extension '+name)\n return ext\n\n def add_library(self,name,sources,**build_info):\n \"\"\" Add library to configuration.\n\n Valid keywords for build_info:\n depends\n macros\n include_dirs\n extra_compiler_args\n f2py_options\n \"\"\"\n build_info = copy.copy(build_info)\n name = name #+ '__OF__' + self.name\n build_info['sources'] = sources\n\n self._fix_paths_dict(build_info)\n \n self.libraries.append((name,build_info))\n\n dist = self.get_distribution()\n if dist is not None:\n self.warn('distutils distribution has been initialized,'\\\n ' it may be too late to add a library '+ name)\n return\n\n def add_scripts(self,*files):\n \"\"\" Add scripts to configuration.\n \"\"\"\n scripts = self._fix_paths(files)\n dist = self.get_distribution()\n if dist is not None:\n dist.scripts.extend(scripts)\n else:\n self.scripts.extend(scripts)\n return\n\n def dict_append(self,**dict):\n for key in self.list_keys:\n a = getattr(self,key)\n a.extend(dict.get(key,[]))\n for key in self.dict_keys:\n a = getattr(self,key)\n a.update(dict.get(key,{}))\n known_keys = self.list_keys + self.dict_keys + self.extra_keys\n for key in dict.keys():\n if key not in known_keys and not hasattr(self,key):\n if key not in ['version']:\n self.warn('Inheriting attribute %r from %r' \\\n % (key,dict.get('name','?')))\n setattr(self,key,dict[key])\n self.extra_keys.append(key)\n return\n\n def __str__(self):\n known_keys = self.list_keys + self.dict_keys + self.extra_keys\n s = '<'+5*'-' + '\\n'\n s += 'Configuration of '+self.name+':\\n'\n for k in known_keys:\n a = getattr(self,k,None)\n if a:\n s += '%s = %r\\n' % (k,a)\n s += 5*'-' + '>'\n return s\n\n def get_config_cmd(self):\n cmd = get_cmd('config')\n cmd.ensure_finalized()\n cmd.dump_source = 0\n cmd.noisy = 0\n old_path = os.environ.get('PATH')\n if old_path:\n path = os.pathsep.join(['.',old_path])\n os.environ['PATH'] = path\n return cmd\n\n def get_build_temp_dir(self):\n cmd = get_cmd('build')\n cmd.ensure_finalized()\n return cmd.build_temp\n\n def have_f77c(self):\n \"\"\" Check for availability of Fortran 77 compiler.\n Use it inside source generating function to ensure that\n setup distribution instance has been initialized.\n \"\"\"\n simple_fortran_subroutine = '''\n subroutine simple\n end\n '''\n config_cmd = self.get_config_cmd()\n flag = config_cmd.try_compile(simple_fortran_subroutine,lang='f77')\n return flag\n\n def have_f90c(self):\n \"\"\" Check for availability of Fortran 90 compiler.\n Use it inside source generating function to ensure that\n setup distribution instance has been initialized.\n \"\"\"\n simple_fortran_subroutine = '''\n subroutine simple\n end\n '''\n config_cmd = self.get_config_cmd()\n flag = config_cmd.try_compile(simple_fortran_subroutine,lang='f90')\n return flag\n\n def append_to(self, extlib):\n \"\"\" Append libraries, include_dirs to extension or library item.\n \"\"\"\n if is_sequence(extlib):\n lib_name, build_info = extlib\n dict_append(build_info,\n libraries=self.libraries,\n include_dirs=self.include_dirs)\n else:\n from numpy.distutils.core import Extension\n assert isinstance(extlib,Extension), repr(extlib)\n extlib.libraries.extend(self.libraries)\n extlib.include_dirs.extend(self.include_dirs)\n return\n\n def _get_svn_revision(self,path):\n \"\"\" Return path's SVN revision number.\n \"\"\"\n entries = njoin(path,'.svn','entries')\n revision = None\n if os.path.isfile(entries):\n f = open(entries)\n m = re.search(r'revision=\"(?P\\d+)\"',f.read())\n f.close()\n if m:\n revision = int(m.group('revision'))\n return revision\n\n def get_version(self):\n \"\"\" Try to get version string of a package.\n \"\"\"\n version = getattr(self,'version',None)\n if version is not None:\n return version\n\n # Get version from version file.\n files = ['__version__.py',\n self.name.split('.')[-1]+'_version.py',\n 'version.py',\n '__svn_version__.py']\n version_vars = ['version',\n '__version__',\n self.name.split('.')[-1]+'_version']\n for f in files:\n fn = njoin(self.local_path,f)\n if os.path.isfile(fn):\n info = (open(fn),fn,('.py','U',1))\n name = os.path.splitext(os.path.basename(fn))[0]\n n = dot_join(self.name,name)\n try:\n version_module = imp.load_module('_'.join(n.split('.')),*info)\n except ImportError,msg:\n self.warn(str(msg))\n version_module = None\n if version_module is None:\n continue\n\n for a in version_vars:\n version = getattr(version_module,a,None)\n if version is not None:\n break\n if version is not None:\n break\n\n if version is not None:\n self.version = version\n return version\n\n # Get version as SVN revision number\n revision = self._get_svn_revision(self.local_path)\n if revision is not None:\n version = str(revision)\n self.version = version\n\n return version\n\n def make_svn_version_py(self):\n \"\"\" Generate package __svn_version__.py file from SVN revision number,\n it will be removed after python exits but will be available\n when sdist, etc commands are executed.\n\n If __svn_version__.py existed before, nothing is done.\n \"\"\"\n target = njoin(self.local_path,'__svn_version__.py')\n if os.path.isfile(target):\n return\n def generate_svn_version_py():\n if not os.path.isfile(target):\n revision = self._get_svn_revision(self.local_path)\n assert revision is not None,'hmm, why I am not inside SVN tree???'\n version = str(revision)\n self.info('Creating %s (version=%r)' % (target,version))\n f = open(target,'w')\n f.write('version = %r\\n' % (version))\n f.close()\n\n import atexit\n def rm_file(f=target,p=self.info):\n try: os.remove(f); p('removed '+f)\n except OSError: pass\n try: os.remove(f+'c'); p('removed '+f+'c')\n except OSError: pass\n atexit.register(rm_file)\n\n return target\n\n self.add_data_files((self.path_in_package, generate_svn_version_py()))\n\n def make_config_py(self,name='__config__'):\n \"\"\" Generate package __config__.py file containing system_info\n information used during building the package.\n \"\"\"\n self.py_modules.append((self.name,name,generate_config_py))\n return\n\n def get_info(self,*names):\n \"\"\" Get resources information.\n \"\"\"\n from system_info import get_info, dict_append\n info_dict = {}\n for a in names:\n dict_append(info_dict,**get_info(a))\n return info_dict\n\nclass BadConfiguration(Configuration):\n \"\"\"\n When the command line is not ok, use this as the configuration class.\n \"\"\"\n def _do_nothing(self, *args, **kw):\n pass\n add_subpackage = _do_nothing\n add_extension = _do_nothing\n add_library = _do_nothing\n add_data_dir = _do_nothing\n add_data_files = _do_nothing\n add_scripts = _do_nothing\n add_headers = _do_nothing\n add_include_dirs = _do_nothing\n make_config_py = _do_nothing\n\n def get_info(self, *args, **kw):\n return {}\n def have_f77c(self, *args, **kw):\n return False\n def have_f90c(self, *args, **kw):\n return False\n\ndef command_line_ok(_cache=[]):\n \"\"\" Return True if command line does not contain any\n help or display requests.\n \"\"\"\n if _cache:\n return _cache[0]\n ok = True\n from distutils.dist import Distribution\n display_opts = ['--'+n for n in Distribution.display_option_names]\n for o in Distribution.display_options:\n if o[1]:\n display_opts.append('-'+o[1])\n for arg in sys.argv:\n if arg.startswith('--help') or arg=='-h' or arg in display_opts:\n ok = False\n break\n _cache.append(ok)\n return ok\n\nif not command_line_ok():\n Configuration = BadConfiguration\n\ndef get_cmd(cmdname, _cache={}):\n if not _cache.has_key(cmdname):\n import distutils.core\n dist = distutils.core._setup_distribution\n if dist is None:\n from distutils.errors import DistutilsInternalError\n raise DistutilsInternalError(\n 'setup distribution instance not initialized')\n cmd = dist.get_command_obj(cmdname)\n _cache[cmdname] = cmd\n return _cache[cmdname]\n\ndef get_numpy_include_dirs():\n # numpy_include_dirs are set by numpy/core/setup.py, otherwise []\n include_dirs = Configuration.numpy_include_dirs[:]\n if not include_dirs:\n import numpy\n if numpy.show_config is None:\n # running from numpy_core source directory\n include_dirs.append(njoin(os.path.dirname(numpy.__file__),\n 'core', 'include'))\n else:\n # using installed numpy core headers\n import numpy.core as core\n include_dirs.append(njoin(os.path.dirname(core.__file__), 'include'))\n # else running numpy/core/setup.py\n return include_dirs\n\n#########################\n\ndef default_config_dict(name = None, parent_name = None, local_path=None):\n \"\"\" Return a configuration dictionary for usage in\n configuration() function defined in file setup_.py.\n \"\"\"\n import warnings\n warnings.warn('Use Configuration(%r,%r,top_path=%r) instead of '\\\n 'deprecated default_config_dict(%r,%r,%r)'\n % (name, parent_name, local_path,\n name, parent_name, local_path,\n ))\n c = Configuration(name, parent_name, local_path)\n return c.todict()\n\n\ndef dict_append(d, **kws):\n for k, v in kws.items():\n if d.has_key(k):\n d[k].extend(v)\n else:\n d[k] = v\n\ndef appendpath(prefix, path):\n if os.path.sep != '/':\n prefix = prefix.replace('/', os.path.sep)\n path = path.replace('/', os.path.sep)\n drive = ''\n if os.path.isabs(path):\n drive = os.path.splitdrive(prefix)[0]\n absprefix = os.path.splitdrive(os.path.abspath(prefix))[1]\n pathdrive, path = os.path.splitdrive(path)\n d = os.path.commonprefix([absprefix, path])\n if os.path.join(absprefix[:len(d)], absprefix[len(d):]) != absprefix \\\n or os.path.join(path[:len(d)], path[len(d):]) != path:\n # Handle invalid paths\n d = os.path.dirname(d)\n subpath = path[len(d):]\n if os.path.isabs(subpath):\n subpath = subpath[1:]\n else:\n subpath = path\n return os.path.normpath(njoin(drive + prefix, subpath))\n\ndef generate_config_py(target):\n \"\"\" Generate config.py file containing system_info information\n used during building the package.\n\n Usage:\\\n config['py_modules'].append((packagename, '__config__',generate_config_py))\n \"\"\"\n from numpy.distutils.system_info import system_info\n from distutils.dir_util import mkpath\n mkpath(os.path.dirname(target))\n f = open(target, 'w')\n f.write('# This file is generated by %s\\n' % (os.path.abspath(sys.argv[0])))\n f.write('# It contains system_info results at the time of building this package.\\n')\n f.write('__all__ = [\"get_info\",\"show\"]\\n\\n')\n for k, i in system_info.saved_results.items():\n f.write('%s=%r\\n' % (k, i))\n f.write('\\ndef get_info(name): g=globals(); return g.get(name,g.get(name+\"_info\",{}))\\n')\n f.write('''\ndef show():\n for name,info_dict in globals().items():\n if name[0]==\"_\" or type(info_dict) is not type({}): continue\n print name+\":\"\n if not info_dict:\n print \" NOT AVAILABLE\"\n for k,v in info_dict.items():\n v = str(v)\n if k==\\'sources\\' and len(v)>200: v = v[:60]+\\' ...\\\\n... \\'+v[-60:]\n print \\' %s = %s\\'%(k,v)\n print\n return\n ''')\n\n f.close()\n return target\n", + "source_code_before": "import os\nimport re\nimport sys\nimport imp\nimport copy\nimport glob\n\n__all__ = ['Configuration', 'get_numpy_include_dirs', 'default_config_dict',\n 'dict_append', 'appendpath', 'generate_config_py',\n 'get_cmd', 'allpath',\n 'terminal_has_colors', 'red_text', 'green_text', 'yellow_text',\n 'blue_text', 'cyan_text', 'cyg2win32', 'all_strings',\n 'has_f_sources', 'has_cxx_sources', 'filter_sources',\n 'get_dependencies', 'is_local_src_dir', 'get_ext_source_files',\n 'get_script_files', 'get_lib_source_files', 'get_data_files',\n 'dot_join', 'get_frame', 'minrelpath','njoin',\n 'is_sequence', 'is_string', 'as_list']\n\ndef allpath(name):\n \"Convert a /-separated pathname to one using the OS's path separator.\"\n splitted = name.split('/')\n return os.path.join(*splitted)\n\ndef get_path(mod_name, parent_path=None):\n \"\"\" Return path of the module.\n\n Returned path is relative to parent_path when given,\n otherwise it is absolute path.\n \"\"\"\n if mod_name == '__main__' and not hasattr('__main__', '__file__'):\n # we're probably running setup.py as execfile(\"setup.py\")\n # (likely we're building an egg)\n d = os.path.abspath('.')\n elif mod_name == '__builtin__':\n #builtin if/then added by Pearu for use in core.run_setup.\n d = os.path.dirname(os.path.abspath(sys.argv[0]))\n else:\n __import__(mod_name)\n mod = sys.modules[mod_name]\n filename = mod.__file__\n d = os.path.dirname(os.path.abspath(filename))\n if parent_path is not None:\n pd = os.path.abspath(parent_path)\n if pd == d[:len(pd)]:\n d = d[len(pd)+1:]\n return d or '.'\n\ndef njoin(*path):\n \"\"\" Join two or more pathname components +\n - convert a /-separated pathname to one using the OS's path separator.\n - resolve `..` from path.\n\n Either passing n arguments as in njoin('a','b'), or a sequence\n of n names as in njoin(['a','b']) is handled.\n \"\"\"\n if not path:\n # njoin()\n joined = ''\n elif is_sequence(path[0]) and len(path) == 1:\n # njoin(['a', 'b'])\n joined = os.path.join(*path[0])\n else:\n # njoin('a', 'b')\n joined = os.path.join(*path)\n if os.path.sep != '/':\n joined = joined.replace('/',os.path.sep)\n return minrelpath(joined)\n\ndef minrelpath(path):\n \"\"\" Resolve `..` from path.\n \"\"\"\n if not is_string(path):\n return path\n if '..' not in path:\n return path\n l = path.split(os.sep)\n j = 1\n while l:\n try:\n i = l.index('..',j)\n except ValueError:\n break\n if l[i-1]=='..':\n j += 1\n else:\n del l[i],l[i-1]\n j = 1\n if not l:\n return ''\n return os.path.join(*l)\n\n# Hooks for colored terminal output.\n# See also http://www.livinglogic.de/Python/ansistyle\ndef terminal_has_colors():\n if sys.platform=='cygwin' and not os.environ.has_key('USE_COLOR'):\n # Avoid importing curses that causes illegal operation\n # with a message:\n # PYTHON2 caused an invalid page fault in\n # module CYGNURSES7.DLL as 015f:18bbfc28\n # Details: Python 2.3.3 [GCC 3.3.1 (cygming special)]\n # ssh to Win32 machine from debian\n # curses.version is 2.2\n # CYGWIN_98-4.10, release 1.5.7(0.109/3/2))\n return 0\n if hasattr(sys.stdout,'isatty') and sys.stdout.isatty():\n try:\n import curses\n curses.setupterm()\n if (curses.tigetnum(\"colors\") >= 0\n and curses.tigetnum(\"pairs\") >= 0\n and ((curses.tigetstr(\"setf\") is not None\n and curses.tigetstr(\"setb\") is not None)\n or (curses.tigetstr(\"setaf\") is not None\n and curses.tigetstr(\"setab\") is not None)\n or curses.tigetstr(\"scp\") is not None)):\n return 1\n except Exception,msg:\n pass\n return 0\n\nif terminal_has_colors():\n def red_text(s): return '\\x1b[31m%s\\x1b[0m'%s\n def green_text(s): return '\\x1b[32m%s\\x1b[0m'%s\n def yellow_text(s): return '\\x1b[33m%s\\x1b[0m'%s\n def blue_text(s): return '\\x1b[34m%s\\x1b[0m'%s\n def cyan_text(s): return '\\x1b[35m%s\\x1b[0m'%s\nelse:\n def red_text(s): return s\n def green_text(s): return s\n def yellow_text(s): return s\n def cyan_text(s): return s\n def blue_text(s): return s\n\n#########################\n\ndef cyg2win32(path):\n if sys.platform=='cygwin' and path.startswith('/cygdrive'):\n path = path[10] + ':' + os.path.normcase(path[11:])\n return path\n\n#########################\n\n#XXX need support for .C that is also C++\ncxx_ext_match = re.compile(r'.*[.](cpp|cxx|cc)\\Z',re.I).match\nfortran_ext_match = re.compile(r'.*[.](f90|f95|f77|for|ftn|f)\\Z',re.I).match\nf90_ext_match = re.compile(r'.*[.](f90|f95)\\Z',re.I).match\nf90_module_name_match = re.compile(r'\\s*module\\s*(?P[\\w_]+)',re.I).match\ndef _get_f90_modules(source):\n \"\"\" Return a list of Fortran f90 module names that\n given source file defines.\n \"\"\"\n if not f90_ext_match(source):\n return []\n modules = []\n f = open(source,'r')\n f_readlines = getattr(f,'xreadlines',f.readlines)\n for line in f_readlines():\n m = f90_module_name_match(line)\n if m:\n name = m.group('name')\n modules.append(name)\n # break # XXX can we assume that there is one module per file?\n f.close()\n return modules\n\ndef is_string(s):\n return isinstance(s, str)\n\ndef all_strings(lst):\n \"\"\" Return True if all items in lst are string objects. \"\"\"\n for item in lst:\n if not is_string(item):\n return False\n return True\n\ndef is_sequence(seq):\n if is_string(seq):\n return False\n try:\n len(seq)\n except:\n return False\n return True\n\ndef as_list(seq):\n if is_sequence(seq):\n return list(seq)\n else:\n return [seq]\n\ndef has_f_sources(sources):\n \"\"\" Return True if sources contains Fortran files \"\"\"\n for source in sources:\n if fortran_ext_match(source):\n return True\n return False\n\ndef has_cxx_sources(sources):\n \"\"\" Return True if sources contains C++ files \"\"\"\n for source in sources:\n if cxx_ext_match(source):\n return True\n return False\n\ndef filter_sources(sources):\n \"\"\" Return four lists of filenames containing\n C, C++, Fortran, and Fortran 90 module sources,\n respectively.\n \"\"\"\n c_sources = []\n cxx_sources = []\n f_sources = []\n fmodule_sources = []\n for source in sources:\n if fortran_ext_match(source):\n modules = _get_f90_modules(source)\n if modules:\n fmodule_sources.append(source)\n else:\n f_sources.append(source)\n elif cxx_ext_match(source):\n cxx_sources.append(source)\n else:\n c_sources.append(source)\n return c_sources, cxx_sources, f_sources, fmodule_sources\n\n\ndef _get_headers(directory_list):\n # get *.h files from list of directories\n headers = []\n for d in directory_list:\n head = glob.glob(os.path.join(d,\"*.h\")) #XXX: *.hpp files??\n headers.extend(head)\n return headers\n\ndef _get_directories(list_of_sources):\n # get unique directories from list of sources.\n direcs = []\n for f in list_of_sources:\n d = os.path.split(f)\n if d[0] != '' and not d[0] in direcs:\n direcs.append(d[0])\n return direcs\n\ndef get_dependencies(sources):\n #XXX scan sources for include statements\n return _get_headers(_get_directories(sources))\n\ndef is_local_src_dir(directory):\n \"\"\" Return true if directory is local directory.\n \"\"\"\n if not is_string(directory):\n return False\n abs_dir = os.path.abspath(directory)\n c = os.path.commonprefix([os.getcwd(),abs_dir])\n new_dir = abs_dir[len(c):].split(os.sep)\n if new_dir and not new_dir[0]:\n new_dir = new_dir[1:]\n if new_dir and new_dir[0]=='build':\n return False\n new_dir = os.sep.join(new_dir)\n return os.path.isdir(new_dir)\n\ndef general_source_files(top_path):\n pruned_directories = {'CVS':1, '.svn':1, 'build':1}\n prune_file_pat = re.compile(r'(?:[~#]|\\.py[co]|\\.o)$')\n for dirpath, dirnames, filenames in os.walk(top_path, topdown=True):\n pruned = [ d for d in dirnames if d not in pruned_directories ]\n dirnames[:] = pruned\n for f in filenames:\n if not prune_file_pat.search(f):\n yield os.path.join(dirpath, f)\n\ndef get_ext_source_files(ext):\n # Get sources and any include files in the same directory.\n filenames = []\n sources = filter(is_string, ext.sources)\n filenames.extend(sources)\n filenames.extend(get_dependencies(sources))\n for d in ext.depends:\n if is_local_src_dir(d):\n filenames.extend(list(general_source_files(d)))\n elif os.path.isfile(d):\n filenames.append(d)\n return filenames\n\ndef get_script_files(scripts):\n scripts = filter(is_string, scripts)\n return scripts\n\ndef get_lib_source_files(lib):\n filenames = []\n sources = lib[1].get('sources',[])\n sources = filter(is_string, sources)\n filenames.extend(sources)\n filenames.extend(get_dependencies(sources))\n depends = lib[1].get('depends',[])\n for d in depends:\n if is_local_src_dir(d):\n filenames.extend(list(general_source_files(d)))\n elif os.path.isfile(d):\n filenames.append(d)\n return filenames\n\ndef get_data_files(data):\n if is_string(data):\n return [data]\n sources = data[1]\n filenames = []\n for s in sources:\n if callable(s):\n continue\n if is_local_src_dir(s):\n filenames.extend(list(general_source_files(s)))\n elif is_string(s):\n if os.path.isfile(s):\n filenames.append(s)\n else:\n print 'Not existing data file:',s\n else:\n raise TypeError,repr(s)\n return filenames\n\ndef dot_join(*args):\n return '.'.join([a for a in args if a])\n\ndef get_frame(level=0):\n try:\n return sys._getframe(level+1)\n except AttributeError:\n frame = sys.exc_info()[2].tb_frame\n for _ in range(level+1):\n frame = frame.f_back\n return frame\n\n######################\n\nclass Configuration(object):\n\n _list_keys = ['packages', 'ext_modules', 'data_files', 'include_dirs',\n 'libraries', 'headers', 'scripts', 'py_modules']\n _dict_keys = ['package_dir']\n\n numpy_include_dirs = []\n\n def __init__(self,\n package_name=None,\n parent_name=None,\n top_path=None,\n package_path=None,\n **attrs):\n \"\"\" Construct configuration instance of a package.\n\n package_name -- name of the package\n Ex.: 'distutils'\n parent_name -- name of the parent package\n Ex.: 'numpy'\n top_path -- directory of the toplevel package\n Ex.: the directory where the numpy package source sits\n package_path -- directory of package. Will be computed by magic from the\n directory of the caller module if not specified\n Ex.: the directory where numpy.distutils is\n \"\"\"\n self.name = dot_join(parent_name, package_name)\n\n caller_frame = get_frame(1)\n caller_name = eval('__name__',caller_frame.f_globals,caller_frame.f_locals)\n\n self.local_path = get_path(caller_name, top_path)\n if top_path is None:\n top_path = self.local_path\n if package_path is None:\n package_path = self.local_path\n elif os.path.isdir(njoin(self.local_path,package_path)):\n package_path = njoin(self.local_path,package_path)\n if not os.path.isdir(package_path):\n raise ValueError(\"%r is not a directory\" % (package_path,))\n self.top_path = top_path\n self.package_path = package_path\n # this is the relative path in the installed package\n self.path_in_package = os.path.join(*self.name.split('.'))\n\n self.list_keys = self._list_keys[:]\n self.dict_keys = self._dict_keys[:]\n\n for n in self.list_keys:\n v = copy.copy(attrs.get(n, []))\n setattr(self, n, as_list(v))\n\n for n in self.dict_keys:\n v = copy.copy(attrs.get(n, {}))\n setattr(self, n, v)\n\n known_keys = self.list_keys + self.dict_keys\n self.extra_keys = []\n for n in attrs.keys():\n if n in known_keys:\n continue\n a = attrs[n]\n setattr(self,n,a)\n if isinstance(a, list):\n self.list_keys.append(n)\n elif isinstance(a, dict):\n self.dict_keys.append(n)\n else:\n self.extra_keys.append(n)\n\n if os.path.exists(njoin(package_path,'__init__.py')):\n self.packages.append(self.name)\n self.package_dir[self.name] = package_path\n\n self.options = dict(\n ignore_setup_xxx_py = False,\n assume_default_configuration = False,\n delegate_options_to_subpackages = False,\n quiet = False,\n )\n\n for i in range(1,3):\n f = get_frame(i)\n try:\n caller_instance = eval('self',f.f_globals,f.f_locals)\n break\n except NameError:\n caller_instance = None\n if isinstance(caller_instance, self.__class__):\n if caller_instance.options['delegate_options_to_subpackages']:\n self.set_options(**caller_instance.options)\n\n def todict(self):\n \"\"\" Return configuration distionary suitable for passing\n to distutils.core.setup() function.\n \"\"\"\n d = {}\n for n in self.list_keys + self.dict_keys + self.extra_keys:\n a = getattr(self,n)\n if a:\n d[n] = a\n if self.name:\n d['name'] = self.name\n return d\n\n def info(self, message):\n if not self.options['quiet']:\n print message\n\n def warn(self, message):\n print>>sys.stderr, 'Warning:',message\n\n\n def set_options(self, **options):\n \"\"\" Configure Configuration instance.\n\n The following options are available:\n - ignore_setup_xxx_py\n - assume_default_configuration\n - delegate_options_to_subpackages\n - quiet\n \"\"\"\n for key, value in options.items():\n if self.options.has_key(key):\n self.options[key] = value\n else:\n raise ValueError,'Unknown option: '+key\n\n def get_distribution(self):\n import distutils.core\n dist = distutils.core._setup_distribution\n return dist\n\n def _wildcard_get_subpackage(self, subpackage_name):\n l = subpackage_name.split('.')\n subpackage_path = njoin([self.local_path]+l)\n dirs = filter(os.path.isdir,glob.glob(subpackage_path))\n config_list = []\n for d in dirs:\n if not os.path.isfile(njoin(d,'__init__.py')):\n continue\n if 'build' in d.split(os.sep):\n continue\n n = '.'.join(d.split(os.sep)[-len(l):])\n c = self.get_subpackage(n)\n config_list.extend(c)\n return config_list\n\n def _get_configuration_from_setup_py(self, setup_py,\n subpackage_name, subpackage_path):\n # In case setup_py imports local modules:\n sys.path.insert(0,os.path.dirname(setup_py))\n try:\n fo_setup_py = open(setup_py, 'U')\n setup_name = os.path.splitext(os.path.basename(setup_py))[0]\n n = dot_join(self.name,setup_name)\n setup_module = imp.load_module('_'.join(n.split('.')),\n fo_setup_py,\n setup_py,\n ('.py', 'U', 1))\n if not hasattr(setup_module,'configuration'):\n if not self.options['assume_default_configuration']:\n self.warn('Assuming default configuration '\\\n '(%s does not define configuration())'\\\n % (setup_module))\n config = Configuration(subpackage_name, self.name,\n self.top_path, subpackage_path)\n else:\n args = (self.name,)\n if setup_module.configuration.func_code.co_argcount > 1:\n args = args + (self.top_path,)\n config = setup_module.configuration(*args)\n finally:\n del sys.path[0]\n return config\n\n def get_subpackage(self,subpackage_name,subpackage_path=None):\n \"\"\" Return list of subpackage configurations.\n\n '*' in subpackage_name is handled as a wildcard.\n \"\"\"\n if subpackage_name is None:\n if subpackage_path is None:\n raise ValueError(\n \"either subpackage_name or subpackage_path must be specified\")\n subpackage_name = os.path.basename(subpackage_path)\n\n # handle wildcards\n l = subpackage_name.split('.')\n if subpackage_path is None and '*' in subpackage_name:\n return self._wildcard_get_subpackage(subpackage_name)\n\n if subpackage_path is None:\n subpackage_path = njoin([self.local_path] + l)\n else:\n subpackage_path = njoin([subpackage_path] + l[:-1])\n subpackage_path = self._fix_paths([subpackage_path])[0]\n\n setup_py = njoin(subpackage_path, 'setup.py')\n if not self.options['ignore_setup_xxx_py']:\n if not os.path.isfile(setup_py):\n setup_py = njoin(subpackage_path,\n 'setup_%s.py' % (subpackage_name))\n\n if not os.path.isfile(setup_py):\n if not self.options['assume_default_configuration']:\n self.warn('Assuming default configuration '\\\n '(%s/{setup_%s,setup}.py was not found)' \\\n % (os.path.dirname(setup_py), subpackage_name))\n config = Configuration(subpackage_name, self.name,\n self.top_path, subpackage_path)\n else:\n config = self._get_configuration_from_setup_py(setup_py,\n subpackage_name,\n subpackage_path)\n\n if config:\n return [config]\n else:\n return []\n\n def add_subpackage(self,subpackage_name,subpackage_path=None):\n \"\"\" Add subpackage to configuration.\n \"\"\"\n config_list = self.get_subpackage(subpackage_name,subpackage_path)\n if not config_list:\n self.warn('No configuration returned, assuming unavailable.')\n for config in config_list:\n try:\n d = config.todict()\n except AttributeError:\n d = config\n self.info('Appending %s configuration to %s' \\\n % (d.get('name'), self.name))\n self.dict_append(**d)\n\n dist = self.get_distribution()\n if dist is not None:\n self.warn('distutils distribution has been initialized,'\\\n ' it may be too late to add a subpackage '+ subpackage_name)\n return\n\n def add_data_dir(self,data_path):\n \"\"\" Recursively add files under data_path to data_files list.\n Argument can be either\n - 2-sequence (,)\n - path to data directory where python datadir suffix defaults\n to package dir.\n If path is not absolute then it's datadir suffix is\n package dir + subdirname of the path.\n \"\"\"\n if is_sequence(data_path):\n d, data_path = data_path\n else:\n d = None\n if not is_string(data_path):\n raise TypeError(\"not a string: %r\" % (data_path,))\n for path in self.paths(data_path):\n if not os.path.exists(path):\n continue\n filenames = list(general_source_files(path))\n if not os.path.isabs(path):\n npath = data_path\n if '*' in npath:\n npath = os.path.join(*(path.split(os.sep)[-len(npath.split(os.sep)):]))\n if d is None:\n d = self.path_in_package\n ds = os.path.join(d, npath)\n self.add_data_files((ds,filenames))\n else:\n if d is None:\n self.add_data_files(*filenames)\n else:\n self.add_data_files((d,filenames))\n return\n\n def add_data_files(self,*files):\n \"\"\" Add data files to configuration data_files.\n Argument(s) can be either\n - 2-sequence (,)\n - paths to data files where python datadir prefix defaults\n to package dir.\n If path is not absolute then it's datadir prefix is\n package dir + dirname of the path.\n \"\"\"\n data_dict = {}\n new_files = []\n for p in files:\n if not is_sequence(p):\n d = self.path_in_package\n if is_string(p) and not os.path.isabs(p):\n pd = os.path.dirname(p)\n if '*' in pd:\n pn = os.path.basename(p)\n n = len(pd.split(os.sep))\n for d1 in filter(os.path.isdir,self.paths(pd)):\n p = os.path.join(d1,pn)\n d1 = os.sep.join(d1.split(os.sep)[-n:])\n new_files.append((appendpath(d,d1),p))\n continue\n d = appendpath(d,pd)\n p = (d,p)\n new_files.append(p)\n\n files = []\n for prefix,filepattern in new_files:\n assert '*' not in prefix, repr((prefix,filepattern))\n if is_string(filepattern):\n file_list = self.paths(filepattern,include_non_existing=False)\n elif callable(filepattern):\n file_list = [filepattern]\n else:\n file_list = self.paths(*filepattern)\n\n nof_path_components = [len(f.split(os.sep))\n for f in file_list if is_string(f)]\n if nof_path_components:\n min_path_components = min(nof_path_components)-1\n else:\n min_path_components = 0\n\n for f in file_list:\n if is_string(f):\n extra_path_components = f.split(os.sep)[min_path_components:-1]\n p = njoin([prefix]+extra_path_components)\n else:\n p = prefix\n if not data_dict.has_key(p):\n data_dict[p] = [f]\n else:\n data_dict[p].append(f)\n\n dist = self.get_distribution()\n if dist is not None:\n dist.data_files.extend(data_dict.items())\n else:\n self.data_files.extend(data_dict.items())\n\n ### XXX Implement add_py_modules\n\n def add_include_dirs(self,*paths):\n \"\"\" Add paths to configuration include directories.\n \"\"\"\n include_dirs = self._fix_paths(paths)\n dist = self.get_distribution()\n if dist is not None:\n dist.include_dirs.extend(include_dirs)\n else:\n self.include_dirs.extend(include_dirs)\n return\n\n def add_headers(self,*files):\n \"\"\" Add installable headers to configuration.\n Argument(s) can be either\n - 2-sequence (,)\n - path(s) to header file(s) where python includedir suffix will default\n to package name.\n \"\"\"\n headers = []\n for path in files:\n if is_string(path):\n [headers.append((self.name,p)) for p in self.paths(path)]\n else:\n if not isinstance(path, (tuple, list)) or len(path) != 2:\n raise TypeError(repr(path))\n [headers.append((path[0],p)) for p in self.paths(path[1])]\n dist = self.get_distribution()\n if dist is not None:\n dist.headers.extend(headers)\n else:\n self.headers.extend(headers)\n return\n\n def _fix_paths(self,paths,include_non_existing=True):\n assert is_sequence(paths), repr(type(paths))\n new_paths = []\n for n in paths:\n if isinstance(n,str):\n if '*' in n or '?' in n:\n p = glob.glob(n)\n p2 = glob.glob(njoin(self.local_path,n))\n if p2:\n new_paths.extend(p2)\n elif p:\n new_paths.extend(p)\n else:\n if include_non_existing:\n new_paths.append(n)\n self.warn('could not resolve pattern in %s: %r' \\\n % (self.local_path,n))\n else:\n n2 = njoin(self.local_path,n)\n if os.path.exists(n2):\n new_paths.append(n2)\n else:\n if os.path.exists(n):\n new_paths.append(n)\n elif include_non_existing:\n new_paths.append(n)\n if not os.path.exists(n):\n self.warn('not existing path in %s: %s' \\\n % (self.local_path,n))\n else:\n new_paths.append(n)\n return map(minrelpath,new_paths)\n\n def paths(self,*paths,**kws):\n \"\"\" Apply glob to paths and prepend local_path if needed.\n \"\"\"\n include_non_existing = kws.get('include_non_existing',True)\n return self._fix_paths(paths,\n include_non_existing=include_non_existing)\n\n def _fix_paths_dict(self,kw):\n for k in kw.keys():\n v = kw[k]\n if k in ['sources','depends','include_dirs','library_dirs',\n 'module_dirs','extra_objects']:\n new_v = self._fix_paths(v)\n kw[k] = new_v\n return\n\n def add_extension(self,name,sources,**kw):\n \"\"\" Add extension to configuration.\n\n Keywords:\n include_dirs, define_macros, undef_macros,\n library_dirs, libraries, runtime_library_dirs,\n extra_objects, extra_compile_args, extra_link_args,\n export_symbols, swig_opts, depends, language,\n f2py_options, module_dirs\n extra_info - dict or list of dict of keywords to be\n appended to keywords.\n \"\"\"\n ext_args = copy.copy(kw)\n ext_args['name'] = dot_join(self.name,name)\n ext_args['sources'] = sources\n\n if ext_args.has_key('extra_info'):\n extra_info = ext_args['extra_info']\n del ext_args['extra_info']\n if isinstance(extra_info, dict):\n extra_info = [extra_info]\n for info in extra_info:\n assert isinstance(info, dict), repr(info)\n dict_append(ext_args,**info)\n\n self._fix_paths_dict(ext_args)\n\n # Resolve out-of-tree dependencies\n libraries = ext_args.get('libraries',[])\n libnames = []\n ext_args['libraries'] = []\n for libname in libraries:\n if isinstance(libname,tuple):\n self._fix_paths_dict(libname[1])\n\n # Handle library names of the form libname@relative/path/to/library\n if '@' in libname:\n lname,lpath = libname.split('@',1)\n lpath = os.path.abspath(njoin(self.local_path,lpath))\n if os.path.isdir(lpath):\n c = self.get_subpackage(None,lpath)\n if isinstance(c,Configuration):\n c = c.todict()\n for l in [l[0] for l in c.get('libraries',[])]:\n llname = l.split('__OF__',1)[0]\n if llname == lname:\n c.pop('name',None)\n dict_append(ext_args,**c)\n break\n continue\n libnames.append(libname)\n\n ext_args['libraries'] = libnames + ext_args['libraries']\n\n from numpy.distutils.core import Extension\n ext = Extension(**ext_args)\n self.ext_modules.append(ext)\n\n dist = self.get_distribution()\n if dist is not None:\n self.warn('distutils distribution has been initialized,'\\\n ' it may be too late to add an extension '+name)\n return ext\n\n def add_library(self,name,sources,**build_info):\n \"\"\" Add library to configuration.\n\n Valid keywords for build_info:\n depends\n macros\n include_dirs\n extra_compiler_args\n f2py_options\n \"\"\"\n build_info = copy.copy(build_info)\n name = name #+ '__OF__' + self.name\n build_info['sources'] = sources\n\n self._fix_paths_dict(build_info)\n \n self.libraries.append((name,build_info))\n\n dist = self.get_distribution()\n if dist is not None:\n self.warn('distutils distribution has been initialized,'\\\n ' it may be too late to add a library '+ name)\n return\n\n def add_scripts(self,*files):\n \"\"\" Add scripts to configuration.\n \"\"\"\n scripts = self._fix_paths(files)\n dist = self.get_distribution()\n if dist is not None:\n dist.scripts.extend(scripts)\n else:\n self.scripts.extend(scripts)\n return\n\n def dict_append(self,**dict):\n for key in self.list_keys:\n a = getattr(self,key)\n a.extend(dict.get(key,[]))\n for key in self.dict_keys:\n a = getattr(self,key)\n a.update(dict.get(key,{}))\n known_keys = self.list_keys + self.dict_keys + self.extra_keys\n for key in dict.keys():\n if key not in known_keys and not hasattr(self,key):\n if key not in ['version']:\n self.warn('Inheriting attribute %r from %r' \\\n % (key,dict.get('name','?')))\n setattr(self,key,dict[key])\n self.extra_keys.append(key)\n return\n\n def __str__(self):\n known_keys = self.list_keys + self.dict_keys + self.extra_keys\n s = '<'+5*'-' + '\\n'\n s += 'Configuration of '+self.name+':\\n'\n for k in known_keys:\n a = getattr(self,k,None)\n if a:\n s += '%s = %r\\n' % (k,a)\n s += 5*'-' + '>'\n return s\n\n def get_config_cmd(self):\n cmd = get_cmd('config')\n cmd.ensure_finalized()\n cmd.dump_source = 0\n cmd.noisy = 0\n old_path = os.environ.get('PATH')\n if old_path:\n path = os.pathsep.join(['.',old_path])\n os.environ['PATH'] = path\n return cmd\n\n def get_build_temp_dir(self):\n cmd = get_cmd('build')\n cmd.ensure_finalized()\n return cmd.build_temp\n\n def have_f77c(self):\n \"\"\" Check for availability of Fortran 77 compiler.\n Use it inside source generating function to ensure that\n setup distribution instance has been initialized.\n \"\"\"\n simple_fortran_subroutine = '''\n subroutine simple\n end\n '''\n config_cmd = self.get_config_cmd()\n flag = config_cmd.try_compile(simple_fortran_subroutine,lang='f77')\n return flag\n\n def have_f90c(self):\n \"\"\" Check for availability of Fortran 90 compiler.\n Use it inside source generating function to ensure that\n setup distribution instance has been initialized.\n \"\"\"\n simple_fortran_subroutine = '''\n subroutine simple\n end\n '''\n config_cmd = self.get_config_cmd()\n flag = config_cmd.try_compile(simple_fortran_subroutine,lang='f90')\n return flag\n\n def append_to(self, extlib):\n \"\"\" Append libraries, include_dirs to extension or library item.\n \"\"\"\n if is_sequence(extlib):\n lib_name, build_info = extlib\n dict_append(build_info,\n libraries=self.libraries,\n include_dirs=self.include_dirs)\n else:\n from numpy.distutils.core import Extension\n assert isinstance(extlib,Extension), repr(extlib)\n extlib.libraries.extend(self.libraries)\n extlib.include_dirs.extend(self.include_dirs)\n return\n\n def _get_svn_revision(self,path):\n \"\"\" Return path's SVN revision number.\n \"\"\"\n entries = njoin(path,'.svn','entries')\n revision = None\n if os.path.isfile(entries):\n f = open(entries)\n m = re.search(r'revision=\"(?P\\d+)\"',f.read())\n f.close()\n if m:\n revision = int(m.group('revision'))\n return revision\n\n def get_version(self):\n \"\"\" Try to get version string of a package.\n \"\"\"\n version = getattr(self,'version',None)\n if version is not None:\n return version\n\n # Get version from version file.\n files = ['__version__.py',\n self.name.split('.')[-1]+'_version.py',\n 'version.py',\n '__svn_version__.py']\n version_vars = ['version',\n '__version__',\n self.name.split('.')[-1]+'_version']\n for f in files:\n fn = njoin(self.local_path,f)\n if os.path.isfile(fn):\n info = (open(fn),fn,('.py','U',1))\n name = os.path.splitext(os.path.basename(fn))[0]\n n = dot_join(self.name,name)\n try:\n version_module = imp.load_module('_'.join(n.split('.')),*info)\n except ImportError,msg:\n self.warn(str(msg))\n version_module = None\n if version_module is None:\n continue\n\n for a in version_vars:\n version = getattr(version_module,a,None)\n if version is not None:\n break\n if version is not None:\n break\n\n if version is not None:\n self.version = version\n return version\n\n # Get version as SVN revision number\n revision = self._get_svn_revision(self.local_path)\n if revision is not None:\n version = str(revision)\n self.version = version\n\n return version\n\n def make_svn_version_py(self):\n \"\"\" Generate package __svn_version__.py file from SVN revision number,\n it will be removed after python exits but will be available\n when sdist, etc commands are executed.\n\n If __svn_version__.py existed before, nothing is done.\n \"\"\"\n target = njoin(self.local_path,'__svn_version__.py')\n if os.path.isfile(target):\n return\n def generate_svn_version_py():\n if not os.path.isfile(target):\n revision = self._get_svn_revision(self.local_path)\n assert revision is not None,'hmm, why I am not inside SVN tree???'\n version = str(revision)\n self.info('Creating %s (version=%r)' % (target,version))\n f = open(target,'w')\n f.write('version = %r\\n' % (version))\n f.close()\n\n import atexit\n def rm_file(f=target,p=self.info):\n try: os.remove(f); p('removed '+f)\n except OSError: pass\n try: os.remove(f+'c'); p('removed '+f+'c')\n except OSError: pass\n atexit.register(rm_file)\n\n return target\n\n self.add_data_files((self.path_in_package, generate_svn_version_py()))\n\n def make_config_py(self,name='__config__'):\n \"\"\" Generate package __config__.py file containing system_info\n information used during building the package.\n \"\"\"\n self.py_modules.append((self.name,name,generate_config_py))\n return\n\n def get_info(self,*names):\n \"\"\" Get resources information.\n \"\"\"\n from system_info import get_info, dict_append\n info_dict = {}\n for a in names:\n dict_append(info_dict,**get_info(a))\n return info_dict\n\nclass BadConfiguration(Configuration):\n \"\"\"\n When the command line is not ok, use this as the configuration class.\n \"\"\"\n def _do_nothing(self, *args, **kw):\n pass\n add_subpackage = _do_nothing\n add_extension = _do_nothing\n add_library = _do_nothing\n add_data_dir = _do_nothing\n add_data_files = _do_nothing\n add_scripts = _do_nothing\n add_headers = _do_nothing\n add_include_dirs = _do_nothing\n make_config_py = _do_nothing\n\n def get_info(self, *args, **kw):\n return {}\n def have_f77c(self, *args, **kw):\n return False\n def have_f90c(self, *args, **kw):\n return False\n\ndef command_line_ok(_cache=[]):\n \"\"\" Return True if command line does not contain any\n help or display requests.\n \"\"\"\n if _cache:\n return _cache[0]\n ok = True\n from distutils.dist import Distribution\n display_opts = ['--'+n for n in Distribution.display_option_names]\n for o in Distribution.display_options:\n if o[1]:\n display_opts.append('-'+o[1])\n for arg in sys.argv:\n if arg.startswith('--help') or arg=='-h' or arg in display_opts:\n ok = False\n break\n _cache.append(ok)\n return ok\n\nif not command_line_ok():\n Configuration = BadConfiguration\n\ndef get_cmd(cmdname, _cache={}):\n if not _cache.has_key(cmdname):\n import distutils.core\n dist = distutils.core._setup_distribution\n if dist is None:\n from distutils.errors import DistutilsInternalError\n raise DistutilsInternalError(\n 'setup distribution instance not initialized')\n cmd = dist.get_command_obj(cmdname)\n _cache[cmdname] = cmd\n return _cache[cmdname]\n\ndef get_numpy_include_dirs():\n # numpy_include_dirs are set by numpy/core/setup.py, otherwise []\n include_dirs = Configuration.numpy_include_dirs[:]\n if not include_dirs:\n import numpy\n if numpy.show_config is None:\n # running from numpy_core source directory\n include_dirs.append(njoin(os.path.dirname(numpy.__file__),\n 'core', 'include'))\n else:\n # using installed numpy core headers\n import numpy.core as core\n include_dirs.append(njoin(os.path.dirname(core.__file__), 'include'))\n # else running numpy/core/setup.py\n return include_dirs\n\n#########################\n\ndef default_config_dict(name = None, parent_name = None, local_path=None):\n \"\"\" Return a configuration dictionary for usage in\n configuration() function defined in file setup_.py.\n \"\"\"\n import warnings\n warnings.warn('Use Configuration(%r,%r,top_path=%r) instead of '\\\n 'deprecated default_config_dict(%r,%r,%r)'\n % (name, parent_name, local_path,\n name, parent_name, local_path,\n ))\n c = Configuration(name, parent_name, local_path)\n return c.todict()\n\n\ndef dict_append(d, **kws):\n for k, v in kws.items():\n if d.has_key(k):\n d[k].extend(v)\n else:\n d[k] = v\n\ndef appendpath(prefix, path):\n if os.path.sep != '/':\n prefix = prefix.replace('/', os.path.sep)\n path = path.replace('/', os.path.sep)\n drive = ''\n if os.path.isabs(path):\n drive = os.path.splitdrive(prefix)[0]\n absprefix = os.path.splitdrive(os.path.abspath(prefix))[1]\n pathdrive, path = os.path.splitdrive(path)\n d = os.path.commonprefix([absprefix, path])\n if os.path.join(absprefix[:len(d)], absprefix[len(d):]) != absprefix \\\n or os.path.join(path[:len(d)], path[len(d):]) != path:\n # Handle invalid paths\n d = os.path.dirname(d)\n subpath = path[len(d):]\n if os.path.isabs(subpath):\n subpath = subpath[1:]\n else:\n subpath = path\n return os.path.normpath(njoin(drive + prefix, subpath))\n\ndef generate_config_py(target):\n \"\"\" Generate config.py file containing system_info information\n used during building the package.\n\n Usage:\\\n config['py_modules'].append((packagename, '__config__',generate_config_py))\n \"\"\"\n from numpy.distutils.system_info import system_info\n from distutils.dir_util import mkpath\n mkpath(os.path.dirname(target))\n f = open(target, 'w')\n f.write('# This file is generated by %s\\n' % (os.path.abspath(sys.argv[0])))\n f.write('# It contains system_info results at the time of building this package.\\n')\n f.write('__all__ = [\"get_info\",\"show\"]\\n\\n')\n for k, i in system_info.saved_results.items():\n f.write('%s=%r\\n' % (k, i))\n f.write('\\ndef get_info(name): g=globals(); return g.get(name,g.get(name+\"_info\",{}))\\n')\n f.write('''\ndef show():\n for name,info_dict in globals().items():\n if name[0]==\"_\" or type(info_dict) is not type({}): continue\n print name+\":\"\n if not info_dict:\n print \" NOT AVAILABLE\"\n for k,v in info_dict.items():\n v = str(v)\n if k==\\'sources\\' and len(v)>200: v = v[:60]+\\' ...\\\\n... \\'+v[-60:]\n print \\' %s = %s\\'%(k,v)\n print\n return\n ''')\n\n f.close()\n return target\n", + "methods": [ + { + "name": "allpath", + "long_name": "allpath( name )", + "filename": "misc_util.py", + "nloc": 4, + "complexity": 1, + "token_count": 24, + "parameters": [ + "name" + ], + "start_line": 19, + "end_line": 22, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 0 + }, + { + "name": "get_path", + "long_name": "get_path( mod_name , parent_path = None )", + "filename": "misc_util.py", + "nloc": 16, + "complexity": 6, + "token_count": 139, + "parameters": [ + "mod_name", + "parent_path" + ], + "start_line": 24, + "end_line": 49, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 26, + "top_nesting_level": 0 + }, + { + "name": "njoin", + "long_name": "njoin( * path )", + "filename": "misc_util.py", + "nloc": 10, + "complexity": 5, + "token_count": 85, + "parameters": [ + "path" + ], + "start_line": 51, + "end_line": 70, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 20, + "top_nesting_level": 0 + }, + { + "name": "minrelpath", + "long_name": "minrelpath( path )", + "filename": "misc_util.py", + "nloc": 20, + "complexity": 7, + "token_count": 101, + "parameters": [ + "path" + ], + "start_line": 72, + "end_line": 93, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 22, + "top_nesting_level": 0 + }, + { + "name": "terminal_has_colors", + "long_name": "terminal_has_colors( )", + "filename": "misc_util.py", + "nloc": 18, + "complexity": 13, + "token_count": 137, + "parameters": [], + "start_line": 97, + "end_line": 122, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 26, + "top_nesting_level": 0 + }, + { + "name": "cyg2win32", + "long_name": "cyg2win32( path )", + "filename": "misc_util.py", + "nloc": 4, + "complexity": 3, + "token_count": 42, + "parameters": [ + "path" + ], + "start_line": 139, + "end_line": 142, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 0 + }, + { + "name": "_get_f90_modules", + "long_name": "_get_f90_modules( source )", + "filename": "misc_util.py", + "nloc": 13, + "complexity": 4, + "token_count": 77, + "parameters": [ + "source" + ], + "start_line": 151, + "end_line": 167, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 17, + "top_nesting_level": 0 + }, + { + "name": "is_string", + "long_name": "is_string( s )", + "filename": "misc_util.py", + "nloc": 2, + "complexity": 1, + "token_count": 12, + "parameters": [ + "s" + ], + "start_line": 169, + "end_line": 170, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 0 + }, + { + "name": "all_strings", + "long_name": "all_strings( lst )", + "filename": "misc_util.py", + "nloc": 5, + "complexity": 3, + "token_count": 22, + "parameters": [ + "lst" + ], + "start_line": 172, + "end_line": 177, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 6, + "top_nesting_level": 0 + }, + { + "name": "is_sequence", + "long_name": "is_sequence( seq )", + "filename": "misc_util.py", + "nloc": 8, + "complexity": 3, + "token_count": 25, + "parameters": [ + "seq" + ], + "start_line": 179, + "end_line": 186, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 8, + "top_nesting_level": 0 + }, + { + "name": "as_list", + "long_name": "as_list( seq )", + "filename": "misc_util.py", + "nloc": 5, + "complexity": 2, + "token_count": 22, + "parameters": [ + "seq" + ], + "start_line": 188, + "end_line": 192, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 5, + "top_nesting_level": 0 + }, + { + "name": "has_f_sources", + "long_name": "has_f_sources( sources )", + "filename": "misc_util.py", + "nloc": 5, + "complexity": 3, + "token_count": 21, + "parameters": [ + "sources" + ], + "start_line": 194, + "end_line": 199, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 6, + "top_nesting_level": 0 + }, + { + "name": "has_cxx_sources", + "long_name": "has_cxx_sources( sources )", + "filename": "misc_util.py", + "nloc": 5, + "complexity": 3, + "token_count": 21, + "parameters": [ + "sources" + ], + "start_line": 201, + "end_line": 206, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 6, + "top_nesting_level": 0 + }, + { + "name": "filter_sources", + "long_name": "filter_sources( sources )", + "filename": "misc_util.py", + "nloc": 17, + "complexity": 5, + "token_count": 84, + "parameters": [ + "sources" + ], + "start_line": 208, + "end_line": 228, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 21, + "top_nesting_level": 0 + }, + { + "name": "_get_headers", + "long_name": "_get_headers( directory_list )", + "filename": "misc_util.py", + "nloc": 6, + "complexity": 2, + "token_count": 39, + "parameters": [ + "directory_list" + ], + "start_line": 231, + "end_line": 237, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 7, + "top_nesting_level": 0 + }, + { + "name": "_get_directories", + "long_name": "_get_directories( list_of_sources )", + "filename": "misc_util.py", + "nloc": 7, + "complexity": 4, + "token_count": 51, + "parameters": [ + "list_of_sources" + ], + "start_line": 239, + "end_line": 246, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 8, + "top_nesting_level": 0 + }, + { + "name": "get_dependencies", + "long_name": "get_dependencies( sources )", + "filename": "misc_util.py", + "nloc": 2, + "complexity": 1, + "token_count": 13, + "parameters": [ + "sources" + ], + "start_line": 248, + "end_line": 250, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 0 + }, + { + "name": "is_local_src_dir", + "long_name": "is_local_src_dir( directory )", + "filename": "misc_util.py", + "nloc": 12, + "complexity": 6, + "token_count": 107, + "parameters": [ + "directory" + ], + "start_line": 252, + "end_line": 265, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 14, + "top_nesting_level": 0 + }, + { + "name": "general_source_files", + "long_name": "general_source_files( top_path )", + "filename": "misc_util.py", + "nloc": 9, + "complexity": 6, + "token_count": 92, + "parameters": [ + "top_path" + ], + "start_line": 267, + "end_line": 275, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 9, + "top_nesting_level": 0 + }, + { + "name": "get_ext_source_files", + "long_name": "get_ext_source_files( ext )", + "filename": "misc_util.py", + "nloc": 11, + "complexity": 4, + "token_count": 77, + "parameters": [ + "ext" + ], + "start_line": 277, + "end_line": 288, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 12, + "top_nesting_level": 0 + }, + { + "name": "get_script_files", + "long_name": "get_script_files( scripts )", + "filename": "misc_util.py", + "nloc": 3, + "complexity": 1, + "token_count": 15, + "parameters": [ + "scripts" + ], + "start_line": 290, + "end_line": 292, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 0 + }, + { + "name": "get_lib_source_files", + "long_name": "get_lib_source_files( lib )", + "filename": "misc_util.py", + "nloc": 13, + "complexity": 4, + "token_count": 101, + "parameters": [ + "lib" + ], + "start_line": 294, + "end_line": 306, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 13, + "top_nesting_level": 0 + }, + { + "name": "get_data_files", + "long_name": "get_data_files( data )", + "filename": "misc_util.py", + "nloc": 18, + "complexity": 7, + "token_count": 94, + "parameters": [ + "data" + ], + "start_line": 308, + "end_line": 325, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 18, + "top_nesting_level": 0 + }, + { + "name": "dot_join", + "long_name": "dot_join( * args )", + "filename": "misc_util.py", + "nloc": 2, + "complexity": 3, + "token_count": 21, + "parameters": [ + "args" + ], + "start_line": 327, + "end_line": 328, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 0 + }, + { + "name": "get_frame", + "long_name": "get_frame( level = 0 )", + "filename": "misc_util.py", + "nloc": 8, + "complexity": 3, + "token_count": 50, + "parameters": [ + "level" + ], + "start_line": 330, + "end_line": 337, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 8, + "top_nesting_level": 0 + }, + { + "name": "__init__", + "long_name": "__init__( self , package_name = None , parent_name = None , top_path = None , package_path = None , ** attrs )", + "filename": "misc_util.py", + "nloc": 61, + "complexity": 16, + "token_count": 458, + "parameters": [ + "self", + "package_name", + "parent_name", + "top_path", + "package_path", + "attrs" + ], + "start_line": 349, + "end_line": 431, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 83, + "top_nesting_level": 1 + }, + { + "name": "todict", + "long_name": "todict( self )", + "filename": "misc_util.py", + "nloc": 9, + "complexity": 4, + "token_count": 57, + "parameters": [ + "self" + ], + "start_line": 433, + "end_line": 444, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 12, + "top_nesting_level": 1 + }, + { + "name": "info", + "long_name": "info( self , message )", + "filename": "misc_util.py", + "nloc": 3, + "complexity": 2, + "token_count": 18, + "parameters": [ + "self", + "message" + ], + "start_line": 446, + "end_line": 448, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "warn", + "long_name": "warn( self , message )", + "filename": "misc_util.py", + "nloc": 2, + "complexity": 1, + "token_count": 17, + "parameters": [ + "self", + "message" + ], + "start_line": 450, + "end_line": 451, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 1 + }, + { + "name": "set_options", + "long_name": "set_options( self , ** options )", + "filename": "misc_util.py", + "nloc": 6, + "complexity": 3, + "token_count": 46, + "parameters": [ + "self", + "options" + ], + "start_line": 454, + "end_line": 467, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 14, + "top_nesting_level": 1 + }, + { + "name": "get_distribution", + "long_name": "get_distribution( self )", + "filename": "misc_util.py", + "nloc": 4, + "complexity": 1, + "token_count": 18, + "parameters": [ + "self" + ], + "start_line": 469, + "end_line": 472, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 1 + }, + { + "name": "_wildcard_get_subpackage", + "long_name": "_wildcard_get_subpackage( self , subpackage_name )", + "filename": "misc_util.py", + "nloc": 14, + "complexity": 4, + "token_count": 122, + "parameters": [ + "self", + "subpackage_name" + ], + "start_line": 474, + "end_line": 487, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 14, + "top_nesting_level": 1 + }, + { + "name": "_get_configuration_from_setup_py", + "long_name": "_get_configuration_from_setup_py( self , setup_py , subpackage_name , subpackage_path )", + "filename": "misc_util.py", + "nloc": 26, + "complexity": 5, + "token_count": 196, + "parameters": [ + "self", + "setup_py", + "subpackage_name", + "subpackage_path" + ], + "start_line": 489, + "end_line": 515, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 27, + "top_nesting_level": 1 + }, + { + "name": "get_subpackage", + "long_name": "get_subpackage( self , subpackage_name , subpackage_path = None )", + "filename": "misc_util.py", + "nloc": 34, + "complexity": 11, + "token_count": 232, + "parameters": [ + "self", + "subpackage_name", + "subpackage_path" + ], + "start_line": 517, + "end_line": 560, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 44, + "top_nesting_level": 1 + }, + { + "name": "add_subpackage", + "long_name": "add_subpackage( self , subpackage_name , subpackage_path = None )", + "filename": "misc_util.py", + "nloc": 17, + "complexity": 5, + "token_count": 103, + "parameters": [ + "self", + "subpackage_name", + "subpackage_path" + ], + "start_line": 562, + "end_line": 581, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 20, + "top_nesting_level": 1 + }, + { + "name": "add_data_dir", + "long_name": "add_data_dir( self , data_path )", + "filename": "misc_util.py", + "nloc": 25, + "complexity": 9, + "token_count": 185, + "parameters": [ + "self", + "data_path" + ], + "start_line": 583, + "end_line": 615, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 33, + "top_nesting_level": 1 + }, + { + "name": "add_data_files", + "long_name": "add_data_files( self , * files )", + "filename": "misc_util.py", + "nloc": 49, + "complexity": 17, + "token_count": 392, + "parameters": [ + "self", + "files" + ], + "start_line": 617, + "end_line": 677, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 61, + "top_nesting_level": 1 + }, + { + "name": "add_include_dirs", + "long_name": "add_include_dirs( self , * paths )", + "filename": "misc_util.py", + "nloc": 8, + "complexity": 2, + "token_count": 49, + "parameters": [ + "self", + "paths" + ], + "start_line": 681, + "end_line": 690, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 10, + "top_nesting_level": 1 + }, + { + "name": "add_headers", + "long_name": "add_headers( self , * files )", + "filename": "misc_util.py", + "nloc": 15, + "complexity": 8, + "token_count": 136, + "parameters": [ + "self", + "files" + ], + "start_line": 692, + "end_line": 712, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 21, + "top_nesting_level": 1 + }, + { + "name": "_fix_paths", + "long_name": "_fix_paths( self , paths , include_non_existing = True )", + "filename": "misc_util.py", + "nloc": 32, + "complexity": 12, + "token_count": 213, + "parameters": [ + "self", + "paths", + "include_non_existing" + ], + "start_line": 714, + "end_line": 745, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 32, + "top_nesting_level": 1 + }, + { + "name": "paths", + "long_name": "paths( self , * paths , ** kws )", + "filename": "misc_util.py", + "nloc": 4, + "complexity": 1, + "token_count": 33, + "parameters": [ + "self", + "paths", + "kws" + ], + "start_line": 747, + "end_line": 752, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 6, + "top_nesting_level": 1 + }, + { + "name": "_fix_paths_dict", + "long_name": "_fix_paths_dict( self , kw )", + "filename": "misc_util.py", + "nloc": 8, + "complexity": 3, + "token_count": 54, + "parameters": [ + "self", + "kw" + ], + "start_line": 754, + "end_line": 761, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 8, + "top_nesting_level": 1 + }, + { + "name": "add_extension", + "long_name": "add_extension( self , name , sources , ** kw )", + "filename": "misc_util.py", + "nloc": 43, + "complexity": 13, + "token_count": 337, + "parameters": [ + "self", + "name", + "sources", + "kw" + ], + "start_line": 763, + "end_line": 825, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 63, + "top_nesting_level": 1 + }, + { + "name": "add_library", + "long_name": "add_library( self , name , sources , ** build_info )", + "filename": "misc_util.py", + "nloc": 11, + "complexity": 2, + "token_count": 72, + "parameters": [ + "self", + "name", + "sources", + "build_info" + ], + "start_line": 827, + "end_line": 849, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 23, + "top_nesting_level": 1 + }, + { + "name": "add_scripts", + "long_name": "add_scripts( self , * files )", + "filename": "misc_util.py", + "nloc": 8, + "complexity": 2, + "token_count": 49, + "parameters": [ + "self", + "files" + ], + "start_line": 851, + "end_line": 860, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 10, + "top_nesting_level": 1 + }, + { + "name": "dict_append", + "long_name": "dict_append( self , ** dict )", + "filename": "misc_util.py", + "nloc": 16, + "complexity": 7, + "token_count": 150, + "parameters": [ + "self", + "dict" + ], + "start_line": 862, + "end_line": 877, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 16, + "top_nesting_level": 1 + }, + { + "name": "__str__", + "long_name": "__str__( self )", + "filename": "misc_util.py", + "nloc": 10, + "complexity": 3, + "token_count": 72, + "parameters": [ + "self" + ], + "start_line": 879, + "end_line": 888, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 10, + "top_nesting_level": 1 + }, + { + "name": "get_config_cmd", + "long_name": "get_config_cmd( self )", + "filename": "misc_util.py", + "nloc": 10, + "complexity": 2, + "token_count": 63, + "parameters": [ + "self" + ], + "start_line": 890, + "end_line": 899, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 10, + "top_nesting_level": 1 + }, + { + "name": "get_build_temp_dir", + "long_name": "get_build_temp_dir( self )", + "filename": "misc_util.py", + "nloc": 4, + "complexity": 1, + "token_count": 20, + "parameters": [ + "self" + ], + "start_line": 901, + "end_line": 904, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 1 + }, + { + "name": "have_f77c", + "long_name": "have_f77c( self )", + "filename": "misc_util.py", + "nloc": 8, + "complexity": 1, + "token_count": 30, + "parameters": [ + "self" + ], + "start_line": 906, + "end_line": 917, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 12, + "top_nesting_level": 1 + }, + { + "name": "have_f90c", + "long_name": "have_f90c( self )", + "filename": "misc_util.py", + "nloc": 8, + "complexity": 1, + "token_count": 30, + "parameters": [ + "self" + ], + "start_line": 919, + "end_line": 930, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 12, + "top_nesting_level": 1 + }, + { + "name": "append_to", + "long_name": "append_to( self , extlib )", + "filename": "misc_util.py", + "nloc": 12, + "complexity": 2, + "token_count": 78, + "parameters": [ + "self", + "extlib" + ], + "start_line": 932, + "end_line": 945, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 14, + "top_nesting_level": 1 + }, + { + "name": "_get_svn_revision", + "long_name": "_get_svn_revision( self , path )", + "filename": "misc_util.py", + "nloc": 10, + "complexity": 3, + "token_count": 73, + "parameters": [ + "self", + "path" + ], + "start_line": 947, + "end_line": 958, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 12, + "top_nesting_level": 1 + }, + { + "name": "get_version", + "long_name": "get_version( self )", + "filename": "misc_util.py", + "nloc": 38, + "complexity": 11, + "token_count": 260, + "parameters": [ + "self" + ], + "start_line": 960, + "end_line": 1006, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 47, + "top_nesting_level": 1 + }, + { + "name": "make_svn_version_py.make_svn_version_py.generate_svn_version_py.rm_file", + "long_name": "make_svn_version_py.make_svn_version_py.generate_svn_version_py.rm_file( f = target , p = self . info )", + "filename": "misc_util.py", + "nloc": 5, + "complexity": 3, + "token_count": 55, + "parameters": [ + "f", + "p" + ], + "start_line": 1029, + "end_line": 1033, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 5, + "top_nesting_level": 3 + }, + { + "name": "make_svn_version_py.generate_svn_version_py", + "long_name": "make_svn_version_py.generate_svn_version_py( )", + "filename": "misc_util.py", + "nloc": 13, + "complexity": 2, + "token_count": 85, + "parameters": [], + "start_line": 1018, + "end_line": 1036, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 19, + "top_nesting_level": 2 + }, + { + "name": "make_svn_version_py", + "long_name": "make_svn_version_py( self )", + "filename": "misc_util.py", + "nloc": 6, + "complexity": 2, + "token_count": 43, + "parameters": [ + "self" + ], + "start_line": 1008, + "end_line": 1038, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 31, + "top_nesting_level": 1 + }, + { + "name": "make_config_py", + "long_name": "make_config_py( self , name = '__config__' )", + "filename": "misc_util.py", + "nloc": 3, + "complexity": 1, + "token_count": 27, + "parameters": [ + "self", + "name" + ], + "start_line": 1040, + "end_line": 1045, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 6, + "top_nesting_level": 1 + }, + { + "name": "get_info", + "long_name": "get_info( self , * names )", + "filename": "misc_util.py", + "nloc": 6, + "complexity": 2, + "token_count": 36, + "parameters": [ + "self", + "names" + ], + "start_line": 1047, + "end_line": 1054, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 8, + "top_nesting_level": 1 + }, + { + "name": "_do_nothing", + "long_name": "_do_nothing( self , * args , ** kw )", + "filename": "misc_util.py", + "nloc": 2, + "complexity": 1, + "token_count": 12, + "parameters": [ + "self", + "args", + "kw" + ], + "start_line": 1060, + "end_line": 1061, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 1 + }, + { + "name": "get_info", + "long_name": "get_info( self , * args , ** kw )", + "filename": "misc_util.py", + "nloc": 2, + "complexity": 1, + "token_count": 14, + "parameters": [ + "self", + "args", + "kw" + ], + "start_line": 1072, + "end_line": 1073, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 1 + }, + { + "name": "have_f77c", + "long_name": "have_f77c( self , * args , ** kw )", + "filename": "misc_util.py", + "nloc": 2, + "complexity": 1, + "token_count": 13, + "parameters": [ + "self", + "args", + "kw" + ], + "start_line": 1074, + "end_line": 1075, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 1 + }, + { + "name": "have_f90c", + "long_name": "have_f90c( self , * args , ** kw )", + "filename": "misc_util.py", + "nloc": 2, + "complexity": 1, + "token_count": 13, + "parameters": [ + "self", + "args", + "kw" + ], + "start_line": 1076, + "end_line": 1077, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 1 + }, + { + "name": "command_line_ok", + "long_name": "command_line_ok( _cache = [ ] )", + "filename": "misc_util.py", + "nloc": 15, + "complexity": 9, + "token_count": 98, + "parameters": [ + "_cache" + ], + "start_line": 1079, + "end_line": 1096, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 18, + "top_nesting_level": 0 + }, + { + "name": "get_cmd", + "long_name": "get_cmd( cmdname , _cache = { } )", + "filename": "misc_util.py", + "nloc": 11, + "complexity": 3, + "token_count": 65, + "parameters": [ + "cmdname", + "_cache" + ], + "start_line": 1101, + "end_line": 1111, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 11, + "top_nesting_level": 0 + }, + { + "name": "get_numpy_include_dirs", + "long_name": "get_numpy_include_dirs( )", + "filename": "misc_util.py", + "nloc": 11, + "complexity": 3, + "token_count": 77, + "parameters": [], + "start_line": 1113, + "end_line": 1127, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 15, + "top_nesting_level": 0 + }, + { + "name": "default_config_dict", + "long_name": "default_config_dict( name = None , parent_name = None , local_path = None )", + "filename": "misc_util.py", + "nloc": 9, + "complexity": 1, + "token_count": 57, + "parameters": [ + "name", + "parent_name", + "local_path" + ], + "start_line": 1131, + "end_line": 1142, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 12, + "top_nesting_level": 0 + }, + { + "name": "dict_append", + "long_name": "dict_append( d , ** kws )", + "filename": "misc_util.py", + "nloc": 6, + "complexity": 3, + "token_count": 44, + "parameters": [ + "d", + "kws" + ], + "start_line": 1145, + "end_line": 1150, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 6, + "top_nesting_level": 0 + }, + { + "name": "appendpath", + "long_name": "appendpath( prefix , path )", + "filename": "misc_util.py", + "nloc": 19, + "complexity": 6, + "token_count": 230, + "parameters": [ + "prefix", + "path" + ], + "start_line": 1152, + "end_line": 1171, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 20, + "top_nesting_level": 0 + }, + { + "name": "generate_config_py", + "long_name": "generate_config_py( target )", + "filename": "misc_util.py", + "nloc": 27, + "complexity": 2, + "token_count": 117, + "parameters": [ + "target" + ], + "start_line": 1173, + "end_line": 1206, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 34, + "top_nesting_level": 0 + } + ], + "methods_before": [ + { + "name": "allpath", + "long_name": "allpath( name )", + "filename": "misc_util.py", + "nloc": 4, + "complexity": 1, + "token_count": 24, + "parameters": [ + "name" + ], + "start_line": 19, + "end_line": 22, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 0 + }, + { + "name": "get_path", + "long_name": "get_path( mod_name , parent_path = None )", + "filename": "misc_util.py", + "nloc": 15, + "complexity": 7, + "token_count": 140, + "parameters": [ + "mod_name", + "parent_path" + ], + "start_line": 24, + "end_line": 46, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 23, + "top_nesting_level": 0 + }, + { + "name": "njoin", + "long_name": "njoin( * path )", + "filename": "misc_util.py", + "nloc": 10, + "complexity": 5, + "token_count": 85, + "parameters": [ + "path" + ], + "start_line": 48, + "end_line": 67, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 20, + "top_nesting_level": 0 + }, + { + "name": "minrelpath", + "long_name": "minrelpath( path )", + "filename": "misc_util.py", + "nloc": 20, + "complexity": 7, + "token_count": 101, + "parameters": [ + "path" + ], + "start_line": 69, + "end_line": 90, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 22, + "top_nesting_level": 0 + }, + { + "name": "terminal_has_colors", + "long_name": "terminal_has_colors( )", + "filename": "misc_util.py", + "nloc": 18, + "complexity": 13, + "token_count": 137, + "parameters": [], + "start_line": 94, + "end_line": 119, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 26, + "top_nesting_level": 0 + }, + { + "name": "cyg2win32", + "long_name": "cyg2win32( path )", + "filename": "misc_util.py", + "nloc": 4, + "complexity": 3, + "token_count": 42, + "parameters": [ + "path" + ], + "start_line": 136, + "end_line": 139, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 0 + }, + { + "name": "_get_f90_modules", + "long_name": "_get_f90_modules( source )", + "filename": "misc_util.py", + "nloc": 13, + "complexity": 4, + "token_count": 77, + "parameters": [ + "source" + ], + "start_line": 148, + "end_line": 164, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 17, + "top_nesting_level": 0 + }, + { + "name": "is_string", + "long_name": "is_string( s )", + "filename": "misc_util.py", + "nloc": 2, + "complexity": 1, + "token_count": 12, + "parameters": [ + "s" + ], + "start_line": 166, + "end_line": 167, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 0 + }, + { + "name": "all_strings", + "long_name": "all_strings( lst )", + "filename": "misc_util.py", + "nloc": 5, + "complexity": 3, + "token_count": 22, + "parameters": [ + "lst" + ], + "start_line": 169, + "end_line": 174, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 6, + "top_nesting_level": 0 + }, + { + "name": "is_sequence", + "long_name": "is_sequence( seq )", + "filename": "misc_util.py", + "nloc": 8, + "complexity": 3, + "token_count": 25, + "parameters": [ + "seq" + ], + "start_line": 176, + "end_line": 183, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 8, + "top_nesting_level": 0 + }, + { + "name": "as_list", + "long_name": "as_list( seq )", + "filename": "misc_util.py", + "nloc": 5, + "complexity": 2, + "token_count": 22, + "parameters": [ + "seq" + ], + "start_line": 185, + "end_line": 189, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 5, + "top_nesting_level": 0 + }, + { + "name": "has_f_sources", + "long_name": "has_f_sources( sources )", + "filename": "misc_util.py", + "nloc": 5, + "complexity": 3, + "token_count": 21, + "parameters": [ + "sources" + ], + "start_line": 191, + "end_line": 196, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 6, + "top_nesting_level": 0 + }, + { + "name": "has_cxx_sources", + "long_name": "has_cxx_sources( sources )", + "filename": "misc_util.py", + "nloc": 5, + "complexity": 3, + "token_count": 21, + "parameters": [ + "sources" + ], + "start_line": 198, + "end_line": 203, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 6, + "top_nesting_level": 0 + }, + { + "name": "filter_sources", + "long_name": "filter_sources( sources )", + "filename": "misc_util.py", + "nloc": 17, + "complexity": 5, + "token_count": 84, + "parameters": [ + "sources" + ], + "start_line": 205, + "end_line": 225, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 21, + "top_nesting_level": 0 + }, + { + "name": "_get_headers", + "long_name": "_get_headers( directory_list )", + "filename": "misc_util.py", + "nloc": 6, + "complexity": 2, + "token_count": 39, + "parameters": [ + "directory_list" + ], + "start_line": 228, + "end_line": 234, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 7, + "top_nesting_level": 0 + }, + { + "name": "_get_directories", + "long_name": "_get_directories( list_of_sources )", + "filename": "misc_util.py", + "nloc": 7, + "complexity": 4, + "token_count": 51, + "parameters": [ + "list_of_sources" + ], + "start_line": 236, + "end_line": 243, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 8, + "top_nesting_level": 0 + }, + { + "name": "get_dependencies", + "long_name": "get_dependencies( sources )", + "filename": "misc_util.py", + "nloc": 2, + "complexity": 1, + "token_count": 13, + "parameters": [ + "sources" + ], + "start_line": 245, + "end_line": 247, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 0 + }, + { + "name": "is_local_src_dir", + "long_name": "is_local_src_dir( directory )", + "filename": "misc_util.py", + "nloc": 12, + "complexity": 6, + "token_count": 107, + "parameters": [ + "directory" + ], + "start_line": 249, + "end_line": 262, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 14, + "top_nesting_level": 0 + }, + { + "name": "general_source_files", + "long_name": "general_source_files( top_path )", + "filename": "misc_util.py", + "nloc": 9, + "complexity": 6, + "token_count": 92, + "parameters": [ + "top_path" + ], + "start_line": 264, + "end_line": 272, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 9, + "top_nesting_level": 0 + }, + { + "name": "get_ext_source_files", + "long_name": "get_ext_source_files( ext )", + "filename": "misc_util.py", + "nloc": 11, + "complexity": 4, + "token_count": 77, + "parameters": [ + "ext" + ], + "start_line": 274, + "end_line": 285, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 12, + "top_nesting_level": 0 + }, + { + "name": "get_script_files", + "long_name": "get_script_files( scripts )", + "filename": "misc_util.py", + "nloc": 3, + "complexity": 1, + "token_count": 15, + "parameters": [ + "scripts" + ], + "start_line": 287, + "end_line": 289, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 0 + }, + { + "name": "get_lib_source_files", + "long_name": "get_lib_source_files( lib )", + "filename": "misc_util.py", + "nloc": 13, + "complexity": 4, + "token_count": 101, + "parameters": [ + "lib" + ], + "start_line": 291, + "end_line": 303, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 13, + "top_nesting_level": 0 + }, + { + "name": "get_data_files", + "long_name": "get_data_files( data )", + "filename": "misc_util.py", + "nloc": 18, + "complexity": 7, + "token_count": 94, + "parameters": [ + "data" + ], + "start_line": 305, + "end_line": 322, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 18, + "top_nesting_level": 0 + }, + { + "name": "dot_join", + "long_name": "dot_join( * args )", + "filename": "misc_util.py", + "nloc": 2, + "complexity": 3, + "token_count": 21, + "parameters": [ + "args" + ], + "start_line": 324, + "end_line": 325, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 0 + }, + { + "name": "get_frame", + "long_name": "get_frame( level = 0 )", + "filename": "misc_util.py", + "nloc": 8, + "complexity": 3, + "token_count": 50, + "parameters": [ + "level" + ], + "start_line": 327, + "end_line": 334, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 8, + "top_nesting_level": 0 + }, + { + "name": "__init__", + "long_name": "__init__( self , package_name = None , parent_name = None , top_path = None , package_path = None , ** attrs )", + "filename": "misc_util.py", + "nloc": 61, + "complexity": 16, + "token_count": 458, + "parameters": [ + "self", + "package_name", + "parent_name", + "top_path", + "package_path", + "attrs" + ], + "start_line": 346, + "end_line": 428, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 83, + "top_nesting_level": 1 + }, + { + "name": "todict", + "long_name": "todict( self )", + "filename": "misc_util.py", + "nloc": 9, + "complexity": 4, + "token_count": 57, + "parameters": [ + "self" + ], + "start_line": 430, + "end_line": 441, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 12, + "top_nesting_level": 1 + }, + { + "name": "info", + "long_name": "info( self , message )", + "filename": "misc_util.py", + "nloc": 3, + "complexity": 2, + "token_count": 18, + "parameters": [ + "self", + "message" + ], + "start_line": 443, + "end_line": 445, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "warn", + "long_name": "warn( self , message )", + "filename": "misc_util.py", + "nloc": 2, + "complexity": 1, + "token_count": 17, + "parameters": [ + "self", + "message" + ], + "start_line": 447, + "end_line": 448, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 1 + }, + { + "name": "set_options", + "long_name": "set_options( self , ** options )", + "filename": "misc_util.py", + "nloc": 6, + "complexity": 3, + "token_count": 46, + "parameters": [ + "self", + "options" + ], + "start_line": 451, + "end_line": 464, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 14, + "top_nesting_level": 1 + }, + { + "name": "get_distribution", + "long_name": "get_distribution( self )", + "filename": "misc_util.py", + "nloc": 4, + "complexity": 1, + "token_count": 18, + "parameters": [ + "self" + ], + "start_line": 466, + "end_line": 469, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 1 + }, + { + "name": "_wildcard_get_subpackage", + "long_name": "_wildcard_get_subpackage( self , subpackage_name )", + "filename": "misc_util.py", + "nloc": 14, + "complexity": 4, + "token_count": 122, + "parameters": [ + "self", + "subpackage_name" + ], + "start_line": 471, + "end_line": 484, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 14, + "top_nesting_level": 1 + }, + { + "name": "_get_configuration_from_setup_py", + "long_name": "_get_configuration_from_setup_py( self , setup_py , subpackage_name , subpackage_path )", + "filename": "misc_util.py", + "nloc": 26, + "complexity": 5, + "token_count": 196, + "parameters": [ + "self", + "setup_py", + "subpackage_name", + "subpackage_path" + ], + "start_line": 486, + "end_line": 512, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 27, + "top_nesting_level": 1 + }, + { + "name": "get_subpackage", + "long_name": "get_subpackage( self , subpackage_name , subpackage_path = None )", + "filename": "misc_util.py", + "nloc": 34, + "complexity": 11, + "token_count": 232, + "parameters": [ + "self", + "subpackage_name", + "subpackage_path" + ], + "start_line": 514, + "end_line": 557, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 44, + "top_nesting_level": 1 + }, + { + "name": "add_subpackage", + "long_name": "add_subpackage( self , subpackage_name , subpackage_path = None )", + "filename": "misc_util.py", + "nloc": 17, + "complexity": 5, + "token_count": 103, + "parameters": [ + "self", + "subpackage_name", + "subpackage_path" + ], + "start_line": 559, + "end_line": 578, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 20, + "top_nesting_level": 1 + }, + { + "name": "add_data_dir", + "long_name": "add_data_dir( self , data_path )", + "filename": "misc_util.py", + "nloc": 25, + "complexity": 9, + "token_count": 185, + "parameters": [ + "self", + "data_path" + ], + "start_line": 580, + "end_line": 612, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 33, + "top_nesting_level": 1 + }, + { + "name": "add_data_files", + "long_name": "add_data_files( self , * files )", + "filename": "misc_util.py", + "nloc": 49, + "complexity": 17, + "token_count": 392, + "parameters": [ + "self", + "files" + ], + "start_line": 614, + "end_line": 674, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 61, + "top_nesting_level": 1 + }, + { + "name": "add_include_dirs", + "long_name": "add_include_dirs( self , * paths )", + "filename": "misc_util.py", + "nloc": 8, + "complexity": 2, + "token_count": 49, + "parameters": [ + "self", + "paths" + ], + "start_line": 678, + "end_line": 687, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 10, + "top_nesting_level": 1 + }, + { + "name": "add_headers", + "long_name": "add_headers( self , * files )", + "filename": "misc_util.py", + "nloc": 15, + "complexity": 8, + "token_count": 136, + "parameters": [ + "self", + "files" + ], + "start_line": 689, + "end_line": 709, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 21, + "top_nesting_level": 1 + }, + { + "name": "_fix_paths", + "long_name": "_fix_paths( self , paths , include_non_existing = True )", + "filename": "misc_util.py", + "nloc": 32, + "complexity": 12, + "token_count": 213, + "parameters": [ + "self", + "paths", + "include_non_existing" + ], + "start_line": 711, + "end_line": 742, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 32, + "top_nesting_level": 1 + }, + { + "name": "paths", + "long_name": "paths( self , * paths , ** kws )", + "filename": "misc_util.py", + "nloc": 4, + "complexity": 1, + "token_count": 33, + "parameters": [ + "self", + "paths", + "kws" + ], + "start_line": 744, + "end_line": 749, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 6, + "top_nesting_level": 1 + }, + { + "name": "_fix_paths_dict", + "long_name": "_fix_paths_dict( self , kw )", + "filename": "misc_util.py", + "nloc": 8, + "complexity": 3, + "token_count": 54, + "parameters": [ + "self", + "kw" + ], + "start_line": 751, + "end_line": 758, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 8, + "top_nesting_level": 1 + }, + { + "name": "add_extension", + "long_name": "add_extension( self , name , sources , ** kw )", + "filename": "misc_util.py", + "nloc": 43, + "complexity": 13, + "token_count": 337, + "parameters": [ + "self", + "name", + "sources", + "kw" + ], + "start_line": 760, + "end_line": 822, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 63, + "top_nesting_level": 1 + }, + { + "name": "add_library", + "long_name": "add_library( self , name , sources , ** build_info )", + "filename": "misc_util.py", + "nloc": 11, + "complexity": 2, + "token_count": 72, + "parameters": [ + "self", + "name", + "sources", + "build_info" + ], + "start_line": 824, + "end_line": 846, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 23, + "top_nesting_level": 1 + }, + { + "name": "add_scripts", + "long_name": "add_scripts( self , * files )", + "filename": "misc_util.py", + "nloc": 8, + "complexity": 2, + "token_count": 49, + "parameters": [ + "self", + "files" + ], + "start_line": 848, + "end_line": 857, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 10, + "top_nesting_level": 1 + }, + { + "name": "dict_append", + "long_name": "dict_append( self , ** dict )", + "filename": "misc_util.py", + "nloc": 16, + "complexity": 7, + "token_count": 150, + "parameters": [ + "self", + "dict" + ], + "start_line": 859, + "end_line": 874, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 16, + "top_nesting_level": 1 + }, + { + "name": "__str__", + "long_name": "__str__( self )", + "filename": "misc_util.py", + "nloc": 10, + "complexity": 3, + "token_count": 72, + "parameters": [ + "self" + ], + "start_line": 876, + "end_line": 885, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 10, + "top_nesting_level": 1 + }, + { + "name": "get_config_cmd", + "long_name": "get_config_cmd( self )", + "filename": "misc_util.py", + "nloc": 10, + "complexity": 2, + "token_count": 63, + "parameters": [ + "self" + ], + "start_line": 887, + "end_line": 896, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 10, + "top_nesting_level": 1 + }, + { + "name": "get_build_temp_dir", + "long_name": "get_build_temp_dir( self )", + "filename": "misc_util.py", + "nloc": 4, + "complexity": 1, + "token_count": 20, + "parameters": [ + "self" + ], + "start_line": 898, + "end_line": 901, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 1 + }, + { + "name": "have_f77c", + "long_name": "have_f77c( self )", + "filename": "misc_util.py", + "nloc": 8, + "complexity": 1, + "token_count": 30, + "parameters": [ + "self" + ], + "start_line": 903, + "end_line": 914, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 12, + "top_nesting_level": 1 + }, + { + "name": "have_f90c", + "long_name": "have_f90c( self )", + "filename": "misc_util.py", + "nloc": 8, + "complexity": 1, + "token_count": 30, + "parameters": [ + "self" + ], + "start_line": 916, + "end_line": 927, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 12, + "top_nesting_level": 1 + }, + { + "name": "append_to", + "long_name": "append_to( self , extlib )", + "filename": "misc_util.py", + "nloc": 12, + "complexity": 2, + "token_count": 78, + "parameters": [ + "self", + "extlib" + ], + "start_line": 929, + "end_line": 942, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 14, + "top_nesting_level": 1 + }, + { + "name": "_get_svn_revision", + "long_name": "_get_svn_revision( self , path )", + "filename": "misc_util.py", + "nloc": 10, + "complexity": 3, + "token_count": 73, + "parameters": [ + "self", + "path" + ], + "start_line": 944, + "end_line": 955, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 12, + "top_nesting_level": 1 + }, + { + "name": "get_version", + "long_name": "get_version( self )", + "filename": "misc_util.py", + "nloc": 38, + "complexity": 11, + "token_count": 260, + "parameters": [ + "self" + ], + "start_line": 957, + "end_line": 1003, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 47, + "top_nesting_level": 1 + }, + { + "name": "make_svn_version_py.make_svn_version_py.generate_svn_version_py.rm_file", + "long_name": "make_svn_version_py.make_svn_version_py.generate_svn_version_py.rm_file( f = target , p = self . info )", + "filename": "misc_util.py", + "nloc": 5, + "complexity": 3, + "token_count": 55, + "parameters": [ + "f", + "p" + ], + "start_line": 1026, + "end_line": 1030, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 5, + "top_nesting_level": 3 + }, + { + "name": "make_svn_version_py.generate_svn_version_py", + "long_name": "make_svn_version_py.generate_svn_version_py( )", + "filename": "misc_util.py", + "nloc": 13, + "complexity": 2, + "token_count": 85, + "parameters": [], + "start_line": 1015, + "end_line": 1033, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 19, + "top_nesting_level": 2 + }, + { + "name": "make_svn_version_py", + "long_name": "make_svn_version_py( self )", + "filename": "misc_util.py", + "nloc": 6, + "complexity": 2, + "token_count": 43, + "parameters": [ + "self" + ], + "start_line": 1005, + "end_line": 1035, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 31, + "top_nesting_level": 1 + }, + { + "name": "make_config_py", + "long_name": "make_config_py( self , name = '__config__' )", + "filename": "misc_util.py", + "nloc": 3, + "complexity": 1, + "token_count": 27, + "parameters": [ + "self", + "name" + ], + "start_line": 1037, + "end_line": 1042, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 6, + "top_nesting_level": 1 + }, + { + "name": "get_info", + "long_name": "get_info( self , * names )", + "filename": "misc_util.py", + "nloc": 6, + "complexity": 2, + "token_count": 36, + "parameters": [ + "self", + "names" + ], + "start_line": 1044, + "end_line": 1051, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 8, + "top_nesting_level": 1 + }, + { + "name": "_do_nothing", + "long_name": "_do_nothing( self , * args , ** kw )", + "filename": "misc_util.py", + "nloc": 2, + "complexity": 1, + "token_count": 12, + "parameters": [ + "self", + "args", + "kw" + ], + "start_line": 1057, + "end_line": 1058, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 1 + }, + { + "name": "get_info", + "long_name": "get_info( self , * args , ** kw )", + "filename": "misc_util.py", + "nloc": 2, + "complexity": 1, + "token_count": 14, + "parameters": [ + "self", + "args", + "kw" + ], + "start_line": 1069, + "end_line": 1070, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 1 + }, + { + "name": "have_f77c", + "long_name": "have_f77c( self , * args , ** kw )", + "filename": "misc_util.py", + "nloc": 2, + "complexity": 1, + "token_count": 13, + "parameters": [ + "self", + "args", + "kw" + ], + "start_line": 1071, + "end_line": 1072, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 1 + }, + { + "name": "have_f90c", + "long_name": "have_f90c( self , * args , ** kw )", + "filename": "misc_util.py", + "nloc": 2, + "complexity": 1, + "token_count": 13, + "parameters": [ + "self", + "args", + "kw" + ], + "start_line": 1073, + "end_line": 1074, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 1 + }, + { + "name": "command_line_ok", + "long_name": "command_line_ok( _cache = [ ] )", + "filename": "misc_util.py", + "nloc": 15, + "complexity": 9, + "token_count": 98, + "parameters": [ + "_cache" + ], + "start_line": 1076, + "end_line": 1093, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 18, + "top_nesting_level": 0 + }, + { + "name": "get_cmd", + "long_name": "get_cmd( cmdname , _cache = { } )", + "filename": "misc_util.py", + "nloc": 11, + "complexity": 3, + "token_count": 65, + "parameters": [ + "cmdname", + "_cache" + ], + "start_line": 1098, + "end_line": 1108, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 11, + "top_nesting_level": 0 + }, + { + "name": "get_numpy_include_dirs", + "long_name": "get_numpy_include_dirs( )", + "filename": "misc_util.py", + "nloc": 11, + "complexity": 3, + "token_count": 77, + "parameters": [], + "start_line": 1110, + "end_line": 1124, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 15, + "top_nesting_level": 0 + }, + { + "name": "default_config_dict", + "long_name": "default_config_dict( name = None , parent_name = None , local_path = None )", + "filename": "misc_util.py", + "nloc": 9, + "complexity": 1, + "token_count": 57, + "parameters": [ + "name", + "parent_name", + "local_path" + ], + "start_line": 1128, + "end_line": 1139, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 12, + "top_nesting_level": 0 + }, + { + "name": "dict_append", + "long_name": "dict_append( d , ** kws )", + "filename": "misc_util.py", + "nloc": 6, + "complexity": 3, + "token_count": 44, + "parameters": [ + "d", + "kws" + ], + "start_line": 1142, + "end_line": 1147, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 6, + "top_nesting_level": 0 + }, + { + "name": "appendpath", + "long_name": "appendpath( prefix , path )", + "filename": "misc_util.py", + "nloc": 19, + "complexity": 6, + "token_count": 230, + "parameters": [ + "prefix", + "path" + ], + "start_line": 1149, + "end_line": 1168, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 20, + "top_nesting_level": 0 + }, + { + "name": "generate_config_py", + "long_name": "generate_config_py( target )", + "filename": "misc_util.py", + "nloc": 27, + "complexity": 2, + "token_count": 117, + "parameters": [ + "target" + ], + "start_line": 1170, + "end_line": 1203, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 34, + "top_nesting_level": 0 + } + ], + "changed_methods": [ + { + "name": "get_path", + "long_name": "get_path( mod_name , parent_path = None )", + "filename": "misc_util.py", + "nloc": 16, + "complexity": 6, + "token_count": 139, + "parameters": [ + "mod_name", + "parent_path" + ], + "start_line": 24, + "end_line": 49, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 26, + "top_nesting_level": 0 + } + ], + "nloc": 907, + "complexity": 293, + "token_count": 6400, + "diff_parsed": { + "added": [ + " if mod_name == '__builtin__':", + " if hasattr(mod,'__file__'):", + " filename = mod.__file__", + " d = os.path.dirname(os.path.abspath(mod.__file__))", + " else:", + " # we're probably running setup.py as execfile(\"setup.py\")", + " # (likely we're building an egg)", + " d = os.path.abspath('.')", + " # hmm, should we use sys.argv[0] like in __builtin__ case?", + "" + ], + "deleted": [ + " if mod_name == '__main__' and not hasattr('__main__', '__file__'):", + " # we're probably running setup.py as execfile(\"setup.py\")", + " # (likely we're building an egg)", + " d = os.path.abspath('.')", + " elif mod_name == '__builtin__':", + " filename = mod.__file__", + " d = os.path.dirname(os.path.abspath(filename))" + ] + } + } + ] + }, + { + "hash": "e5e72a41b507f9d18564aa881c9482c76d399c45", + "msg": "Fixes to help compilation on Windows with MSVC", + "author": { + "name": "Travis Oliphant", + "email": "oliphant@enthought.com" + }, + "committer": { + "name": "Travis Oliphant", + "email": "oliphant@enthought.com" + }, + "author_date": "2006-02-09T17:25:54+00:00", + "author_timezone": 0, + "committer_date": "2006-02-09T17:25:54+00:00", + "committer_timezone": 0, + "branches": [ + "main" + ], + "in_main_branch": true, + "merge": false, + "parents": [ + "44f0e40eed3cc04292f1295ae524a1d5aedb382c" + ], + "project_name": "repo_copy", + "project_path": "/tmp/tmpdjwupkfu/repo_copy", + "deletions": 6, + "insertions": 60, + "lines": 66, + "files": 4, + "dmm_unit_size": 0.5909090909090909, + "dmm_unit_complexity": 0.9545454545454546, + "dmm_unit_interfacing": 1.0, + "modified_files": [ + { + "old_path": "numpy/distutils/misc_util.py", + "new_path": "numpy/distutils/misc_util.py", + "filename": "misc_util.py", + "extension": "py", + "change_type": "MODIFY", + "diff": "@@ -7,7 +7,7 @@\n \n __all__ = ['Configuration', 'get_numpy_include_dirs', 'default_config_dict',\n 'dict_append', 'appendpath', 'generate_config_py',\n- 'get_cmd', 'allpath',\n+ 'get_cmd', 'allpath', 'get_mathlibs',\n 'terminal_has_colors', 'red_text', 'green_text', 'yellow_text',\n 'blue_text', 'cyan_text', 'cyg2win32', 'all_strings',\n 'has_f_sources', 'has_cxx_sources', 'filter_sources',\n@@ -69,6 +69,23 @@ def njoin(*path):\n joined = joined.replace('/',os.path.sep)\n return minrelpath(joined)\n \n+def get_mathlibs(path=None):\n+ \"\"\" Return the MATHLIB line from config.h\n+ \"\"\"\n+ if path is None:\n+ path = get_numpy_include_dirs()[0]\n+ config_file = os.path.join(path,'config.h')\n+ fid = open(config_file)\n+ mathlibs = []\n+ s = '#define MATHLIB'\n+ for line in fid.readlines():\n+ if line.startswith(s):\n+ value = line[len(s):].strip()\n+ if value:\n+ mathlibs.extend(value.split(','))\n+ fid.close()\n+ return mathlibs\n+ \n def minrelpath(path):\n \"\"\" Resolve `..` from path.\n \"\"\"\n@@ -76,6 +93,8 @@ def minrelpath(path):\n return path\n if '..' not in path:\n return path\n+ if os.sep != '/':\n+ path.replace('/',os.sep)\n l = path.split(os.sep)\n j = 1\n while l:\n", + "added_lines": 20, + "deleted_lines": 1, + "source_code": "import os\nimport re\nimport sys\nimport imp\nimport copy\nimport glob\n\n__all__ = ['Configuration', 'get_numpy_include_dirs', 'default_config_dict',\n 'dict_append', 'appendpath', 'generate_config_py',\n 'get_cmd', 'allpath', 'get_mathlibs',\n 'terminal_has_colors', 'red_text', 'green_text', 'yellow_text',\n 'blue_text', 'cyan_text', 'cyg2win32', 'all_strings',\n 'has_f_sources', 'has_cxx_sources', 'filter_sources',\n 'get_dependencies', 'is_local_src_dir', 'get_ext_source_files',\n 'get_script_files', 'get_lib_source_files', 'get_data_files',\n 'dot_join', 'get_frame', 'minrelpath','njoin',\n 'is_sequence', 'is_string', 'as_list']\n\ndef allpath(name):\n \"Convert a /-separated pathname to one using the OS's path separator.\"\n splitted = name.split('/')\n return os.path.join(*splitted)\n\ndef get_path(mod_name, parent_path=None):\n \"\"\" Return path of the module.\n\n Returned path is relative to parent_path when given,\n otherwise it is absolute path.\n \"\"\"\n if mod_name == '__builtin__':\n #builtin if/then added by Pearu for use in core.run_setup.\n d = os.path.dirname(os.path.abspath(sys.argv[0]))\n else:\n __import__(mod_name)\n mod = sys.modules[mod_name]\n if hasattr(mod,'__file__'):\n filename = mod.__file__\n d = os.path.dirname(os.path.abspath(mod.__file__))\n else:\n # we're probably running setup.py as execfile(\"setup.py\")\n # (likely we're building an egg) \n d = os.path.abspath('.')\n # hmm, should we use sys.argv[0] like in __builtin__ case?\n\n if parent_path is not None:\n pd = os.path.abspath(parent_path)\n if pd == d[:len(pd)]:\n d = d[len(pd)+1:]\n return d or '.'\n\ndef njoin(*path):\n \"\"\" Join two or more pathname components +\n - convert a /-separated pathname to one using the OS's path separator.\n - resolve `..` from path.\n\n Either passing n arguments as in njoin('a','b'), or a sequence\n of n names as in njoin(['a','b']) is handled.\n \"\"\"\n if not path:\n # njoin()\n joined = ''\n elif is_sequence(path[0]) and len(path) == 1:\n # njoin(['a', 'b'])\n joined = os.path.join(*path[0])\n else:\n # njoin('a', 'b')\n joined = os.path.join(*path)\n if os.path.sep != '/':\n joined = joined.replace('/',os.path.sep)\n return minrelpath(joined)\n\ndef get_mathlibs(path=None):\n \"\"\" Return the MATHLIB line from config.h\n \"\"\"\n if path is None:\n path = get_numpy_include_dirs()[0]\n config_file = os.path.join(path,'config.h')\n fid = open(config_file)\n mathlibs = []\n s = '#define MATHLIB'\n for line in fid.readlines():\n if line.startswith(s):\n value = line[len(s):].strip()\n if value:\n mathlibs.extend(value.split(','))\n fid.close()\n return mathlibs\n \ndef minrelpath(path):\n \"\"\" Resolve `..` from path.\n \"\"\"\n if not is_string(path):\n return path\n if '..' not in path:\n return path\n if os.sep != '/':\n path.replace('/',os.sep)\n l = path.split(os.sep)\n j = 1\n while l:\n try:\n i = l.index('..',j)\n except ValueError:\n break\n if l[i-1]=='..':\n j += 1\n else:\n del l[i],l[i-1]\n j = 1\n if not l:\n return ''\n return os.path.join(*l)\n\n# Hooks for colored terminal output.\n# See also http://www.livinglogic.de/Python/ansistyle\ndef terminal_has_colors():\n if sys.platform=='cygwin' and not os.environ.has_key('USE_COLOR'):\n # Avoid importing curses that causes illegal operation\n # with a message:\n # PYTHON2 caused an invalid page fault in\n # module CYGNURSES7.DLL as 015f:18bbfc28\n # Details: Python 2.3.3 [GCC 3.3.1 (cygming special)]\n # ssh to Win32 machine from debian\n # curses.version is 2.2\n # CYGWIN_98-4.10, release 1.5.7(0.109/3/2))\n return 0\n if hasattr(sys.stdout,'isatty') and sys.stdout.isatty():\n try:\n import curses\n curses.setupterm()\n if (curses.tigetnum(\"colors\") >= 0\n and curses.tigetnum(\"pairs\") >= 0\n and ((curses.tigetstr(\"setf\") is not None\n and curses.tigetstr(\"setb\") is not None)\n or (curses.tigetstr(\"setaf\") is not None\n and curses.tigetstr(\"setab\") is not None)\n or curses.tigetstr(\"scp\") is not None)):\n return 1\n except Exception,msg:\n pass\n return 0\n\nif terminal_has_colors():\n def red_text(s): return '\\x1b[31m%s\\x1b[0m'%s\n def green_text(s): return '\\x1b[32m%s\\x1b[0m'%s\n def yellow_text(s): return '\\x1b[33m%s\\x1b[0m'%s\n def blue_text(s): return '\\x1b[34m%s\\x1b[0m'%s\n def cyan_text(s): return '\\x1b[35m%s\\x1b[0m'%s\nelse:\n def red_text(s): return s\n def green_text(s): return s\n def yellow_text(s): return s\n def cyan_text(s): return s\n def blue_text(s): return s\n\n#########################\n\ndef cyg2win32(path):\n if sys.platform=='cygwin' and path.startswith('/cygdrive'):\n path = path[10] + ':' + os.path.normcase(path[11:])\n return path\n\n#########################\n\n#XXX need support for .C that is also C++\ncxx_ext_match = re.compile(r'.*[.](cpp|cxx|cc)\\Z',re.I).match\nfortran_ext_match = re.compile(r'.*[.](f90|f95|f77|for|ftn|f)\\Z',re.I).match\nf90_ext_match = re.compile(r'.*[.](f90|f95)\\Z',re.I).match\nf90_module_name_match = re.compile(r'\\s*module\\s*(?P[\\w_]+)',re.I).match\ndef _get_f90_modules(source):\n \"\"\" Return a list of Fortran f90 module names that\n given source file defines.\n \"\"\"\n if not f90_ext_match(source):\n return []\n modules = []\n f = open(source,'r')\n f_readlines = getattr(f,'xreadlines',f.readlines)\n for line in f_readlines():\n m = f90_module_name_match(line)\n if m:\n name = m.group('name')\n modules.append(name)\n # break # XXX can we assume that there is one module per file?\n f.close()\n return modules\n\ndef is_string(s):\n return isinstance(s, str)\n\ndef all_strings(lst):\n \"\"\" Return True if all items in lst are string objects. \"\"\"\n for item in lst:\n if not is_string(item):\n return False\n return True\n\ndef is_sequence(seq):\n if is_string(seq):\n return False\n try:\n len(seq)\n except:\n return False\n return True\n\ndef as_list(seq):\n if is_sequence(seq):\n return list(seq)\n else:\n return [seq]\n\ndef has_f_sources(sources):\n \"\"\" Return True if sources contains Fortran files \"\"\"\n for source in sources:\n if fortran_ext_match(source):\n return True\n return False\n\ndef has_cxx_sources(sources):\n \"\"\" Return True if sources contains C++ files \"\"\"\n for source in sources:\n if cxx_ext_match(source):\n return True\n return False\n\ndef filter_sources(sources):\n \"\"\" Return four lists of filenames containing\n C, C++, Fortran, and Fortran 90 module sources,\n respectively.\n \"\"\"\n c_sources = []\n cxx_sources = []\n f_sources = []\n fmodule_sources = []\n for source in sources:\n if fortran_ext_match(source):\n modules = _get_f90_modules(source)\n if modules:\n fmodule_sources.append(source)\n else:\n f_sources.append(source)\n elif cxx_ext_match(source):\n cxx_sources.append(source)\n else:\n c_sources.append(source)\n return c_sources, cxx_sources, f_sources, fmodule_sources\n\n\ndef _get_headers(directory_list):\n # get *.h files from list of directories\n headers = []\n for d in directory_list:\n head = glob.glob(os.path.join(d,\"*.h\")) #XXX: *.hpp files??\n headers.extend(head)\n return headers\n\ndef _get_directories(list_of_sources):\n # get unique directories from list of sources.\n direcs = []\n for f in list_of_sources:\n d = os.path.split(f)\n if d[0] != '' and not d[0] in direcs:\n direcs.append(d[0])\n return direcs\n\ndef get_dependencies(sources):\n #XXX scan sources for include statements\n return _get_headers(_get_directories(sources))\n\ndef is_local_src_dir(directory):\n \"\"\" Return true if directory is local directory.\n \"\"\"\n if not is_string(directory):\n return False\n abs_dir = os.path.abspath(directory)\n c = os.path.commonprefix([os.getcwd(),abs_dir])\n new_dir = abs_dir[len(c):].split(os.sep)\n if new_dir and not new_dir[0]:\n new_dir = new_dir[1:]\n if new_dir and new_dir[0]=='build':\n return False\n new_dir = os.sep.join(new_dir)\n return os.path.isdir(new_dir)\n\ndef general_source_files(top_path):\n pruned_directories = {'CVS':1, '.svn':1, 'build':1}\n prune_file_pat = re.compile(r'(?:[~#]|\\.py[co]|\\.o)$')\n for dirpath, dirnames, filenames in os.walk(top_path, topdown=True):\n pruned = [ d for d in dirnames if d not in pruned_directories ]\n dirnames[:] = pruned\n for f in filenames:\n if not prune_file_pat.search(f):\n yield os.path.join(dirpath, f)\n\ndef get_ext_source_files(ext):\n # Get sources and any include files in the same directory.\n filenames = []\n sources = filter(is_string, ext.sources)\n filenames.extend(sources)\n filenames.extend(get_dependencies(sources))\n for d in ext.depends:\n if is_local_src_dir(d):\n filenames.extend(list(general_source_files(d)))\n elif os.path.isfile(d):\n filenames.append(d)\n return filenames\n\ndef get_script_files(scripts):\n scripts = filter(is_string, scripts)\n return scripts\n\ndef get_lib_source_files(lib):\n filenames = []\n sources = lib[1].get('sources',[])\n sources = filter(is_string, sources)\n filenames.extend(sources)\n filenames.extend(get_dependencies(sources))\n depends = lib[1].get('depends',[])\n for d in depends:\n if is_local_src_dir(d):\n filenames.extend(list(general_source_files(d)))\n elif os.path.isfile(d):\n filenames.append(d)\n return filenames\n\ndef get_data_files(data):\n if is_string(data):\n return [data]\n sources = data[1]\n filenames = []\n for s in sources:\n if callable(s):\n continue\n if is_local_src_dir(s):\n filenames.extend(list(general_source_files(s)))\n elif is_string(s):\n if os.path.isfile(s):\n filenames.append(s)\n else:\n print 'Not existing data file:',s\n else:\n raise TypeError,repr(s)\n return filenames\n\ndef dot_join(*args):\n return '.'.join([a for a in args if a])\n\ndef get_frame(level=0):\n try:\n return sys._getframe(level+1)\n except AttributeError:\n frame = sys.exc_info()[2].tb_frame\n for _ in range(level+1):\n frame = frame.f_back\n return frame\n\n######################\n\nclass Configuration(object):\n\n _list_keys = ['packages', 'ext_modules', 'data_files', 'include_dirs',\n 'libraries', 'headers', 'scripts', 'py_modules']\n _dict_keys = ['package_dir']\n\n numpy_include_dirs = []\n\n def __init__(self,\n package_name=None,\n parent_name=None,\n top_path=None,\n package_path=None,\n **attrs):\n \"\"\" Construct configuration instance of a package.\n\n package_name -- name of the package\n Ex.: 'distutils'\n parent_name -- name of the parent package\n Ex.: 'numpy'\n top_path -- directory of the toplevel package\n Ex.: the directory where the numpy package source sits\n package_path -- directory of package. Will be computed by magic from the\n directory of the caller module if not specified\n Ex.: the directory where numpy.distutils is\n \"\"\"\n self.name = dot_join(parent_name, package_name)\n\n caller_frame = get_frame(1)\n caller_name = eval('__name__',caller_frame.f_globals,caller_frame.f_locals)\n\n self.local_path = get_path(caller_name, top_path)\n if top_path is None:\n top_path = self.local_path\n if package_path is None:\n package_path = self.local_path\n elif os.path.isdir(njoin(self.local_path,package_path)):\n package_path = njoin(self.local_path,package_path)\n if not os.path.isdir(package_path):\n raise ValueError(\"%r is not a directory\" % (package_path,))\n self.top_path = top_path\n self.package_path = package_path\n # this is the relative path in the installed package\n self.path_in_package = os.path.join(*self.name.split('.'))\n\n self.list_keys = self._list_keys[:]\n self.dict_keys = self._dict_keys[:]\n\n for n in self.list_keys:\n v = copy.copy(attrs.get(n, []))\n setattr(self, n, as_list(v))\n\n for n in self.dict_keys:\n v = copy.copy(attrs.get(n, {}))\n setattr(self, n, v)\n\n known_keys = self.list_keys + self.dict_keys\n self.extra_keys = []\n for n in attrs.keys():\n if n in known_keys:\n continue\n a = attrs[n]\n setattr(self,n,a)\n if isinstance(a, list):\n self.list_keys.append(n)\n elif isinstance(a, dict):\n self.dict_keys.append(n)\n else:\n self.extra_keys.append(n)\n\n if os.path.exists(njoin(package_path,'__init__.py')):\n self.packages.append(self.name)\n self.package_dir[self.name] = package_path\n\n self.options = dict(\n ignore_setup_xxx_py = False,\n assume_default_configuration = False,\n delegate_options_to_subpackages = False,\n quiet = False,\n )\n\n for i in range(1,3):\n f = get_frame(i)\n try:\n caller_instance = eval('self',f.f_globals,f.f_locals)\n break\n except NameError:\n caller_instance = None\n if isinstance(caller_instance, self.__class__):\n if caller_instance.options['delegate_options_to_subpackages']:\n self.set_options(**caller_instance.options)\n\n def todict(self):\n \"\"\" Return configuration distionary suitable for passing\n to distutils.core.setup() function.\n \"\"\"\n d = {}\n for n in self.list_keys + self.dict_keys + self.extra_keys:\n a = getattr(self,n)\n if a:\n d[n] = a\n if self.name:\n d['name'] = self.name\n return d\n\n def info(self, message):\n if not self.options['quiet']:\n print message\n\n def warn(self, message):\n print>>sys.stderr, 'Warning:',message\n\n\n def set_options(self, **options):\n \"\"\" Configure Configuration instance.\n\n The following options are available:\n - ignore_setup_xxx_py\n - assume_default_configuration\n - delegate_options_to_subpackages\n - quiet\n \"\"\"\n for key, value in options.items():\n if self.options.has_key(key):\n self.options[key] = value\n else:\n raise ValueError,'Unknown option: '+key\n\n def get_distribution(self):\n import distutils.core\n dist = distutils.core._setup_distribution\n return dist\n\n def _wildcard_get_subpackage(self, subpackage_name):\n l = subpackage_name.split('.')\n subpackage_path = njoin([self.local_path]+l)\n dirs = filter(os.path.isdir,glob.glob(subpackage_path))\n config_list = []\n for d in dirs:\n if not os.path.isfile(njoin(d,'__init__.py')):\n continue\n if 'build' in d.split(os.sep):\n continue\n n = '.'.join(d.split(os.sep)[-len(l):])\n c = self.get_subpackage(n)\n config_list.extend(c)\n return config_list\n\n def _get_configuration_from_setup_py(self, setup_py,\n subpackage_name, subpackage_path):\n # In case setup_py imports local modules:\n sys.path.insert(0,os.path.dirname(setup_py))\n try:\n fo_setup_py = open(setup_py, 'U')\n setup_name = os.path.splitext(os.path.basename(setup_py))[0]\n n = dot_join(self.name,setup_name)\n setup_module = imp.load_module('_'.join(n.split('.')),\n fo_setup_py,\n setup_py,\n ('.py', 'U', 1))\n if not hasattr(setup_module,'configuration'):\n if not self.options['assume_default_configuration']:\n self.warn('Assuming default configuration '\\\n '(%s does not define configuration())'\\\n % (setup_module))\n config = Configuration(subpackage_name, self.name,\n self.top_path, subpackage_path)\n else:\n args = (self.name,)\n if setup_module.configuration.func_code.co_argcount > 1:\n args = args + (self.top_path,)\n config = setup_module.configuration(*args)\n finally:\n del sys.path[0]\n return config\n\n def get_subpackage(self,subpackage_name,subpackage_path=None):\n \"\"\" Return list of subpackage configurations.\n\n '*' in subpackage_name is handled as a wildcard.\n \"\"\"\n if subpackage_name is None:\n if subpackage_path is None:\n raise ValueError(\n \"either subpackage_name or subpackage_path must be specified\")\n subpackage_name = os.path.basename(subpackage_path)\n\n # handle wildcards\n l = subpackage_name.split('.')\n if subpackage_path is None and '*' in subpackage_name:\n return self._wildcard_get_subpackage(subpackage_name)\n\n if subpackage_path is None:\n subpackage_path = njoin([self.local_path] + l)\n else:\n subpackage_path = njoin([subpackage_path] + l[:-1])\n subpackage_path = self._fix_paths([subpackage_path])[0]\n\n setup_py = njoin(subpackage_path, 'setup.py')\n if not self.options['ignore_setup_xxx_py']:\n if not os.path.isfile(setup_py):\n setup_py = njoin(subpackage_path,\n 'setup_%s.py' % (subpackage_name))\n\n if not os.path.isfile(setup_py):\n if not self.options['assume_default_configuration']:\n self.warn('Assuming default configuration '\\\n '(%s/{setup_%s,setup}.py was not found)' \\\n % (os.path.dirname(setup_py), subpackage_name))\n config = Configuration(subpackage_name, self.name,\n self.top_path, subpackage_path)\n else:\n config = self._get_configuration_from_setup_py(setup_py,\n subpackage_name,\n subpackage_path)\n\n if config:\n return [config]\n else:\n return []\n\n def add_subpackage(self,subpackage_name,subpackage_path=None):\n \"\"\" Add subpackage to configuration.\n \"\"\"\n config_list = self.get_subpackage(subpackage_name,subpackage_path)\n if not config_list:\n self.warn('No configuration returned, assuming unavailable.')\n for config in config_list:\n try:\n d = config.todict()\n except AttributeError:\n d = config\n self.info('Appending %s configuration to %s' \\\n % (d.get('name'), self.name))\n self.dict_append(**d)\n\n dist = self.get_distribution()\n if dist is not None:\n self.warn('distutils distribution has been initialized,'\\\n ' it may be too late to add a subpackage '+ subpackage_name)\n return\n\n def add_data_dir(self,data_path):\n \"\"\" Recursively add files under data_path to data_files list.\n Argument can be either\n - 2-sequence (,)\n - path to data directory where python datadir suffix defaults\n to package dir.\n If path is not absolute then it's datadir suffix is\n package dir + subdirname of the path.\n \"\"\"\n if is_sequence(data_path):\n d, data_path = data_path\n else:\n d = None\n if not is_string(data_path):\n raise TypeError(\"not a string: %r\" % (data_path,))\n for path in self.paths(data_path):\n if not os.path.exists(path):\n continue\n filenames = list(general_source_files(path))\n if not os.path.isabs(path):\n npath = data_path\n if '*' in npath:\n npath = os.path.join(*(path.split(os.sep)[-len(npath.split(os.sep)):]))\n if d is None:\n d = self.path_in_package\n ds = os.path.join(d, npath)\n self.add_data_files((ds,filenames))\n else:\n if d is None:\n self.add_data_files(*filenames)\n else:\n self.add_data_files((d,filenames))\n return\n\n def add_data_files(self,*files):\n \"\"\" Add data files to configuration data_files.\n Argument(s) can be either\n - 2-sequence (,)\n - paths to data files where python datadir prefix defaults\n to package dir.\n If path is not absolute then it's datadir prefix is\n package dir + dirname of the path.\n \"\"\"\n data_dict = {}\n new_files = []\n for p in files:\n if not is_sequence(p):\n d = self.path_in_package\n if is_string(p) and not os.path.isabs(p):\n pd = os.path.dirname(p)\n if '*' in pd:\n pn = os.path.basename(p)\n n = len(pd.split(os.sep))\n for d1 in filter(os.path.isdir,self.paths(pd)):\n p = os.path.join(d1,pn)\n d1 = os.sep.join(d1.split(os.sep)[-n:])\n new_files.append((appendpath(d,d1),p))\n continue\n d = appendpath(d,pd)\n p = (d,p)\n new_files.append(p)\n\n files = []\n for prefix,filepattern in new_files:\n assert '*' not in prefix, repr((prefix,filepattern))\n if is_string(filepattern):\n file_list = self.paths(filepattern,include_non_existing=False)\n elif callable(filepattern):\n file_list = [filepattern]\n else:\n file_list = self.paths(*filepattern)\n\n nof_path_components = [len(f.split(os.sep))\n for f in file_list if is_string(f)]\n if nof_path_components:\n min_path_components = min(nof_path_components)-1\n else:\n min_path_components = 0\n\n for f in file_list:\n if is_string(f):\n extra_path_components = f.split(os.sep)[min_path_components:-1]\n p = njoin([prefix]+extra_path_components)\n else:\n p = prefix\n if not data_dict.has_key(p):\n data_dict[p] = [f]\n else:\n data_dict[p].append(f)\n\n dist = self.get_distribution()\n if dist is not None:\n dist.data_files.extend(data_dict.items())\n else:\n self.data_files.extend(data_dict.items())\n\n ### XXX Implement add_py_modules\n\n def add_include_dirs(self,*paths):\n \"\"\" Add paths to configuration include directories.\n \"\"\"\n include_dirs = self._fix_paths(paths)\n dist = self.get_distribution()\n if dist is not None:\n dist.include_dirs.extend(include_dirs)\n else:\n self.include_dirs.extend(include_dirs)\n return\n\n def add_headers(self,*files):\n \"\"\" Add installable headers to configuration.\n Argument(s) can be either\n - 2-sequence (,)\n - path(s) to header file(s) where python includedir suffix will default\n to package name.\n \"\"\"\n headers = []\n for path in files:\n if is_string(path):\n [headers.append((self.name,p)) for p in self.paths(path)]\n else:\n if not isinstance(path, (tuple, list)) or len(path) != 2:\n raise TypeError(repr(path))\n [headers.append((path[0],p)) for p in self.paths(path[1])]\n dist = self.get_distribution()\n if dist is not None:\n dist.headers.extend(headers)\n else:\n self.headers.extend(headers)\n return\n\n def _fix_paths(self,paths,include_non_existing=True):\n assert is_sequence(paths), repr(type(paths))\n new_paths = []\n for n in paths:\n if isinstance(n,str):\n if '*' in n or '?' in n:\n p = glob.glob(n)\n p2 = glob.glob(njoin(self.local_path,n))\n if p2:\n new_paths.extend(p2)\n elif p:\n new_paths.extend(p)\n else:\n if include_non_existing:\n new_paths.append(n)\n self.warn('could not resolve pattern in %s: %r' \\\n % (self.local_path,n))\n else:\n n2 = njoin(self.local_path,n)\n if os.path.exists(n2):\n new_paths.append(n2)\n else:\n if os.path.exists(n):\n new_paths.append(n)\n elif include_non_existing:\n new_paths.append(n)\n if not os.path.exists(n):\n self.warn('not existing path in %s: %s' \\\n % (self.local_path,n))\n else:\n new_paths.append(n)\n return map(minrelpath,new_paths)\n\n def paths(self,*paths,**kws):\n \"\"\" Apply glob to paths and prepend local_path if needed.\n \"\"\"\n include_non_existing = kws.get('include_non_existing',True)\n return self._fix_paths(paths,\n include_non_existing=include_non_existing)\n\n def _fix_paths_dict(self,kw):\n for k in kw.keys():\n v = kw[k]\n if k in ['sources','depends','include_dirs','library_dirs',\n 'module_dirs','extra_objects']:\n new_v = self._fix_paths(v)\n kw[k] = new_v\n return\n\n def add_extension(self,name,sources,**kw):\n \"\"\" Add extension to configuration.\n\n Keywords:\n include_dirs, define_macros, undef_macros,\n library_dirs, libraries, runtime_library_dirs,\n extra_objects, extra_compile_args, extra_link_args,\n export_symbols, swig_opts, depends, language,\n f2py_options, module_dirs\n extra_info - dict or list of dict of keywords to be\n appended to keywords.\n \"\"\"\n ext_args = copy.copy(kw)\n ext_args['name'] = dot_join(self.name,name)\n ext_args['sources'] = sources\n\n if ext_args.has_key('extra_info'):\n extra_info = ext_args['extra_info']\n del ext_args['extra_info']\n if isinstance(extra_info, dict):\n extra_info = [extra_info]\n for info in extra_info:\n assert isinstance(info, dict), repr(info)\n dict_append(ext_args,**info)\n\n self._fix_paths_dict(ext_args)\n\n # Resolve out-of-tree dependencies\n libraries = ext_args.get('libraries',[])\n libnames = []\n ext_args['libraries'] = []\n for libname in libraries:\n if isinstance(libname,tuple):\n self._fix_paths_dict(libname[1])\n\n # Handle library names of the form libname@relative/path/to/library\n if '@' in libname:\n lname,lpath = libname.split('@',1)\n lpath = os.path.abspath(njoin(self.local_path,lpath))\n if os.path.isdir(lpath):\n c = self.get_subpackage(None,lpath)\n if isinstance(c,Configuration):\n c = c.todict()\n for l in [l[0] for l in c.get('libraries',[])]:\n llname = l.split('__OF__',1)[0]\n if llname == lname:\n c.pop('name',None)\n dict_append(ext_args,**c)\n break\n continue\n libnames.append(libname)\n\n ext_args['libraries'] = libnames + ext_args['libraries']\n\n from numpy.distutils.core import Extension\n ext = Extension(**ext_args)\n self.ext_modules.append(ext)\n\n dist = self.get_distribution()\n if dist is not None:\n self.warn('distutils distribution has been initialized,'\\\n ' it may be too late to add an extension '+name)\n return ext\n\n def add_library(self,name,sources,**build_info):\n \"\"\" Add library to configuration.\n\n Valid keywords for build_info:\n depends\n macros\n include_dirs\n extra_compiler_args\n f2py_options\n \"\"\"\n build_info = copy.copy(build_info)\n name = name #+ '__OF__' + self.name\n build_info['sources'] = sources\n\n self._fix_paths_dict(build_info)\n \n self.libraries.append((name,build_info))\n\n dist = self.get_distribution()\n if dist is not None:\n self.warn('distutils distribution has been initialized,'\\\n ' it may be too late to add a library '+ name)\n return\n\n def add_scripts(self,*files):\n \"\"\" Add scripts to configuration.\n \"\"\"\n scripts = self._fix_paths(files)\n dist = self.get_distribution()\n if dist is not None:\n dist.scripts.extend(scripts)\n else:\n self.scripts.extend(scripts)\n return\n\n def dict_append(self,**dict):\n for key in self.list_keys:\n a = getattr(self,key)\n a.extend(dict.get(key,[]))\n for key in self.dict_keys:\n a = getattr(self,key)\n a.update(dict.get(key,{}))\n known_keys = self.list_keys + self.dict_keys + self.extra_keys\n for key in dict.keys():\n if key not in known_keys and not hasattr(self,key):\n if key not in ['version']:\n self.warn('Inheriting attribute %r from %r' \\\n % (key,dict.get('name','?')))\n setattr(self,key,dict[key])\n self.extra_keys.append(key)\n return\n\n def __str__(self):\n known_keys = self.list_keys + self.dict_keys + self.extra_keys\n s = '<'+5*'-' + '\\n'\n s += 'Configuration of '+self.name+':\\n'\n for k in known_keys:\n a = getattr(self,k,None)\n if a:\n s += '%s = %r\\n' % (k,a)\n s += 5*'-' + '>'\n return s\n\n def get_config_cmd(self):\n cmd = get_cmd('config')\n cmd.ensure_finalized()\n cmd.dump_source = 0\n cmd.noisy = 0\n old_path = os.environ.get('PATH')\n if old_path:\n path = os.pathsep.join(['.',old_path])\n os.environ['PATH'] = path\n return cmd\n\n def get_build_temp_dir(self):\n cmd = get_cmd('build')\n cmd.ensure_finalized()\n return cmd.build_temp\n\n def have_f77c(self):\n \"\"\" Check for availability of Fortran 77 compiler.\n Use it inside source generating function to ensure that\n setup distribution instance has been initialized.\n \"\"\"\n simple_fortran_subroutine = '''\n subroutine simple\n end\n '''\n config_cmd = self.get_config_cmd()\n flag = config_cmd.try_compile(simple_fortran_subroutine,lang='f77')\n return flag\n\n def have_f90c(self):\n \"\"\" Check for availability of Fortran 90 compiler.\n Use it inside source generating function to ensure that\n setup distribution instance has been initialized.\n \"\"\"\n simple_fortran_subroutine = '''\n subroutine simple\n end\n '''\n config_cmd = self.get_config_cmd()\n flag = config_cmd.try_compile(simple_fortran_subroutine,lang='f90')\n return flag\n\n def append_to(self, extlib):\n \"\"\" Append libraries, include_dirs to extension or library item.\n \"\"\"\n if is_sequence(extlib):\n lib_name, build_info = extlib\n dict_append(build_info,\n libraries=self.libraries,\n include_dirs=self.include_dirs)\n else:\n from numpy.distutils.core import Extension\n assert isinstance(extlib,Extension), repr(extlib)\n extlib.libraries.extend(self.libraries)\n extlib.include_dirs.extend(self.include_dirs)\n return\n\n def _get_svn_revision(self,path):\n \"\"\" Return path's SVN revision number.\n \"\"\"\n entries = njoin(path,'.svn','entries')\n revision = None\n if os.path.isfile(entries):\n f = open(entries)\n m = re.search(r'revision=\"(?P\\d+)\"',f.read())\n f.close()\n if m:\n revision = int(m.group('revision'))\n return revision\n\n def get_version(self):\n \"\"\" Try to get version string of a package.\n \"\"\"\n version = getattr(self,'version',None)\n if version is not None:\n return version\n\n # Get version from version file.\n files = ['__version__.py',\n self.name.split('.')[-1]+'_version.py',\n 'version.py',\n '__svn_version__.py']\n version_vars = ['version',\n '__version__',\n self.name.split('.')[-1]+'_version']\n for f in files:\n fn = njoin(self.local_path,f)\n if os.path.isfile(fn):\n info = (open(fn),fn,('.py','U',1))\n name = os.path.splitext(os.path.basename(fn))[0]\n n = dot_join(self.name,name)\n try:\n version_module = imp.load_module('_'.join(n.split('.')),*info)\n except ImportError,msg:\n self.warn(str(msg))\n version_module = None\n if version_module is None:\n continue\n\n for a in version_vars:\n version = getattr(version_module,a,None)\n if version is not None:\n break\n if version is not None:\n break\n\n if version is not None:\n self.version = version\n return version\n\n # Get version as SVN revision number\n revision = self._get_svn_revision(self.local_path)\n if revision is not None:\n version = str(revision)\n self.version = version\n\n return version\n\n def make_svn_version_py(self):\n \"\"\" Generate package __svn_version__.py file from SVN revision number,\n it will be removed after python exits but will be available\n when sdist, etc commands are executed.\n\n If __svn_version__.py existed before, nothing is done.\n \"\"\"\n target = njoin(self.local_path,'__svn_version__.py')\n if os.path.isfile(target):\n return\n def generate_svn_version_py():\n if not os.path.isfile(target):\n revision = self._get_svn_revision(self.local_path)\n assert revision is not None,'hmm, why I am not inside SVN tree???'\n version = str(revision)\n self.info('Creating %s (version=%r)' % (target,version))\n f = open(target,'w')\n f.write('version = %r\\n' % (version))\n f.close()\n\n import atexit\n def rm_file(f=target,p=self.info):\n try: os.remove(f); p('removed '+f)\n except OSError: pass\n try: os.remove(f+'c'); p('removed '+f+'c')\n except OSError: pass\n atexit.register(rm_file)\n\n return target\n\n self.add_data_files((self.path_in_package, generate_svn_version_py()))\n\n def make_config_py(self,name='__config__'):\n \"\"\" Generate package __config__.py file containing system_info\n information used during building the package.\n \"\"\"\n self.py_modules.append((self.name,name,generate_config_py))\n return\n\n def get_info(self,*names):\n \"\"\" Get resources information.\n \"\"\"\n from system_info import get_info, dict_append\n info_dict = {}\n for a in names:\n dict_append(info_dict,**get_info(a))\n return info_dict\n\nclass BadConfiguration(Configuration):\n \"\"\"\n When the command line is not ok, use this as the configuration class.\n \"\"\"\n def _do_nothing(self, *args, **kw):\n pass\n add_subpackage = _do_nothing\n add_extension = _do_nothing\n add_library = _do_nothing\n add_data_dir = _do_nothing\n add_data_files = _do_nothing\n add_scripts = _do_nothing\n add_headers = _do_nothing\n add_include_dirs = _do_nothing\n make_config_py = _do_nothing\n\n def get_info(self, *args, **kw):\n return {}\n def have_f77c(self, *args, **kw):\n return False\n def have_f90c(self, *args, **kw):\n return False\n\ndef command_line_ok(_cache=[]):\n \"\"\" Return True if command line does not contain any\n help or display requests.\n \"\"\"\n if _cache:\n return _cache[0]\n ok = True\n from distutils.dist import Distribution\n display_opts = ['--'+n for n in Distribution.display_option_names]\n for o in Distribution.display_options:\n if o[1]:\n display_opts.append('-'+o[1])\n for arg in sys.argv:\n if arg.startswith('--help') or arg=='-h' or arg in display_opts:\n ok = False\n break\n _cache.append(ok)\n return ok\n\nif not command_line_ok():\n Configuration = BadConfiguration\n\ndef get_cmd(cmdname, _cache={}):\n if not _cache.has_key(cmdname):\n import distutils.core\n dist = distutils.core._setup_distribution\n if dist is None:\n from distutils.errors import DistutilsInternalError\n raise DistutilsInternalError(\n 'setup distribution instance not initialized')\n cmd = dist.get_command_obj(cmdname)\n _cache[cmdname] = cmd\n return _cache[cmdname]\n\ndef get_numpy_include_dirs():\n # numpy_include_dirs are set by numpy/core/setup.py, otherwise []\n include_dirs = Configuration.numpy_include_dirs[:]\n if not include_dirs:\n import numpy\n if numpy.show_config is None:\n # running from numpy_core source directory\n include_dirs.append(njoin(os.path.dirname(numpy.__file__),\n 'core', 'include'))\n else:\n # using installed numpy core headers\n import numpy.core as core\n include_dirs.append(njoin(os.path.dirname(core.__file__), 'include'))\n # else running numpy/core/setup.py\n return include_dirs\n\n#########################\n\ndef default_config_dict(name = None, parent_name = None, local_path=None):\n \"\"\" Return a configuration dictionary for usage in\n configuration() function defined in file setup_.py.\n \"\"\"\n import warnings\n warnings.warn('Use Configuration(%r,%r,top_path=%r) instead of '\\\n 'deprecated default_config_dict(%r,%r,%r)'\n % (name, parent_name, local_path,\n name, parent_name, local_path,\n ))\n c = Configuration(name, parent_name, local_path)\n return c.todict()\n\n\ndef dict_append(d, **kws):\n for k, v in kws.items():\n if d.has_key(k):\n d[k].extend(v)\n else:\n d[k] = v\n\ndef appendpath(prefix, path):\n if os.path.sep != '/':\n prefix = prefix.replace('/', os.path.sep)\n path = path.replace('/', os.path.sep)\n drive = ''\n if os.path.isabs(path):\n drive = os.path.splitdrive(prefix)[0]\n absprefix = os.path.splitdrive(os.path.abspath(prefix))[1]\n pathdrive, path = os.path.splitdrive(path)\n d = os.path.commonprefix([absprefix, path])\n if os.path.join(absprefix[:len(d)], absprefix[len(d):]) != absprefix \\\n or os.path.join(path[:len(d)], path[len(d):]) != path:\n # Handle invalid paths\n d = os.path.dirname(d)\n subpath = path[len(d):]\n if os.path.isabs(subpath):\n subpath = subpath[1:]\n else:\n subpath = path\n return os.path.normpath(njoin(drive + prefix, subpath))\n\ndef generate_config_py(target):\n \"\"\" Generate config.py file containing system_info information\n used during building the package.\n\n Usage:\\\n config['py_modules'].append((packagename, '__config__',generate_config_py))\n \"\"\"\n from numpy.distutils.system_info import system_info\n from distutils.dir_util import mkpath\n mkpath(os.path.dirname(target))\n f = open(target, 'w')\n f.write('# This file is generated by %s\\n' % (os.path.abspath(sys.argv[0])))\n f.write('# It contains system_info results at the time of building this package.\\n')\n f.write('__all__ = [\"get_info\",\"show\"]\\n\\n')\n for k, i in system_info.saved_results.items():\n f.write('%s=%r\\n' % (k, i))\n f.write('\\ndef get_info(name): g=globals(); return g.get(name,g.get(name+\"_info\",{}))\\n')\n f.write('''\ndef show():\n for name,info_dict in globals().items():\n if name[0]==\"_\" or type(info_dict) is not type({}): continue\n print name+\":\"\n if not info_dict:\n print \" NOT AVAILABLE\"\n for k,v in info_dict.items():\n v = str(v)\n if k==\\'sources\\' and len(v)>200: v = v[:60]+\\' ...\\\\n... \\'+v[-60:]\n print \\' %s = %s\\'%(k,v)\n print\n return\n ''')\n\n f.close()\n return target\n", + "source_code_before": "import os\nimport re\nimport sys\nimport imp\nimport copy\nimport glob\n\n__all__ = ['Configuration', 'get_numpy_include_dirs', 'default_config_dict',\n 'dict_append', 'appendpath', 'generate_config_py',\n 'get_cmd', 'allpath',\n 'terminal_has_colors', 'red_text', 'green_text', 'yellow_text',\n 'blue_text', 'cyan_text', 'cyg2win32', 'all_strings',\n 'has_f_sources', 'has_cxx_sources', 'filter_sources',\n 'get_dependencies', 'is_local_src_dir', 'get_ext_source_files',\n 'get_script_files', 'get_lib_source_files', 'get_data_files',\n 'dot_join', 'get_frame', 'minrelpath','njoin',\n 'is_sequence', 'is_string', 'as_list']\n\ndef allpath(name):\n \"Convert a /-separated pathname to one using the OS's path separator.\"\n splitted = name.split('/')\n return os.path.join(*splitted)\n\ndef get_path(mod_name, parent_path=None):\n \"\"\" Return path of the module.\n\n Returned path is relative to parent_path when given,\n otherwise it is absolute path.\n \"\"\"\n if mod_name == '__builtin__':\n #builtin if/then added by Pearu for use in core.run_setup.\n d = os.path.dirname(os.path.abspath(sys.argv[0]))\n else:\n __import__(mod_name)\n mod = sys.modules[mod_name]\n if hasattr(mod,'__file__'):\n filename = mod.__file__\n d = os.path.dirname(os.path.abspath(mod.__file__))\n else:\n # we're probably running setup.py as execfile(\"setup.py\")\n # (likely we're building an egg) \n d = os.path.abspath('.')\n # hmm, should we use sys.argv[0] like in __builtin__ case?\n\n if parent_path is not None:\n pd = os.path.abspath(parent_path)\n if pd == d[:len(pd)]:\n d = d[len(pd)+1:]\n return d or '.'\n\ndef njoin(*path):\n \"\"\" Join two or more pathname components +\n - convert a /-separated pathname to one using the OS's path separator.\n - resolve `..` from path.\n\n Either passing n arguments as in njoin('a','b'), or a sequence\n of n names as in njoin(['a','b']) is handled.\n \"\"\"\n if not path:\n # njoin()\n joined = ''\n elif is_sequence(path[0]) and len(path) == 1:\n # njoin(['a', 'b'])\n joined = os.path.join(*path[0])\n else:\n # njoin('a', 'b')\n joined = os.path.join(*path)\n if os.path.sep != '/':\n joined = joined.replace('/',os.path.sep)\n return minrelpath(joined)\n\ndef minrelpath(path):\n \"\"\" Resolve `..` from path.\n \"\"\"\n if not is_string(path):\n return path\n if '..' not in path:\n return path\n l = path.split(os.sep)\n j = 1\n while l:\n try:\n i = l.index('..',j)\n except ValueError:\n break\n if l[i-1]=='..':\n j += 1\n else:\n del l[i],l[i-1]\n j = 1\n if not l:\n return ''\n return os.path.join(*l)\n\n# Hooks for colored terminal output.\n# See also http://www.livinglogic.de/Python/ansistyle\ndef terminal_has_colors():\n if sys.platform=='cygwin' and not os.environ.has_key('USE_COLOR'):\n # Avoid importing curses that causes illegal operation\n # with a message:\n # PYTHON2 caused an invalid page fault in\n # module CYGNURSES7.DLL as 015f:18bbfc28\n # Details: Python 2.3.3 [GCC 3.3.1 (cygming special)]\n # ssh to Win32 machine from debian\n # curses.version is 2.2\n # CYGWIN_98-4.10, release 1.5.7(0.109/3/2))\n return 0\n if hasattr(sys.stdout,'isatty') and sys.stdout.isatty():\n try:\n import curses\n curses.setupterm()\n if (curses.tigetnum(\"colors\") >= 0\n and curses.tigetnum(\"pairs\") >= 0\n and ((curses.tigetstr(\"setf\") is not None\n and curses.tigetstr(\"setb\") is not None)\n or (curses.tigetstr(\"setaf\") is not None\n and curses.tigetstr(\"setab\") is not None)\n or curses.tigetstr(\"scp\") is not None)):\n return 1\n except Exception,msg:\n pass\n return 0\n\nif terminal_has_colors():\n def red_text(s): return '\\x1b[31m%s\\x1b[0m'%s\n def green_text(s): return '\\x1b[32m%s\\x1b[0m'%s\n def yellow_text(s): return '\\x1b[33m%s\\x1b[0m'%s\n def blue_text(s): return '\\x1b[34m%s\\x1b[0m'%s\n def cyan_text(s): return '\\x1b[35m%s\\x1b[0m'%s\nelse:\n def red_text(s): return s\n def green_text(s): return s\n def yellow_text(s): return s\n def cyan_text(s): return s\n def blue_text(s): return s\n\n#########################\n\ndef cyg2win32(path):\n if sys.platform=='cygwin' and path.startswith('/cygdrive'):\n path = path[10] + ':' + os.path.normcase(path[11:])\n return path\n\n#########################\n\n#XXX need support for .C that is also C++\ncxx_ext_match = re.compile(r'.*[.](cpp|cxx|cc)\\Z',re.I).match\nfortran_ext_match = re.compile(r'.*[.](f90|f95|f77|for|ftn|f)\\Z',re.I).match\nf90_ext_match = re.compile(r'.*[.](f90|f95)\\Z',re.I).match\nf90_module_name_match = re.compile(r'\\s*module\\s*(?P[\\w_]+)',re.I).match\ndef _get_f90_modules(source):\n \"\"\" Return a list of Fortran f90 module names that\n given source file defines.\n \"\"\"\n if not f90_ext_match(source):\n return []\n modules = []\n f = open(source,'r')\n f_readlines = getattr(f,'xreadlines',f.readlines)\n for line in f_readlines():\n m = f90_module_name_match(line)\n if m:\n name = m.group('name')\n modules.append(name)\n # break # XXX can we assume that there is one module per file?\n f.close()\n return modules\n\ndef is_string(s):\n return isinstance(s, str)\n\ndef all_strings(lst):\n \"\"\" Return True if all items in lst are string objects. \"\"\"\n for item in lst:\n if not is_string(item):\n return False\n return True\n\ndef is_sequence(seq):\n if is_string(seq):\n return False\n try:\n len(seq)\n except:\n return False\n return True\n\ndef as_list(seq):\n if is_sequence(seq):\n return list(seq)\n else:\n return [seq]\n\ndef has_f_sources(sources):\n \"\"\" Return True if sources contains Fortran files \"\"\"\n for source in sources:\n if fortran_ext_match(source):\n return True\n return False\n\ndef has_cxx_sources(sources):\n \"\"\" Return True if sources contains C++ files \"\"\"\n for source in sources:\n if cxx_ext_match(source):\n return True\n return False\n\ndef filter_sources(sources):\n \"\"\" Return four lists of filenames containing\n C, C++, Fortran, and Fortran 90 module sources,\n respectively.\n \"\"\"\n c_sources = []\n cxx_sources = []\n f_sources = []\n fmodule_sources = []\n for source in sources:\n if fortran_ext_match(source):\n modules = _get_f90_modules(source)\n if modules:\n fmodule_sources.append(source)\n else:\n f_sources.append(source)\n elif cxx_ext_match(source):\n cxx_sources.append(source)\n else:\n c_sources.append(source)\n return c_sources, cxx_sources, f_sources, fmodule_sources\n\n\ndef _get_headers(directory_list):\n # get *.h files from list of directories\n headers = []\n for d in directory_list:\n head = glob.glob(os.path.join(d,\"*.h\")) #XXX: *.hpp files??\n headers.extend(head)\n return headers\n\ndef _get_directories(list_of_sources):\n # get unique directories from list of sources.\n direcs = []\n for f in list_of_sources:\n d = os.path.split(f)\n if d[0] != '' and not d[0] in direcs:\n direcs.append(d[0])\n return direcs\n\ndef get_dependencies(sources):\n #XXX scan sources for include statements\n return _get_headers(_get_directories(sources))\n\ndef is_local_src_dir(directory):\n \"\"\" Return true if directory is local directory.\n \"\"\"\n if not is_string(directory):\n return False\n abs_dir = os.path.abspath(directory)\n c = os.path.commonprefix([os.getcwd(),abs_dir])\n new_dir = abs_dir[len(c):].split(os.sep)\n if new_dir and not new_dir[0]:\n new_dir = new_dir[1:]\n if new_dir and new_dir[0]=='build':\n return False\n new_dir = os.sep.join(new_dir)\n return os.path.isdir(new_dir)\n\ndef general_source_files(top_path):\n pruned_directories = {'CVS':1, '.svn':1, 'build':1}\n prune_file_pat = re.compile(r'(?:[~#]|\\.py[co]|\\.o)$')\n for dirpath, dirnames, filenames in os.walk(top_path, topdown=True):\n pruned = [ d for d in dirnames if d not in pruned_directories ]\n dirnames[:] = pruned\n for f in filenames:\n if not prune_file_pat.search(f):\n yield os.path.join(dirpath, f)\n\ndef get_ext_source_files(ext):\n # Get sources and any include files in the same directory.\n filenames = []\n sources = filter(is_string, ext.sources)\n filenames.extend(sources)\n filenames.extend(get_dependencies(sources))\n for d in ext.depends:\n if is_local_src_dir(d):\n filenames.extend(list(general_source_files(d)))\n elif os.path.isfile(d):\n filenames.append(d)\n return filenames\n\ndef get_script_files(scripts):\n scripts = filter(is_string, scripts)\n return scripts\n\ndef get_lib_source_files(lib):\n filenames = []\n sources = lib[1].get('sources',[])\n sources = filter(is_string, sources)\n filenames.extend(sources)\n filenames.extend(get_dependencies(sources))\n depends = lib[1].get('depends',[])\n for d in depends:\n if is_local_src_dir(d):\n filenames.extend(list(general_source_files(d)))\n elif os.path.isfile(d):\n filenames.append(d)\n return filenames\n\ndef get_data_files(data):\n if is_string(data):\n return [data]\n sources = data[1]\n filenames = []\n for s in sources:\n if callable(s):\n continue\n if is_local_src_dir(s):\n filenames.extend(list(general_source_files(s)))\n elif is_string(s):\n if os.path.isfile(s):\n filenames.append(s)\n else:\n print 'Not existing data file:',s\n else:\n raise TypeError,repr(s)\n return filenames\n\ndef dot_join(*args):\n return '.'.join([a for a in args if a])\n\ndef get_frame(level=0):\n try:\n return sys._getframe(level+1)\n except AttributeError:\n frame = sys.exc_info()[2].tb_frame\n for _ in range(level+1):\n frame = frame.f_back\n return frame\n\n######################\n\nclass Configuration(object):\n\n _list_keys = ['packages', 'ext_modules', 'data_files', 'include_dirs',\n 'libraries', 'headers', 'scripts', 'py_modules']\n _dict_keys = ['package_dir']\n\n numpy_include_dirs = []\n\n def __init__(self,\n package_name=None,\n parent_name=None,\n top_path=None,\n package_path=None,\n **attrs):\n \"\"\" Construct configuration instance of a package.\n\n package_name -- name of the package\n Ex.: 'distutils'\n parent_name -- name of the parent package\n Ex.: 'numpy'\n top_path -- directory of the toplevel package\n Ex.: the directory where the numpy package source sits\n package_path -- directory of package. Will be computed by magic from the\n directory of the caller module if not specified\n Ex.: the directory where numpy.distutils is\n \"\"\"\n self.name = dot_join(parent_name, package_name)\n\n caller_frame = get_frame(1)\n caller_name = eval('__name__',caller_frame.f_globals,caller_frame.f_locals)\n\n self.local_path = get_path(caller_name, top_path)\n if top_path is None:\n top_path = self.local_path\n if package_path is None:\n package_path = self.local_path\n elif os.path.isdir(njoin(self.local_path,package_path)):\n package_path = njoin(self.local_path,package_path)\n if not os.path.isdir(package_path):\n raise ValueError(\"%r is not a directory\" % (package_path,))\n self.top_path = top_path\n self.package_path = package_path\n # this is the relative path in the installed package\n self.path_in_package = os.path.join(*self.name.split('.'))\n\n self.list_keys = self._list_keys[:]\n self.dict_keys = self._dict_keys[:]\n\n for n in self.list_keys:\n v = copy.copy(attrs.get(n, []))\n setattr(self, n, as_list(v))\n\n for n in self.dict_keys:\n v = copy.copy(attrs.get(n, {}))\n setattr(self, n, v)\n\n known_keys = self.list_keys + self.dict_keys\n self.extra_keys = []\n for n in attrs.keys():\n if n in known_keys:\n continue\n a = attrs[n]\n setattr(self,n,a)\n if isinstance(a, list):\n self.list_keys.append(n)\n elif isinstance(a, dict):\n self.dict_keys.append(n)\n else:\n self.extra_keys.append(n)\n\n if os.path.exists(njoin(package_path,'__init__.py')):\n self.packages.append(self.name)\n self.package_dir[self.name] = package_path\n\n self.options = dict(\n ignore_setup_xxx_py = False,\n assume_default_configuration = False,\n delegate_options_to_subpackages = False,\n quiet = False,\n )\n\n for i in range(1,3):\n f = get_frame(i)\n try:\n caller_instance = eval('self',f.f_globals,f.f_locals)\n break\n except NameError:\n caller_instance = None\n if isinstance(caller_instance, self.__class__):\n if caller_instance.options['delegate_options_to_subpackages']:\n self.set_options(**caller_instance.options)\n\n def todict(self):\n \"\"\" Return configuration distionary suitable for passing\n to distutils.core.setup() function.\n \"\"\"\n d = {}\n for n in self.list_keys + self.dict_keys + self.extra_keys:\n a = getattr(self,n)\n if a:\n d[n] = a\n if self.name:\n d['name'] = self.name\n return d\n\n def info(self, message):\n if not self.options['quiet']:\n print message\n\n def warn(self, message):\n print>>sys.stderr, 'Warning:',message\n\n\n def set_options(self, **options):\n \"\"\" Configure Configuration instance.\n\n The following options are available:\n - ignore_setup_xxx_py\n - assume_default_configuration\n - delegate_options_to_subpackages\n - quiet\n \"\"\"\n for key, value in options.items():\n if self.options.has_key(key):\n self.options[key] = value\n else:\n raise ValueError,'Unknown option: '+key\n\n def get_distribution(self):\n import distutils.core\n dist = distutils.core._setup_distribution\n return dist\n\n def _wildcard_get_subpackage(self, subpackage_name):\n l = subpackage_name.split('.')\n subpackage_path = njoin([self.local_path]+l)\n dirs = filter(os.path.isdir,glob.glob(subpackage_path))\n config_list = []\n for d in dirs:\n if not os.path.isfile(njoin(d,'__init__.py')):\n continue\n if 'build' in d.split(os.sep):\n continue\n n = '.'.join(d.split(os.sep)[-len(l):])\n c = self.get_subpackage(n)\n config_list.extend(c)\n return config_list\n\n def _get_configuration_from_setup_py(self, setup_py,\n subpackage_name, subpackage_path):\n # In case setup_py imports local modules:\n sys.path.insert(0,os.path.dirname(setup_py))\n try:\n fo_setup_py = open(setup_py, 'U')\n setup_name = os.path.splitext(os.path.basename(setup_py))[0]\n n = dot_join(self.name,setup_name)\n setup_module = imp.load_module('_'.join(n.split('.')),\n fo_setup_py,\n setup_py,\n ('.py', 'U', 1))\n if not hasattr(setup_module,'configuration'):\n if not self.options['assume_default_configuration']:\n self.warn('Assuming default configuration '\\\n '(%s does not define configuration())'\\\n % (setup_module))\n config = Configuration(subpackage_name, self.name,\n self.top_path, subpackage_path)\n else:\n args = (self.name,)\n if setup_module.configuration.func_code.co_argcount > 1:\n args = args + (self.top_path,)\n config = setup_module.configuration(*args)\n finally:\n del sys.path[0]\n return config\n\n def get_subpackage(self,subpackage_name,subpackage_path=None):\n \"\"\" Return list of subpackage configurations.\n\n '*' in subpackage_name is handled as a wildcard.\n \"\"\"\n if subpackage_name is None:\n if subpackage_path is None:\n raise ValueError(\n \"either subpackage_name or subpackage_path must be specified\")\n subpackage_name = os.path.basename(subpackage_path)\n\n # handle wildcards\n l = subpackage_name.split('.')\n if subpackage_path is None and '*' in subpackage_name:\n return self._wildcard_get_subpackage(subpackage_name)\n\n if subpackage_path is None:\n subpackage_path = njoin([self.local_path] + l)\n else:\n subpackage_path = njoin([subpackage_path] + l[:-1])\n subpackage_path = self._fix_paths([subpackage_path])[0]\n\n setup_py = njoin(subpackage_path, 'setup.py')\n if not self.options['ignore_setup_xxx_py']:\n if not os.path.isfile(setup_py):\n setup_py = njoin(subpackage_path,\n 'setup_%s.py' % (subpackage_name))\n\n if not os.path.isfile(setup_py):\n if not self.options['assume_default_configuration']:\n self.warn('Assuming default configuration '\\\n '(%s/{setup_%s,setup}.py was not found)' \\\n % (os.path.dirname(setup_py), subpackage_name))\n config = Configuration(subpackage_name, self.name,\n self.top_path, subpackage_path)\n else:\n config = self._get_configuration_from_setup_py(setup_py,\n subpackage_name,\n subpackage_path)\n\n if config:\n return [config]\n else:\n return []\n\n def add_subpackage(self,subpackage_name,subpackage_path=None):\n \"\"\" Add subpackage to configuration.\n \"\"\"\n config_list = self.get_subpackage(subpackage_name,subpackage_path)\n if not config_list:\n self.warn('No configuration returned, assuming unavailable.')\n for config in config_list:\n try:\n d = config.todict()\n except AttributeError:\n d = config\n self.info('Appending %s configuration to %s' \\\n % (d.get('name'), self.name))\n self.dict_append(**d)\n\n dist = self.get_distribution()\n if dist is not None:\n self.warn('distutils distribution has been initialized,'\\\n ' it may be too late to add a subpackage '+ subpackage_name)\n return\n\n def add_data_dir(self,data_path):\n \"\"\" Recursively add files under data_path to data_files list.\n Argument can be either\n - 2-sequence (,)\n - path to data directory where python datadir suffix defaults\n to package dir.\n If path is not absolute then it's datadir suffix is\n package dir + subdirname of the path.\n \"\"\"\n if is_sequence(data_path):\n d, data_path = data_path\n else:\n d = None\n if not is_string(data_path):\n raise TypeError(\"not a string: %r\" % (data_path,))\n for path in self.paths(data_path):\n if not os.path.exists(path):\n continue\n filenames = list(general_source_files(path))\n if not os.path.isabs(path):\n npath = data_path\n if '*' in npath:\n npath = os.path.join(*(path.split(os.sep)[-len(npath.split(os.sep)):]))\n if d is None:\n d = self.path_in_package\n ds = os.path.join(d, npath)\n self.add_data_files((ds,filenames))\n else:\n if d is None:\n self.add_data_files(*filenames)\n else:\n self.add_data_files((d,filenames))\n return\n\n def add_data_files(self,*files):\n \"\"\" Add data files to configuration data_files.\n Argument(s) can be either\n - 2-sequence (,)\n - paths to data files where python datadir prefix defaults\n to package dir.\n If path is not absolute then it's datadir prefix is\n package dir + dirname of the path.\n \"\"\"\n data_dict = {}\n new_files = []\n for p in files:\n if not is_sequence(p):\n d = self.path_in_package\n if is_string(p) and not os.path.isabs(p):\n pd = os.path.dirname(p)\n if '*' in pd:\n pn = os.path.basename(p)\n n = len(pd.split(os.sep))\n for d1 in filter(os.path.isdir,self.paths(pd)):\n p = os.path.join(d1,pn)\n d1 = os.sep.join(d1.split(os.sep)[-n:])\n new_files.append((appendpath(d,d1),p))\n continue\n d = appendpath(d,pd)\n p = (d,p)\n new_files.append(p)\n\n files = []\n for prefix,filepattern in new_files:\n assert '*' not in prefix, repr((prefix,filepattern))\n if is_string(filepattern):\n file_list = self.paths(filepattern,include_non_existing=False)\n elif callable(filepattern):\n file_list = [filepattern]\n else:\n file_list = self.paths(*filepattern)\n\n nof_path_components = [len(f.split(os.sep))\n for f in file_list if is_string(f)]\n if nof_path_components:\n min_path_components = min(nof_path_components)-1\n else:\n min_path_components = 0\n\n for f in file_list:\n if is_string(f):\n extra_path_components = f.split(os.sep)[min_path_components:-1]\n p = njoin([prefix]+extra_path_components)\n else:\n p = prefix\n if not data_dict.has_key(p):\n data_dict[p] = [f]\n else:\n data_dict[p].append(f)\n\n dist = self.get_distribution()\n if dist is not None:\n dist.data_files.extend(data_dict.items())\n else:\n self.data_files.extend(data_dict.items())\n\n ### XXX Implement add_py_modules\n\n def add_include_dirs(self,*paths):\n \"\"\" Add paths to configuration include directories.\n \"\"\"\n include_dirs = self._fix_paths(paths)\n dist = self.get_distribution()\n if dist is not None:\n dist.include_dirs.extend(include_dirs)\n else:\n self.include_dirs.extend(include_dirs)\n return\n\n def add_headers(self,*files):\n \"\"\" Add installable headers to configuration.\n Argument(s) can be either\n - 2-sequence (,)\n - path(s) to header file(s) where python includedir suffix will default\n to package name.\n \"\"\"\n headers = []\n for path in files:\n if is_string(path):\n [headers.append((self.name,p)) for p in self.paths(path)]\n else:\n if not isinstance(path, (tuple, list)) or len(path) != 2:\n raise TypeError(repr(path))\n [headers.append((path[0],p)) for p in self.paths(path[1])]\n dist = self.get_distribution()\n if dist is not None:\n dist.headers.extend(headers)\n else:\n self.headers.extend(headers)\n return\n\n def _fix_paths(self,paths,include_non_existing=True):\n assert is_sequence(paths), repr(type(paths))\n new_paths = []\n for n in paths:\n if isinstance(n,str):\n if '*' in n or '?' in n:\n p = glob.glob(n)\n p2 = glob.glob(njoin(self.local_path,n))\n if p2:\n new_paths.extend(p2)\n elif p:\n new_paths.extend(p)\n else:\n if include_non_existing:\n new_paths.append(n)\n self.warn('could not resolve pattern in %s: %r' \\\n % (self.local_path,n))\n else:\n n2 = njoin(self.local_path,n)\n if os.path.exists(n2):\n new_paths.append(n2)\n else:\n if os.path.exists(n):\n new_paths.append(n)\n elif include_non_existing:\n new_paths.append(n)\n if not os.path.exists(n):\n self.warn('not existing path in %s: %s' \\\n % (self.local_path,n))\n else:\n new_paths.append(n)\n return map(minrelpath,new_paths)\n\n def paths(self,*paths,**kws):\n \"\"\" Apply glob to paths and prepend local_path if needed.\n \"\"\"\n include_non_existing = kws.get('include_non_existing',True)\n return self._fix_paths(paths,\n include_non_existing=include_non_existing)\n\n def _fix_paths_dict(self,kw):\n for k in kw.keys():\n v = kw[k]\n if k in ['sources','depends','include_dirs','library_dirs',\n 'module_dirs','extra_objects']:\n new_v = self._fix_paths(v)\n kw[k] = new_v\n return\n\n def add_extension(self,name,sources,**kw):\n \"\"\" Add extension to configuration.\n\n Keywords:\n include_dirs, define_macros, undef_macros,\n library_dirs, libraries, runtime_library_dirs,\n extra_objects, extra_compile_args, extra_link_args,\n export_symbols, swig_opts, depends, language,\n f2py_options, module_dirs\n extra_info - dict or list of dict of keywords to be\n appended to keywords.\n \"\"\"\n ext_args = copy.copy(kw)\n ext_args['name'] = dot_join(self.name,name)\n ext_args['sources'] = sources\n\n if ext_args.has_key('extra_info'):\n extra_info = ext_args['extra_info']\n del ext_args['extra_info']\n if isinstance(extra_info, dict):\n extra_info = [extra_info]\n for info in extra_info:\n assert isinstance(info, dict), repr(info)\n dict_append(ext_args,**info)\n\n self._fix_paths_dict(ext_args)\n\n # Resolve out-of-tree dependencies\n libraries = ext_args.get('libraries',[])\n libnames = []\n ext_args['libraries'] = []\n for libname in libraries:\n if isinstance(libname,tuple):\n self._fix_paths_dict(libname[1])\n\n # Handle library names of the form libname@relative/path/to/library\n if '@' in libname:\n lname,lpath = libname.split('@',1)\n lpath = os.path.abspath(njoin(self.local_path,lpath))\n if os.path.isdir(lpath):\n c = self.get_subpackage(None,lpath)\n if isinstance(c,Configuration):\n c = c.todict()\n for l in [l[0] for l in c.get('libraries',[])]:\n llname = l.split('__OF__',1)[0]\n if llname == lname:\n c.pop('name',None)\n dict_append(ext_args,**c)\n break\n continue\n libnames.append(libname)\n\n ext_args['libraries'] = libnames + ext_args['libraries']\n\n from numpy.distutils.core import Extension\n ext = Extension(**ext_args)\n self.ext_modules.append(ext)\n\n dist = self.get_distribution()\n if dist is not None:\n self.warn('distutils distribution has been initialized,'\\\n ' it may be too late to add an extension '+name)\n return ext\n\n def add_library(self,name,sources,**build_info):\n \"\"\" Add library to configuration.\n\n Valid keywords for build_info:\n depends\n macros\n include_dirs\n extra_compiler_args\n f2py_options\n \"\"\"\n build_info = copy.copy(build_info)\n name = name #+ '__OF__' + self.name\n build_info['sources'] = sources\n\n self._fix_paths_dict(build_info)\n \n self.libraries.append((name,build_info))\n\n dist = self.get_distribution()\n if dist is not None:\n self.warn('distutils distribution has been initialized,'\\\n ' it may be too late to add a library '+ name)\n return\n\n def add_scripts(self,*files):\n \"\"\" Add scripts to configuration.\n \"\"\"\n scripts = self._fix_paths(files)\n dist = self.get_distribution()\n if dist is not None:\n dist.scripts.extend(scripts)\n else:\n self.scripts.extend(scripts)\n return\n\n def dict_append(self,**dict):\n for key in self.list_keys:\n a = getattr(self,key)\n a.extend(dict.get(key,[]))\n for key in self.dict_keys:\n a = getattr(self,key)\n a.update(dict.get(key,{}))\n known_keys = self.list_keys + self.dict_keys + self.extra_keys\n for key in dict.keys():\n if key not in known_keys and not hasattr(self,key):\n if key not in ['version']:\n self.warn('Inheriting attribute %r from %r' \\\n % (key,dict.get('name','?')))\n setattr(self,key,dict[key])\n self.extra_keys.append(key)\n return\n\n def __str__(self):\n known_keys = self.list_keys + self.dict_keys + self.extra_keys\n s = '<'+5*'-' + '\\n'\n s += 'Configuration of '+self.name+':\\n'\n for k in known_keys:\n a = getattr(self,k,None)\n if a:\n s += '%s = %r\\n' % (k,a)\n s += 5*'-' + '>'\n return s\n\n def get_config_cmd(self):\n cmd = get_cmd('config')\n cmd.ensure_finalized()\n cmd.dump_source = 0\n cmd.noisy = 0\n old_path = os.environ.get('PATH')\n if old_path:\n path = os.pathsep.join(['.',old_path])\n os.environ['PATH'] = path\n return cmd\n\n def get_build_temp_dir(self):\n cmd = get_cmd('build')\n cmd.ensure_finalized()\n return cmd.build_temp\n\n def have_f77c(self):\n \"\"\" Check for availability of Fortran 77 compiler.\n Use it inside source generating function to ensure that\n setup distribution instance has been initialized.\n \"\"\"\n simple_fortran_subroutine = '''\n subroutine simple\n end\n '''\n config_cmd = self.get_config_cmd()\n flag = config_cmd.try_compile(simple_fortran_subroutine,lang='f77')\n return flag\n\n def have_f90c(self):\n \"\"\" Check for availability of Fortran 90 compiler.\n Use it inside source generating function to ensure that\n setup distribution instance has been initialized.\n \"\"\"\n simple_fortran_subroutine = '''\n subroutine simple\n end\n '''\n config_cmd = self.get_config_cmd()\n flag = config_cmd.try_compile(simple_fortran_subroutine,lang='f90')\n return flag\n\n def append_to(self, extlib):\n \"\"\" Append libraries, include_dirs to extension or library item.\n \"\"\"\n if is_sequence(extlib):\n lib_name, build_info = extlib\n dict_append(build_info,\n libraries=self.libraries,\n include_dirs=self.include_dirs)\n else:\n from numpy.distutils.core import Extension\n assert isinstance(extlib,Extension), repr(extlib)\n extlib.libraries.extend(self.libraries)\n extlib.include_dirs.extend(self.include_dirs)\n return\n\n def _get_svn_revision(self,path):\n \"\"\" Return path's SVN revision number.\n \"\"\"\n entries = njoin(path,'.svn','entries')\n revision = None\n if os.path.isfile(entries):\n f = open(entries)\n m = re.search(r'revision=\"(?P\\d+)\"',f.read())\n f.close()\n if m:\n revision = int(m.group('revision'))\n return revision\n\n def get_version(self):\n \"\"\" Try to get version string of a package.\n \"\"\"\n version = getattr(self,'version',None)\n if version is not None:\n return version\n\n # Get version from version file.\n files = ['__version__.py',\n self.name.split('.')[-1]+'_version.py',\n 'version.py',\n '__svn_version__.py']\n version_vars = ['version',\n '__version__',\n self.name.split('.')[-1]+'_version']\n for f in files:\n fn = njoin(self.local_path,f)\n if os.path.isfile(fn):\n info = (open(fn),fn,('.py','U',1))\n name = os.path.splitext(os.path.basename(fn))[0]\n n = dot_join(self.name,name)\n try:\n version_module = imp.load_module('_'.join(n.split('.')),*info)\n except ImportError,msg:\n self.warn(str(msg))\n version_module = None\n if version_module is None:\n continue\n\n for a in version_vars:\n version = getattr(version_module,a,None)\n if version is not None:\n break\n if version is not None:\n break\n\n if version is not None:\n self.version = version\n return version\n\n # Get version as SVN revision number\n revision = self._get_svn_revision(self.local_path)\n if revision is not None:\n version = str(revision)\n self.version = version\n\n return version\n\n def make_svn_version_py(self):\n \"\"\" Generate package __svn_version__.py file from SVN revision number,\n it will be removed after python exits but will be available\n when sdist, etc commands are executed.\n\n If __svn_version__.py existed before, nothing is done.\n \"\"\"\n target = njoin(self.local_path,'__svn_version__.py')\n if os.path.isfile(target):\n return\n def generate_svn_version_py():\n if not os.path.isfile(target):\n revision = self._get_svn_revision(self.local_path)\n assert revision is not None,'hmm, why I am not inside SVN tree???'\n version = str(revision)\n self.info('Creating %s (version=%r)' % (target,version))\n f = open(target,'w')\n f.write('version = %r\\n' % (version))\n f.close()\n\n import atexit\n def rm_file(f=target,p=self.info):\n try: os.remove(f); p('removed '+f)\n except OSError: pass\n try: os.remove(f+'c'); p('removed '+f+'c')\n except OSError: pass\n atexit.register(rm_file)\n\n return target\n\n self.add_data_files((self.path_in_package, generate_svn_version_py()))\n\n def make_config_py(self,name='__config__'):\n \"\"\" Generate package __config__.py file containing system_info\n information used during building the package.\n \"\"\"\n self.py_modules.append((self.name,name,generate_config_py))\n return\n\n def get_info(self,*names):\n \"\"\" Get resources information.\n \"\"\"\n from system_info import get_info, dict_append\n info_dict = {}\n for a in names:\n dict_append(info_dict,**get_info(a))\n return info_dict\n\nclass BadConfiguration(Configuration):\n \"\"\"\n When the command line is not ok, use this as the configuration class.\n \"\"\"\n def _do_nothing(self, *args, **kw):\n pass\n add_subpackage = _do_nothing\n add_extension = _do_nothing\n add_library = _do_nothing\n add_data_dir = _do_nothing\n add_data_files = _do_nothing\n add_scripts = _do_nothing\n add_headers = _do_nothing\n add_include_dirs = _do_nothing\n make_config_py = _do_nothing\n\n def get_info(self, *args, **kw):\n return {}\n def have_f77c(self, *args, **kw):\n return False\n def have_f90c(self, *args, **kw):\n return False\n\ndef command_line_ok(_cache=[]):\n \"\"\" Return True if command line does not contain any\n help or display requests.\n \"\"\"\n if _cache:\n return _cache[0]\n ok = True\n from distutils.dist import Distribution\n display_opts = ['--'+n for n in Distribution.display_option_names]\n for o in Distribution.display_options:\n if o[1]:\n display_opts.append('-'+o[1])\n for arg in sys.argv:\n if arg.startswith('--help') or arg=='-h' or arg in display_opts:\n ok = False\n break\n _cache.append(ok)\n return ok\n\nif not command_line_ok():\n Configuration = BadConfiguration\n\ndef get_cmd(cmdname, _cache={}):\n if not _cache.has_key(cmdname):\n import distutils.core\n dist = distutils.core._setup_distribution\n if dist is None:\n from distutils.errors import DistutilsInternalError\n raise DistutilsInternalError(\n 'setup distribution instance not initialized')\n cmd = dist.get_command_obj(cmdname)\n _cache[cmdname] = cmd\n return _cache[cmdname]\n\ndef get_numpy_include_dirs():\n # numpy_include_dirs are set by numpy/core/setup.py, otherwise []\n include_dirs = Configuration.numpy_include_dirs[:]\n if not include_dirs:\n import numpy\n if numpy.show_config is None:\n # running from numpy_core source directory\n include_dirs.append(njoin(os.path.dirname(numpy.__file__),\n 'core', 'include'))\n else:\n # using installed numpy core headers\n import numpy.core as core\n include_dirs.append(njoin(os.path.dirname(core.__file__), 'include'))\n # else running numpy/core/setup.py\n return include_dirs\n\n#########################\n\ndef default_config_dict(name = None, parent_name = None, local_path=None):\n \"\"\" Return a configuration dictionary for usage in\n configuration() function defined in file setup_.py.\n \"\"\"\n import warnings\n warnings.warn('Use Configuration(%r,%r,top_path=%r) instead of '\\\n 'deprecated default_config_dict(%r,%r,%r)'\n % (name, parent_name, local_path,\n name, parent_name, local_path,\n ))\n c = Configuration(name, parent_name, local_path)\n return c.todict()\n\n\ndef dict_append(d, **kws):\n for k, v in kws.items():\n if d.has_key(k):\n d[k].extend(v)\n else:\n d[k] = v\n\ndef appendpath(prefix, path):\n if os.path.sep != '/':\n prefix = prefix.replace('/', os.path.sep)\n path = path.replace('/', os.path.sep)\n drive = ''\n if os.path.isabs(path):\n drive = os.path.splitdrive(prefix)[0]\n absprefix = os.path.splitdrive(os.path.abspath(prefix))[1]\n pathdrive, path = os.path.splitdrive(path)\n d = os.path.commonprefix([absprefix, path])\n if os.path.join(absprefix[:len(d)], absprefix[len(d):]) != absprefix \\\n or os.path.join(path[:len(d)], path[len(d):]) != path:\n # Handle invalid paths\n d = os.path.dirname(d)\n subpath = path[len(d):]\n if os.path.isabs(subpath):\n subpath = subpath[1:]\n else:\n subpath = path\n return os.path.normpath(njoin(drive + prefix, subpath))\n\ndef generate_config_py(target):\n \"\"\" Generate config.py file containing system_info information\n used during building the package.\n\n Usage:\\\n config['py_modules'].append((packagename, '__config__',generate_config_py))\n \"\"\"\n from numpy.distutils.system_info import system_info\n from distutils.dir_util import mkpath\n mkpath(os.path.dirname(target))\n f = open(target, 'w')\n f.write('# This file is generated by %s\\n' % (os.path.abspath(sys.argv[0])))\n f.write('# It contains system_info results at the time of building this package.\\n')\n f.write('__all__ = [\"get_info\",\"show\"]\\n\\n')\n for k, i in system_info.saved_results.items():\n f.write('%s=%r\\n' % (k, i))\n f.write('\\ndef get_info(name): g=globals(); return g.get(name,g.get(name+\"_info\",{}))\\n')\n f.write('''\ndef show():\n for name,info_dict in globals().items():\n if name[0]==\"_\" or type(info_dict) is not type({}): continue\n print name+\":\"\n if not info_dict:\n print \" NOT AVAILABLE\"\n for k,v in info_dict.items():\n v = str(v)\n if k==\\'sources\\' and len(v)>200: v = v[:60]+\\' ...\\\\n... \\'+v[-60:]\n print \\' %s = %s\\'%(k,v)\n print\n return\n ''')\n\n f.close()\n return target\n", + "methods": [ + { + "name": "allpath", + "long_name": "allpath( name )", + "filename": "misc_util.py", + "nloc": 4, + "complexity": 1, + "token_count": 24, + "parameters": [ + "name" + ], + "start_line": 19, + "end_line": 22, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 0 + }, + { + "name": "get_path", + "long_name": "get_path( mod_name , parent_path = None )", + "filename": "misc_util.py", + "nloc": 16, + "complexity": 6, + "token_count": 139, + "parameters": [ + "mod_name", + "parent_path" + ], + "start_line": 24, + "end_line": 49, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 26, + "top_nesting_level": 0 + }, + { + "name": "njoin", + "long_name": "njoin( * path )", + "filename": "misc_util.py", + "nloc": 10, + "complexity": 5, + "token_count": 85, + "parameters": [ + "path" + ], + "start_line": 51, + "end_line": 70, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 20, + "top_nesting_level": 0 + }, + { + "name": "get_mathlibs", + "long_name": "get_mathlibs( path = None )", + "filename": "misc_util.py", + "nloc": 14, + "complexity": 5, + "token_count": 98, + "parameters": [ + "path" + ], + "start_line": 72, + "end_line": 87, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 16, + "top_nesting_level": 0 + }, + { + "name": "minrelpath", + "long_name": "minrelpath( path )", + "filename": "misc_util.py", + "nloc": 22, + "complexity": 8, + "token_count": 118, + "parameters": [ + "path" + ], + "start_line": 89, + "end_line": 112, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 24, + "top_nesting_level": 0 + }, + { + "name": "terminal_has_colors", + "long_name": "terminal_has_colors( )", + "filename": "misc_util.py", + "nloc": 18, + "complexity": 13, + "token_count": 137, + "parameters": [], + "start_line": 116, + "end_line": 141, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 26, + "top_nesting_level": 0 + }, + { + "name": "cyg2win32", + "long_name": "cyg2win32( path )", + "filename": "misc_util.py", + "nloc": 4, + "complexity": 3, + "token_count": 42, + "parameters": [ + "path" + ], + "start_line": 158, + "end_line": 161, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 0 + }, + { + "name": "_get_f90_modules", + "long_name": "_get_f90_modules( source )", + "filename": "misc_util.py", + "nloc": 13, + "complexity": 4, + "token_count": 77, + "parameters": [ + "source" + ], + "start_line": 170, + "end_line": 186, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 17, + "top_nesting_level": 0 + }, + { + "name": "is_string", + "long_name": "is_string( s )", + "filename": "misc_util.py", + "nloc": 2, + "complexity": 1, + "token_count": 12, + "parameters": [ + "s" + ], + "start_line": 188, + "end_line": 189, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 0 + }, + { + "name": "all_strings", + "long_name": "all_strings( lst )", + "filename": "misc_util.py", + "nloc": 5, + "complexity": 3, + "token_count": 22, + "parameters": [ + "lst" + ], + "start_line": 191, + "end_line": 196, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 6, + "top_nesting_level": 0 + }, + { + "name": "is_sequence", + "long_name": "is_sequence( seq )", + "filename": "misc_util.py", + "nloc": 8, + "complexity": 3, + "token_count": 25, + "parameters": [ + "seq" + ], + "start_line": 198, + "end_line": 205, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 8, + "top_nesting_level": 0 + }, + { + "name": "as_list", + "long_name": "as_list( seq )", + "filename": "misc_util.py", + "nloc": 5, + "complexity": 2, + "token_count": 22, + "parameters": [ + "seq" + ], + "start_line": 207, + "end_line": 211, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 5, + "top_nesting_level": 0 + }, + { + "name": "has_f_sources", + "long_name": "has_f_sources( sources )", + "filename": "misc_util.py", + "nloc": 5, + "complexity": 3, + "token_count": 21, + "parameters": [ + "sources" + ], + "start_line": 213, + "end_line": 218, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 6, + "top_nesting_level": 0 + }, + { + "name": "has_cxx_sources", + "long_name": "has_cxx_sources( sources )", + "filename": "misc_util.py", + "nloc": 5, + "complexity": 3, + "token_count": 21, + "parameters": [ + "sources" + ], + "start_line": 220, + "end_line": 225, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 6, + "top_nesting_level": 0 + }, + { + "name": "filter_sources", + "long_name": "filter_sources( sources )", + "filename": "misc_util.py", + "nloc": 17, + "complexity": 5, + "token_count": 84, + "parameters": [ + "sources" + ], + "start_line": 227, + "end_line": 247, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 21, + "top_nesting_level": 0 + }, + { + "name": "_get_headers", + "long_name": "_get_headers( directory_list )", + "filename": "misc_util.py", + "nloc": 6, + "complexity": 2, + "token_count": 39, + "parameters": [ + "directory_list" + ], + "start_line": 250, + "end_line": 256, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 7, + "top_nesting_level": 0 + }, + { + "name": "_get_directories", + "long_name": "_get_directories( list_of_sources )", + "filename": "misc_util.py", + "nloc": 7, + "complexity": 4, + "token_count": 51, + "parameters": [ + "list_of_sources" + ], + "start_line": 258, + "end_line": 265, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 8, + "top_nesting_level": 0 + }, + { + "name": "get_dependencies", + "long_name": "get_dependencies( sources )", + "filename": "misc_util.py", + "nloc": 2, + "complexity": 1, + "token_count": 13, + "parameters": [ + "sources" + ], + "start_line": 267, + "end_line": 269, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 0 + }, + { + "name": "is_local_src_dir", + "long_name": "is_local_src_dir( directory )", + "filename": "misc_util.py", + "nloc": 12, + "complexity": 6, + "token_count": 107, + "parameters": [ + "directory" + ], + "start_line": 271, + "end_line": 284, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 14, + "top_nesting_level": 0 + }, + { + "name": "general_source_files", + "long_name": "general_source_files( top_path )", + "filename": "misc_util.py", + "nloc": 9, + "complexity": 6, + "token_count": 92, + "parameters": [ + "top_path" + ], + "start_line": 286, + "end_line": 294, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 9, + "top_nesting_level": 0 + }, + { + "name": "get_ext_source_files", + "long_name": "get_ext_source_files( ext )", + "filename": "misc_util.py", + "nloc": 11, + "complexity": 4, + "token_count": 77, + "parameters": [ + "ext" + ], + "start_line": 296, + "end_line": 307, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 12, + "top_nesting_level": 0 + }, + { + "name": "get_script_files", + "long_name": "get_script_files( scripts )", + "filename": "misc_util.py", + "nloc": 3, + "complexity": 1, + "token_count": 15, + "parameters": [ + "scripts" + ], + "start_line": 309, + "end_line": 311, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 0 + }, + { + "name": "get_lib_source_files", + "long_name": "get_lib_source_files( lib )", + "filename": "misc_util.py", + "nloc": 13, + "complexity": 4, + "token_count": 101, + "parameters": [ + "lib" + ], + "start_line": 313, + "end_line": 325, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 13, + "top_nesting_level": 0 + }, + { + "name": "get_data_files", + "long_name": "get_data_files( data )", + "filename": "misc_util.py", + "nloc": 18, + "complexity": 7, + "token_count": 94, + "parameters": [ + "data" + ], + "start_line": 327, + "end_line": 344, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 18, + "top_nesting_level": 0 + }, + { + "name": "dot_join", + "long_name": "dot_join( * args )", + "filename": "misc_util.py", + "nloc": 2, + "complexity": 3, + "token_count": 21, + "parameters": [ + "args" + ], + "start_line": 346, + "end_line": 347, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 0 + }, + { + "name": "get_frame", + "long_name": "get_frame( level = 0 )", + "filename": "misc_util.py", + "nloc": 8, + "complexity": 3, + "token_count": 50, + "parameters": [ + "level" + ], + "start_line": 349, + "end_line": 356, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 8, + "top_nesting_level": 0 + }, + { + "name": "__init__", + "long_name": "__init__( self , package_name = None , parent_name = None , top_path = None , package_path = None , ** attrs )", + "filename": "misc_util.py", + "nloc": 61, + "complexity": 16, + "token_count": 458, + "parameters": [ + "self", + "package_name", + "parent_name", + "top_path", + "package_path", + "attrs" + ], + "start_line": 368, + "end_line": 450, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 83, + "top_nesting_level": 1 + }, + { + "name": "todict", + "long_name": "todict( self )", + "filename": "misc_util.py", + "nloc": 9, + "complexity": 4, + "token_count": 57, + "parameters": [ + "self" + ], + "start_line": 452, + "end_line": 463, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 12, + "top_nesting_level": 1 + }, + { + "name": "info", + "long_name": "info( self , message )", + "filename": "misc_util.py", + "nloc": 3, + "complexity": 2, + "token_count": 18, + "parameters": [ + "self", + "message" + ], + "start_line": 465, + "end_line": 467, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "warn", + "long_name": "warn( self , message )", + "filename": "misc_util.py", + "nloc": 2, + "complexity": 1, + "token_count": 17, + "parameters": [ + "self", + "message" + ], + "start_line": 469, + "end_line": 470, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 1 + }, + { + "name": "set_options", + "long_name": "set_options( self , ** options )", + "filename": "misc_util.py", + "nloc": 6, + "complexity": 3, + "token_count": 46, + "parameters": [ + "self", + "options" + ], + "start_line": 473, + "end_line": 486, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 14, + "top_nesting_level": 1 + }, + { + "name": "get_distribution", + "long_name": "get_distribution( self )", + "filename": "misc_util.py", + "nloc": 4, + "complexity": 1, + "token_count": 18, + "parameters": [ + "self" + ], + "start_line": 488, + "end_line": 491, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 1 + }, + { + "name": "_wildcard_get_subpackage", + "long_name": "_wildcard_get_subpackage( self , subpackage_name )", + "filename": "misc_util.py", + "nloc": 14, + "complexity": 4, + "token_count": 122, + "parameters": [ + "self", + "subpackage_name" + ], + "start_line": 493, + "end_line": 506, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 14, + "top_nesting_level": 1 + }, + { + "name": "_get_configuration_from_setup_py", + "long_name": "_get_configuration_from_setup_py( self , setup_py , subpackage_name , subpackage_path )", + "filename": "misc_util.py", + "nloc": 26, + "complexity": 5, + "token_count": 196, + "parameters": [ + "self", + "setup_py", + "subpackage_name", + "subpackage_path" + ], + "start_line": 508, + "end_line": 534, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 27, + "top_nesting_level": 1 + }, + { + "name": "get_subpackage", + "long_name": "get_subpackage( self , subpackage_name , subpackage_path = None )", + "filename": "misc_util.py", + "nloc": 34, + "complexity": 11, + "token_count": 232, + "parameters": [ + "self", + "subpackage_name", + "subpackage_path" + ], + "start_line": 536, + "end_line": 579, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 44, + "top_nesting_level": 1 + }, + { + "name": "add_subpackage", + "long_name": "add_subpackage( self , subpackage_name , subpackage_path = None )", + "filename": "misc_util.py", + "nloc": 17, + "complexity": 5, + "token_count": 103, + "parameters": [ + "self", + "subpackage_name", + "subpackage_path" + ], + "start_line": 581, + "end_line": 600, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 20, + "top_nesting_level": 1 + }, + { + "name": "add_data_dir", + "long_name": "add_data_dir( self , data_path )", + "filename": "misc_util.py", + "nloc": 25, + "complexity": 9, + "token_count": 185, + "parameters": [ + "self", + "data_path" + ], + "start_line": 602, + "end_line": 634, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 33, + "top_nesting_level": 1 + }, + { + "name": "add_data_files", + "long_name": "add_data_files( self , * files )", + "filename": "misc_util.py", + "nloc": 49, + "complexity": 17, + "token_count": 392, + "parameters": [ + "self", + "files" + ], + "start_line": 636, + "end_line": 696, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 61, + "top_nesting_level": 1 + }, + { + "name": "add_include_dirs", + "long_name": "add_include_dirs( self , * paths )", + "filename": "misc_util.py", + "nloc": 8, + "complexity": 2, + "token_count": 49, + "parameters": [ + "self", + "paths" + ], + "start_line": 700, + "end_line": 709, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 10, + "top_nesting_level": 1 + }, + { + "name": "add_headers", + "long_name": "add_headers( self , * files )", + "filename": "misc_util.py", + "nloc": 15, + "complexity": 8, + "token_count": 136, + "parameters": [ + "self", + "files" + ], + "start_line": 711, + "end_line": 731, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 21, + "top_nesting_level": 1 + }, + { + "name": "_fix_paths", + "long_name": "_fix_paths( self , paths , include_non_existing = True )", + "filename": "misc_util.py", + "nloc": 32, + "complexity": 12, + "token_count": 213, + "parameters": [ + "self", + "paths", + "include_non_existing" + ], + "start_line": 733, + "end_line": 764, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 32, + "top_nesting_level": 1 + }, + { + "name": "paths", + "long_name": "paths( self , * paths , ** kws )", + "filename": "misc_util.py", + "nloc": 4, + "complexity": 1, + "token_count": 33, + "parameters": [ + "self", + "paths", + "kws" + ], + "start_line": 766, + "end_line": 771, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 6, + "top_nesting_level": 1 + }, + { + "name": "_fix_paths_dict", + "long_name": "_fix_paths_dict( self , kw )", + "filename": "misc_util.py", + "nloc": 8, + "complexity": 3, + "token_count": 54, + "parameters": [ + "self", + "kw" + ], + "start_line": 773, + "end_line": 780, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 8, + "top_nesting_level": 1 + }, + { + "name": "add_extension", + "long_name": "add_extension( self , name , sources , ** kw )", + "filename": "misc_util.py", + "nloc": 43, + "complexity": 13, + "token_count": 337, + "parameters": [ + "self", + "name", + "sources", + "kw" + ], + "start_line": 782, + "end_line": 844, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 63, + "top_nesting_level": 1 + }, + { + "name": "add_library", + "long_name": "add_library( self , name , sources , ** build_info )", + "filename": "misc_util.py", + "nloc": 11, + "complexity": 2, + "token_count": 72, + "parameters": [ + "self", + "name", + "sources", + "build_info" + ], + "start_line": 846, + "end_line": 868, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 23, + "top_nesting_level": 1 + }, + { + "name": "add_scripts", + "long_name": "add_scripts( self , * files )", + "filename": "misc_util.py", + "nloc": 8, + "complexity": 2, + "token_count": 49, + "parameters": [ + "self", + "files" + ], + "start_line": 870, + "end_line": 879, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 10, + "top_nesting_level": 1 + }, + { + "name": "dict_append", + "long_name": "dict_append( self , ** dict )", + "filename": "misc_util.py", + "nloc": 16, + "complexity": 7, + "token_count": 150, + "parameters": [ + "self", + "dict" + ], + "start_line": 881, + "end_line": 896, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 16, + "top_nesting_level": 1 + }, + { + "name": "__str__", + "long_name": "__str__( self )", + "filename": "misc_util.py", + "nloc": 10, + "complexity": 3, + "token_count": 72, + "parameters": [ + "self" + ], + "start_line": 898, + "end_line": 907, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 10, + "top_nesting_level": 1 + }, + { + "name": "get_config_cmd", + "long_name": "get_config_cmd( self )", + "filename": "misc_util.py", + "nloc": 10, + "complexity": 2, + "token_count": 63, + "parameters": [ + "self" + ], + "start_line": 909, + "end_line": 918, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 10, + "top_nesting_level": 1 + }, + { + "name": "get_build_temp_dir", + "long_name": "get_build_temp_dir( self )", + "filename": "misc_util.py", + "nloc": 4, + "complexity": 1, + "token_count": 20, + "parameters": [ + "self" + ], + "start_line": 920, + "end_line": 923, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 1 + }, + { + "name": "have_f77c", + "long_name": "have_f77c( self )", + "filename": "misc_util.py", + "nloc": 8, + "complexity": 1, + "token_count": 30, + "parameters": [ + "self" + ], + "start_line": 925, + "end_line": 936, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 12, + "top_nesting_level": 1 + }, + { + "name": "have_f90c", + "long_name": "have_f90c( self )", + "filename": "misc_util.py", + "nloc": 8, + "complexity": 1, + "token_count": 30, + "parameters": [ + "self" + ], + "start_line": 938, + "end_line": 949, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 12, + "top_nesting_level": 1 + }, + { + "name": "append_to", + "long_name": "append_to( self , extlib )", + "filename": "misc_util.py", + "nloc": 12, + "complexity": 2, + "token_count": 78, + "parameters": [ + "self", + "extlib" + ], + "start_line": 951, + "end_line": 964, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 14, + "top_nesting_level": 1 + }, + { + "name": "_get_svn_revision", + "long_name": "_get_svn_revision( self , path )", + "filename": "misc_util.py", + "nloc": 10, + "complexity": 3, + "token_count": 73, + "parameters": [ + "self", + "path" + ], + "start_line": 966, + "end_line": 977, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 12, + "top_nesting_level": 1 + }, + { + "name": "get_version", + "long_name": "get_version( self )", + "filename": "misc_util.py", + "nloc": 38, + "complexity": 11, + "token_count": 260, + "parameters": [ + "self" + ], + "start_line": 979, + "end_line": 1025, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 47, + "top_nesting_level": 1 + }, + { + "name": "make_svn_version_py.make_svn_version_py.generate_svn_version_py.rm_file", + "long_name": "make_svn_version_py.make_svn_version_py.generate_svn_version_py.rm_file( f = target , p = self . info )", + "filename": "misc_util.py", + "nloc": 5, + "complexity": 3, + "token_count": 55, + "parameters": [ + "f", + "p" + ], + "start_line": 1048, + "end_line": 1052, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 5, + "top_nesting_level": 3 + }, + { + "name": "make_svn_version_py.generate_svn_version_py", + "long_name": "make_svn_version_py.generate_svn_version_py( )", + "filename": "misc_util.py", + "nloc": 13, + "complexity": 2, + "token_count": 85, + "parameters": [], + "start_line": 1037, + "end_line": 1055, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 19, + "top_nesting_level": 2 + }, + { + "name": "make_svn_version_py", + "long_name": "make_svn_version_py( self )", + "filename": "misc_util.py", + "nloc": 6, + "complexity": 2, + "token_count": 43, + "parameters": [ + "self" + ], + "start_line": 1027, + "end_line": 1057, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 31, + "top_nesting_level": 1 + }, + { + "name": "make_config_py", + "long_name": "make_config_py( self , name = '__config__' )", + "filename": "misc_util.py", + "nloc": 3, + "complexity": 1, + "token_count": 27, + "parameters": [ + "self", + "name" + ], + "start_line": 1059, + "end_line": 1064, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 6, + "top_nesting_level": 1 + }, + { + "name": "get_info", + "long_name": "get_info( self , * names )", + "filename": "misc_util.py", + "nloc": 6, + "complexity": 2, + "token_count": 36, + "parameters": [ + "self", + "names" + ], + "start_line": 1066, + "end_line": 1073, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 8, + "top_nesting_level": 1 + }, + { + "name": "_do_nothing", + "long_name": "_do_nothing( self , * args , ** kw )", + "filename": "misc_util.py", + "nloc": 2, + "complexity": 1, + "token_count": 12, + "parameters": [ + "self", + "args", + "kw" + ], + "start_line": 1079, + "end_line": 1080, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 1 + }, + { + "name": "get_info", + "long_name": "get_info( self , * args , ** kw )", + "filename": "misc_util.py", + "nloc": 2, + "complexity": 1, + "token_count": 14, + "parameters": [ + "self", + "args", + "kw" + ], + "start_line": 1091, + "end_line": 1092, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 1 + }, + { + "name": "have_f77c", + "long_name": "have_f77c( self , * args , ** kw )", + "filename": "misc_util.py", + "nloc": 2, + "complexity": 1, + "token_count": 13, + "parameters": [ + "self", + "args", + "kw" + ], + "start_line": 1093, + "end_line": 1094, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 1 + }, + { + "name": "have_f90c", + "long_name": "have_f90c( self , * args , ** kw )", + "filename": "misc_util.py", + "nloc": 2, + "complexity": 1, + "token_count": 13, + "parameters": [ + "self", + "args", + "kw" + ], + "start_line": 1095, + "end_line": 1096, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 1 + }, + { + "name": "command_line_ok", + "long_name": "command_line_ok( _cache = [ ] )", + "filename": "misc_util.py", + "nloc": 15, + "complexity": 9, + "token_count": 98, + "parameters": [ + "_cache" + ], + "start_line": 1098, + "end_line": 1115, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 18, + "top_nesting_level": 0 + }, + { + "name": "get_cmd", + "long_name": "get_cmd( cmdname , _cache = { } )", + "filename": "misc_util.py", + "nloc": 11, + "complexity": 3, + "token_count": 65, + "parameters": [ + "cmdname", + "_cache" + ], + "start_line": 1120, + "end_line": 1130, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 11, + "top_nesting_level": 0 + }, + { + "name": "get_numpy_include_dirs", + "long_name": "get_numpy_include_dirs( )", + "filename": "misc_util.py", + "nloc": 11, + "complexity": 3, + "token_count": 77, + "parameters": [], + "start_line": 1132, + "end_line": 1146, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 15, + "top_nesting_level": 0 + }, + { + "name": "default_config_dict", + "long_name": "default_config_dict( name = None , parent_name = None , local_path = None )", + "filename": "misc_util.py", + "nloc": 9, + "complexity": 1, + "token_count": 57, + "parameters": [ + "name", + "parent_name", + "local_path" + ], + "start_line": 1150, + "end_line": 1161, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 12, + "top_nesting_level": 0 + }, + { + "name": "dict_append", + "long_name": "dict_append( d , ** kws )", + "filename": "misc_util.py", + "nloc": 6, + "complexity": 3, + "token_count": 44, + "parameters": [ + "d", + "kws" + ], + "start_line": 1164, + "end_line": 1169, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 6, + "top_nesting_level": 0 + }, + { + "name": "appendpath", + "long_name": "appendpath( prefix , path )", + "filename": "misc_util.py", + "nloc": 19, + "complexity": 6, + "token_count": 230, + "parameters": [ + "prefix", + "path" + ], + "start_line": 1171, + "end_line": 1190, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 20, + "top_nesting_level": 0 + }, + { + "name": "generate_config_py", + "long_name": "generate_config_py( target )", + "filename": "misc_util.py", + "nloc": 27, + "complexity": 2, + "token_count": 117, + "parameters": [ + "target" + ], + "start_line": 1192, + "end_line": 1225, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 34, + "top_nesting_level": 0 + } + ], + "methods_before": [ + { + "name": "allpath", + "long_name": "allpath( name )", + "filename": "misc_util.py", + "nloc": 4, + "complexity": 1, + "token_count": 24, + "parameters": [ + "name" + ], + "start_line": 19, + "end_line": 22, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 0 + }, + { + "name": "get_path", + "long_name": "get_path( mod_name , parent_path = None )", + "filename": "misc_util.py", + "nloc": 16, + "complexity": 6, + "token_count": 139, + "parameters": [ + "mod_name", + "parent_path" + ], + "start_line": 24, + "end_line": 49, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 26, + "top_nesting_level": 0 + }, + { + "name": "njoin", + "long_name": "njoin( * path )", + "filename": "misc_util.py", + "nloc": 10, + "complexity": 5, + "token_count": 85, + "parameters": [ + "path" + ], + "start_line": 51, + "end_line": 70, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 20, + "top_nesting_level": 0 + }, + { + "name": "minrelpath", + "long_name": "minrelpath( path )", + "filename": "misc_util.py", + "nloc": 20, + "complexity": 7, + "token_count": 101, + "parameters": [ + "path" + ], + "start_line": 72, + "end_line": 93, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 22, + "top_nesting_level": 0 + }, + { + "name": "terminal_has_colors", + "long_name": "terminal_has_colors( )", + "filename": "misc_util.py", + "nloc": 18, + "complexity": 13, + "token_count": 137, + "parameters": [], + "start_line": 97, + "end_line": 122, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 26, + "top_nesting_level": 0 + }, + { + "name": "cyg2win32", + "long_name": "cyg2win32( path )", + "filename": "misc_util.py", + "nloc": 4, + "complexity": 3, + "token_count": 42, + "parameters": [ + "path" + ], + "start_line": 139, + "end_line": 142, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 0 + }, + { + "name": "_get_f90_modules", + "long_name": "_get_f90_modules( source )", + "filename": "misc_util.py", + "nloc": 13, + "complexity": 4, + "token_count": 77, + "parameters": [ + "source" + ], + "start_line": 151, + "end_line": 167, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 17, + "top_nesting_level": 0 + }, + { + "name": "is_string", + "long_name": "is_string( s )", + "filename": "misc_util.py", + "nloc": 2, + "complexity": 1, + "token_count": 12, + "parameters": [ + "s" + ], + "start_line": 169, + "end_line": 170, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 0 + }, + { + "name": "all_strings", + "long_name": "all_strings( lst )", + "filename": "misc_util.py", + "nloc": 5, + "complexity": 3, + "token_count": 22, + "parameters": [ + "lst" + ], + "start_line": 172, + "end_line": 177, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 6, + "top_nesting_level": 0 + }, + { + "name": "is_sequence", + "long_name": "is_sequence( seq )", + "filename": "misc_util.py", + "nloc": 8, + "complexity": 3, + "token_count": 25, + "parameters": [ + "seq" + ], + "start_line": 179, + "end_line": 186, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 8, + "top_nesting_level": 0 + }, + { + "name": "as_list", + "long_name": "as_list( seq )", + "filename": "misc_util.py", + "nloc": 5, + "complexity": 2, + "token_count": 22, + "parameters": [ + "seq" + ], + "start_line": 188, + "end_line": 192, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 5, + "top_nesting_level": 0 + }, + { + "name": "has_f_sources", + "long_name": "has_f_sources( sources )", + "filename": "misc_util.py", + "nloc": 5, + "complexity": 3, + "token_count": 21, + "parameters": [ + "sources" + ], + "start_line": 194, + "end_line": 199, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 6, + "top_nesting_level": 0 + }, + { + "name": "has_cxx_sources", + "long_name": "has_cxx_sources( sources )", + "filename": "misc_util.py", + "nloc": 5, + "complexity": 3, + "token_count": 21, + "parameters": [ + "sources" + ], + "start_line": 201, + "end_line": 206, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 6, + "top_nesting_level": 0 + }, + { + "name": "filter_sources", + "long_name": "filter_sources( sources )", + "filename": "misc_util.py", + "nloc": 17, + "complexity": 5, + "token_count": 84, + "parameters": [ + "sources" + ], + "start_line": 208, + "end_line": 228, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 21, + "top_nesting_level": 0 + }, + { + "name": "_get_headers", + "long_name": "_get_headers( directory_list )", + "filename": "misc_util.py", + "nloc": 6, + "complexity": 2, + "token_count": 39, + "parameters": [ + "directory_list" + ], + "start_line": 231, + "end_line": 237, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 7, + "top_nesting_level": 0 + }, + { + "name": "_get_directories", + "long_name": "_get_directories( list_of_sources )", + "filename": "misc_util.py", + "nloc": 7, + "complexity": 4, + "token_count": 51, + "parameters": [ + "list_of_sources" + ], + "start_line": 239, + "end_line": 246, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 8, + "top_nesting_level": 0 + }, + { + "name": "get_dependencies", + "long_name": "get_dependencies( sources )", + "filename": "misc_util.py", + "nloc": 2, + "complexity": 1, + "token_count": 13, + "parameters": [ + "sources" + ], + "start_line": 248, + "end_line": 250, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 0 + }, + { + "name": "is_local_src_dir", + "long_name": "is_local_src_dir( directory )", + "filename": "misc_util.py", + "nloc": 12, + "complexity": 6, + "token_count": 107, + "parameters": [ + "directory" + ], + "start_line": 252, + "end_line": 265, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 14, + "top_nesting_level": 0 + }, + { + "name": "general_source_files", + "long_name": "general_source_files( top_path )", + "filename": "misc_util.py", + "nloc": 9, + "complexity": 6, + "token_count": 92, + "parameters": [ + "top_path" + ], + "start_line": 267, + "end_line": 275, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 9, + "top_nesting_level": 0 + }, + { + "name": "get_ext_source_files", + "long_name": "get_ext_source_files( ext )", + "filename": "misc_util.py", + "nloc": 11, + "complexity": 4, + "token_count": 77, + "parameters": [ + "ext" + ], + "start_line": 277, + "end_line": 288, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 12, + "top_nesting_level": 0 + }, + { + "name": "get_script_files", + "long_name": "get_script_files( scripts )", + "filename": "misc_util.py", + "nloc": 3, + "complexity": 1, + "token_count": 15, + "parameters": [ + "scripts" + ], + "start_line": 290, + "end_line": 292, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 0 + }, + { + "name": "get_lib_source_files", + "long_name": "get_lib_source_files( lib )", + "filename": "misc_util.py", + "nloc": 13, + "complexity": 4, + "token_count": 101, + "parameters": [ + "lib" + ], + "start_line": 294, + "end_line": 306, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 13, + "top_nesting_level": 0 + }, + { + "name": "get_data_files", + "long_name": "get_data_files( data )", + "filename": "misc_util.py", + "nloc": 18, + "complexity": 7, + "token_count": 94, + "parameters": [ + "data" + ], + "start_line": 308, + "end_line": 325, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 18, + "top_nesting_level": 0 + }, + { + "name": "dot_join", + "long_name": "dot_join( * args )", + "filename": "misc_util.py", + "nloc": 2, + "complexity": 3, + "token_count": 21, + "parameters": [ + "args" + ], + "start_line": 327, + "end_line": 328, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 0 + }, + { + "name": "get_frame", + "long_name": "get_frame( level = 0 )", + "filename": "misc_util.py", + "nloc": 8, + "complexity": 3, + "token_count": 50, + "parameters": [ + "level" + ], + "start_line": 330, + "end_line": 337, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 8, + "top_nesting_level": 0 + }, + { + "name": "__init__", + "long_name": "__init__( self , package_name = None , parent_name = None , top_path = None , package_path = None , ** attrs )", + "filename": "misc_util.py", + "nloc": 61, + "complexity": 16, + "token_count": 458, + "parameters": [ + "self", + "package_name", + "parent_name", + "top_path", + "package_path", + "attrs" + ], + "start_line": 349, + "end_line": 431, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 83, + "top_nesting_level": 1 + }, + { + "name": "todict", + "long_name": "todict( self )", + "filename": "misc_util.py", + "nloc": 9, + "complexity": 4, + "token_count": 57, + "parameters": [ + "self" + ], + "start_line": 433, + "end_line": 444, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 12, + "top_nesting_level": 1 + }, + { + "name": "info", + "long_name": "info( self , message )", + "filename": "misc_util.py", + "nloc": 3, + "complexity": 2, + "token_count": 18, + "parameters": [ + "self", + "message" + ], + "start_line": 446, + "end_line": 448, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "warn", + "long_name": "warn( self , message )", + "filename": "misc_util.py", + "nloc": 2, + "complexity": 1, + "token_count": 17, + "parameters": [ + "self", + "message" + ], + "start_line": 450, + "end_line": 451, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 1 + }, + { + "name": "set_options", + "long_name": "set_options( self , ** options )", + "filename": "misc_util.py", + "nloc": 6, + "complexity": 3, + "token_count": 46, + "parameters": [ + "self", + "options" + ], + "start_line": 454, + "end_line": 467, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 14, + "top_nesting_level": 1 + }, + { + "name": "get_distribution", + "long_name": "get_distribution( self )", + "filename": "misc_util.py", + "nloc": 4, + "complexity": 1, + "token_count": 18, + "parameters": [ + "self" + ], + "start_line": 469, + "end_line": 472, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 1 + }, + { + "name": "_wildcard_get_subpackage", + "long_name": "_wildcard_get_subpackage( self , subpackage_name )", + "filename": "misc_util.py", + "nloc": 14, + "complexity": 4, + "token_count": 122, + "parameters": [ + "self", + "subpackage_name" + ], + "start_line": 474, + "end_line": 487, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 14, + "top_nesting_level": 1 + }, + { + "name": "_get_configuration_from_setup_py", + "long_name": "_get_configuration_from_setup_py( self , setup_py , subpackage_name , subpackage_path )", + "filename": "misc_util.py", + "nloc": 26, + "complexity": 5, + "token_count": 196, + "parameters": [ + "self", + "setup_py", + "subpackage_name", + "subpackage_path" + ], + "start_line": 489, + "end_line": 515, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 27, + "top_nesting_level": 1 + }, + { + "name": "get_subpackage", + "long_name": "get_subpackage( self , subpackage_name , subpackage_path = None )", + "filename": "misc_util.py", + "nloc": 34, + "complexity": 11, + "token_count": 232, + "parameters": [ + "self", + "subpackage_name", + "subpackage_path" + ], + "start_line": 517, + "end_line": 560, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 44, + "top_nesting_level": 1 + }, + { + "name": "add_subpackage", + "long_name": "add_subpackage( self , subpackage_name , subpackage_path = None )", + "filename": "misc_util.py", + "nloc": 17, + "complexity": 5, + "token_count": 103, + "parameters": [ + "self", + "subpackage_name", + "subpackage_path" + ], + "start_line": 562, + "end_line": 581, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 20, + "top_nesting_level": 1 + }, + { + "name": "add_data_dir", + "long_name": "add_data_dir( self , data_path )", + "filename": "misc_util.py", + "nloc": 25, + "complexity": 9, + "token_count": 185, + "parameters": [ + "self", + "data_path" + ], + "start_line": 583, + "end_line": 615, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 33, + "top_nesting_level": 1 + }, + { + "name": "add_data_files", + "long_name": "add_data_files( self , * files )", + "filename": "misc_util.py", + "nloc": 49, + "complexity": 17, + "token_count": 392, + "parameters": [ + "self", + "files" + ], + "start_line": 617, + "end_line": 677, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 61, + "top_nesting_level": 1 + }, + { + "name": "add_include_dirs", + "long_name": "add_include_dirs( self , * paths )", + "filename": "misc_util.py", + "nloc": 8, + "complexity": 2, + "token_count": 49, + "parameters": [ + "self", + "paths" + ], + "start_line": 681, + "end_line": 690, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 10, + "top_nesting_level": 1 + }, + { + "name": "add_headers", + "long_name": "add_headers( self , * files )", + "filename": "misc_util.py", + "nloc": 15, + "complexity": 8, + "token_count": 136, + "parameters": [ + "self", + "files" + ], + "start_line": 692, + "end_line": 712, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 21, + "top_nesting_level": 1 + }, + { + "name": "_fix_paths", + "long_name": "_fix_paths( self , paths , include_non_existing = True )", + "filename": "misc_util.py", + "nloc": 32, + "complexity": 12, + "token_count": 213, + "parameters": [ + "self", + "paths", + "include_non_existing" + ], + "start_line": 714, + "end_line": 745, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 32, + "top_nesting_level": 1 + }, + { + "name": "paths", + "long_name": "paths( self , * paths , ** kws )", + "filename": "misc_util.py", + "nloc": 4, + "complexity": 1, + "token_count": 33, + "parameters": [ + "self", + "paths", + "kws" + ], + "start_line": 747, + "end_line": 752, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 6, + "top_nesting_level": 1 + }, + { + "name": "_fix_paths_dict", + "long_name": "_fix_paths_dict( self , kw )", + "filename": "misc_util.py", + "nloc": 8, + "complexity": 3, + "token_count": 54, + "parameters": [ + "self", + "kw" + ], + "start_line": 754, + "end_line": 761, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 8, + "top_nesting_level": 1 + }, + { + "name": "add_extension", + "long_name": "add_extension( self , name , sources , ** kw )", + "filename": "misc_util.py", + "nloc": 43, + "complexity": 13, + "token_count": 337, + "parameters": [ + "self", + "name", + "sources", + "kw" + ], + "start_line": 763, + "end_line": 825, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 63, + "top_nesting_level": 1 + }, + { + "name": "add_library", + "long_name": "add_library( self , name , sources , ** build_info )", + "filename": "misc_util.py", + "nloc": 11, + "complexity": 2, + "token_count": 72, + "parameters": [ + "self", + "name", + "sources", + "build_info" + ], + "start_line": 827, + "end_line": 849, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 23, + "top_nesting_level": 1 + }, + { + "name": "add_scripts", + "long_name": "add_scripts( self , * files )", + "filename": "misc_util.py", + "nloc": 8, + "complexity": 2, + "token_count": 49, + "parameters": [ + "self", + "files" + ], + "start_line": 851, + "end_line": 860, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 10, + "top_nesting_level": 1 + }, + { + "name": "dict_append", + "long_name": "dict_append( self , ** dict )", + "filename": "misc_util.py", + "nloc": 16, + "complexity": 7, + "token_count": 150, + "parameters": [ + "self", + "dict" + ], + "start_line": 862, + "end_line": 877, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 16, + "top_nesting_level": 1 + }, + { + "name": "__str__", + "long_name": "__str__( self )", + "filename": "misc_util.py", + "nloc": 10, + "complexity": 3, + "token_count": 72, + "parameters": [ + "self" + ], + "start_line": 879, + "end_line": 888, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 10, + "top_nesting_level": 1 + }, + { + "name": "get_config_cmd", + "long_name": "get_config_cmd( self )", + "filename": "misc_util.py", + "nloc": 10, + "complexity": 2, + "token_count": 63, + "parameters": [ + "self" + ], + "start_line": 890, + "end_line": 899, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 10, + "top_nesting_level": 1 + }, + { + "name": "get_build_temp_dir", + "long_name": "get_build_temp_dir( self )", + "filename": "misc_util.py", + "nloc": 4, + "complexity": 1, + "token_count": 20, + "parameters": [ + "self" + ], + "start_line": 901, + "end_line": 904, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 1 + }, + { + "name": "have_f77c", + "long_name": "have_f77c( self )", + "filename": "misc_util.py", + "nloc": 8, + "complexity": 1, + "token_count": 30, + "parameters": [ + "self" + ], + "start_line": 906, + "end_line": 917, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 12, + "top_nesting_level": 1 + }, + { + "name": "have_f90c", + "long_name": "have_f90c( self )", + "filename": "misc_util.py", + "nloc": 8, + "complexity": 1, + "token_count": 30, + "parameters": [ + "self" + ], + "start_line": 919, + "end_line": 930, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 12, + "top_nesting_level": 1 + }, + { + "name": "append_to", + "long_name": "append_to( self , extlib )", + "filename": "misc_util.py", + "nloc": 12, + "complexity": 2, + "token_count": 78, + "parameters": [ + "self", + "extlib" + ], + "start_line": 932, + "end_line": 945, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 14, + "top_nesting_level": 1 + }, + { + "name": "_get_svn_revision", + "long_name": "_get_svn_revision( self , path )", + "filename": "misc_util.py", + "nloc": 10, + "complexity": 3, + "token_count": 73, + "parameters": [ + "self", + "path" + ], + "start_line": 947, + "end_line": 958, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 12, + "top_nesting_level": 1 + }, + { + "name": "get_version", + "long_name": "get_version( self )", + "filename": "misc_util.py", + "nloc": 38, + "complexity": 11, + "token_count": 260, + "parameters": [ + "self" + ], + "start_line": 960, + "end_line": 1006, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 47, + "top_nesting_level": 1 + }, + { + "name": "make_svn_version_py.make_svn_version_py.generate_svn_version_py.rm_file", + "long_name": "make_svn_version_py.make_svn_version_py.generate_svn_version_py.rm_file( f = target , p = self . info )", + "filename": "misc_util.py", + "nloc": 5, + "complexity": 3, + "token_count": 55, + "parameters": [ + "f", + "p" + ], + "start_line": 1029, + "end_line": 1033, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 5, + "top_nesting_level": 3 + }, + { + "name": "make_svn_version_py.generate_svn_version_py", + "long_name": "make_svn_version_py.generate_svn_version_py( )", + "filename": "misc_util.py", + "nloc": 13, + "complexity": 2, + "token_count": 85, + "parameters": [], + "start_line": 1018, + "end_line": 1036, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 19, + "top_nesting_level": 2 + }, + { + "name": "make_svn_version_py", + "long_name": "make_svn_version_py( self )", + "filename": "misc_util.py", + "nloc": 6, + "complexity": 2, + "token_count": 43, + "parameters": [ + "self" + ], + "start_line": 1008, + "end_line": 1038, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 31, + "top_nesting_level": 1 + }, + { + "name": "make_config_py", + "long_name": "make_config_py( self , name = '__config__' )", + "filename": "misc_util.py", + "nloc": 3, + "complexity": 1, + "token_count": 27, + "parameters": [ + "self", + "name" + ], + "start_line": 1040, + "end_line": 1045, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 6, + "top_nesting_level": 1 + }, + { + "name": "get_info", + "long_name": "get_info( self , * names )", + "filename": "misc_util.py", + "nloc": 6, + "complexity": 2, + "token_count": 36, + "parameters": [ + "self", + "names" + ], + "start_line": 1047, + "end_line": 1054, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 8, + "top_nesting_level": 1 + }, + { + "name": "_do_nothing", + "long_name": "_do_nothing( self , * args , ** kw )", + "filename": "misc_util.py", + "nloc": 2, + "complexity": 1, + "token_count": 12, + "parameters": [ + "self", + "args", + "kw" + ], + "start_line": 1060, + "end_line": 1061, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 1 + }, + { + "name": "get_info", + "long_name": "get_info( self , * args , ** kw )", + "filename": "misc_util.py", + "nloc": 2, + "complexity": 1, + "token_count": 14, + "parameters": [ + "self", + "args", + "kw" + ], + "start_line": 1072, + "end_line": 1073, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 1 + }, + { + "name": "have_f77c", + "long_name": "have_f77c( self , * args , ** kw )", + "filename": "misc_util.py", + "nloc": 2, + "complexity": 1, + "token_count": 13, + "parameters": [ + "self", + "args", + "kw" + ], + "start_line": 1074, + "end_line": 1075, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 1 + }, + { + "name": "have_f90c", + "long_name": "have_f90c( self , * args , ** kw )", + "filename": "misc_util.py", + "nloc": 2, + "complexity": 1, + "token_count": 13, + "parameters": [ + "self", + "args", + "kw" + ], + "start_line": 1076, + "end_line": 1077, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 1 + }, + { + "name": "command_line_ok", + "long_name": "command_line_ok( _cache = [ ] )", + "filename": "misc_util.py", + "nloc": 15, + "complexity": 9, + "token_count": 98, + "parameters": [ + "_cache" + ], + "start_line": 1079, + "end_line": 1096, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 18, + "top_nesting_level": 0 + }, + { + "name": "get_cmd", + "long_name": "get_cmd( cmdname , _cache = { } )", + "filename": "misc_util.py", + "nloc": 11, + "complexity": 3, + "token_count": 65, + "parameters": [ + "cmdname", + "_cache" + ], + "start_line": 1101, + "end_line": 1111, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 11, + "top_nesting_level": 0 + }, + { + "name": "get_numpy_include_dirs", + "long_name": "get_numpy_include_dirs( )", + "filename": "misc_util.py", + "nloc": 11, + "complexity": 3, + "token_count": 77, + "parameters": [], + "start_line": 1113, + "end_line": 1127, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 15, + "top_nesting_level": 0 + }, + { + "name": "default_config_dict", + "long_name": "default_config_dict( name = None , parent_name = None , local_path = None )", + "filename": "misc_util.py", + "nloc": 9, + "complexity": 1, + "token_count": 57, + "parameters": [ + "name", + "parent_name", + "local_path" + ], + "start_line": 1131, + "end_line": 1142, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 12, + "top_nesting_level": 0 + }, + { + "name": "dict_append", + "long_name": "dict_append( d , ** kws )", + "filename": "misc_util.py", + "nloc": 6, + "complexity": 3, + "token_count": 44, + "parameters": [ + "d", + "kws" + ], + "start_line": 1145, + "end_line": 1150, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 6, + "top_nesting_level": 0 + }, + { + "name": "appendpath", + "long_name": "appendpath( prefix , path )", + "filename": "misc_util.py", + "nloc": 19, + "complexity": 6, + "token_count": 230, + "parameters": [ + "prefix", + "path" + ], + "start_line": 1152, + "end_line": 1171, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 20, + "top_nesting_level": 0 + }, + { + "name": "generate_config_py", + "long_name": "generate_config_py( target )", + "filename": "misc_util.py", + "nloc": 27, + "complexity": 2, + "token_count": 117, + "parameters": [ + "target" + ], + "start_line": 1173, + "end_line": 1206, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 34, + "top_nesting_level": 0 + } + ], + "changed_methods": [ + { + "name": "minrelpath", + "long_name": "minrelpath( path )", + "filename": "misc_util.py", + "nloc": 22, + "complexity": 8, + "token_count": 118, + "parameters": [ + "path" + ], + "start_line": 89, + "end_line": 112, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 24, + "top_nesting_level": 0 + }, + { + "name": "get_mathlibs", + "long_name": "get_mathlibs( path = None )", + "filename": "misc_util.py", + "nloc": 14, + "complexity": 5, + "token_count": 98, + "parameters": [ + "path" + ], + "start_line": 72, + "end_line": 87, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 16, + "top_nesting_level": 0 + } + ], + "nloc": 923, + "complexity": 299, + "token_count": 6518, + "diff_parsed": { + "added": [ + " 'get_cmd', 'allpath', 'get_mathlibs',", + "def get_mathlibs(path=None):", + " \"\"\" Return the MATHLIB line from config.h", + " \"\"\"", + " if path is None:", + " path = get_numpy_include_dirs()[0]", + " config_file = os.path.join(path,'config.h')", + " fid = open(config_file)", + " mathlibs = []", + " s = '#define MATHLIB'", + " for line in fid.readlines():", + " if line.startswith(s):", + " value = line[len(s):].strip()", + " if value:", + " mathlibs.extend(value.split(','))", + " fid.close()", + " return mathlibs", + "", + " if os.sep != '/':", + " path.replace('/',os.sep)" + ], + "deleted": [ + " 'get_cmd', 'allpath'," + ] + } + }, + { + "old_path": "numpy/distutils/system_info.py", + "new_path": "numpy/distutils/system_info.py", + "filename": "system_info.py", + "extension": "py", + "change_type": "MODIFY", + "diff": "@@ -110,11 +110,13 @@\n import ConfigParser\n from exec_command import find_executable, exec_command, get_pythonexe\n from numpy.distutils.misc_util import is_sequence, is_string\n+import distutils.sysconfig\n \n from distutils.sysconfig import get_config_vars\n \n if sys.platform == 'win32':\n- default_lib_dirs = ['C:\\\\'] # probably not very helpful...\n+ default_lib_dirs = ['C:\\\\',\n+ join(distutils.sysconfig.EXEC_PREFIX, 'libs')]\n default_include_dirs = []\n default_src_dirs = ['.']\n default_x11_lib_dirs = []\n", + "added_lines": 3, + "deleted_lines": 1, + "source_code": "#!/usr/bin/env python\n\"\"\"\nThis file defines a set of system_info classes for getting\ninformation about various resources (libraries, library directories,\ninclude directories, etc.) in the system. Currently, the following\nclasses are available:\n\n atlas_info\n atlas_threads_info\n atlas_blas_info\n atlas_blas_threads_info\n lapack_atlas_info\n blas_info\n lapack_info\n blas_opt_info # usage recommended\n lapack_opt_info # usage recommended\n fftw_info,dfftw_info,sfftw_info\n fftw_threads_info,dfftw_threads_info,sfftw_threads_info\n djbfft_info\n x11_info\n lapack_src_info\n blas_src_info\n numpy_info\n numarray_info\n numpy_info\n boost_python_info\n agg2_info\n wx_info\n gdk_pixbuf_xlib_2_info\n gdk_pixbuf_2_info\n gdk_x11_2_info\n gtkp_x11_2_info\n gtkp_2_info\n xft_info\n freetype2_info\n\nUsage:\n info_dict = get_info()\n where is a string 'atlas','x11','fftw','lapack','blas',\n 'lapack_src', 'blas_src', etc. For a complete list of allowed names,\n see the definition of get_info() function below.\n\n Returned info_dict is a dictionary which is compatible with\n distutils.setup keyword arguments. If info_dict == {}, then the\n asked resource is not available (system_info could not find it).\n\n Several *_info classes specify an environment variable to specify\n the locations of software. When setting the corresponding environment\n variable to 'None' then the software will be ignored, even when it\n is available in system.\n\nGlobal parameters:\n system_info.search_static_first - search static libraries (.a)\n in precedence to shared ones (.so, .sl) if enabled.\n system_info.verbosity - output the results to stdout if enabled.\n\nThe file 'site.cfg' in the same directory as this module is read\nfor configuration options. The format is that used by ConfigParser (i.e.,\nWindows .INI style). The section DEFAULT has options that are the default\nfor each section. The available sections are fftw, atlas, and x11. Appropiate\ndefaults are used if nothing is specified.\n\nThe order of finding the locations of resources is the following:\n 1. environment variable\n 2. section in site.cfg\n 3. DEFAULT section in site.cfg\nOnly the first complete match is returned.\n\nExample:\n----------\n[DEFAULT]\nlibrary_dirs = /usr/lib:/usr/local/lib:/opt/lib\ninclude_dirs = /usr/include:/usr/local/include:/opt/include\nsrc_dirs = /usr/local/src:/opt/src\n# search static libraries (.a) in preference to shared ones (.so)\nsearch_static_first = 0\n\n[fftw]\nfftw_libs = rfftw, fftw\nfftw_opt_libs = rfftw_threaded, fftw_threaded\n# if the above aren't found, look for {s,d}fftw_libs and {s,d}fftw_opt_libs\n\n[atlas]\nlibrary_dirs = /usr/lib/3dnow:/usr/lib/3dnow/atlas\n# for overriding the names of the atlas libraries\natlas_libs = lapack, f77blas, cblas, atlas\n\n[x11]\nlibrary_dirs = /usr/X11R6/lib\ninclude_dirs = /usr/X11R6/include\n----------\n\nAuthors:\n Pearu Peterson , February 2002\n David M. Cooke , April 2002\n\nCopyright 2002 Pearu Peterson all rights reserved,\nPearu Peterson \nPermission to use, modify, and distribute this software is given under the\nterms of the SciPy (BSD style) license. See LICENSE.txt that came with\nthis distribution for specifics.\n\nNO WARRANTY IS EXPRESSED OR IMPLIED. USE AT YOUR OWN RISK.\n\"\"\"\n\nimport sys,os,re\nimport warnings\nfrom distutils.errors import DistutilsError\nfrom glob import glob\nimport ConfigParser\nfrom exec_command import find_executable, exec_command, get_pythonexe\nfrom numpy.distutils.misc_util import is_sequence, is_string\nimport distutils.sysconfig\n\nfrom distutils.sysconfig import get_config_vars\n\nif sys.platform == 'win32':\n default_lib_dirs = ['C:\\\\',\n join(distutils.sysconfig.EXEC_PREFIX, 'libs')]\n default_include_dirs = []\n default_src_dirs = ['.']\n default_x11_lib_dirs = []\n default_x11_include_dirs = []\nelse:\n default_lib_dirs = ['/usr/local/lib', '/opt/lib', '/usr/lib',\n '/opt/local/lib', '/sw/lib']\n default_include_dirs = ['/usr/local/include',\n '/opt/include', '/usr/include',\n '/opt/local/include', '/sw/include']\n default_src_dirs = ['.','/usr/local/src', '/opt/src','/sw/src']\n default_x11_lib_dirs = ['/usr/X11R6/lib','/usr/X11/lib','/usr/lib']\n default_x11_include_dirs = ['/usr/X11R6/include','/usr/X11/include',\n '/usr/include']\n\nif os.path.join(sys.prefix, 'lib') not in default_lib_dirs:\n default_lib_dirs.insert(0,os.path.join(sys.prefix, 'lib'))\n default_include_dirs.append(os.path.join(sys.prefix, 'include'))\n default_src_dirs.append(os.path.join(sys.prefix, 'src'))\n\ndefault_lib_dirs = filter(os.path.isdir, default_lib_dirs)\ndefault_include_dirs = filter(os.path.isdir, default_include_dirs)\ndefault_src_dirs = filter(os.path.isdir, default_src_dirs)\n\nso_ext = get_config_vars('SO')[0] or ''\n\ndef get_info(name,notfound_action=0):\n \"\"\"\n notfound_action:\n 0 - do nothing\n 1 - display warning message\n 2 - raise error\n \"\"\"\n cl = {'atlas':atlas_info, # use lapack_opt or blas_opt instead\n 'atlas_threads':atlas_threads_info, # ditto\n 'atlas_blas':atlas_blas_info,\n 'atlas_blas_threads':atlas_blas_threads_info,\n 'lapack_atlas':lapack_atlas_info, # use lapack_opt instead\n 'lapack_atlas_threads':lapack_atlas_threads_info, # ditto\n 'mkl':mkl_info,\n 'lapack_mkl':lapack_mkl_info, # use lapack_opt instead\n 'blas_mkl':blas_mkl_info, # use blas_opt instead\n 'x11':x11_info,\n 'fft_opt':fft_opt_info,\n 'fftw':fftw_info,\n 'fftw2':fftw2_info,\n 'fftw3':fftw3_info,\n 'dfftw':dfftw_info,\n 'sfftw':sfftw_info,\n 'fftw_threads':fftw_threads_info,\n 'dfftw_threads':dfftw_threads_info,\n 'sfftw_threads':sfftw_threads_info,\n 'djbfft':djbfft_info,\n 'blas':blas_info, # use blas_opt instead\n 'lapack':lapack_info, # use lapack_opt instead\n 'lapack_src':lapack_src_info,\n 'blas_src':blas_src_info,\n 'numpy':numpy_info,\n 'f2py':f2py_info,\n 'Numeric':Numeric_info,\n 'numarray':numarray_info,\n 'lapack_opt':lapack_opt_info,\n 'blas_opt':blas_opt_info,\n 'boost_python':boost_python_info,\n 'agg2':agg2_info,\n 'wx':wx_info,\n 'gdk_pixbuf_xlib_2':gdk_pixbuf_xlib_2_info,\n 'gdk-pixbuf-xlib-2.0':gdk_pixbuf_xlib_2_info,\n 'gdk_pixbuf_2':gdk_pixbuf_2_info,\n 'gdk-pixbuf-2.0':gdk_pixbuf_2_info,\n 'gdk':gdk_info,\n 'gdk_2':gdk_2_info,\n 'gdk-2.0':gdk_2_info,\n 'gdk_x11_2':gdk_x11_2_info,\n 'gdk-x11-2.0':gdk_x11_2_info,\n 'gtkp_x11_2':gtkp_x11_2_info,\n 'gtk+-x11-2.0':gtkp_x11_2_info,\n 'gtkp_2':gtkp_2_info,\n 'gtk+-2.0':gtkp_2_info,\n 'xft':xft_info,\n 'freetype2':freetype2_info,\n }.get(name.lower(),system_info)\n return cl().get_info(notfound_action)\n\nclass NotFoundError(DistutilsError):\n \"\"\"Some third-party program or library is not found.\"\"\"\n\nclass AtlasNotFoundError(NotFoundError):\n \"\"\"\n Atlas (http://math-atlas.sourceforge.net/) libraries not found.\n Directories to search for the libraries can be specified in the\n numpy/distutils/site.cfg file (section [atlas]) or by setting\n the ATLAS environment variable.\"\"\"\n\nclass LapackNotFoundError(NotFoundError):\n \"\"\"\n Lapack (http://www.netlib.org/lapack/) libraries not found.\n Directories to search for the libraries can be specified in the\n numpy/distutils/site.cfg file (section [lapack]) or by setting\n the LAPACK environment variable.\"\"\"\n\nclass LapackSrcNotFoundError(LapackNotFoundError):\n \"\"\"\n Lapack (http://www.netlib.org/lapack/) sources not found.\n Directories to search for the sources can be specified in the\n numpy/distutils/site.cfg file (section [lapack_src]) or by setting\n the LAPACK_SRC environment variable.\"\"\"\n\nclass BlasNotFoundError(NotFoundError):\n \"\"\"\n Blas (http://www.netlib.org/blas/) libraries not found.\n Directories to search for the libraries can be specified in the\n numpy/distutils/site.cfg file (section [blas]) or by setting\n the BLAS environment variable.\"\"\"\n\nclass BlasSrcNotFoundError(BlasNotFoundError):\n \"\"\"\n Blas (http://www.netlib.org/blas/) sources not found.\n Directories to search for the sources can be specified in the\n numpy/distutils/site.cfg file (section [blas_src]) or by setting\n the BLAS_SRC environment variable.\"\"\"\n\nclass FFTWNotFoundError(NotFoundError):\n \"\"\"\n FFTW (http://www.fftw.org/) libraries not found.\n Directories to search for the libraries can be specified in the\n numpy/distutils/site.cfg file (section [fftw]) or by setting\n the FFTW environment variable.\"\"\"\n\nclass DJBFFTNotFoundError(NotFoundError):\n \"\"\"\n DJBFFT (http://cr.yp.to/djbfft.html) libraries not found.\n Directories to search for the libraries can be specified in the\n numpy/distutils/site.cfg file (section [djbfft]) or by setting\n the DJBFFT environment variable.\"\"\"\n\nclass NumericNotFoundError(NotFoundError):\n \"\"\"\n Numeric (http://www.numpy.org/) module not found.\n Get it from above location, install it, and retry setup.py.\"\"\"\n\nclass X11NotFoundError(NotFoundError):\n \"\"\"X11 libraries not found.\"\"\"\n\nclass system_info:\n\n \"\"\" get_info() is the only public method. Don't use others.\n \"\"\"\n section = 'DEFAULT'\n dir_env_var = None\n search_static_first = 0 # XXX: disabled by default, may disappear in\n # future unless it is proved to be useful.\n verbosity = 1\n saved_results = {}\n\n notfounderror = NotFoundError\n\n def __init__ (self,\n default_lib_dirs=default_lib_dirs,\n default_include_dirs=default_include_dirs,\n verbosity = 1,\n ):\n self.__class__.info = {}\n self.local_prefixes = []\n defaults = {}\n defaults['libraries'] = ''\n defaults['library_dirs'] = os.pathsep.join(default_lib_dirs)\n defaults['include_dirs'] = os.pathsep.join(default_include_dirs)\n defaults['src_dirs'] = os.pathsep.join(default_src_dirs)\n defaults['search_static_first'] = str(self.search_static_first)\n self.cp = ConfigParser.ConfigParser(defaults)\n try:\n f = __file__\n except NameError,msg:\n f = sys.argv[0]\n cf = os.path.join(os.path.split(os.path.abspath(f))[0],\n 'site.cfg')\n self.cp.read([cf])\n if not self.cp.has_section(self.section):\n self.cp.add_section(self.section)\n self.search_static_first = self.cp.getboolean(self.section,\n 'search_static_first')\n assert isinstance(self.search_static_first, int)\n\n def calc_libraries_info(self):\n libs = self.get_libraries()\n dirs = self.get_lib_dirs()\n info = {}\n for lib in libs:\n i = None\n for d in dirs:\n i = self.check_libs(d,[lib])\n if i is not None:\n break\n if i is not None:\n dict_append(info,**i)\n else:\n print 'Library %s was not found. Ignoring' % (lib)\n return info\n\n def set_info(self,**info):\n if info:\n lib_info = self.calc_libraries_info()\n dict_append(info,**lib_info)\n self.saved_results[self.__class__.__name__] = info\n\n def has_info(self):\n return self.saved_results.has_key(self.__class__.__name__)\n\n def get_info(self,notfound_action=0):\n \"\"\" Return a dictonary with items that are compatible\n with numpy.distutils.setup keyword arguments.\n \"\"\"\n flag = 0\n if not self.has_info():\n flag = 1\n if self.verbosity>0:\n print self.__class__.__name__ + ':'\n if hasattr(self, 'calc_info'):\n self.calc_info()\n if notfound_action:\n if not self.has_info():\n if notfound_action==1:\n warnings.warn(self.notfounderror.__doc__)\n elif notfound_action==2:\n raise self.notfounderror,self.notfounderror.__doc__\n else:\n raise ValueError(repr(notfound_action))\n\n if self.verbosity>0:\n if not self.has_info():\n print ' NOT AVAILABLE'\n self.set_info()\n else:\n print ' FOUND:'\n\n res = self.saved_results.get(self.__class__.__name__)\n if self.verbosity>0 and flag:\n for k,v in res.items():\n v = str(v)\n if k=='sources' and len(v)>200: v = v[:60]+' ...\\n... '+v[-60:]\n print ' %s = %s'%(k,v)\n print\n\n return res\n\n def get_paths(self, section, key):\n dirs = self.cp.get(section, key).split(os.pathsep)\n env_var = self.dir_env_var\n if env_var:\n if is_sequence(env_var):\n e0 = env_var[-1]\n for e in env_var:\n if os.environ.has_key(e):\n e0 = e\n break\n if not env_var[0]==e0:\n print 'Setting %s=%s' % (env_var[0],e0)\n env_var = e0\n if env_var and os.environ.has_key(env_var):\n d = os.environ[env_var]\n if d=='None':\n print 'Disabled',self.__class__.__name__,'(%s is None)' \\\n % (self.dir_env_var)\n return []\n if os.path.isfile(d):\n dirs = [os.path.dirname(d)] + dirs\n l = getattr(self,'_lib_names',[])\n if len(l)==1:\n b = os.path.basename(d)\n b = os.path.splitext(b)[0]\n if b[:3]=='lib':\n print 'Replacing _lib_names[0]==%r with %r' \\\n % (self._lib_names[0], b[3:])\n self._lib_names[0] = b[3:]\n else:\n ds = d.split(os.pathsep)\n ds2 = []\n for d in ds:\n if os.path.isdir(d):\n ds2.append(d)\n for dd in ['include','lib']:\n d1 = os.path.join(d,dd)\n if os.path.isdir(d1):\n ds2.append(d1)\n dirs = ds2 + dirs\n default_dirs = self.cp.get('DEFAULT', key).split(os.pathsep)\n dirs.extend(default_dirs)\n ret = []\n [ret.append(d) for d in dirs if os.path.isdir(d) and d not in ret]\n if self.verbosity>1:\n print '(',key,'=',':'.join(ret),')'\n return ret\n\n def get_lib_dirs(self, key='library_dirs'):\n return self.get_paths(self.section, key)\n\n def get_include_dirs(self, key='include_dirs'):\n return self.get_paths(self.section, key)\n\n def get_src_dirs(self, key='src_dirs'):\n return self.get_paths(self.section, key)\n\n def get_libs(self, key, default):\n try:\n libs = self.cp.get(self.section, key)\n except ConfigParser.NoOptionError:\n if not default:\n return []\n if is_string(default):\n return [default]\n return default\n return [b for b in [a.strip() for a in libs.split(',')] if b]\n\n def get_libraries(self, key='libraries'):\n return self.get_libs(key,'')\n\n def check_libs(self,lib_dir,libs,opt_libs =[]):\n \"\"\" If static or shared libraries are available then return\n their info dictionary. \"\"\"\n if self.search_static_first:\n exts = ['.a',so_ext]\n else:\n exts = [so_ext,'.a']\n if sys.platform=='cygwin':\n exts.append('.dll.a')\n for ext in exts:\n info = self._check_libs(lib_dir,libs,opt_libs,[ext])\n if info is not None: return info\n return\n\n def check_libs2(self,lib_dir,libs,opt_libs =[]):\n \"\"\" If static or shared libraries are available then return\n their info dictionary. \"\"\"\n if self.search_static_first:\n exts = ['.a',so_ext]\n else:\n exts = [so_ext,'.a']\n if sys.platform=='cygwin':\n exts.append('.dll.a')\n info = self._check_libs(lib_dir,libs,opt_libs,exts)\n if info is not None: return info\n return\n\n def _lib_list(self, lib_dir, libs, exts):\n assert is_string(lib_dir)\n liblist = []\n for l in libs:\n for ext in exts:\n p = self.combine_paths(lib_dir, 'lib'+l+ext)\n if p:\n assert len(p)==1\n liblist.append(p[0])\n break\n return liblist\n\n def _extract_lib_names(self,libs):\n return [os.path.splitext(os.path.basename(p))[0][3:] \\\n for p in libs]\n\n def _check_libs(self,lib_dir,libs, opt_libs, exts):\n found_libs = self._lib_list(lib_dir, libs, exts)\n if len(found_libs) == len(libs):\n found_libs = self._extract_lib_names(found_libs)\n info = {'libraries' : found_libs, 'library_dirs' : [lib_dir]}\n opt_found_libs = self._lib_list(lib_dir, opt_libs, exts)\n if len(opt_found_libs) == len(opt_libs):\n opt_found_libs = self._extract_lib_names(opt_found_libs)\n info['libraries'].extend(opt_found_libs)\n return info\n\n def combine_paths(self,*args):\n return combine_paths(*args,**{'verbosity':self.verbosity})\n\n\nclass fft_opt_info(system_info):\n\n def calc_info(self):\n info = {}\n fftw_info = get_info('fftw3') or get_info('fftw2') or get_info('dfftw')\n djbfft_info = get_info('djbfft')\n if fftw_info:\n dict_append(info,**fftw_info)\n if djbfft_info:\n dict_append(info,**djbfft_info)\n self.set_info(**info)\n return\n\n\nclass fftw_info(system_info):\n #variables to override\n section = 'fftw'\n dir_env_var = 'FFTW'\n notfounderror = FFTWNotFoundError\n ver_info = [ { 'name':'fftw3',\n 'libs':['fftw3'],\n 'includes':['fftw3.h'],\n 'macros':[('SCIPY_FFTW3_H',None)]},\n { 'name':'fftw2',\n 'libs':['rfftw', 'fftw'],\n 'includes':['fftw.h','rfftw.h'],\n 'macros':[('SCIPY_FFTW_H',None)]}]\n\n def __init__(self):\n system_info.__init__(self)\n\n def calc_ver_info(self,ver_param):\n \"\"\"Returns True on successful version detection, else False\"\"\"\n lib_dirs = self.get_lib_dirs()\n incl_dirs = self.get_include_dirs()\n incl_dir = None\n libs = self.get_libs(self.section+'_libs', ver_param['libs'])\n info = None\n for d in lib_dirs:\n r = self.check_libs(d,libs)\n if r is not None:\n info = r\n break\n if info is not None:\n flag = 0\n for d in incl_dirs:\n if len(self.combine_paths(d,ver_param['includes']))==len(ver_param['includes']):\n dict_append(info,include_dirs=[d])\n flag = 1\n incl_dirs = [d]\n incl_dir = d\n break\n if flag:\n dict_append(info,define_macros=ver_param['macros'])\n else:\n info = None\n if info is not None:\n self.set_info(**info)\n return True\n else:\n if self.verbosity>0:\n print ' %s not found' % (ver_param['name'])\n return False\n\n def calc_info(self):\n for i in self.ver_info:\n if self.calc_ver_info(i):\n break\n\nclass fftw2_info(fftw_info):\n #variables to override\n section = 'fftw'\n dir_env_var = 'FFTW'\n notfounderror = FFTWNotFoundError\n ver_info = [ { 'name':'fftw2',\n 'libs':['rfftw', 'fftw'],\n 'includes':['fftw.h','rfftw.h'],\n 'macros':[('SCIPY_FFTW_H',None)]}\n ]\n\nclass fftw3_info(fftw_info):\n #variables to override\n section = 'fftw3'\n dir_env_var = 'FFTW3'\n notfounderror = FFTWNotFoundError\n ver_info = [ { 'name':'fftw3',\n 'libs':['fftw3'],\n 'includes':['fftw3.h'],\n 'macros':[('SCIPY_FFTW3_H',None)]},\n ]\n\nclass dfftw_info(fftw_info):\n section = 'fftw'\n dir_env_var = 'FFTW'\n ver_info = [ { 'name':'dfftw',\n 'libs':['drfftw','dfftw'],\n 'includes':['dfftw.h','drfftw.h'],\n 'macros':[('SCIPY_DFFTW_H',None)]} ]\n\nclass sfftw_info(fftw_info):\n section = 'fftw'\n dir_env_var = 'FFTW'\n ver_info = [ { 'name':'sfftw',\n 'libs':['srfftw','sfftw'],\n 'includes':['sfftw.h','srfftw.h'],\n 'macros':[('SCIPY_SFFTW_H',None)]} ]\n\nclass fftw_threads_info(fftw_info):\n section = 'fftw'\n dir_env_var = 'FFTW'\n ver_info = [ { 'name':'fftw threads',\n 'libs':['rfftw_threads','fftw_threads'],\n 'includes':['fftw_threads.h','rfftw_threads.h'],\n 'macros':[('SCIPY_FFTW_THREADS_H',None)]} ]\n\nclass dfftw_threads_info(fftw_info):\n section = 'fftw'\n dir_env_var = 'FFTW'\n ver_info = [ { 'name':'dfftw threads',\n 'libs':['drfftw_threads','dfftw_threads'],\n 'includes':['dfftw_threads.h','drfftw_threads.h'],\n 'macros':[('SCIPY_DFFTW_THREADS_H',None)]} ]\n\nclass sfftw_threads_info(fftw_info):\n section = 'fftw'\n dir_env_var = 'FFTW'\n ver_info = [ { 'name':'sfftw threads',\n 'libs':['srfftw_threads','sfftw_threads'],\n 'includes':['sfftw_threads.h','srfftw_threads.h'],\n 'macros':[('SCIPY_SFFTW_THREADS_H',None)]} ]\n\nclass djbfft_info(system_info):\n section = 'djbfft'\n dir_env_var = 'DJBFFT'\n notfounderror = DJBFFTNotFoundError\n\n def get_paths(self, section, key):\n pre_dirs = system_info.get_paths(self, section, key)\n dirs = []\n for d in pre_dirs:\n dirs.extend(self.combine_paths(d,['djbfft'])+[d])\n return [ d for d in dirs if os.path.isdir(d) ]\n\n def calc_info(self):\n lib_dirs = self.get_lib_dirs()\n incl_dirs = self.get_include_dirs()\n info = None\n for d in lib_dirs:\n p = self.combine_paths (d,['djbfft.a'])\n if p:\n info = {'extra_objects':p}\n break\n p = self.combine_paths (d,['libdjbfft.a','libdjbfft'+so_ext])\n if p:\n info = {'libraries':['djbfft'],'library_dirs':[d]}\n break\n if info is None:\n return\n for d in incl_dirs:\n if len(self.combine_paths(d,['fftc8.h','fftfreq.h']))==2:\n dict_append(info,include_dirs=[d],\n define_macros=[('SCIPY_DJBFFT_H',None)])\n self.set_info(**info)\n return\n return\n\nclass mkl_info(system_info):\n section = 'mkl'\n dir_env_var = 'MKL'\n _lib_mkl = ['mkl','vml','guide']\n\n def get_mkl_rootdir(self):\n mklroot = os.environ.get('MKLROOT',None)\n if mklroot is not None:\n return mklroot\n paths = os.environ.get('LD_LIBRARY_PATH','').split(os.pathsep)\n ld_so_conf = '/etc/ld.so.conf'\n if os.path.isfile(ld_so_conf):\n for d in open(ld_so_conf,'r').readlines():\n d = d.strip()\n if d: paths.append(d)\n intel_mkl_dirs = []\n for path in paths:\n path_atoms = path.split(os.sep)\n for m in path_atoms:\n if m.startswith('mkl'):\n d = os.sep.join(path_atoms[:path_atoms.index(m)+2])\n intel_mkl_dirs.append(d)\n break\n for d in paths:\n dirs = glob(os.path.join(d,'mkl','*')) + glob(os.path.join(d,'mkl*'))\n for d in dirs:\n if os.path.isdir(os.path.join(d,'lib')):\n return d\n return None\n\n def __init__(self):\n mklroot = self.get_mkl_rootdir()\n if mklroot is None:\n system_info.__init__(self)\n else:\n from cpuinfo import cpu\n if cpu.is_Itanium():\n plt = '64'\n l = 'mkl_ipf'\n elif cpu.is_Xeon():\n plt = 'em64t'\n l = 'mkl_em64t'\n else:\n plt = '32'\n l = 'mkl_ia32'\n if l not in self._lib_mkl:\n self._lib_mkl.insert(0,l)\n system_info.__init__(self,\n default_lib_dirs=[os.path.join(mklroot,'lib',plt)],\n default_include_dirs=[os.path.join(mklroot,'include')])\n\n def calc_info(self):\n lib_dirs = self.get_lib_dirs()\n incl_dirs = self.get_include_dirs()\n mkl_libs = self.get_libs('mkl_libs',self._lib_mkl)\n mkl = None\n for d in lib_dirs:\n mkl = self.check_libs2(d,mkl_libs)\n if mkl is not None:\n break\n if mkl is None:\n return\n info = {}\n dict_append(info,**mkl)\n dict_append(info,libraries = ['pthread'], include_dirs = incl_dirs)\n self.set_info(**info)\n\nclass lapack_mkl_info(mkl_info):\n\n def calc_info(self):\n mkl = get_info('mkl')\n if not mkl:\n return\n lapack_libs = self.get_libs('lapack_libs',['mkl_lapack'])\n info = {'libraries': lapack_libs}\n dict_append(info,**mkl)\n self.set_info(**info)\n\nclass blas_mkl_info(mkl_info):\n pass\n\nclass atlas_info(system_info):\n section = 'atlas'\n dir_env_var = 'ATLAS'\n _lib_names = ['f77blas','cblas']\n if sys.platform[:7]=='freebsd':\n _lib_atlas = ['atlas_r']\n _lib_lapack = ['alapack_r']\n else:\n _lib_atlas = ['atlas']\n _lib_lapack = ['lapack']\n\n notfounderror = AtlasNotFoundError\n\n def get_paths(self, section, key):\n pre_dirs = system_info.get_paths(self, section, key)\n dirs = []\n for d in pre_dirs:\n dirs.extend(self.combine_paths(d,['atlas*','ATLAS*',\n 'sse','3dnow','sse2'])+[d])\n return [ d for d in dirs if os.path.isdir(d) ]\n\n def calc_info(self):\n lib_dirs = self.get_lib_dirs()\n info = {}\n atlas_libs = self.get_libs('atlas_libs',\n self._lib_names + self._lib_atlas)\n lapack_libs = self.get_libs('lapack_libs',self._lib_lapack)\n atlas = None\n lapack = None\n atlas_1 = None\n for d in lib_dirs:\n atlas = self.check_libs(d,atlas_libs,[])\n lapack_atlas = self.check_libs(d,['lapack_atlas'],[])\n if atlas is not None:\n lib_dirs2 = self.combine_paths(d,['atlas*','ATLAS*'])+[d]\n for d2 in lib_dirs2:\n lapack = self.check_libs(d2,lapack_libs,[])\n if lapack is not None:\n break\n else:\n lapack = None\n if lapack is not None:\n break\n if atlas:\n atlas_1 = atlas\n print self.__class__\n if atlas is None:\n atlas = atlas_1\n if atlas is None:\n return\n include_dirs = self.get_include_dirs()\n h = (self.combine_paths(lib_dirs+include_dirs,'cblas.h') or [None])[0]\n if h:\n h = os.path.dirname(h)\n dict_append(info,include_dirs=[h])\n info['language'] = 'c'\n if lapack is not None:\n dict_append(info,**lapack)\n dict_append(info,**atlas)\n elif 'lapack_atlas' in atlas['libraries']:\n dict_append(info,**atlas)\n dict_append(info,define_macros=[('ATLAS_WITH_LAPACK_ATLAS',None)])\n self.set_info(**info)\n return\n else:\n dict_append(info,**atlas)\n dict_append(info,define_macros=[('ATLAS_WITHOUT_LAPACK',None)])\n message = \"\"\"\n*********************************************************************\n Could not find lapack library within the ATLAS installation.\n*********************************************************************\n\"\"\"\n warnings.warn(message)\n self.set_info(**info)\n return\n\n # Check if lapack library is complete, only warn if it is not.\n lapack_dir = lapack['library_dirs'][0]\n lapack_name = lapack['libraries'][0]\n lapack_lib = None\n for e in ['.a',so_ext]:\n fn = os.path.join(lapack_dir,'lib'+lapack_name+e)\n if os.path.exists(fn):\n lapack_lib = fn\n break\n if lapack_lib is not None:\n sz = os.stat(lapack_lib)[6]\n if sz <= 4000*1024:\n message = \"\"\"\n*********************************************************************\n Lapack library (from ATLAS) is probably incomplete:\n size of %s is %sk (expected >4000k)\n\n Follow the instructions in the KNOWN PROBLEMS section of the file\n numpy/INSTALL.txt.\n*********************************************************************\n\"\"\" % (lapack_lib,sz/1024)\n warnings.warn(message)\n else:\n info['language'] = 'f77'\n\n self.set_info(**info)\n\nclass atlas_blas_info(atlas_info):\n _lib_names = ['f77blas','cblas']\n\n def calc_info(self):\n lib_dirs = self.get_lib_dirs()\n info = {}\n atlas_libs = self.get_libs('atlas_libs',\n self._lib_names + self._lib_atlas)\n atlas = None\n for d in lib_dirs:\n atlas = self.check_libs(d,atlas_libs,[])\n if atlas is not None:\n break\n if atlas is None:\n return\n include_dirs = self.get_include_dirs()\n h = (self.combine_paths(lib_dirs+include_dirs,'cblas.h') or [None])[0]\n if h:\n h = os.path.dirname(h)\n dict_append(info,include_dirs=[h])\n info['language'] = 'c'\n\n dict_append(info,**atlas)\n\n self.set_info(**info)\n return\n\n\nclass atlas_threads_info(atlas_info):\n dir_env_var = ['PTATLAS','ATLAS']\n _lib_names = ['ptf77blas','ptcblas']\n\nclass atlas_blas_threads_info(atlas_blas_info):\n dir_env_var = ['PTATLAS','ATLAS']\n _lib_names = ['ptf77blas','ptcblas']\n\nclass lapack_atlas_info(atlas_info):\n _lib_names = ['lapack_atlas'] + atlas_info._lib_names\n\nclass lapack_atlas_threads_info(atlas_threads_info):\n _lib_names = ['lapack_atlas'] + atlas_threads_info._lib_names\n\nclass lapack_info(system_info):\n section = 'lapack'\n dir_env_var = 'LAPACK'\n _lib_names = ['lapack']\n notfounderror = LapackNotFoundError\n\n def calc_info(self):\n lib_dirs = self.get_lib_dirs()\n\n lapack_libs = self.get_libs('lapack_libs', self._lib_names)\n for d in lib_dirs:\n lapack = self.check_libs(d,lapack_libs,[])\n if lapack is not None:\n info = lapack\n break\n else:\n return\n info['language'] = 'f77'\n self.set_info(**info)\n\nclass lapack_src_info(system_info):\n section = 'lapack_src'\n dir_env_var = 'LAPACK_SRC'\n notfounderror = LapackSrcNotFoundError\n\n def get_paths(self, section, key):\n pre_dirs = system_info.get_paths(self, section, key)\n dirs = []\n for d in pre_dirs:\n dirs.extend([d] + self.combine_paths(d,['LAPACK*/SRC','SRC']))\n return [ d for d in dirs if os.path.isdir(d) ]\n\n def calc_info(self):\n src_dirs = self.get_src_dirs()\n src_dir = ''\n for d in src_dirs:\n if os.path.isfile(os.path.join(d,'dgesv.f')):\n src_dir = d\n break\n if not src_dir:\n #XXX: Get sources from netlib. May be ask first.\n return\n # The following is extracted from LAPACK-3.0/SRC/Makefile\n allaux='''\n ilaenv ieeeck lsame lsamen xerbla\n ''' # *.f\n laux = '''\n bdsdc bdsqr disna labad lacpy ladiv lae2 laebz laed0 laed1\n laed2 laed3 laed4 laed5 laed6 laed7 laed8 laed9 laeda laev2\n lagtf lagts lamch lamrg lanst lapy2 lapy3 larnv larrb larre\n larrf lartg laruv las2 lascl lasd0 lasd1 lasd2 lasd3 lasd4\n lasd5 lasd6 lasd7 lasd8 lasd9 lasda lasdq lasdt laset lasq1\n lasq2 lasq3 lasq4 lasq5 lasq6 lasr lasrt lassq lasv2 pttrf\n stebz stedc steqr sterf\n ''' # [s|d]*.f\n lasrc = '''\n gbbrd gbcon gbequ gbrfs gbsv gbsvx gbtf2 gbtrf gbtrs gebak\n gebal gebd2 gebrd gecon geequ gees geesx geev geevx gegs gegv\n gehd2 gehrd gelq2 gelqf gels gelsd gelss gelsx gelsy geql2\n geqlf geqp3 geqpf geqr2 geqrf gerfs gerq2 gerqf gesc2 gesdd\n gesv gesvd gesvx getc2 getf2 getrf getri getrs ggbak ggbal\n gges ggesx ggev ggevx ggglm gghrd gglse ggqrf ggrqf ggsvd\n ggsvp gtcon gtrfs gtsv gtsvx gttrf gttrs gtts2 hgeqz hsein\n hseqr labrd lacon laein lags2 lagtm lahqr lahrd laic1 lals0\n lalsa lalsd langb lange langt lanhs lansb lansp lansy lantb\n lantp lantr lapll lapmt laqgb laqge laqp2 laqps laqsb laqsp\n laqsy lar1v lar2v larf larfb larfg larft larfx largv larrv\n lartv larz larzb larzt laswp lasyf latbs latdf latps latrd\n latrs latrz latzm lauu2 lauum pbcon pbequ pbrfs pbstf pbsv\n pbsvx pbtf2 pbtrf pbtrs pocon poequ porfs posv posvx potf2\n potrf potri potrs ppcon ppequ pprfs ppsv ppsvx pptrf pptri\n pptrs ptcon pteqr ptrfs ptsv ptsvx pttrs ptts2 spcon sprfs\n spsv spsvx sptrf sptri sptrs stegr stein sycon syrfs sysv\n sysvx sytf2 sytrf sytri sytrs tbcon tbrfs tbtrs tgevc tgex2\n tgexc tgsen tgsja tgsna tgsy2 tgsyl tpcon tprfs tptri tptrs\n trcon trevc trexc trrfs trsen trsna trsyl trti2 trtri trtrs\n tzrqf tzrzf\n ''' # [s|c|d|z]*.f\n sd_lasrc = '''\n laexc lag2 lagv2 laln2 lanv2 laqtr lasy2 opgtr opmtr org2l\n org2r orgbr orghr orgl2 orglq orgql orgqr orgr2 orgrq orgtr\n orm2l orm2r ormbr ormhr orml2 ormlq ormql ormqr ormr2 ormr3\n ormrq ormrz ormtr rscl sbev sbevd sbevx sbgst sbgv sbgvd sbgvx\n sbtrd spev spevd spevx spgst spgv spgvd spgvx sptrd stev stevd\n stevr stevx syev syevd syevr syevx sygs2 sygst sygv sygvd\n sygvx sytd2 sytrd\n ''' # [s|d]*.f\n cz_lasrc = '''\n bdsqr hbev hbevd hbevx hbgst hbgv hbgvd hbgvx hbtrd hecon heev\n heevd heevr heevx hegs2 hegst hegv hegvd hegvx herfs hesv\n hesvx hetd2 hetf2 hetrd hetrf hetri hetrs hpcon hpev hpevd\n hpevx hpgst hpgv hpgvd hpgvx hprfs hpsv hpsvx hptrd hptrf\n hptri hptrs lacgv lacp2 lacpy lacrm lacrt ladiv laed0 laed7\n laed8 laesy laev2 lahef lanhb lanhe lanhp lanht laqhb laqhe\n laqhp larcm larnv lartg lascl laset lasr lassq pttrf rot spmv\n spr stedc steqr symv syr ung2l ung2r ungbr unghr ungl2 unglq\n ungql ungqr ungr2 ungrq ungtr unm2l unm2r unmbr unmhr unml2\n unmlq unmql unmqr unmr2 unmr3 unmrq unmrz unmtr upgtr upmtr\n ''' # [c|z]*.f\n #######\n sclaux = laux + ' econd ' # s*.f\n dzlaux = laux + ' secnd ' # d*.f\n slasrc = lasrc + sd_lasrc # s*.f\n dlasrc = lasrc + sd_lasrc # d*.f\n clasrc = lasrc + cz_lasrc + ' srot srscl ' # c*.f\n zlasrc = lasrc + cz_lasrc + ' drot drscl ' # z*.f\n oclasrc = ' icmax1 scsum1 ' # *.f\n ozlasrc = ' izmax1 dzsum1 ' # *.f\n sources = ['s%s.f'%f for f in (sclaux+slasrc).split()] \\\n + ['d%s.f'%f for f in (dzlaux+dlasrc).split()] \\\n + ['c%s.f'%f for f in (clasrc).split()] \\\n + ['z%s.f'%f for f in (zlasrc).split()] \\\n + ['%s.f'%f for f in (allaux+oclasrc+ozlasrc).split()]\n sources = [os.path.join(src_dir,f) for f in sources]\n #XXX: should we check here actual existence of source files?\n info = {'sources':sources,'language':'f77'}\n self.set_info(**info)\n\natlas_version_c_text = r'''\n/* This file is generated from numpy_distutils/system_info.py */\n#ifdef __CPLUSPLUS__\nextern \"C\" {\n#endif\n#include \"Python.h\"\nstatic PyMethodDef module_methods[] = { {NULL,NULL} };\nDL_EXPORT(void) initatlas_version(void) {\n void ATL_buildinfo(void);\n ATL_buildinfo();\n Py_InitModule(\"atlas_version\", module_methods);\n}\n#ifdef __CPLUSCPLUS__\n}\n#endif\n'''\n\ndef _get_build_temp():\n from distutils.util import get_platform\n plat_specifier = \".%s-%s\" % (get_platform(), sys.version[0:3])\n return os.path.join('build','temp'+plat_specifier)\n\ndef get_atlas_version(**config):\n os.environ['NO_SCIPY_IMPORT']='get_atlas_version'\n from core import Extension, setup\n from misc_util import get_cmd\n import log\n magic = hex(hash(repr(config)))\n def atlas_version_c(extension, build_dir,magic=magic):\n source = os.path.join(build_dir,'atlas_version_%s.c' % (magic))\n if os.path.isfile(source):\n from distutils.dep_util import newer\n if newer(source,__file__):\n return source\n f = open(source,'w')\n f.write(atlas_version_c_text)\n f.close()\n return source\n ext = Extension('atlas_version',\n sources=[atlas_version_c],\n **config)\n build_dir = _get_build_temp()\n extra_args = ['--build-lib',build_dir]\n for a in sys.argv:\n if re.match('[-][-]compiler[=]',a):\n extra_args.append(a)\n import distutils.core\n old_dist = distutils.core._setup_distribution\n distutils.core._setup_distribution = None\n try:\n dist = setup(ext_modules=[ext],\n script_name = 'get_atlas_version',\n script_args = ['build_src','build_ext']+extra_args)\n except Exception,msg:\n print \"##### msg: %s\" % msg\n if not msg:\n msg = \"Unknown Exception\"\n log.warn(msg)\n return None\n distutils.core._setup_distribution = old_dist\n\n from distutils.sysconfig import get_config_var\n so_ext = get_config_var('SO')\n target = os.path.join(build_dir,'atlas_version'+so_ext)\n cmd = [get_pythonexe(),'-c',\n '\"import imp,os;os.environ[\\\\\"NO_SCIPY_IMPORT\\\\\"]='\\\n '\\\\\"system_info.get_atlas_version:load atlas_version\\\\\";'\\\n 'imp.load_dynamic(\\\\\"atlas_version\\\\\",\\\\\"%s\\\\\")\"'\\\n % (os.path.basename(target))]\n s,o = exec_command(cmd,execute_in=os.path.dirname(target),use_tee=0)\n atlas_version = None\n if not s:\n m = re.search(r'ATLAS version (?P\\d+[.]\\d+[.]\\d+)',o)\n if m:\n atlas_version = m.group('version')\n if atlas_version is None:\n if re.search(r'undefined symbol: ATL_buildinfo',o,re.M):\n atlas_version = '3.2.1_pre3.3.6'\n else:\n print 'Command:',' '.join(cmd)\n print 'Status:',s\n print 'Output:',o\n return atlas_version\n\n\nclass lapack_opt_info(system_info):\n\n def calc_info(self):\n\n if sys.platform=='darwin' and not os.environ.get('ATLAS',None):\n args = []\n link_args = []\n if os.path.exists('/System/Library/Frameworks/Accelerate.framework/'):\n args.extend(['-faltivec'])\n link_args.extend(['-Wl,-framework','-Wl,Accelerate'])\n elif os.path.exists('/System/Library/Frameworks/vecLib.framework/'):\n args.extend(['-faltivec'])\n link_args.extend(['-Wl,-framework','-Wl,vecLib'])\n if args:\n self.set_info(extra_compile_args=args,\n extra_link_args=link_args,\n define_macros=[('NO_ATLAS_INFO',3)])\n return\n\n lapack_mkl_info = get_info('lapack_mkl')\n if lapack_mkl_info:\n self.set_info(**lapack_mkl_info)\n return\n\n atlas_info = get_info('atlas_threads')\n if not atlas_info:\n atlas_info = get_info('atlas')\n #atlas_info = {} ## uncomment for testing\n atlas_version = None\n need_lapack = 0\n need_blas = 0\n info = {}\n if atlas_info:\n version_info = atlas_info.copy()\n atlas_version = get_atlas_version(**version_info)\n if not atlas_info.has_key('define_macros'):\n atlas_info['define_macros'] = []\n if atlas_version is None:\n atlas_info['define_macros'].append(('NO_ATLAS_INFO',2))\n else:\n atlas_info['define_macros'].append(('ATLAS_INFO',\n '\"\\\\\"%s\\\\\"\"' % atlas_version))\n\t\tif atlas_version=='3.2.1_pre3.3.6':\n\t\t atlas_info['define_macros'].append(('NO_ATLAS_INFO',4))\n l = atlas_info.get('define_macros',[])\n if ('ATLAS_WITH_LAPACK_ATLAS',None) in l \\\n or ('ATLAS_WITHOUT_LAPACK',None) in l:\n need_lapack = 1\n info = atlas_info\n else:\n warnings.warn(AtlasNotFoundError.__doc__)\n need_blas = 1\n need_lapack = 1\n dict_append(info,define_macros=[('NO_ATLAS_INFO',1)])\n\n if need_lapack:\n lapack_info = get_info('lapack')\n #lapack_info = {} ## uncomment for testing\n if lapack_info:\n dict_append(info,**lapack_info)\n else:\n warnings.warn(LapackNotFoundError.__doc__)\n lapack_src_info = get_info('lapack_src')\n if not lapack_src_info:\n warnings.warn(LapackSrcNotFoundError.__doc__)\n return\n dict_append(info,libraries=[('flapack_src',lapack_src_info)])\n\n if need_blas:\n blas_info = get_info('blas')\n #blas_info = {} ## uncomment for testing\n if blas_info:\n dict_append(info,**blas_info)\n else:\n warnings.warn(BlasNotFoundError.__doc__)\n blas_src_info = get_info('blas_src')\n if not blas_src_info:\n warnings.warn(BlasSrcNotFoundError.__doc__)\n return\n dict_append(info,libraries=[('fblas_src',blas_src_info)])\n\n self.set_info(**info)\n return\n\n\nclass blas_opt_info(system_info):\n\n def calc_info(self):\n\n if sys.platform=='darwin' and not os.environ.get('ATLAS',None):\n args = []\n link_args = []\n if os.path.exists('/System/Library/Frameworks/Accelerate.framework/'):\n args.extend(['-faltivec',\n '-I/System/Library/Frameworks/vecLib.framework/Headers',\n ])\n link_args.extend(['-Wl,-framework','-Wl,Accelerate'])\n elif os.path.exists('/System/Library/Frameworks/vecLib.framework/'):\n args.extend(['-faltivec',\n '-I/System/Library/Frameworks/vecLib.framework/Headers',\n ])\n link_args.extend(['-Wl,-framework','-Wl,vecLib'])\n if args:\n self.set_info(extra_compile_args=args,\n extra_link_args=link_args,\n define_macros=[('NO_ATLAS_INFO',3)])\n return\n\n blas_mkl_info = get_info('blas_mkl')\n if blas_mkl_info:\n self.set_info(**blas_mkl_info)\n return\n\n atlas_info = get_info('atlas_blas_threads')\n if not atlas_info:\n atlas_info = get_info('atlas_blas')\n atlas_version = None\n need_blas = 0\n info = {}\n if atlas_info:\n version_info = atlas_info.copy()\n atlas_version = get_atlas_version(**version_info)\n if not atlas_info.has_key('define_macros'):\n atlas_info['define_macros'] = []\n if atlas_version is None:\n atlas_info['define_macros'].append(('NO_ATLAS_INFO',2))\n else:\n atlas_info['define_macros'].append(('ATLAS_INFO',\n '\"\\\\\"%s\\\\\"\"' % atlas_version))\n info = atlas_info\n else:\n warnings.warn(AtlasNotFoundError.__doc__)\n need_blas = 1\n dict_append(info,define_macros=[('NO_ATLAS_INFO',1)])\n\n if need_blas:\n blas_info = get_info('blas')\n if blas_info:\n dict_append(info,**blas_info)\n else:\n warnings.warn(BlasNotFoundError.__doc__)\n blas_src_info = get_info('blas_src')\n if not blas_src_info:\n warnings.warn(BlasSrcNotFoundError.__doc__)\n return\n dict_append(info,libraries=[('fblas_src',blas_src_info)])\n\n self.set_info(**info)\n return\n\n\nclass blas_info(system_info):\n section = 'blas'\n dir_env_var = 'BLAS'\n _lib_names = ['blas']\n notfounderror = BlasNotFoundError\n\n def calc_info(self):\n lib_dirs = self.get_lib_dirs()\n\n blas_libs = self.get_libs('blas_libs', self._lib_names)\n for d in lib_dirs:\n blas = self.check_libs(d,blas_libs,[])\n if blas is not None:\n info = blas\n break\n else:\n return\n info['language'] = 'f77' # XXX: is it generally true?\n self.set_info(**info)\n\n\nclass blas_src_info(system_info):\n section = 'blas_src'\n dir_env_var = 'BLAS_SRC'\n notfounderror = BlasSrcNotFoundError\n\n def get_paths(self, section, key):\n pre_dirs = system_info.get_paths(self, section, key)\n dirs = []\n for d in pre_dirs:\n dirs.extend([d] + self.combine_paths(d,['blas']))\n return [ d for d in dirs if os.path.isdir(d) ]\n\n def calc_info(self):\n src_dirs = self.get_src_dirs()\n src_dir = ''\n for d in src_dirs:\n if os.path.isfile(os.path.join(d,'daxpy.f')):\n src_dir = d\n break\n if not src_dir:\n #XXX: Get sources from netlib. May be ask first.\n return\n blas1 = '''\n caxpy csscal dnrm2 dzasum saxpy srotg zdotc ccopy cswap drot\n dznrm2 scasum srotm zdotu cdotc dasum drotg icamax scnrm2\n srotmg zdrot cdotu daxpy drotm idamax scopy sscal zdscal crotg\n dcabs1 drotmg isamax sdot sswap zrotg cscal dcopy dscal izamax\n snrm2 zaxpy zscal csrot ddot dswap sasum srot zcopy zswap\n '''\n blas2 = '''\n cgbmv chpmv ctrsv dsymv dtrsv sspr2 strmv zhemv ztpmv cgemv\n chpr dgbmv dsyr lsame ssymv strsv zher ztpsv cgerc chpr2 dgemv\n dsyr2 sgbmv ssyr xerbla zher2 ztrmv cgeru ctbmv dger dtbmv\n sgemv ssyr2 zgbmv zhpmv ztrsv chbmv ctbsv dsbmv dtbsv sger\n stbmv zgemv zhpr chemv ctpmv dspmv dtpmv ssbmv stbsv zgerc\n zhpr2 cher ctpsv dspr dtpsv sspmv stpmv zgeru ztbmv cher2\n ctrmv dspr2 dtrmv sspr stpsv zhbmv ztbsv\n '''\n blas3 = '''\n cgemm csymm ctrsm dsyrk sgemm strmm zhemm zsyr2k chemm csyr2k\n dgemm dtrmm ssymm strsm zher2k zsyrk cher2k csyrk dsymm dtrsm\n ssyr2k zherk ztrmm cherk ctrmm dsyr2k ssyrk zgemm zsymm ztrsm\n '''\n sources = [os.path.join(src_dir,f+'.f') \\\n for f in (blas1+blas2+blas3).split()]\n #XXX: should we check here actual existence of source files?\n info = {'sources':sources,'language':'f77'}\n self.set_info(**info)\n\nclass x11_info(system_info):\n section = 'x11'\n notfounderror = X11NotFoundError\n\n def __init__(self):\n system_info.__init__(self,\n default_lib_dirs=default_x11_lib_dirs,\n default_include_dirs=default_x11_include_dirs)\n\n def calc_info(self):\n if sys.platform in ['win32']:\n return\n lib_dirs = self.get_lib_dirs()\n include_dirs = self.get_include_dirs()\n x11_libs = self.get_libs('x11_libs', ['X11'])\n for lib_dir in lib_dirs:\n info = self.check_libs(lib_dir, x11_libs, [])\n if info is not None:\n break\n else:\n return\n inc_dir = None\n for d in include_dirs:\n if self.combine_paths(d, 'X11/X.h'):\n inc_dir = d\n break\n if inc_dir is not None:\n dict_append(info, include_dirs=[inc_dir])\n self.set_info(**info)\n\nclass _numpy_info(system_info):\n section = 'Numeric'\n modulename = 'Numeric'\n notfounderror = NumericNotFoundError\n\n def __init__(self):\n from distutils.sysconfig import get_python_inc\n include_dirs = []\n try:\n module = __import__(self.modulename)\n prefix = []\n for name in module.__file__.split(os.sep):\n if name=='lib':\n break\n prefix.append(name)\n include_dirs.append(get_python_inc(prefix=os.sep.join(prefix)))\n except ImportError:\n pass\n py_incl_dir = get_python_inc()\n include_dirs.append(py_incl_dir)\n for d in default_include_dirs:\n d = os.path.join(d, os.path.basename(py_incl_dir))\n if d not in include_dirs:\n include_dirs.append(d)\n system_info.__init__(self,\n default_lib_dirs=[],\n default_include_dirs=include_dirs)\n\n def calc_info(self):\n try:\n module = __import__(self.modulename)\n except ImportError:\n return\n info = {}\n macros = []\n for v in ['__version__','version']:\n vrs = getattr(module,v,None)\n if vrs is None:\n continue\n macros = [(self.modulename.upper()+'_VERSION',\n '\"\\\\\"%s\\\\\"\"' % (vrs)),\n (self.modulename.upper(),None)]\n break\n## try:\n## macros.append(\n## (self.modulename.upper()+'_VERSION_HEX',\n## hex(vstr2hex(module.__version__))),\n## )\n## except Exception,msg:\n## print msg\n dict_append(info, define_macros = macros)\n include_dirs = self.get_include_dirs()\n inc_dir = None\n for d in include_dirs:\n if self.combine_paths(d,\n os.path.join(self.modulename,\n 'arrayobject.h')):\n inc_dir = d\n break\n if inc_dir is not None:\n dict_append(info, include_dirs=[inc_dir])\n if info:\n self.set_info(**info)\n return\n\nclass numarray_info(_numpy_info):\n section = 'numarray'\n modulename = 'numarray'\n\nclass Numeric_info(_numpy_info):\n section = 'Numeric'\n modulename = 'Numeric'\n\nclass numpy_info(_numpy_info):\n section = 'numpy'\n modulename = 'numpy'\n\nclass f2py_info(system_info):\n def calc_info(self):\n try:\n import numpy.f2py as f2py\n except ImportError:\n return\n f2py_dir = os.path.join(os.path.dirname(f2py.__file__),'src')\n self.set_info(sources = [os.path.join(f2py_dir,'fortranobject.c')],\n include_dirs = [f2py_dir])\n return\n\nclass boost_python_info(system_info):\n section = 'boost_python'\n dir_env_var = 'BOOST'\n\n def get_paths(self, section, key):\n pre_dirs = system_info.get_paths(self, section, key)\n dirs = []\n for d in pre_dirs:\n dirs.extend([d] + self.combine_paths(d,['boost*']))\n return [ d for d in dirs if os.path.isdir(d) ]\n\n def calc_info(self):\n from distutils.sysconfig import get_python_inc\n src_dirs = self.get_src_dirs()\n src_dir = ''\n for d in src_dirs:\n if os.path.isfile(os.path.join(d,'libs','python','src','module.cpp')):\n src_dir = d\n break\n if not src_dir:\n return\n py_incl_dir = get_python_inc()\n srcs_dir = os.path.join(src_dir,'libs','python','src')\n bpl_srcs = glob(os.path.join(srcs_dir,'*.cpp'))\n bpl_srcs += glob(os.path.join(srcs_dir,'*','*.cpp'))\n info = {'libraries':[('boost_python_src',{'include_dirs':[src_dir,py_incl_dir],\n 'sources':bpl_srcs})],\n 'include_dirs':[src_dir],\n }\n if info:\n self.set_info(**info)\n return\n\nclass agg2_info(system_info):\n section = 'agg2'\n dir_env_var = 'AGG2'\n\n def get_paths(self, section, key):\n pre_dirs = system_info.get_paths(self, section, key)\n dirs = []\n for d in pre_dirs:\n dirs.extend([d] + self.combine_paths(d,['agg2*']))\n return [ d for d in dirs if os.path.isdir(d) ]\n\n def calc_info(self):\n src_dirs = self.get_src_dirs()\n src_dir = ''\n for d in src_dirs:\n if os.path.isfile(os.path.join(d,'src','agg_affine_matrix.cpp')):\n src_dir = d\n break\n if not src_dir:\n return\n if sys.platform=='win32':\n agg2_srcs = glob(os.path.join(src_dir,'src','platform','win32','agg_win32_bmp.cpp'))\n else:\n agg2_srcs = glob(os.path.join(src_dir,'src','*.cpp'))\n agg2_srcs += [os.path.join(src_dir,'src','platform','X11','agg_platform_support.cpp')]\n\n info = {'libraries':[('agg2_src',{'sources':agg2_srcs,\n 'include_dirs':[os.path.join(src_dir,'include')],\n })],\n 'include_dirs':[os.path.join(src_dir,'include')],\n }\n if info:\n self.set_info(**info)\n return\n\nclass _pkg_config_info(system_info):\n section = None\n config_env_var = 'PKG_CONFIG'\n default_config_exe = 'pkg-config'\n append_config_exe = ''\n version_macro_name = None\n release_macro_name = None\n version_flag = '--modversion'\n cflags_flag = '--cflags'\n\n def get_config_exe(self):\n if os.environ.has_key(self.config_env_var):\n return os.environ[self.config_env_var]\n return self.default_config_exe\n def get_config_output(self, config_exe, option):\n s,o = exec_command(config_exe+' '+self.append_config_exe+' '+option,use_tee=0)\n if not s:\n return o\n\n def calc_info(self):\n config_exe = find_executable(self.get_config_exe())\n if not os.path.isfile(config_exe):\n print 'File not found: %s. Cannot determine %s info.' \\\n % (config_exe, self.section)\n return\n info = {}\n macros = []\n libraries = []\n library_dirs = []\n include_dirs = []\n extra_link_args = []\n extra_compile_args = []\n version = self.get_config_output(config_exe,self.version_flag)\n if version:\n macros.append((self.__class__.__name__.split('.')[-1].upper(),\n '\"\\\\\"%s\\\\\"\"' % (version)))\n if self.version_macro_name:\n macros.append((self.version_macro_name+'_%s' % (version.replace('.','_')),None))\n if self.release_macro_name:\n release = self.get_config_output(config_exe,'--release')\n if release:\n macros.append((self.release_macro_name+'_%s' % (release.replace('.','_')),None))\n opts = self.get_config_output(config_exe,'--libs')\n if opts:\n for opt in opts.split():\n if opt[:2]=='-l':\n libraries.append(opt[2:])\n elif opt[:2]=='-L':\n library_dirs.append(opt[2:])\n else:\n extra_link_args.append(opt)\n opts = self.get_config_output(config_exe,self.cflags_flag)\n if opts:\n for opt in opts.split():\n if opt[:2]=='-I':\n include_dirs.append(opt[2:])\n elif opt[:2]=='-D':\n if '=' in opt:\n n,v = opt[2:].split('=')\n macros.append((n,v))\n else:\n macros.append((opt[2:],None))\n else:\n extra_compile_args.append(opt)\n if macros: dict_append(info, define_macros = macros)\n if libraries: dict_append(info, libraries = libraries)\n if library_dirs: dict_append(info, library_dirs = library_dirs)\n if include_dirs: dict_append(info, include_dirs = include_dirs)\n if extra_link_args: dict_append(info, extra_link_args = extra_link_args)\n if extra_compile_args: dict_append(info, extra_compile_args = extra_compile_args)\n if info:\n self.set_info(**info)\n return\n\nclass wx_info(_pkg_config_info):\n section = 'wx'\n config_env_var = 'WX_CONFIG'\n default_config_exe = 'wx-config'\n append_config_exe = ''\n version_macro_name = 'WX_VERSION'\n release_macro_name = 'WX_RELEASE'\n version_flag = '--version'\n cflags_flag = '--cxxflags'\n\nclass gdk_pixbuf_xlib_2_info(_pkg_config_info):\n section = 'gdk_pixbuf_xlib_2'\n append_config_exe = 'gdk-pixbuf-xlib-2.0'\n version_macro_name = 'GDK_PIXBUF_XLIB_VERSION'\n\nclass gdk_pixbuf_2_info(_pkg_config_info):\n section = 'gdk_pixbuf_2'\n append_config_exe = 'gdk-pixbuf-2.0'\n version_macro_name = 'GDK_PIXBUF_VERSION'\n\nclass gdk_x11_2_info(_pkg_config_info):\n section = 'gdk_x11_2'\n append_config_exe = 'gdk-x11-2.0'\n version_macro_name = 'GDK_X11_VERSION'\n\nclass gdk_2_info(_pkg_config_info):\n section = 'gdk_2'\n append_config_exe = 'gdk-2.0'\n version_macro_name = 'GDK_VERSION'\n\nclass gdk_info(_pkg_config_info):\n section = 'gdk'\n append_config_exe = 'gdk'\n version_macro_name = 'GDK_VERSION'\n\nclass gtkp_x11_2_info(_pkg_config_info):\n section = 'gtkp_x11_2'\n append_config_exe = 'gtk+-x11-2.0'\n version_macro_name = 'GTK_X11_VERSION'\n\n\nclass gtkp_2_info(_pkg_config_info):\n section = 'gtkp_2'\n append_config_exe = 'gtk+-2.0'\n version_macro_name = 'GTK_VERSION'\n\nclass xft_info(_pkg_config_info):\n section = 'xft'\n append_config_exe = 'xft'\n version_macro_name = 'XFT_VERSION'\n\nclass freetype2_info(_pkg_config_info):\n section = 'freetype2'\n append_config_exe = 'freetype2'\n version_macro_name = 'FREETYPE2_VERSION'\n\n## def vstr2hex(version):\n## bits = []\n## n = [24,16,8,4,0]\n## r = 0\n## for s in version.split('.'):\n## r |= int(s) << n[0]\n## del n[0]\n## return r\n\n#--------------------------------------------------------------------\n\ndef combine_paths(*args,**kws):\n \"\"\" Return a list of existing paths composed by all combinations of\n items from arguments.\n \"\"\"\n r = []\n for a in args:\n if not a: continue\n if is_string(a):\n a = [a]\n r.append(a)\n args = r\n if not args: return []\n if len(args)==1:\n result = reduce(lambda a,b:a+b,map(glob,args[0]),[])\n elif len (args)==2:\n result = []\n for a0 in args[0]:\n for a1 in args[1]:\n result.extend(glob(os.path.join(a0,a1)))\n else:\n result = combine_paths(*(combine_paths(args[0],args[1])+args[2:]))\n verbosity = kws.get('verbosity',1)\n if verbosity>1 and result:\n print '(','paths:',','.join(result),')'\n return result\n\nlanguage_map = {'c':0,'c++':1,'f77':2,'f90':3}\ninv_language_map = {0:'c',1:'c++',2:'f77',3:'f90'}\ndef dict_append(d,**kws):\n languages = []\n for k,v in kws.items():\n if k=='language':\n languages.append(v)\n continue\n if d.has_key(k):\n if k in ['library_dirs','include_dirs','define_macros']:\n [d[k].append(vv) for vv in v if vv not in d[k]]\n else:\n d[k].extend(v)\n else:\n d[k] = v\n if languages:\n l = inv_language_map[max([language_map.get(l,0) for l in languages])]\n d['language'] = l\n return\n\ndef show_all():\n import system_info\n import pprint\n match_info = re.compile(r'.*?_info').match\n show_only = []\n for n in sys.argv[1:]:\n if n[-5:] != '_info':\n n = n + '_info'\n show_only.append(n)\n show_all = not show_only\n for n in filter(match_info,dir(system_info)):\n if n in ['system_info','get_info']: continue\n if not show_all:\n if n not in show_only: continue\n del show_only[show_only.index(n)]\n c = getattr(system_info,n)()\n c.verbosity = 2\n r = c.get_info()\n if show_only:\n print 'Info classes not defined:',','.join(show_only)\nif __name__ == \"__main__\":\n show_all()\n", + "source_code_before": "#!/usr/bin/env python\n\"\"\"\nThis file defines a set of system_info classes for getting\ninformation about various resources (libraries, library directories,\ninclude directories, etc.) in the system. Currently, the following\nclasses are available:\n\n atlas_info\n atlas_threads_info\n atlas_blas_info\n atlas_blas_threads_info\n lapack_atlas_info\n blas_info\n lapack_info\n blas_opt_info # usage recommended\n lapack_opt_info # usage recommended\n fftw_info,dfftw_info,sfftw_info\n fftw_threads_info,dfftw_threads_info,sfftw_threads_info\n djbfft_info\n x11_info\n lapack_src_info\n blas_src_info\n numpy_info\n numarray_info\n numpy_info\n boost_python_info\n agg2_info\n wx_info\n gdk_pixbuf_xlib_2_info\n gdk_pixbuf_2_info\n gdk_x11_2_info\n gtkp_x11_2_info\n gtkp_2_info\n xft_info\n freetype2_info\n\nUsage:\n info_dict = get_info()\n where is a string 'atlas','x11','fftw','lapack','blas',\n 'lapack_src', 'blas_src', etc. For a complete list of allowed names,\n see the definition of get_info() function below.\n\n Returned info_dict is a dictionary which is compatible with\n distutils.setup keyword arguments. If info_dict == {}, then the\n asked resource is not available (system_info could not find it).\n\n Several *_info classes specify an environment variable to specify\n the locations of software. When setting the corresponding environment\n variable to 'None' then the software will be ignored, even when it\n is available in system.\n\nGlobal parameters:\n system_info.search_static_first - search static libraries (.a)\n in precedence to shared ones (.so, .sl) if enabled.\n system_info.verbosity - output the results to stdout if enabled.\n\nThe file 'site.cfg' in the same directory as this module is read\nfor configuration options. The format is that used by ConfigParser (i.e.,\nWindows .INI style). The section DEFAULT has options that are the default\nfor each section. The available sections are fftw, atlas, and x11. Appropiate\ndefaults are used if nothing is specified.\n\nThe order of finding the locations of resources is the following:\n 1. environment variable\n 2. section in site.cfg\n 3. DEFAULT section in site.cfg\nOnly the first complete match is returned.\n\nExample:\n----------\n[DEFAULT]\nlibrary_dirs = /usr/lib:/usr/local/lib:/opt/lib\ninclude_dirs = /usr/include:/usr/local/include:/opt/include\nsrc_dirs = /usr/local/src:/opt/src\n# search static libraries (.a) in preference to shared ones (.so)\nsearch_static_first = 0\n\n[fftw]\nfftw_libs = rfftw, fftw\nfftw_opt_libs = rfftw_threaded, fftw_threaded\n# if the above aren't found, look for {s,d}fftw_libs and {s,d}fftw_opt_libs\n\n[atlas]\nlibrary_dirs = /usr/lib/3dnow:/usr/lib/3dnow/atlas\n# for overriding the names of the atlas libraries\natlas_libs = lapack, f77blas, cblas, atlas\n\n[x11]\nlibrary_dirs = /usr/X11R6/lib\ninclude_dirs = /usr/X11R6/include\n----------\n\nAuthors:\n Pearu Peterson , February 2002\n David M. Cooke , April 2002\n\nCopyright 2002 Pearu Peterson all rights reserved,\nPearu Peterson \nPermission to use, modify, and distribute this software is given under the\nterms of the SciPy (BSD style) license. See LICENSE.txt that came with\nthis distribution for specifics.\n\nNO WARRANTY IS EXPRESSED OR IMPLIED. USE AT YOUR OWN RISK.\n\"\"\"\n\nimport sys,os,re\nimport warnings\nfrom distutils.errors import DistutilsError\nfrom glob import glob\nimport ConfigParser\nfrom exec_command import find_executable, exec_command, get_pythonexe\nfrom numpy.distutils.misc_util import is_sequence, is_string\n\nfrom distutils.sysconfig import get_config_vars\n\nif sys.platform == 'win32':\n default_lib_dirs = ['C:\\\\'] # probably not very helpful...\n default_include_dirs = []\n default_src_dirs = ['.']\n default_x11_lib_dirs = []\n default_x11_include_dirs = []\nelse:\n default_lib_dirs = ['/usr/local/lib', '/opt/lib', '/usr/lib',\n '/opt/local/lib', '/sw/lib']\n default_include_dirs = ['/usr/local/include',\n '/opt/include', '/usr/include',\n '/opt/local/include', '/sw/include']\n default_src_dirs = ['.','/usr/local/src', '/opt/src','/sw/src']\n default_x11_lib_dirs = ['/usr/X11R6/lib','/usr/X11/lib','/usr/lib']\n default_x11_include_dirs = ['/usr/X11R6/include','/usr/X11/include',\n '/usr/include']\n\nif os.path.join(sys.prefix, 'lib') not in default_lib_dirs:\n default_lib_dirs.insert(0,os.path.join(sys.prefix, 'lib'))\n default_include_dirs.append(os.path.join(sys.prefix, 'include'))\n default_src_dirs.append(os.path.join(sys.prefix, 'src'))\n\ndefault_lib_dirs = filter(os.path.isdir, default_lib_dirs)\ndefault_include_dirs = filter(os.path.isdir, default_include_dirs)\ndefault_src_dirs = filter(os.path.isdir, default_src_dirs)\n\nso_ext = get_config_vars('SO')[0] or ''\n\ndef get_info(name,notfound_action=0):\n \"\"\"\n notfound_action:\n 0 - do nothing\n 1 - display warning message\n 2 - raise error\n \"\"\"\n cl = {'atlas':atlas_info, # use lapack_opt or blas_opt instead\n 'atlas_threads':atlas_threads_info, # ditto\n 'atlas_blas':atlas_blas_info,\n 'atlas_blas_threads':atlas_blas_threads_info,\n 'lapack_atlas':lapack_atlas_info, # use lapack_opt instead\n 'lapack_atlas_threads':lapack_atlas_threads_info, # ditto\n 'mkl':mkl_info,\n 'lapack_mkl':lapack_mkl_info, # use lapack_opt instead\n 'blas_mkl':blas_mkl_info, # use blas_opt instead\n 'x11':x11_info,\n 'fft_opt':fft_opt_info,\n 'fftw':fftw_info,\n 'fftw2':fftw2_info,\n 'fftw3':fftw3_info,\n 'dfftw':dfftw_info,\n 'sfftw':sfftw_info,\n 'fftw_threads':fftw_threads_info,\n 'dfftw_threads':dfftw_threads_info,\n 'sfftw_threads':sfftw_threads_info,\n 'djbfft':djbfft_info,\n 'blas':blas_info, # use blas_opt instead\n 'lapack':lapack_info, # use lapack_opt instead\n 'lapack_src':lapack_src_info,\n 'blas_src':blas_src_info,\n 'numpy':numpy_info,\n 'f2py':f2py_info,\n 'Numeric':Numeric_info,\n 'numarray':numarray_info,\n 'lapack_opt':lapack_opt_info,\n 'blas_opt':blas_opt_info,\n 'boost_python':boost_python_info,\n 'agg2':agg2_info,\n 'wx':wx_info,\n 'gdk_pixbuf_xlib_2':gdk_pixbuf_xlib_2_info,\n 'gdk-pixbuf-xlib-2.0':gdk_pixbuf_xlib_2_info,\n 'gdk_pixbuf_2':gdk_pixbuf_2_info,\n 'gdk-pixbuf-2.0':gdk_pixbuf_2_info,\n 'gdk':gdk_info,\n 'gdk_2':gdk_2_info,\n 'gdk-2.0':gdk_2_info,\n 'gdk_x11_2':gdk_x11_2_info,\n 'gdk-x11-2.0':gdk_x11_2_info,\n 'gtkp_x11_2':gtkp_x11_2_info,\n 'gtk+-x11-2.0':gtkp_x11_2_info,\n 'gtkp_2':gtkp_2_info,\n 'gtk+-2.0':gtkp_2_info,\n 'xft':xft_info,\n 'freetype2':freetype2_info,\n }.get(name.lower(),system_info)\n return cl().get_info(notfound_action)\n\nclass NotFoundError(DistutilsError):\n \"\"\"Some third-party program or library is not found.\"\"\"\n\nclass AtlasNotFoundError(NotFoundError):\n \"\"\"\n Atlas (http://math-atlas.sourceforge.net/) libraries not found.\n Directories to search for the libraries can be specified in the\n numpy/distutils/site.cfg file (section [atlas]) or by setting\n the ATLAS environment variable.\"\"\"\n\nclass LapackNotFoundError(NotFoundError):\n \"\"\"\n Lapack (http://www.netlib.org/lapack/) libraries not found.\n Directories to search for the libraries can be specified in the\n numpy/distutils/site.cfg file (section [lapack]) or by setting\n the LAPACK environment variable.\"\"\"\n\nclass LapackSrcNotFoundError(LapackNotFoundError):\n \"\"\"\n Lapack (http://www.netlib.org/lapack/) sources not found.\n Directories to search for the sources can be specified in the\n numpy/distutils/site.cfg file (section [lapack_src]) or by setting\n the LAPACK_SRC environment variable.\"\"\"\n\nclass BlasNotFoundError(NotFoundError):\n \"\"\"\n Blas (http://www.netlib.org/blas/) libraries not found.\n Directories to search for the libraries can be specified in the\n numpy/distutils/site.cfg file (section [blas]) or by setting\n the BLAS environment variable.\"\"\"\n\nclass BlasSrcNotFoundError(BlasNotFoundError):\n \"\"\"\n Blas (http://www.netlib.org/blas/) sources not found.\n Directories to search for the sources can be specified in the\n numpy/distutils/site.cfg file (section [blas_src]) or by setting\n the BLAS_SRC environment variable.\"\"\"\n\nclass FFTWNotFoundError(NotFoundError):\n \"\"\"\n FFTW (http://www.fftw.org/) libraries not found.\n Directories to search for the libraries can be specified in the\n numpy/distutils/site.cfg file (section [fftw]) or by setting\n the FFTW environment variable.\"\"\"\n\nclass DJBFFTNotFoundError(NotFoundError):\n \"\"\"\n DJBFFT (http://cr.yp.to/djbfft.html) libraries not found.\n Directories to search for the libraries can be specified in the\n numpy/distutils/site.cfg file (section [djbfft]) or by setting\n the DJBFFT environment variable.\"\"\"\n\nclass NumericNotFoundError(NotFoundError):\n \"\"\"\n Numeric (http://www.numpy.org/) module not found.\n Get it from above location, install it, and retry setup.py.\"\"\"\n\nclass X11NotFoundError(NotFoundError):\n \"\"\"X11 libraries not found.\"\"\"\n\nclass system_info:\n\n \"\"\" get_info() is the only public method. Don't use others.\n \"\"\"\n section = 'DEFAULT'\n dir_env_var = None\n search_static_first = 0 # XXX: disabled by default, may disappear in\n # future unless it is proved to be useful.\n verbosity = 1\n saved_results = {}\n\n notfounderror = NotFoundError\n\n def __init__ (self,\n default_lib_dirs=default_lib_dirs,\n default_include_dirs=default_include_dirs,\n verbosity = 1,\n ):\n self.__class__.info = {}\n self.local_prefixes = []\n defaults = {}\n defaults['libraries'] = ''\n defaults['library_dirs'] = os.pathsep.join(default_lib_dirs)\n defaults['include_dirs'] = os.pathsep.join(default_include_dirs)\n defaults['src_dirs'] = os.pathsep.join(default_src_dirs)\n defaults['search_static_first'] = str(self.search_static_first)\n self.cp = ConfigParser.ConfigParser(defaults)\n try:\n f = __file__\n except NameError,msg:\n f = sys.argv[0]\n cf = os.path.join(os.path.split(os.path.abspath(f))[0],\n 'site.cfg')\n self.cp.read([cf])\n if not self.cp.has_section(self.section):\n self.cp.add_section(self.section)\n self.search_static_first = self.cp.getboolean(self.section,\n 'search_static_first')\n assert isinstance(self.search_static_first, int)\n\n def calc_libraries_info(self):\n libs = self.get_libraries()\n dirs = self.get_lib_dirs()\n info = {}\n for lib in libs:\n i = None\n for d in dirs:\n i = self.check_libs(d,[lib])\n if i is not None:\n break\n if i is not None:\n dict_append(info,**i)\n else:\n print 'Library %s was not found. Ignoring' % (lib)\n return info\n\n def set_info(self,**info):\n if info:\n lib_info = self.calc_libraries_info()\n dict_append(info,**lib_info)\n self.saved_results[self.__class__.__name__] = info\n\n def has_info(self):\n return self.saved_results.has_key(self.__class__.__name__)\n\n def get_info(self,notfound_action=0):\n \"\"\" Return a dictonary with items that are compatible\n with numpy.distutils.setup keyword arguments.\n \"\"\"\n flag = 0\n if not self.has_info():\n flag = 1\n if self.verbosity>0:\n print self.__class__.__name__ + ':'\n if hasattr(self, 'calc_info'):\n self.calc_info()\n if notfound_action:\n if not self.has_info():\n if notfound_action==1:\n warnings.warn(self.notfounderror.__doc__)\n elif notfound_action==2:\n raise self.notfounderror,self.notfounderror.__doc__\n else:\n raise ValueError(repr(notfound_action))\n\n if self.verbosity>0:\n if not self.has_info():\n print ' NOT AVAILABLE'\n self.set_info()\n else:\n print ' FOUND:'\n\n res = self.saved_results.get(self.__class__.__name__)\n if self.verbosity>0 and flag:\n for k,v in res.items():\n v = str(v)\n if k=='sources' and len(v)>200: v = v[:60]+' ...\\n... '+v[-60:]\n print ' %s = %s'%(k,v)\n print\n\n return res\n\n def get_paths(self, section, key):\n dirs = self.cp.get(section, key).split(os.pathsep)\n env_var = self.dir_env_var\n if env_var:\n if is_sequence(env_var):\n e0 = env_var[-1]\n for e in env_var:\n if os.environ.has_key(e):\n e0 = e\n break\n if not env_var[0]==e0:\n print 'Setting %s=%s' % (env_var[0],e0)\n env_var = e0\n if env_var and os.environ.has_key(env_var):\n d = os.environ[env_var]\n if d=='None':\n print 'Disabled',self.__class__.__name__,'(%s is None)' \\\n % (self.dir_env_var)\n return []\n if os.path.isfile(d):\n dirs = [os.path.dirname(d)] + dirs\n l = getattr(self,'_lib_names',[])\n if len(l)==1:\n b = os.path.basename(d)\n b = os.path.splitext(b)[0]\n if b[:3]=='lib':\n print 'Replacing _lib_names[0]==%r with %r' \\\n % (self._lib_names[0], b[3:])\n self._lib_names[0] = b[3:]\n else:\n ds = d.split(os.pathsep)\n ds2 = []\n for d in ds:\n if os.path.isdir(d):\n ds2.append(d)\n for dd in ['include','lib']:\n d1 = os.path.join(d,dd)\n if os.path.isdir(d1):\n ds2.append(d1)\n dirs = ds2 + dirs\n default_dirs = self.cp.get('DEFAULT', key).split(os.pathsep)\n dirs.extend(default_dirs)\n ret = []\n [ret.append(d) for d in dirs if os.path.isdir(d) and d not in ret]\n if self.verbosity>1:\n print '(',key,'=',':'.join(ret),')'\n return ret\n\n def get_lib_dirs(self, key='library_dirs'):\n return self.get_paths(self.section, key)\n\n def get_include_dirs(self, key='include_dirs'):\n return self.get_paths(self.section, key)\n\n def get_src_dirs(self, key='src_dirs'):\n return self.get_paths(self.section, key)\n\n def get_libs(self, key, default):\n try:\n libs = self.cp.get(self.section, key)\n except ConfigParser.NoOptionError:\n if not default:\n return []\n if is_string(default):\n return [default]\n return default\n return [b for b in [a.strip() for a in libs.split(',')] if b]\n\n def get_libraries(self, key='libraries'):\n return self.get_libs(key,'')\n\n def check_libs(self,lib_dir,libs,opt_libs =[]):\n \"\"\" If static or shared libraries are available then return\n their info dictionary. \"\"\"\n if self.search_static_first:\n exts = ['.a',so_ext]\n else:\n exts = [so_ext,'.a']\n if sys.platform=='cygwin':\n exts.append('.dll.a')\n for ext in exts:\n info = self._check_libs(lib_dir,libs,opt_libs,[ext])\n if info is not None: return info\n return\n\n def check_libs2(self,lib_dir,libs,opt_libs =[]):\n \"\"\" If static or shared libraries are available then return\n their info dictionary. \"\"\"\n if self.search_static_first:\n exts = ['.a',so_ext]\n else:\n exts = [so_ext,'.a']\n if sys.platform=='cygwin':\n exts.append('.dll.a')\n info = self._check_libs(lib_dir,libs,opt_libs,exts)\n if info is not None: return info\n return\n\n def _lib_list(self, lib_dir, libs, exts):\n assert is_string(lib_dir)\n liblist = []\n for l in libs:\n for ext in exts:\n p = self.combine_paths(lib_dir, 'lib'+l+ext)\n if p:\n assert len(p)==1\n liblist.append(p[0])\n break\n return liblist\n\n def _extract_lib_names(self,libs):\n return [os.path.splitext(os.path.basename(p))[0][3:] \\\n for p in libs]\n\n def _check_libs(self,lib_dir,libs, opt_libs, exts):\n found_libs = self._lib_list(lib_dir, libs, exts)\n if len(found_libs) == len(libs):\n found_libs = self._extract_lib_names(found_libs)\n info = {'libraries' : found_libs, 'library_dirs' : [lib_dir]}\n opt_found_libs = self._lib_list(lib_dir, opt_libs, exts)\n if len(opt_found_libs) == len(opt_libs):\n opt_found_libs = self._extract_lib_names(opt_found_libs)\n info['libraries'].extend(opt_found_libs)\n return info\n\n def combine_paths(self,*args):\n return combine_paths(*args,**{'verbosity':self.verbosity})\n\n\nclass fft_opt_info(system_info):\n\n def calc_info(self):\n info = {}\n fftw_info = get_info('fftw3') or get_info('fftw2') or get_info('dfftw')\n djbfft_info = get_info('djbfft')\n if fftw_info:\n dict_append(info,**fftw_info)\n if djbfft_info:\n dict_append(info,**djbfft_info)\n self.set_info(**info)\n return\n\n\nclass fftw_info(system_info):\n #variables to override\n section = 'fftw'\n dir_env_var = 'FFTW'\n notfounderror = FFTWNotFoundError\n ver_info = [ { 'name':'fftw3',\n 'libs':['fftw3'],\n 'includes':['fftw3.h'],\n 'macros':[('SCIPY_FFTW3_H',None)]},\n { 'name':'fftw2',\n 'libs':['rfftw', 'fftw'],\n 'includes':['fftw.h','rfftw.h'],\n 'macros':[('SCIPY_FFTW_H',None)]}]\n\n def __init__(self):\n system_info.__init__(self)\n\n def calc_ver_info(self,ver_param):\n \"\"\"Returns True on successful version detection, else False\"\"\"\n lib_dirs = self.get_lib_dirs()\n incl_dirs = self.get_include_dirs()\n incl_dir = None\n libs = self.get_libs(self.section+'_libs', ver_param['libs'])\n info = None\n for d in lib_dirs:\n r = self.check_libs(d,libs)\n if r is not None:\n info = r\n break\n if info is not None:\n flag = 0\n for d in incl_dirs:\n if len(self.combine_paths(d,ver_param['includes']))==len(ver_param['includes']):\n dict_append(info,include_dirs=[d])\n flag = 1\n incl_dirs = [d]\n incl_dir = d\n break\n if flag:\n dict_append(info,define_macros=ver_param['macros'])\n else:\n info = None\n if info is not None:\n self.set_info(**info)\n return True\n else:\n if self.verbosity>0:\n print ' %s not found' % (ver_param['name'])\n return False\n\n def calc_info(self):\n for i in self.ver_info:\n if self.calc_ver_info(i):\n break\n\nclass fftw2_info(fftw_info):\n #variables to override\n section = 'fftw'\n dir_env_var = 'FFTW'\n notfounderror = FFTWNotFoundError\n ver_info = [ { 'name':'fftw2',\n 'libs':['rfftw', 'fftw'],\n 'includes':['fftw.h','rfftw.h'],\n 'macros':[('SCIPY_FFTW_H',None)]}\n ]\n\nclass fftw3_info(fftw_info):\n #variables to override\n section = 'fftw3'\n dir_env_var = 'FFTW3'\n notfounderror = FFTWNotFoundError\n ver_info = [ { 'name':'fftw3',\n 'libs':['fftw3'],\n 'includes':['fftw3.h'],\n 'macros':[('SCIPY_FFTW3_H',None)]},\n ]\n\nclass dfftw_info(fftw_info):\n section = 'fftw'\n dir_env_var = 'FFTW'\n ver_info = [ { 'name':'dfftw',\n 'libs':['drfftw','dfftw'],\n 'includes':['dfftw.h','drfftw.h'],\n 'macros':[('SCIPY_DFFTW_H',None)]} ]\n\nclass sfftw_info(fftw_info):\n section = 'fftw'\n dir_env_var = 'FFTW'\n ver_info = [ { 'name':'sfftw',\n 'libs':['srfftw','sfftw'],\n 'includes':['sfftw.h','srfftw.h'],\n 'macros':[('SCIPY_SFFTW_H',None)]} ]\n\nclass fftw_threads_info(fftw_info):\n section = 'fftw'\n dir_env_var = 'FFTW'\n ver_info = [ { 'name':'fftw threads',\n 'libs':['rfftw_threads','fftw_threads'],\n 'includes':['fftw_threads.h','rfftw_threads.h'],\n 'macros':[('SCIPY_FFTW_THREADS_H',None)]} ]\n\nclass dfftw_threads_info(fftw_info):\n section = 'fftw'\n dir_env_var = 'FFTW'\n ver_info = [ { 'name':'dfftw threads',\n 'libs':['drfftw_threads','dfftw_threads'],\n 'includes':['dfftw_threads.h','drfftw_threads.h'],\n 'macros':[('SCIPY_DFFTW_THREADS_H',None)]} ]\n\nclass sfftw_threads_info(fftw_info):\n section = 'fftw'\n dir_env_var = 'FFTW'\n ver_info = [ { 'name':'sfftw threads',\n 'libs':['srfftw_threads','sfftw_threads'],\n 'includes':['sfftw_threads.h','srfftw_threads.h'],\n 'macros':[('SCIPY_SFFTW_THREADS_H',None)]} ]\n\nclass djbfft_info(system_info):\n section = 'djbfft'\n dir_env_var = 'DJBFFT'\n notfounderror = DJBFFTNotFoundError\n\n def get_paths(self, section, key):\n pre_dirs = system_info.get_paths(self, section, key)\n dirs = []\n for d in pre_dirs:\n dirs.extend(self.combine_paths(d,['djbfft'])+[d])\n return [ d for d in dirs if os.path.isdir(d) ]\n\n def calc_info(self):\n lib_dirs = self.get_lib_dirs()\n incl_dirs = self.get_include_dirs()\n info = None\n for d in lib_dirs:\n p = self.combine_paths (d,['djbfft.a'])\n if p:\n info = {'extra_objects':p}\n break\n p = self.combine_paths (d,['libdjbfft.a','libdjbfft'+so_ext])\n if p:\n info = {'libraries':['djbfft'],'library_dirs':[d]}\n break\n if info is None:\n return\n for d in incl_dirs:\n if len(self.combine_paths(d,['fftc8.h','fftfreq.h']))==2:\n dict_append(info,include_dirs=[d],\n define_macros=[('SCIPY_DJBFFT_H',None)])\n self.set_info(**info)\n return\n return\n\nclass mkl_info(system_info):\n section = 'mkl'\n dir_env_var = 'MKL'\n _lib_mkl = ['mkl','vml','guide']\n\n def get_mkl_rootdir(self):\n mklroot = os.environ.get('MKLROOT',None)\n if mklroot is not None:\n return mklroot\n paths = os.environ.get('LD_LIBRARY_PATH','').split(os.pathsep)\n ld_so_conf = '/etc/ld.so.conf'\n if os.path.isfile(ld_so_conf):\n for d in open(ld_so_conf,'r').readlines():\n d = d.strip()\n if d: paths.append(d)\n intel_mkl_dirs = []\n for path in paths:\n path_atoms = path.split(os.sep)\n for m in path_atoms:\n if m.startswith('mkl'):\n d = os.sep.join(path_atoms[:path_atoms.index(m)+2])\n intel_mkl_dirs.append(d)\n break\n for d in paths:\n dirs = glob(os.path.join(d,'mkl','*')) + glob(os.path.join(d,'mkl*'))\n for d in dirs:\n if os.path.isdir(os.path.join(d,'lib')):\n return d\n return None\n\n def __init__(self):\n mklroot = self.get_mkl_rootdir()\n if mklroot is None:\n system_info.__init__(self)\n else:\n from cpuinfo import cpu\n if cpu.is_Itanium():\n plt = '64'\n l = 'mkl_ipf'\n elif cpu.is_Xeon():\n plt = 'em64t'\n l = 'mkl_em64t'\n else:\n plt = '32'\n l = 'mkl_ia32'\n if l not in self._lib_mkl:\n self._lib_mkl.insert(0,l)\n system_info.__init__(self,\n default_lib_dirs=[os.path.join(mklroot,'lib',plt)],\n default_include_dirs=[os.path.join(mklroot,'include')])\n\n def calc_info(self):\n lib_dirs = self.get_lib_dirs()\n incl_dirs = self.get_include_dirs()\n mkl_libs = self.get_libs('mkl_libs',self._lib_mkl)\n mkl = None\n for d in lib_dirs:\n mkl = self.check_libs2(d,mkl_libs)\n if mkl is not None:\n break\n if mkl is None:\n return\n info = {}\n dict_append(info,**mkl)\n dict_append(info,libraries = ['pthread'], include_dirs = incl_dirs)\n self.set_info(**info)\n\nclass lapack_mkl_info(mkl_info):\n\n def calc_info(self):\n mkl = get_info('mkl')\n if not mkl:\n return\n lapack_libs = self.get_libs('lapack_libs',['mkl_lapack'])\n info = {'libraries': lapack_libs}\n dict_append(info,**mkl)\n self.set_info(**info)\n\nclass blas_mkl_info(mkl_info):\n pass\n\nclass atlas_info(system_info):\n section = 'atlas'\n dir_env_var = 'ATLAS'\n _lib_names = ['f77blas','cblas']\n if sys.platform[:7]=='freebsd':\n _lib_atlas = ['atlas_r']\n _lib_lapack = ['alapack_r']\n else:\n _lib_atlas = ['atlas']\n _lib_lapack = ['lapack']\n\n notfounderror = AtlasNotFoundError\n\n def get_paths(self, section, key):\n pre_dirs = system_info.get_paths(self, section, key)\n dirs = []\n for d in pre_dirs:\n dirs.extend(self.combine_paths(d,['atlas*','ATLAS*',\n 'sse','3dnow','sse2'])+[d])\n return [ d for d in dirs if os.path.isdir(d) ]\n\n def calc_info(self):\n lib_dirs = self.get_lib_dirs()\n info = {}\n atlas_libs = self.get_libs('atlas_libs',\n self._lib_names + self._lib_atlas)\n lapack_libs = self.get_libs('lapack_libs',self._lib_lapack)\n atlas = None\n lapack = None\n atlas_1 = None\n for d in lib_dirs:\n atlas = self.check_libs(d,atlas_libs,[])\n lapack_atlas = self.check_libs(d,['lapack_atlas'],[])\n if atlas is not None:\n lib_dirs2 = self.combine_paths(d,['atlas*','ATLAS*'])+[d]\n for d2 in lib_dirs2:\n lapack = self.check_libs(d2,lapack_libs,[])\n if lapack is not None:\n break\n else:\n lapack = None\n if lapack is not None:\n break\n if atlas:\n atlas_1 = atlas\n print self.__class__\n if atlas is None:\n atlas = atlas_1\n if atlas is None:\n return\n include_dirs = self.get_include_dirs()\n h = (self.combine_paths(lib_dirs+include_dirs,'cblas.h') or [None])[0]\n if h:\n h = os.path.dirname(h)\n dict_append(info,include_dirs=[h])\n info['language'] = 'c'\n if lapack is not None:\n dict_append(info,**lapack)\n dict_append(info,**atlas)\n elif 'lapack_atlas' in atlas['libraries']:\n dict_append(info,**atlas)\n dict_append(info,define_macros=[('ATLAS_WITH_LAPACK_ATLAS',None)])\n self.set_info(**info)\n return\n else:\n dict_append(info,**atlas)\n dict_append(info,define_macros=[('ATLAS_WITHOUT_LAPACK',None)])\n message = \"\"\"\n*********************************************************************\n Could not find lapack library within the ATLAS installation.\n*********************************************************************\n\"\"\"\n warnings.warn(message)\n self.set_info(**info)\n return\n\n # Check if lapack library is complete, only warn if it is not.\n lapack_dir = lapack['library_dirs'][0]\n lapack_name = lapack['libraries'][0]\n lapack_lib = None\n for e in ['.a',so_ext]:\n fn = os.path.join(lapack_dir,'lib'+lapack_name+e)\n if os.path.exists(fn):\n lapack_lib = fn\n break\n if lapack_lib is not None:\n sz = os.stat(lapack_lib)[6]\n if sz <= 4000*1024:\n message = \"\"\"\n*********************************************************************\n Lapack library (from ATLAS) is probably incomplete:\n size of %s is %sk (expected >4000k)\n\n Follow the instructions in the KNOWN PROBLEMS section of the file\n numpy/INSTALL.txt.\n*********************************************************************\n\"\"\" % (lapack_lib,sz/1024)\n warnings.warn(message)\n else:\n info['language'] = 'f77'\n\n self.set_info(**info)\n\nclass atlas_blas_info(atlas_info):\n _lib_names = ['f77blas','cblas']\n\n def calc_info(self):\n lib_dirs = self.get_lib_dirs()\n info = {}\n atlas_libs = self.get_libs('atlas_libs',\n self._lib_names + self._lib_atlas)\n atlas = None\n for d in lib_dirs:\n atlas = self.check_libs(d,atlas_libs,[])\n if atlas is not None:\n break\n if atlas is None:\n return\n include_dirs = self.get_include_dirs()\n h = (self.combine_paths(lib_dirs+include_dirs,'cblas.h') or [None])[0]\n if h:\n h = os.path.dirname(h)\n dict_append(info,include_dirs=[h])\n info['language'] = 'c'\n\n dict_append(info,**atlas)\n\n self.set_info(**info)\n return\n\n\nclass atlas_threads_info(atlas_info):\n dir_env_var = ['PTATLAS','ATLAS']\n _lib_names = ['ptf77blas','ptcblas']\n\nclass atlas_blas_threads_info(atlas_blas_info):\n dir_env_var = ['PTATLAS','ATLAS']\n _lib_names = ['ptf77blas','ptcblas']\n\nclass lapack_atlas_info(atlas_info):\n _lib_names = ['lapack_atlas'] + atlas_info._lib_names\n\nclass lapack_atlas_threads_info(atlas_threads_info):\n _lib_names = ['lapack_atlas'] + atlas_threads_info._lib_names\n\nclass lapack_info(system_info):\n section = 'lapack'\n dir_env_var = 'LAPACK'\n _lib_names = ['lapack']\n notfounderror = LapackNotFoundError\n\n def calc_info(self):\n lib_dirs = self.get_lib_dirs()\n\n lapack_libs = self.get_libs('lapack_libs', self._lib_names)\n for d in lib_dirs:\n lapack = self.check_libs(d,lapack_libs,[])\n if lapack is not None:\n info = lapack\n break\n else:\n return\n info['language'] = 'f77'\n self.set_info(**info)\n\nclass lapack_src_info(system_info):\n section = 'lapack_src'\n dir_env_var = 'LAPACK_SRC'\n notfounderror = LapackSrcNotFoundError\n\n def get_paths(self, section, key):\n pre_dirs = system_info.get_paths(self, section, key)\n dirs = []\n for d in pre_dirs:\n dirs.extend([d] + self.combine_paths(d,['LAPACK*/SRC','SRC']))\n return [ d for d in dirs if os.path.isdir(d) ]\n\n def calc_info(self):\n src_dirs = self.get_src_dirs()\n src_dir = ''\n for d in src_dirs:\n if os.path.isfile(os.path.join(d,'dgesv.f')):\n src_dir = d\n break\n if not src_dir:\n #XXX: Get sources from netlib. May be ask first.\n return\n # The following is extracted from LAPACK-3.0/SRC/Makefile\n allaux='''\n ilaenv ieeeck lsame lsamen xerbla\n ''' # *.f\n laux = '''\n bdsdc bdsqr disna labad lacpy ladiv lae2 laebz laed0 laed1\n laed2 laed3 laed4 laed5 laed6 laed7 laed8 laed9 laeda laev2\n lagtf lagts lamch lamrg lanst lapy2 lapy3 larnv larrb larre\n larrf lartg laruv las2 lascl lasd0 lasd1 lasd2 lasd3 lasd4\n lasd5 lasd6 lasd7 lasd8 lasd9 lasda lasdq lasdt laset lasq1\n lasq2 lasq3 lasq4 lasq5 lasq6 lasr lasrt lassq lasv2 pttrf\n stebz stedc steqr sterf\n ''' # [s|d]*.f\n lasrc = '''\n gbbrd gbcon gbequ gbrfs gbsv gbsvx gbtf2 gbtrf gbtrs gebak\n gebal gebd2 gebrd gecon geequ gees geesx geev geevx gegs gegv\n gehd2 gehrd gelq2 gelqf gels gelsd gelss gelsx gelsy geql2\n geqlf geqp3 geqpf geqr2 geqrf gerfs gerq2 gerqf gesc2 gesdd\n gesv gesvd gesvx getc2 getf2 getrf getri getrs ggbak ggbal\n gges ggesx ggev ggevx ggglm gghrd gglse ggqrf ggrqf ggsvd\n ggsvp gtcon gtrfs gtsv gtsvx gttrf gttrs gtts2 hgeqz hsein\n hseqr labrd lacon laein lags2 lagtm lahqr lahrd laic1 lals0\n lalsa lalsd langb lange langt lanhs lansb lansp lansy lantb\n lantp lantr lapll lapmt laqgb laqge laqp2 laqps laqsb laqsp\n laqsy lar1v lar2v larf larfb larfg larft larfx largv larrv\n lartv larz larzb larzt laswp lasyf latbs latdf latps latrd\n latrs latrz latzm lauu2 lauum pbcon pbequ pbrfs pbstf pbsv\n pbsvx pbtf2 pbtrf pbtrs pocon poequ porfs posv posvx potf2\n potrf potri potrs ppcon ppequ pprfs ppsv ppsvx pptrf pptri\n pptrs ptcon pteqr ptrfs ptsv ptsvx pttrs ptts2 spcon sprfs\n spsv spsvx sptrf sptri sptrs stegr stein sycon syrfs sysv\n sysvx sytf2 sytrf sytri sytrs tbcon tbrfs tbtrs tgevc tgex2\n tgexc tgsen tgsja tgsna tgsy2 tgsyl tpcon tprfs tptri tptrs\n trcon trevc trexc trrfs trsen trsna trsyl trti2 trtri trtrs\n tzrqf tzrzf\n ''' # [s|c|d|z]*.f\n sd_lasrc = '''\n laexc lag2 lagv2 laln2 lanv2 laqtr lasy2 opgtr opmtr org2l\n org2r orgbr orghr orgl2 orglq orgql orgqr orgr2 orgrq orgtr\n orm2l orm2r ormbr ormhr orml2 ormlq ormql ormqr ormr2 ormr3\n ormrq ormrz ormtr rscl sbev sbevd sbevx sbgst sbgv sbgvd sbgvx\n sbtrd spev spevd spevx spgst spgv spgvd spgvx sptrd stev stevd\n stevr stevx syev syevd syevr syevx sygs2 sygst sygv sygvd\n sygvx sytd2 sytrd\n ''' # [s|d]*.f\n cz_lasrc = '''\n bdsqr hbev hbevd hbevx hbgst hbgv hbgvd hbgvx hbtrd hecon heev\n heevd heevr heevx hegs2 hegst hegv hegvd hegvx herfs hesv\n hesvx hetd2 hetf2 hetrd hetrf hetri hetrs hpcon hpev hpevd\n hpevx hpgst hpgv hpgvd hpgvx hprfs hpsv hpsvx hptrd hptrf\n hptri hptrs lacgv lacp2 lacpy lacrm lacrt ladiv laed0 laed7\n laed8 laesy laev2 lahef lanhb lanhe lanhp lanht laqhb laqhe\n laqhp larcm larnv lartg lascl laset lasr lassq pttrf rot spmv\n spr stedc steqr symv syr ung2l ung2r ungbr unghr ungl2 unglq\n ungql ungqr ungr2 ungrq ungtr unm2l unm2r unmbr unmhr unml2\n unmlq unmql unmqr unmr2 unmr3 unmrq unmrz unmtr upgtr upmtr\n ''' # [c|z]*.f\n #######\n sclaux = laux + ' econd ' # s*.f\n dzlaux = laux + ' secnd ' # d*.f\n slasrc = lasrc + sd_lasrc # s*.f\n dlasrc = lasrc + sd_lasrc # d*.f\n clasrc = lasrc + cz_lasrc + ' srot srscl ' # c*.f\n zlasrc = lasrc + cz_lasrc + ' drot drscl ' # z*.f\n oclasrc = ' icmax1 scsum1 ' # *.f\n ozlasrc = ' izmax1 dzsum1 ' # *.f\n sources = ['s%s.f'%f for f in (sclaux+slasrc).split()] \\\n + ['d%s.f'%f for f in (dzlaux+dlasrc).split()] \\\n + ['c%s.f'%f for f in (clasrc).split()] \\\n + ['z%s.f'%f for f in (zlasrc).split()] \\\n + ['%s.f'%f for f in (allaux+oclasrc+ozlasrc).split()]\n sources = [os.path.join(src_dir,f) for f in sources]\n #XXX: should we check here actual existence of source files?\n info = {'sources':sources,'language':'f77'}\n self.set_info(**info)\n\natlas_version_c_text = r'''\n/* This file is generated from numpy_distutils/system_info.py */\n#ifdef __CPLUSPLUS__\nextern \"C\" {\n#endif\n#include \"Python.h\"\nstatic PyMethodDef module_methods[] = { {NULL,NULL} };\nDL_EXPORT(void) initatlas_version(void) {\n void ATL_buildinfo(void);\n ATL_buildinfo();\n Py_InitModule(\"atlas_version\", module_methods);\n}\n#ifdef __CPLUSCPLUS__\n}\n#endif\n'''\n\ndef _get_build_temp():\n from distutils.util import get_platform\n plat_specifier = \".%s-%s\" % (get_platform(), sys.version[0:3])\n return os.path.join('build','temp'+plat_specifier)\n\ndef get_atlas_version(**config):\n os.environ['NO_SCIPY_IMPORT']='get_atlas_version'\n from core import Extension, setup\n from misc_util import get_cmd\n import log\n magic = hex(hash(repr(config)))\n def atlas_version_c(extension, build_dir,magic=magic):\n source = os.path.join(build_dir,'atlas_version_%s.c' % (magic))\n if os.path.isfile(source):\n from distutils.dep_util import newer\n if newer(source,__file__):\n return source\n f = open(source,'w')\n f.write(atlas_version_c_text)\n f.close()\n return source\n ext = Extension('atlas_version',\n sources=[atlas_version_c],\n **config)\n build_dir = _get_build_temp()\n extra_args = ['--build-lib',build_dir]\n for a in sys.argv:\n if re.match('[-][-]compiler[=]',a):\n extra_args.append(a)\n import distutils.core\n old_dist = distutils.core._setup_distribution\n distutils.core._setup_distribution = None\n try:\n dist = setup(ext_modules=[ext],\n script_name = 'get_atlas_version',\n script_args = ['build_src','build_ext']+extra_args)\n except Exception,msg:\n print \"##### msg: %s\" % msg\n if not msg:\n msg = \"Unknown Exception\"\n log.warn(msg)\n return None\n distutils.core._setup_distribution = old_dist\n\n from distutils.sysconfig import get_config_var\n so_ext = get_config_var('SO')\n target = os.path.join(build_dir,'atlas_version'+so_ext)\n cmd = [get_pythonexe(),'-c',\n '\"import imp,os;os.environ[\\\\\"NO_SCIPY_IMPORT\\\\\"]='\\\n '\\\\\"system_info.get_atlas_version:load atlas_version\\\\\";'\\\n 'imp.load_dynamic(\\\\\"atlas_version\\\\\",\\\\\"%s\\\\\")\"'\\\n % (os.path.basename(target))]\n s,o = exec_command(cmd,execute_in=os.path.dirname(target),use_tee=0)\n atlas_version = None\n if not s:\n m = re.search(r'ATLAS version (?P\\d+[.]\\d+[.]\\d+)',o)\n if m:\n atlas_version = m.group('version')\n if atlas_version is None:\n if re.search(r'undefined symbol: ATL_buildinfo',o,re.M):\n atlas_version = '3.2.1_pre3.3.6'\n else:\n print 'Command:',' '.join(cmd)\n print 'Status:',s\n print 'Output:',o\n return atlas_version\n\n\nclass lapack_opt_info(system_info):\n\n def calc_info(self):\n\n if sys.platform=='darwin' and not os.environ.get('ATLAS',None):\n args = []\n link_args = []\n if os.path.exists('/System/Library/Frameworks/Accelerate.framework/'):\n args.extend(['-faltivec'])\n link_args.extend(['-Wl,-framework','-Wl,Accelerate'])\n elif os.path.exists('/System/Library/Frameworks/vecLib.framework/'):\n args.extend(['-faltivec'])\n link_args.extend(['-Wl,-framework','-Wl,vecLib'])\n if args:\n self.set_info(extra_compile_args=args,\n extra_link_args=link_args,\n define_macros=[('NO_ATLAS_INFO',3)])\n return\n\n lapack_mkl_info = get_info('lapack_mkl')\n if lapack_mkl_info:\n self.set_info(**lapack_mkl_info)\n return\n\n atlas_info = get_info('atlas_threads')\n if not atlas_info:\n atlas_info = get_info('atlas')\n #atlas_info = {} ## uncomment for testing\n atlas_version = None\n need_lapack = 0\n need_blas = 0\n info = {}\n if atlas_info:\n version_info = atlas_info.copy()\n atlas_version = get_atlas_version(**version_info)\n if not atlas_info.has_key('define_macros'):\n atlas_info['define_macros'] = []\n if atlas_version is None:\n atlas_info['define_macros'].append(('NO_ATLAS_INFO',2))\n else:\n atlas_info['define_macros'].append(('ATLAS_INFO',\n '\"\\\\\"%s\\\\\"\"' % atlas_version))\n\t\tif atlas_version=='3.2.1_pre3.3.6':\n\t\t atlas_info['define_macros'].append(('NO_ATLAS_INFO',4))\n l = atlas_info.get('define_macros',[])\n if ('ATLAS_WITH_LAPACK_ATLAS',None) in l \\\n or ('ATLAS_WITHOUT_LAPACK',None) in l:\n need_lapack = 1\n info = atlas_info\n else:\n warnings.warn(AtlasNotFoundError.__doc__)\n need_blas = 1\n need_lapack = 1\n dict_append(info,define_macros=[('NO_ATLAS_INFO',1)])\n\n if need_lapack:\n lapack_info = get_info('lapack')\n #lapack_info = {} ## uncomment for testing\n if lapack_info:\n dict_append(info,**lapack_info)\n else:\n warnings.warn(LapackNotFoundError.__doc__)\n lapack_src_info = get_info('lapack_src')\n if not lapack_src_info:\n warnings.warn(LapackSrcNotFoundError.__doc__)\n return\n dict_append(info,libraries=[('flapack_src',lapack_src_info)])\n\n if need_blas:\n blas_info = get_info('blas')\n #blas_info = {} ## uncomment for testing\n if blas_info:\n dict_append(info,**blas_info)\n else:\n warnings.warn(BlasNotFoundError.__doc__)\n blas_src_info = get_info('blas_src')\n if not blas_src_info:\n warnings.warn(BlasSrcNotFoundError.__doc__)\n return\n dict_append(info,libraries=[('fblas_src',blas_src_info)])\n\n self.set_info(**info)\n return\n\n\nclass blas_opt_info(system_info):\n\n def calc_info(self):\n\n if sys.platform=='darwin' and not os.environ.get('ATLAS',None):\n args = []\n link_args = []\n if os.path.exists('/System/Library/Frameworks/Accelerate.framework/'):\n args.extend(['-faltivec',\n '-I/System/Library/Frameworks/vecLib.framework/Headers',\n ])\n link_args.extend(['-Wl,-framework','-Wl,Accelerate'])\n elif os.path.exists('/System/Library/Frameworks/vecLib.framework/'):\n args.extend(['-faltivec',\n '-I/System/Library/Frameworks/vecLib.framework/Headers',\n ])\n link_args.extend(['-Wl,-framework','-Wl,vecLib'])\n if args:\n self.set_info(extra_compile_args=args,\n extra_link_args=link_args,\n define_macros=[('NO_ATLAS_INFO',3)])\n return\n\n blas_mkl_info = get_info('blas_mkl')\n if blas_mkl_info:\n self.set_info(**blas_mkl_info)\n return\n\n atlas_info = get_info('atlas_blas_threads')\n if not atlas_info:\n atlas_info = get_info('atlas_blas')\n atlas_version = None\n need_blas = 0\n info = {}\n if atlas_info:\n version_info = atlas_info.copy()\n atlas_version = get_atlas_version(**version_info)\n if not atlas_info.has_key('define_macros'):\n atlas_info['define_macros'] = []\n if atlas_version is None:\n atlas_info['define_macros'].append(('NO_ATLAS_INFO',2))\n else:\n atlas_info['define_macros'].append(('ATLAS_INFO',\n '\"\\\\\"%s\\\\\"\"' % atlas_version))\n info = atlas_info\n else:\n warnings.warn(AtlasNotFoundError.__doc__)\n need_blas = 1\n dict_append(info,define_macros=[('NO_ATLAS_INFO',1)])\n\n if need_blas:\n blas_info = get_info('blas')\n if blas_info:\n dict_append(info,**blas_info)\n else:\n warnings.warn(BlasNotFoundError.__doc__)\n blas_src_info = get_info('blas_src')\n if not blas_src_info:\n warnings.warn(BlasSrcNotFoundError.__doc__)\n return\n dict_append(info,libraries=[('fblas_src',blas_src_info)])\n\n self.set_info(**info)\n return\n\n\nclass blas_info(system_info):\n section = 'blas'\n dir_env_var = 'BLAS'\n _lib_names = ['blas']\n notfounderror = BlasNotFoundError\n\n def calc_info(self):\n lib_dirs = self.get_lib_dirs()\n\n blas_libs = self.get_libs('blas_libs', self._lib_names)\n for d in lib_dirs:\n blas = self.check_libs(d,blas_libs,[])\n if blas is not None:\n info = blas\n break\n else:\n return\n info['language'] = 'f77' # XXX: is it generally true?\n self.set_info(**info)\n\n\nclass blas_src_info(system_info):\n section = 'blas_src'\n dir_env_var = 'BLAS_SRC'\n notfounderror = BlasSrcNotFoundError\n\n def get_paths(self, section, key):\n pre_dirs = system_info.get_paths(self, section, key)\n dirs = []\n for d in pre_dirs:\n dirs.extend([d] + self.combine_paths(d,['blas']))\n return [ d for d in dirs if os.path.isdir(d) ]\n\n def calc_info(self):\n src_dirs = self.get_src_dirs()\n src_dir = ''\n for d in src_dirs:\n if os.path.isfile(os.path.join(d,'daxpy.f')):\n src_dir = d\n break\n if not src_dir:\n #XXX: Get sources from netlib. May be ask first.\n return\n blas1 = '''\n caxpy csscal dnrm2 dzasum saxpy srotg zdotc ccopy cswap drot\n dznrm2 scasum srotm zdotu cdotc dasum drotg icamax scnrm2\n srotmg zdrot cdotu daxpy drotm idamax scopy sscal zdscal crotg\n dcabs1 drotmg isamax sdot sswap zrotg cscal dcopy dscal izamax\n snrm2 zaxpy zscal csrot ddot dswap sasum srot zcopy zswap\n '''\n blas2 = '''\n cgbmv chpmv ctrsv dsymv dtrsv sspr2 strmv zhemv ztpmv cgemv\n chpr dgbmv dsyr lsame ssymv strsv zher ztpsv cgerc chpr2 dgemv\n dsyr2 sgbmv ssyr xerbla zher2 ztrmv cgeru ctbmv dger dtbmv\n sgemv ssyr2 zgbmv zhpmv ztrsv chbmv ctbsv dsbmv dtbsv sger\n stbmv zgemv zhpr chemv ctpmv dspmv dtpmv ssbmv stbsv zgerc\n zhpr2 cher ctpsv dspr dtpsv sspmv stpmv zgeru ztbmv cher2\n ctrmv dspr2 dtrmv sspr stpsv zhbmv ztbsv\n '''\n blas3 = '''\n cgemm csymm ctrsm dsyrk sgemm strmm zhemm zsyr2k chemm csyr2k\n dgemm dtrmm ssymm strsm zher2k zsyrk cher2k csyrk dsymm dtrsm\n ssyr2k zherk ztrmm cherk ctrmm dsyr2k ssyrk zgemm zsymm ztrsm\n '''\n sources = [os.path.join(src_dir,f+'.f') \\\n for f in (blas1+blas2+blas3).split()]\n #XXX: should we check here actual existence of source files?\n info = {'sources':sources,'language':'f77'}\n self.set_info(**info)\n\nclass x11_info(system_info):\n section = 'x11'\n notfounderror = X11NotFoundError\n\n def __init__(self):\n system_info.__init__(self,\n default_lib_dirs=default_x11_lib_dirs,\n default_include_dirs=default_x11_include_dirs)\n\n def calc_info(self):\n if sys.platform in ['win32']:\n return\n lib_dirs = self.get_lib_dirs()\n include_dirs = self.get_include_dirs()\n x11_libs = self.get_libs('x11_libs', ['X11'])\n for lib_dir in lib_dirs:\n info = self.check_libs(lib_dir, x11_libs, [])\n if info is not None:\n break\n else:\n return\n inc_dir = None\n for d in include_dirs:\n if self.combine_paths(d, 'X11/X.h'):\n inc_dir = d\n break\n if inc_dir is not None:\n dict_append(info, include_dirs=[inc_dir])\n self.set_info(**info)\n\nclass _numpy_info(system_info):\n section = 'Numeric'\n modulename = 'Numeric'\n notfounderror = NumericNotFoundError\n\n def __init__(self):\n from distutils.sysconfig import get_python_inc\n include_dirs = []\n try:\n module = __import__(self.modulename)\n prefix = []\n for name in module.__file__.split(os.sep):\n if name=='lib':\n break\n prefix.append(name)\n include_dirs.append(get_python_inc(prefix=os.sep.join(prefix)))\n except ImportError:\n pass\n py_incl_dir = get_python_inc()\n include_dirs.append(py_incl_dir)\n for d in default_include_dirs:\n d = os.path.join(d, os.path.basename(py_incl_dir))\n if d not in include_dirs:\n include_dirs.append(d)\n system_info.__init__(self,\n default_lib_dirs=[],\n default_include_dirs=include_dirs)\n\n def calc_info(self):\n try:\n module = __import__(self.modulename)\n except ImportError:\n return\n info = {}\n macros = []\n for v in ['__version__','version']:\n vrs = getattr(module,v,None)\n if vrs is None:\n continue\n macros = [(self.modulename.upper()+'_VERSION',\n '\"\\\\\"%s\\\\\"\"' % (vrs)),\n (self.modulename.upper(),None)]\n break\n## try:\n## macros.append(\n## (self.modulename.upper()+'_VERSION_HEX',\n## hex(vstr2hex(module.__version__))),\n## )\n## except Exception,msg:\n## print msg\n dict_append(info, define_macros = macros)\n include_dirs = self.get_include_dirs()\n inc_dir = None\n for d in include_dirs:\n if self.combine_paths(d,\n os.path.join(self.modulename,\n 'arrayobject.h')):\n inc_dir = d\n break\n if inc_dir is not None:\n dict_append(info, include_dirs=[inc_dir])\n if info:\n self.set_info(**info)\n return\n\nclass numarray_info(_numpy_info):\n section = 'numarray'\n modulename = 'numarray'\n\nclass Numeric_info(_numpy_info):\n section = 'Numeric'\n modulename = 'Numeric'\n\nclass numpy_info(_numpy_info):\n section = 'numpy'\n modulename = 'numpy'\n\nclass f2py_info(system_info):\n def calc_info(self):\n try:\n import numpy.f2py as f2py\n except ImportError:\n return\n f2py_dir = os.path.join(os.path.dirname(f2py.__file__),'src')\n self.set_info(sources = [os.path.join(f2py_dir,'fortranobject.c')],\n include_dirs = [f2py_dir])\n return\n\nclass boost_python_info(system_info):\n section = 'boost_python'\n dir_env_var = 'BOOST'\n\n def get_paths(self, section, key):\n pre_dirs = system_info.get_paths(self, section, key)\n dirs = []\n for d in pre_dirs:\n dirs.extend([d] + self.combine_paths(d,['boost*']))\n return [ d for d in dirs if os.path.isdir(d) ]\n\n def calc_info(self):\n from distutils.sysconfig import get_python_inc\n src_dirs = self.get_src_dirs()\n src_dir = ''\n for d in src_dirs:\n if os.path.isfile(os.path.join(d,'libs','python','src','module.cpp')):\n src_dir = d\n break\n if not src_dir:\n return\n py_incl_dir = get_python_inc()\n srcs_dir = os.path.join(src_dir,'libs','python','src')\n bpl_srcs = glob(os.path.join(srcs_dir,'*.cpp'))\n bpl_srcs += glob(os.path.join(srcs_dir,'*','*.cpp'))\n info = {'libraries':[('boost_python_src',{'include_dirs':[src_dir,py_incl_dir],\n 'sources':bpl_srcs})],\n 'include_dirs':[src_dir],\n }\n if info:\n self.set_info(**info)\n return\n\nclass agg2_info(system_info):\n section = 'agg2'\n dir_env_var = 'AGG2'\n\n def get_paths(self, section, key):\n pre_dirs = system_info.get_paths(self, section, key)\n dirs = []\n for d in pre_dirs:\n dirs.extend([d] + self.combine_paths(d,['agg2*']))\n return [ d for d in dirs if os.path.isdir(d) ]\n\n def calc_info(self):\n src_dirs = self.get_src_dirs()\n src_dir = ''\n for d in src_dirs:\n if os.path.isfile(os.path.join(d,'src','agg_affine_matrix.cpp')):\n src_dir = d\n break\n if not src_dir:\n return\n if sys.platform=='win32':\n agg2_srcs = glob(os.path.join(src_dir,'src','platform','win32','agg_win32_bmp.cpp'))\n else:\n agg2_srcs = glob(os.path.join(src_dir,'src','*.cpp'))\n agg2_srcs += [os.path.join(src_dir,'src','platform','X11','agg_platform_support.cpp')]\n\n info = {'libraries':[('agg2_src',{'sources':agg2_srcs,\n 'include_dirs':[os.path.join(src_dir,'include')],\n })],\n 'include_dirs':[os.path.join(src_dir,'include')],\n }\n if info:\n self.set_info(**info)\n return\n\nclass _pkg_config_info(system_info):\n section = None\n config_env_var = 'PKG_CONFIG'\n default_config_exe = 'pkg-config'\n append_config_exe = ''\n version_macro_name = None\n release_macro_name = None\n version_flag = '--modversion'\n cflags_flag = '--cflags'\n\n def get_config_exe(self):\n if os.environ.has_key(self.config_env_var):\n return os.environ[self.config_env_var]\n return self.default_config_exe\n def get_config_output(self, config_exe, option):\n s,o = exec_command(config_exe+' '+self.append_config_exe+' '+option,use_tee=0)\n if not s:\n return o\n\n def calc_info(self):\n config_exe = find_executable(self.get_config_exe())\n if not os.path.isfile(config_exe):\n print 'File not found: %s. Cannot determine %s info.' \\\n % (config_exe, self.section)\n return\n info = {}\n macros = []\n libraries = []\n library_dirs = []\n include_dirs = []\n extra_link_args = []\n extra_compile_args = []\n version = self.get_config_output(config_exe,self.version_flag)\n if version:\n macros.append((self.__class__.__name__.split('.')[-1].upper(),\n '\"\\\\\"%s\\\\\"\"' % (version)))\n if self.version_macro_name:\n macros.append((self.version_macro_name+'_%s' % (version.replace('.','_')),None))\n if self.release_macro_name:\n release = self.get_config_output(config_exe,'--release')\n if release:\n macros.append((self.release_macro_name+'_%s' % (release.replace('.','_')),None))\n opts = self.get_config_output(config_exe,'--libs')\n if opts:\n for opt in opts.split():\n if opt[:2]=='-l':\n libraries.append(opt[2:])\n elif opt[:2]=='-L':\n library_dirs.append(opt[2:])\n else:\n extra_link_args.append(opt)\n opts = self.get_config_output(config_exe,self.cflags_flag)\n if opts:\n for opt in opts.split():\n if opt[:2]=='-I':\n include_dirs.append(opt[2:])\n elif opt[:2]=='-D':\n if '=' in opt:\n n,v = opt[2:].split('=')\n macros.append((n,v))\n else:\n macros.append((opt[2:],None))\n else:\n extra_compile_args.append(opt)\n if macros: dict_append(info, define_macros = macros)\n if libraries: dict_append(info, libraries = libraries)\n if library_dirs: dict_append(info, library_dirs = library_dirs)\n if include_dirs: dict_append(info, include_dirs = include_dirs)\n if extra_link_args: dict_append(info, extra_link_args = extra_link_args)\n if extra_compile_args: dict_append(info, extra_compile_args = extra_compile_args)\n if info:\n self.set_info(**info)\n return\n\nclass wx_info(_pkg_config_info):\n section = 'wx'\n config_env_var = 'WX_CONFIG'\n default_config_exe = 'wx-config'\n append_config_exe = ''\n version_macro_name = 'WX_VERSION'\n release_macro_name = 'WX_RELEASE'\n version_flag = '--version'\n cflags_flag = '--cxxflags'\n\nclass gdk_pixbuf_xlib_2_info(_pkg_config_info):\n section = 'gdk_pixbuf_xlib_2'\n append_config_exe = 'gdk-pixbuf-xlib-2.0'\n version_macro_name = 'GDK_PIXBUF_XLIB_VERSION'\n\nclass gdk_pixbuf_2_info(_pkg_config_info):\n section = 'gdk_pixbuf_2'\n append_config_exe = 'gdk-pixbuf-2.0'\n version_macro_name = 'GDK_PIXBUF_VERSION'\n\nclass gdk_x11_2_info(_pkg_config_info):\n section = 'gdk_x11_2'\n append_config_exe = 'gdk-x11-2.0'\n version_macro_name = 'GDK_X11_VERSION'\n\nclass gdk_2_info(_pkg_config_info):\n section = 'gdk_2'\n append_config_exe = 'gdk-2.0'\n version_macro_name = 'GDK_VERSION'\n\nclass gdk_info(_pkg_config_info):\n section = 'gdk'\n append_config_exe = 'gdk'\n version_macro_name = 'GDK_VERSION'\n\nclass gtkp_x11_2_info(_pkg_config_info):\n section = 'gtkp_x11_2'\n append_config_exe = 'gtk+-x11-2.0'\n version_macro_name = 'GTK_X11_VERSION'\n\n\nclass gtkp_2_info(_pkg_config_info):\n section = 'gtkp_2'\n append_config_exe = 'gtk+-2.0'\n version_macro_name = 'GTK_VERSION'\n\nclass xft_info(_pkg_config_info):\n section = 'xft'\n append_config_exe = 'xft'\n version_macro_name = 'XFT_VERSION'\n\nclass freetype2_info(_pkg_config_info):\n section = 'freetype2'\n append_config_exe = 'freetype2'\n version_macro_name = 'FREETYPE2_VERSION'\n\n## def vstr2hex(version):\n## bits = []\n## n = [24,16,8,4,0]\n## r = 0\n## for s in version.split('.'):\n## r |= int(s) << n[0]\n## del n[0]\n## return r\n\n#--------------------------------------------------------------------\n\ndef combine_paths(*args,**kws):\n \"\"\" Return a list of existing paths composed by all combinations of\n items from arguments.\n \"\"\"\n r = []\n for a in args:\n if not a: continue\n if is_string(a):\n a = [a]\n r.append(a)\n args = r\n if not args: return []\n if len(args)==1:\n result = reduce(lambda a,b:a+b,map(glob,args[0]),[])\n elif len (args)==2:\n result = []\n for a0 in args[0]:\n for a1 in args[1]:\n result.extend(glob(os.path.join(a0,a1)))\n else:\n result = combine_paths(*(combine_paths(args[0],args[1])+args[2:]))\n verbosity = kws.get('verbosity',1)\n if verbosity>1 and result:\n print '(','paths:',','.join(result),')'\n return result\n\nlanguage_map = {'c':0,'c++':1,'f77':2,'f90':3}\ninv_language_map = {0:'c',1:'c++',2:'f77',3:'f90'}\ndef dict_append(d,**kws):\n languages = []\n for k,v in kws.items():\n if k=='language':\n languages.append(v)\n continue\n if d.has_key(k):\n if k in ['library_dirs','include_dirs','define_macros']:\n [d[k].append(vv) for vv in v if vv not in d[k]]\n else:\n d[k].extend(v)\n else:\n d[k] = v\n if languages:\n l = inv_language_map[max([language_map.get(l,0) for l in languages])]\n d['language'] = l\n return\n\ndef show_all():\n import system_info\n import pprint\n match_info = re.compile(r'.*?_info').match\n show_only = []\n for n in sys.argv[1:]:\n if n[-5:] != '_info':\n n = n + '_info'\n show_only.append(n)\n show_all = not show_only\n for n in filter(match_info,dir(system_info)):\n if n in ['system_info','get_info']: continue\n if not show_all:\n if n not in show_only: continue\n del show_only[show_only.index(n)]\n c = getattr(system_info,n)()\n c.verbosity = 2\n r = c.get_info()\n if show_only:\n print 'Info classes not defined:',','.join(show_only)\nif __name__ == \"__main__\":\n show_all()\n", + "methods": [ + { + "name": "get_info", + "long_name": "get_info( name , notfound_action = 0 )", + "filename": "system_info.py", + "nloc": 51, + "complexity": 1, + "token_count": 226, + "parameters": [ + "name", + "notfound_action" + ], + "start_line": 146, + "end_line": 202, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 57, + "top_nesting_level": 0 + }, + { + "name": "__init__", + "long_name": "__init__( self , default_lib_dirs = default_lib_dirs , default_include_dirs = default_include_dirs , verbosity = 1 , )", + "filename": "system_info.py", + "nloc": 26, + "complexity": 3, + "token_count": 207, + "parameters": [ + "self", + "default_lib_dirs", + "default_include_dirs", + "verbosity" + ], + "start_line": 277, + "end_line": 302, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 26, + "top_nesting_level": 1 + }, + { + "name": "calc_libraries_info", + "long_name": "calc_libraries_info( self )", + "filename": "system_info.py", + "nloc": 15, + "complexity": 5, + "token_count": 78, + "parameters": [ + "self" + ], + "start_line": 304, + "end_line": 318, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 15, + "top_nesting_level": 1 + }, + { + "name": "set_info", + "long_name": "set_info( self , ** info )", + "filename": "system_info.py", + "nloc": 5, + "complexity": 2, + "token_count": 37, + "parameters": [ + "self", + "info" + ], + "start_line": 320, + "end_line": 324, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 5, + "top_nesting_level": 1 + }, + { + "name": "has_info", + "long_name": "has_info( self )", + "filename": "system_info.py", + "nloc": 2, + "complexity": 1, + "token_count": 18, + "parameters": [ + "self" + ], + "start_line": 326, + "end_line": 327, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 1 + }, + { + "name": "get_info", + "long_name": "get_info( self , notfound_action = 0 )", + "filename": "system_info.py", + "nloc": 30, + "complexity": 15, + "token_count": 208, + "parameters": [ + "self", + "notfound_action" + ], + "start_line": 329, + "end_line": 364, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 36, + "top_nesting_level": 1 + }, + { + "name": "get_paths", + "long_name": "get_paths( self , section , key )", + "filename": "system_info.py", + "nloc": 47, + "complexity": 20, + "token_count": 399, + "parameters": [ + "self", + "section", + "key" + ], + "start_line": 366, + "end_line": 412, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 47, + "top_nesting_level": 1 + }, + { + "name": "get_lib_dirs", + "long_name": "get_lib_dirs( self , key = 'library_dirs' )", + "filename": "system_info.py", + "nloc": 2, + "complexity": 1, + "token_count": 20, + "parameters": [ + "self", + "key" + ], + "start_line": 414, + "end_line": 415, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 1 + }, + { + "name": "get_include_dirs", + "long_name": "get_include_dirs( self , key = 'include_dirs' )", + "filename": "system_info.py", + "nloc": 2, + "complexity": 1, + "token_count": 20, + "parameters": [ + "self", + "key" + ], + "start_line": 417, + "end_line": 418, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 1 + }, + { + "name": "get_src_dirs", + "long_name": "get_src_dirs( self , key = 'src_dirs' )", + "filename": "system_info.py", + "nloc": 2, + "complexity": 1, + "token_count": 20, + "parameters": [ + "self", + "key" + ], + "start_line": 420, + "end_line": 421, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 1 + }, + { + "name": "get_libs", + "long_name": "get_libs( self , key , default )", + "filename": "system_info.py", + "nloc": 10, + "complexity": 7, + "token_count": 74, + "parameters": [ + "self", + "key", + "default" + ], + "start_line": 423, + "end_line": 432, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 10, + "top_nesting_level": 1 + }, + { + "name": "get_libraries", + "long_name": "get_libraries( self , key = 'libraries' )", + "filename": "system_info.py", + "nloc": 2, + "complexity": 1, + "token_count": 18, + "parameters": [ + "self", + "key" + ], + "start_line": 434, + "end_line": 435, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 1 + }, + { + "name": "check_libs", + "long_name": "check_libs( self , lib_dir , libs , opt_libs = [ ] )", + "filename": "system_info.py", + "nloc": 11, + "complexity": 5, + "token_count": 79, + "parameters": [ + "self", + "lib_dir", + "libs", + "opt_libs" + ], + "start_line": 437, + "end_line": 449, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 13, + "top_nesting_level": 1 + }, + { + "name": "check_libs2", + "long_name": "check_libs2( self , lib_dir , libs , opt_libs = [ ] )", + "filename": "system_info.py", + "nloc": 10, + "complexity": 4, + "token_count": 72, + "parameters": [ + "self", + "lib_dir", + "libs", + "opt_libs" + ], + "start_line": 451, + "end_line": 462, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 12, + "top_nesting_level": 1 + }, + { + "name": "_lib_list", + "long_name": "_lib_list( self , lib_dir , libs , exts )", + "filename": "system_info.py", + "nloc": 11, + "complexity": 4, + "token_count": 66, + "parameters": [ + "self", + "lib_dir", + "libs", + "exts" + ], + "start_line": 464, + "end_line": 474, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 11, + "top_nesting_level": 1 + }, + { + "name": "_extract_lib_names", + "long_name": "_extract_lib_names( self , libs )", + "filename": "system_info.py", + "nloc": 3, + "complexity": 2, + "token_count": 37, + "parameters": [ + "self", + "libs" + ], + "start_line": 476, + "end_line": 478, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "_check_libs", + "long_name": "_check_libs( self , lib_dir , libs , opt_libs , exts )", + "filename": "system_info.py", + "nloc": 10, + "complexity": 3, + "token_count": 99, + "parameters": [ + "self", + "lib_dir", + "libs", + "opt_libs", + "exts" + ], + "start_line": 480, + "end_line": 489, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 10, + "top_nesting_level": 1 + }, + { + "name": "combine_paths", + "long_name": "combine_paths( self , * args )", + "filename": "system_info.py", + "nloc": 2, + "complexity": 1, + "token_count": 23, + "parameters": [ + "self", + "args" + ], + "start_line": 491, + "end_line": 492, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 1 + }, + { + "name": "calc_info", + "long_name": "calc_info( self )", + "filename": "system_info.py", + "nloc": 10, + "complexity": 5, + "token_count": 59, + "parameters": [ + "self" + ], + "start_line": 497, + "end_line": 506, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 10, + "top_nesting_level": 1 + }, + { + "name": "__init__", + "long_name": "__init__( self )", + "filename": "system_info.py", + "nloc": 2, + "complexity": 1, + "token_count": 11, + "parameters": [ + "self" + ], + "start_line": 523, + "end_line": 524, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 1 + }, + { + "name": "calc_ver_info", + "long_name": "calc_ver_info( self , ver_param )", + "filename": "system_info.py", + "nloc": 31, + "complexity": 9, + "token_count": 184, + "parameters": [ + "self", + "ver_param" + ], + "start_line": 526, + "end_line": 557, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 32, + "top_nesting_level": 1 + }, + { + "name": "calc_info", + "long_name": "calc_info( self )", + "filename": "system_info.py", + "nloc": 4, + "complexity": 3, + "token_count": 21, + "parameters": [ + "self" + ], + "start_line": 559, + "end_line": 562, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 1 + }, + { + "name": "get_paths", + "long_name": "get_paths( self , section , key )", + "filename": "system_info.py", + "nloc": 6, + "complexity": 4, + "token_count": 66, + "parameters": [ + "self", + "section", + "key" + ], + "start_line": 631, + "end_line": 636, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 6, + "top_nesting_level": 1 + }, + { + "name": "calc_info", + "long_name": "calc_info( self )", + "filename": "system_info.py", + "nloc": 22, + "complexity": 7, + "token_count": 144, + "parameters": [ + "self" + ], + "start_line": 638, + "end_line": 659, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 22, + "top_nesting_level": 1 + }, + { + "name": "get_mkl_rootdir", + "long_name": "get_mkl_rootdir( self )", + "filename": "system_info.py", + "nloc": 24, + "complexity": 11, + "token_count": 211, + "parameters": [ + "self" + ], + "start_line": 666, + "end_line": 689, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 24, + "top_nesting_level": 1 + }, + { + "name": "__init__", + "long_name": "__init__( self )", + "filename": "system_info.py", + "nloc": 20, + "complexity": 5, + "token_count": 119, + "parameters": [ + "self" + ], + "start_line": 691, + "end_line": 710, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 20, + "top_nesting_level": 1 + }, + { + "name": "calc_info", + "long_name": "calc_info( self )", + "filename": "system_info.py", + "nloc": 15, + "complexity": 4, + "token_count": 94, + "parameters": [ + "self" + ], + "start_line": 712, + "end_line": 726, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 15, + "top_nesting_level": 1 + }, + { + "name": "calc_info", + "long_name": "calc_info( self )", + "filename": "system_info.py", + "nloc": 8, + "complexity": 2, + "token_count": 49, + "parameters": [ + "self" + ], + "start_line": 730, + "end_line": 737, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 8, + "top_nesting_level": 1 + }, + { + "name": "get_paths", + "long_name": "get_paths( self , section , key )", + "filename": "system_info.py", + "nloc": 7, + "complexity": 4, + "token_count": 74, + "parameters": [ + "self", + "section", + "key" + ], + "start_line": 755, + "end_line": 761, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 7, + "top_nesting_level": 1 + }, + { + "name": "calc_info", + "long_name": "calc_info( self )", + "filename": "system_info.py", + "nloc": 78, + "complexity": 17, + "token_count": 441, + "parameters": [ + "self" + ], + "start_line": 763, + "end_line": 843, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 81, + "top_nesting_level": 1 + }, + { + "name": "calc_info", + "long_name": "calc_info( self )", + "filename": "system_info.py", + "nloc": 21, + "complexity": 6, + "token_count": 138, + "parameters": [ + "self" + ], + "start_line": 848, + "end_line": 870, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 23, + "top_nesting_level": 1 + }, + { + "name": "calc_info", + "long_name": "calc_info( self )", + "filename": "system_info.py", + "nloc": 12, + "complexity": 3, + "token_count": 68, + "parameters": [ + "self" + ], + "start_line": 893, + "end_line": 905, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 13, + "top_nesting_level": 1 + }, + { + "name": "get_paths", + "long_name": "get_paths( self , section , key )", + "filename": "system_info.py", + "nloc": 6, + "complexity": 4, + "token_count": 68, + "parameters": [ + "self", + "section", + "key" + ], + "start_line": 912, + "end_line": 917, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 6, + "top_nesting_level": 1 + }, + { + "name": "calc_info", + "long_name": "calc_info( self )", + "filename": "system_info.py", + "nloc": 81, + "complexity": 10, + "token_count": 232, + "parameters": [ + "self" + ], + "start_line": 919, + "end_line": 1003, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 85, + "top_nesting_level": 1 + }, + { + "name": "_get_build_temp", + "long_name": "_get_build_temp( )", + "filename": "system_info.py", + "nloc": 4, + "complexity": 1, + "token_count": 41, + "parameters": [], + "start_line": 1022, + "end_line": 1025, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 0 + }, + { + "name": "get_atlas_version.atlas_version_c", + "long_name": "get_atlas_version.atlas_version_c( extension , build_dir , magic = magic )", + "filename": "system_info.py", + "nloc": 10, + "complexity": 3, + "token_count": 74, + "parameters": [ + "extension", + "build_dir", + "magic" + ], + "start_line": 1033, + "end_line": 1042, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 10, + "top_nesting_level": 1 + }, + { + "name": "get_atlas_version", + "long_name": "get_atlas_version( ** config )", + "filename": "system_info.py", + "nloc": 51, + "complexity": 9, + "token_count": 314, + "parameters": [ + "config" + ], + "start_line": 1027, + "end_line": 1087, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 61, + "top_nesting_level": 0 + }, + { + "name": "calc_info", + "long_name": "calc_info( self )", + "filename": "system_info.py", + "nloc": 72, + "complexity": 20, + "token_count": 443, + "parameters": [ + "self" + ], + "start_line": 1092, + "end_line": 1172, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 81, + "top_nesting_level": 1 + }, + { + "name": "calc_info", + "long_name": "calc_info( self )", + "filename": "system_info.py", + "nloc": 57, + "complexity": 14, + "token_count": 331, + "parameters": [ + "self" + ], + "start_line": 1177, + "end_line": 1238, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 62, + "top_nesting_level": 1 + }, + { + "name": "calc_info", + "long_name": "calc_info( self )", + "filename": "system_info.py", + "nloc": 12, + "complexity": 3, + "token_count": 68, + "parameters": [ + "self" + ], + "start_line": 1247, + "end_line": 1259, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 13, + "top_nesting_level": 1 + }, + { + "name": "get_paths", + "long_name": "get_paths( self , section , key )", + "filename": "system_info.py", + "nloc": 6, + "complexity": 4, + "token_count": 66, + "parameters": [ + "self", + "section", + "key" + ], + "start_line": 1267, + "end_line": 1272, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 6, + "top_nesting_level": 1 + }, + { + "name": "calc_info", + "long_name": "calc_info( self )", + "filename": "system_info.py", + "nloc": 34, + "complexity": 5, + "token_count": 106, + "parameters": [ + "self" + ], + "start_line": 1274, + "end_line": 1309, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 36, + "top_nesting_level": 1 + }, + { + "name": "__init__", + "long_name": "__init__( self )", + "filename": "system_info.py", + "nloc": 4, + "complexity": 1, + "token_count": 19, + "parameters": [ + "self" + ], + "start_line": 1315, + "end_line": 1318, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 1 + }, + { + "name": "calc_info", + "long_name": "calc_info( self )", + "filename": "system_info.py", + "nloc": 20, + "complexity": 7, + "token_count": 114, + "parameters": [ + "self" + ], + "start_line": 1320, + "end_line": 1339, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 20, + "top_nesting_level": 1 + }, + { + "name": "__init__", + "long_name": "__init__( self )", + "filename": "system_info.py", + "nloc": 22, + "complexity": 6, + "token_count": 139, + "parameters": [ + "self" + ], + "start_line": 1346, + "end_line": 1367, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 22, + "top_nesting_level": 1 + }, + { + "name": "calc_info", + "long_name": "calc_info( self )", + "filename": "system_info.py", + "nloc": 29, + "complexity": 8, + "token_count": 161, + "parameters": [ + "self" + ], + "start_line": 1369, + "end_line": 1404, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 36, + "top_nesting_level": 1 + }, + { + "name": "calc_info", + "long_name": "calc_info( self )", + "filename": "system_info.py", + "nloc": 9, + "complexity": 2, + "token_count": 64, + "parameters": [ + "self" + ], + "start_line": 1419, + "end_line": 1427, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 9, + "top_nesting_level": 1 + }, + { + "name": "get_paths", + "long_name": "get_paths( self , section , key )", + "filename": "system_info.py", + "nloc": 6, + "complexity": 4, + "token_count": 66, + "parameters": [ + "self", + "section", + "key" + ], + "start_line": 1433, + "end_line": 1438, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 6, + "top_nesting_level": 1 + }, + { + "name": "calc_info", + "long_name": "calc_info( self )", + "filename": "system_info.py", + "nloc": 21, + "complexity": 5, + "token_count": 156, + "parameters": [ + "self" + ], + "start_line": 1440, + "end_line": 1460, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 21, + "top_nesting_level": 1 + }, + { + "name": "get_paths", + "long_name": "get_paths( self , section , key )", + "filename": "system_info.py", + "nloc": 6, + "complexity": 4, + "token_count": 66, + "parameters": [ + "self", + "section", + "key" + ], + "start_line": 1466, + "end_line": 1471, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 6, + "top_nesting_level": 1 + }, + { + "name": "calc_info", + "long_name": "calc_info( self )", + "filename": "system_info.py", + "nloc": 22, + "complexity": 6, + "token_count": 177, + "parameters": [ + "self" + ], + "start_line": 1473, + "end_line": 1495, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 23, + "top_nesting_level": 1 + }, + { + "name": "get_config_exe", + "long_name": "get_config_exe( self )", + "filename": "system_info.py", + "nloc": 4, + "complexity": 2, + "token_count": 30, + "parameters": [ + "self" + ], + "start_line": 1507, + "end_line": 1510, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 1 + }, + { + "name": "get_config_output", + "long_name": "get_config_output( self , config_exe , option )", + "filename": "system_info.py", + "nloc": 4, + "complexity": 2, + "token_count": 37, + "parameters": [ + "self", + "config_exe", + "option" + ], + "start_line": 1511, + "end_line": 1514, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 1 + }, + { + "name": "calc_info", + "long_name": "calc_info( self )", + "filename": "system_info.py", + "nloc": 54, + "complexity": 22, + "token_count": 435, + "parameters": [ + "self" + ], + "start_line": 1516, + "end_line": 1569, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 54, + "top_nesting_level": 1 + }, + { + "name": "combine_paths", + "long_name": "combine_paths( * args , ** kws )", + "filename": "system_info.py", + "nloc": 22, + "complexity": 11, + "token_count": 191, + "parameters": [ + "args", + "kws" + ], + "start_line": 1638, + "end_line": 1662, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 25, + "top_nesting_level": 0 + }, + { + "name": "dict_append", + "long_name": "dict_append( d , ** kws )", + "filename": "system_info.py", + "nloc": 17, + "complexity": 9, + "token_count": 128, + "parameters": [ + "d", + "kws" + ], + "start_line": 1666, + "end_line": 1682, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 17, + "top_nesting_level": 0 + }, + { + "name": "show_all", + "long_name": "show_all( )", + "filename": "system_info.py", + "nloc": 20, + "complexity": 8, + "token_count": 137, + "parameters": [], + "start_line": 1684, + "end_line": 1703, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 20, + "top_nesting_level": 0 + } + ], + "methods_before": [ + { + "name": "get_info", + "long_name": "get_info( name , notfound_action = 0 )", + "filename": "system_info.py", + "nloc": 51, + "complexity": 1, + "token_count": 226, + "parameters": [ + "name", + "notfound_action" + ], + "start_line": 144, + "end_line": 200, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 57, + "top_nesting_level": 0 + }, + { + "name": "__init__", + "long_name": "__init__( self , default_lib_dirs = default_lib_dirs , default_include_dirs = default_include_dirs , verbosity = 1 , )", + "filename": "system_info.py", + "nloc": 26, + "complexity": 3, + "token_count": 207, + "parameters": [ + "self", + "default_lib_dirs", + "default_include_dirs", + "verbosity" + ], + "start_line": 275, + "end_line": 300, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 26, + "top_nesting_level": 1 + }, + { + "name": "calc_libraries_info", + "long_name": "calc_libraries_info( self )", + "filename": "system_info.py", + "nloc": 15, + "complexity": 5, + "token_count": 78, + "parameters": [ + "self" + ], + "start_line": 302, + "end_line": 316, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 15, + "top_nesting_level": 1 + }, + { + "name": "set_info", + "long_name": "set_info( self , ** info )", + "filename": "system_info.py", + "nloc": 5, + "complexity": 2, + "token_count": 37, + "parameters": [ + "self", + "info" + ], + "start_line": 318, + "end_line": 322, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 5, + "top_nesting_level": 1 + }, + { + "name": "has_info", + "long_name": "has_info( self )", + "filename": "system_info.py", + "nloc": 2, + "complexity": 1, + "token_count": 18, + "parameters": [ + "self" + ], + "start_line": 324, + "end_line": 325, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 1 + }, + { + "name": "get_info", + "long_name": "get_info( self , notfound_action = 0 )", + "filename": "system_info.py", + "nloc": 30, + "complexity": 15, + "token_count": 208, + "parameters": [ + "self", + "notfound_action" + ], + "start_line": 327, + "end_line": 362, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 36, + "top_nesting_level": 1 + }, + { + "name": "get_paths", + "long_name": "get_paths( self , section , key )", + "filename": "system_info.py", + "nloc": 47, + "complexity": 20, + "token_count": 399, + "parameters": [ + "self", + "section", + "key" + ], + "start_line": 364, + "end_line": 410, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 47, + "top_nesting_level": 1 + }, + { + "name": "get_lib_dirs", + "long_name": "get_lib_dirs( self , key = 'library_dirs' )", + "filename": "system_info.py", + "nloc": 2, + "complexity": 1, + "token_count": 20, + "parameters": [ + "self", + "key" + ], + "start_line": 412, + "end_line": 413, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 1 + }, + { + "name": "get_include_dirs", + "long_name": "get_include_dirs( self , key = 'include_dirs' )", + "filename": "system_info.py", + "nloc": 2, + "complexity": 1, + "token_count": 20, + "parameters": [ + "self", + "key" + ], + "start_line": 415, + "end_line": 416, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 1 + }, + { + "name": "get_src_dirs", + "long_name": "get_src_dirs( self , key = 'src_dirs' )", + "filename": "system_info.py", + "nloc": 2, + "complexity": 1, + "token_count": 20, + "parameters": [ + "self", + "key" + ], + "start_line": 418, + "end_line": 419, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 1 + }, + { + "name": "get_libs", + "long_name": "get_libs( self , key , default )", + "filename": "system_info.py", + "nloc": 10, + "complexity": 7, + "token_count": 74, + "parameters": [ + "self", + "key", + "default" + ], + "start_line": 421, + "end_line": 430, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 10, + "top_nesting_level": 1 + }, + { + "name": "get_libraries", + "long_name": "get_libraries( self , key = 'libraries' )", + "filename": "system_info.py", + "nloc": 2, + "complexity": 1, + "token_count": 18, + "parameters": [ + "self", + "key" + ], + "start_line": 432, + "end_line": 433, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 1 + }, + { + "name": "check_libs", + "long_name": "check_libs( self , lib_dir , libs , opt_libs = [ ] )", + "filename": "system_info.py", + "nloc": 11, + "complexity": 5, + "token_count": 79, + "parameters": [ + "self", + "lib_dir", + "libs", + "opt_libs" + ], + "start_line": 435, + "end_line": 447, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 13, + "top_nesting_level": 1 + }, + { + "name": "check_libs2", + "long_name": "check_libs2( self , lib_dir , libs , opt_libs = [ ] )", + "filename": "system_info.py", + "nloc": 10, + "complexity": 4, + "token_count": 72, + "parameters": [ + "self", + "lib_dir", + "libs", + "opt_libs" + ], + "start_line": 449, + "end_line": 460, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 12, + "top_nesting_level": 1 + }, + { + "name": "_lib_list", + "long_name": "_lib_list( self , lib_dir , libs , exts )", + "filename": "system_info.py", + "nloc": 11, + "complexity": 4, + "token_count": 66, + "parameters": [ + "self", + "lib_dir", + "libs", + "exts" + ], + "start_line": 462, + "end_line": 472, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 11, + "top_nesting_level": 1 + }, + { + "name": "_extract_lib_names", + "long_name": "_extract_lib_names( self , libs )", + "filename": "system_info.py", + "nloc": 3, + "complexity": 2, + "token_count": 37, + "parameters": [ + "self", + "libs" + ], + "start_line": 474, + "end_line": 476, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "_check_libs", + "long_name": "_check_libs( self , lib_dir , libs , opt_libs , exts )", + "filename": "system_info.py", + "nloc": 10, + "complexity": 3, + "token_count": 99, + "parameters": [ + "self", + "lib_dir", + "libs", + "opt_libs", + "exts" + ], + "start_line": 478, + "end_line": 487, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 10, + "top_nesting_level": 1 + }, + { + "name": "combine_paths", + "long_name": "combine_paths( self , * args )", + "filename": "system_info.py", + "nloc": 2, + "complexity": 1, + "token_count": 23, + "parameters": [ + "self", + "args" + ], + "start_line": 489, + "end_line": 490, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 1 + }, + { + "name": "calc_info", + "long_name": "calc_info( self )", + "filename": "system_info.py", + "nloc": 10, + "complexity": 5, + "token_count": 59, + "parameters": [ + "self" + ], + "start_line": 495, + "end_line": 504, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 10, + "top_nesting_level": 1 + }, + { + "name": "__init__", + "long_name": "__init__( self )", + "filename": "system_info.py", + "nloc": 2, + "complexity": 1, + "token_count": 11, + "parameters": [ + "self" + ], + "start_line": 521, + "end_line": 522, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 1 + }, + { + "name": "calc_ver_info", + "long_name": "calc_ver_info( self , ver_param )", + "filename": "system_info.py", + "nloc": 31, + "complexity": 9, + "token_count": 184, + "parameters": [ + "self", + "ver_param" + ], + "start_line": 524, + "end_line": 555, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 32, + "top_nesting_level": 1 + }, + { + "name": "calc_info", + "long_name": "calc_info( self )", + "filename": "system_info.py", + "nloc": 4, + "complexity": 3, + "token_count": 21, + "parameters": [ + "self" + ], + "start_line": 557, + "end_line": 560, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 1 + }, + { + "name": "get_paths", + "long_name": "get_paths( self , section , key )", + "filename": "system_info.py", + "nloc": 6, + "complexity": 4, + "token_count": 66, + "parameters": [ + "self", + "section", + "key" + ], + "start_line": 629, + "end_line": 634, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 6, + "top_nesting_level": 1 + }, + { + "name": "calc_info", + "long_name": "calc_info( self )", + "filename": "system_info.py", + "nloc": 22, + "complexity": 7, + "token_count": 144, + "parameters": [ + "self" + ], + "start_line": 636, + "end_line": 657, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 22, + "top_nesting_level": 1 + }, + { + "name": "get_mkl_rootdir", + "long_name": "get_mkl_rootdir( self )", + "filename": "system_info.py", + "nloc": 24, + "complexity": 11, + "token_count": 211, + "parameters": [ + "self" + ], + "start_line": 664, + "end_line": 687, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 24, + "top_nesting_level": 1 + }, + { + "name": "__init__", + "long_name": "__init__( self )", + "filename": "system_info.py", + "nloc": 20, + "complexity": 5, + "token_count": 119, + "parameters": [ + "self" + ], + "start_line": 689, + "end_line": 708, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 20, + "top_nesting_level": 1 + }, + { + "name": "calc_info", + "long_name": "calc_info( self )", + "filename": "system_info.py", + "nloc": 15, + "complexity": 4, + "token_count": 94, + "parameters": [ + "self" + ], + "start_line": 710, + "end_line": 724, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 15, + "top_nesting_level": 1 + }, + { + "name": "calc_info", + "long_name": "calc_info( self )", + "filename": "system_info.py", + "nloc": 8, + "complexity": 2, + "token_count": 49, + "parameters": [ + "self" + ], + "start_line": 728, + "end_line": 735, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 8, + "top_nesting_level": 1 + }, + { + "name": "get_paths", + "long_name": "get_paths( self , section , key )", + "filename": "system_info.py", + "nloc": 7, + "complexity": 4, + "token_count": 74, + "parameters": [ + "self", + "section", + "key" + ], + "start_line": 753, + "end_line": 759, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 7, + "top_nesting_level": 1 + }, + { + "name": "calc_info", + "long_name": "calc_info( self )", + "filename": "system_info.py", + "nloc": 78, + "complexity": 17, + "token_count": 441, + "parameters": [ + "self" + ], + "start_line": 761, + "end_line": 841, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 81, + "top_nesting_level": 1 + }, + { + "name": "calc_info", + "long_name": "calc_info( self )", + "filename": "system_info.py", + "nloc": 21, + "complexity": 6, + "token_count": 138, + "parameters": [ + "self" + ], + "start_line": 846, + "end_line": 868, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 23, + "top_nesting_level": 1 + }, + { + "name": "calc_info", + "long_name": "calc_info( self )", + "filename": "system_info.py", + "nloc": 12, + "complexity": 3, + "token_count": 68, + "parameters": [ + "self" + ], + "start_line": 891, + "end_line": 903, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 13, + "top_nesting_level": 1 + }, + { + "name": "get_paths", + "long_name": "get_paths( self , section , key )", + "filename": "system_info.py", + "nloc": 6, + "complexity": 4, + "token_count": 68, + "parameters": [ + "self", + "section", + "key" + ], + "start_line": 910, + "end_line": 915, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 6, + "top_nesting_level": 1 + }, + { + "name": "calc_info", + "long_name": "calc_info( self )", + "filename": "system_info.py", + "nloc": 81, + "complexity": 10, + "token_count": 232, + "parameters": [ + "self" + ], + "start_line": 917, + "end_line": 1001, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 85, + "top_nesting_level": 1 + }, + { + "name": "_get_build_temp", + "long_name": "_get_build_temp( )", + "filename": "system_info.py", + "nloc": 4, + "complexity": 1, + "token_count": 41, + "parameters": [], + "start_line": 1020, + "end_line": 1023, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 0 + }, + { + "name": "get_atlas_version.atlas_version_c", + "long_name": "get_atlas_version.atlas_version_c( extension , build_dir , magic = magic )", + "filename": "system_info.py", + "nloc": 10, + "complexity": 3, + "token_count": 74, + "parameters": [ + "extension", + "build_dir", + "magic" + ], + "start_line": 1031, + "end_line": 1040, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 10, + "top_nesting_level": 1 + }, + { + "name": "get_atlas_version", + "long_name": "get_atlas_version( ** config )", + "filename": "system_info.py", + "nloc": 51, + "complexity": 9, + "token_count": 314, + "parameters": [ + "config" + ], + "start_line": 1025, + "end_line": 1085, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 61, + "top_nesting_level": 0 + }, + { + "name": "calc_info", + "long_name": "calc_info( self )", + "filename": "system_info.py", + "nloc": 72, + "complexity": 20, + "token_count": 443, + "parameters": [ + "self" + ], + "start_line": 1090, + "end_line": 1170, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 81, + "top_nesting_level": 1 + }, + { + "name": "calc_info", + "long_name": "calc_info( self )", + "filename": "system_info.py", + "nloc": 57, + "complexity": 14, + "token_count": 331, + "parameters": [ + "self" + ], + "start_line": 1175, + "end_line": 1236, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 62, + "top_nesting_level": 1 + }, + { + "name": "calc_info", + "long_name": "calc_info( self )", + "filename": "system_info.py", + "nloc": 12, + "complexity": 3, + "token_count": 68, + "parameters": [ + "self" + ], + "start_line": 1245, + "end_line": 1257, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 13, + "top_nesting_level": 1 + }, + { + "name": "get_paths", + "long_name": "get_paths( self , section , key )", + "filename": "system_info.py", + "nloc": 6, + "complexity": 4, + "token_count": 66, + "parameters": [ + "self", + "section", + "key" + ], + "start_line": 1265, + "end_line": 1270, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 6, + "top_nesting_level": 1 + }, + { + "name": "calc_info", + "long_name": "calc_info( self )", + "filename": "system_info.py", + "nloc": 34, + "complexity": 5, + "token_count": 106, + "parameters": [ + "self" + ], + "start_line": 1272, + "end_line": 1307, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 36, + "top_nesting_level": 1 + }, + { + "name": "__init__", + "long_name": "__init__( self )", + "filename": "system_info.py", + "nloc": 4, + "complexity": 1, + "token_count": 19, + "parameters": [ + "self" + ], + "start_line": 1313, + "end_line": 1316, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 1 + }, + { + "name": "calc_info", + "long_name": "calc_info( self )", + "filename": "system_info.py", + "nloc": 20, + "complexity": 7, + "token_count": 114, + "parameters": [ + "self" + ], + "start_line": 1318, + "end_line": 1337, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 20, + "top_nesting_level": 1 + }, + { + "name": "__init__", + "long_name": "__init__( self )", + "filename": "system_info.py", + "nloc": 22, + "complexity": 6, + "token_count": 139, + "parameters": [ + "self" + ], + "start_line": 1344, + "end_line": 1365, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 22, + "top_nesting_level": 1 + }, + { + "name": "calc_info", + "long_name": "calc_info( self )", + "filename": "system_info.py", + "nloc": 29, + "complexity": 8, + "token_count": 161, + "parameters": [ + "self" + ], + "start_line": 1367, + "end_line": 1402, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 36, + "top_nesting_level": 1 + }, + { + "name": "calc_info", + "long_name": "calc_info( self )", + "filename": "system_info.py", + "nloc": 9, + "complexity": 2, + "token_count": 64, + "parameters": [ + "self" + ], + "start_line": 1417, + "end_line": 1425, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 9, + "top_nesting_level": 1 + }, + { + "name": "get_paths", + "long_name": "get_paths( self , section , key )", + "filename": "system_info.py", + "nloc": 6, + "complexity": 4, + "token_count": 66, + "parameters": [ + "self", + "section", + "key" + ], + "start_line": 1431, + "end_line": 1436, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 6, + "top_nesting_level": 1 + }, + { + "name": "calc_info", + "long_name": "calc_info( self )", + "filename": "system_info.py", + "nloc": 21, + "complexity": 5, + "token_count": 156, + "parameters": [ + "self" + ], + "start_line": 1438, + "end_line": 1458, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 21, + "top_nesting_level": 1 + }, + { + "name": "get_paths", + "long_name": "get_paths( self , section , key )", + "filename": "system_info.py", + "nloc": 6, + "complexity": 4, + "token_count": 66, + "parameters": [ + "self", + "section", + "key" + ], + "start_line": 1464, + "end_line": 1469, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 6, + "top_nesting_level": 1 + }, + { + "name": "calc_info", + "long_name": "calc_info( self )", + "filename": "system_info.py", + "nloc": 22, + "complexity": 6, + "token_count": 177, + "parameters": [ + "self" + ], + "start_line": 1471, + "end_line": 1493, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 23, + "top_nesting_level": 1 + }, + { + "name": "get_config_exe", + "long_name": "get_config_exe( self )", + "filename": "system_info.py", + "nloc": 4, + "complexity": 2, + "token_count": 30, + "parameters": [ + "self" + ], + "start_line": 1505, + "end_line": 1508, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 1 + }, + { + "name": "get_config_output", + "long_name": "get_config_output( self , config_exe , option )", + "filename": "system_info.py", + "nloc": 4, + "complexity": 2, + "token_count": 37, + "parameters": [ + "self", + "config_exe", + "option" + ], + "start_line": 1509, + "end_line": 1512, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 1 + }, + { + "name": "calc_info", + "long_name": "calc_info( self )", + "filename": "system_info.py", + "nloc": 54, + "complexity": 22, + "token_count": 435, + "parameters": [ + "self" + ], + "start_line": 1514, + "end_line": 1567, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 54, + "top_nesting_level": 1 + }, + { + "name": "combine_paths", + "long_name": "combine_paths( * args , ** kws )", + "filename": "system_info.py", + "nloc": 22, + "complexity": 11, + "token_count": 191, + "parameters": [ + "args", + "kws" + ], + "start_line": 1636, + "end_line": 1660, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 25, + "top_nesting_level": 0 + }, + { + "name": "dict_append", + "long_name": "dict_append( d , ** kws )", + "filename": "system_info.py", + "nloc": 17, + "complexity": 9, + "token_count": 128, + "parameters": [ + "d", + "kws" + ], + "start_line": 1664, + "end_line": 1680, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 17, + "top_nesting_level": 0 + }, + { + "name": "show_all", + "long_name": "show_all( )", + "filename": "system_info.py", + "nloc": 20, + "complexity": 8, + "token_count": 137, + "parameters": [], + "start_line": 1682, + "end_line": 1701, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 20, + "top_nesting_level": 0 + } + ], + "changed_methods": [], + "nloc": 1506, + "complexity": 328, + "token_count": 8477, + "diff_parsed": { + "added": [ + "import distutils.sysconfig", + " default_lib_dirs = ['C:\\\\',", + " join(distutils.sysconfig.EXEC_PREFIX, 'libs')]" + ], + "deleted": [ + " default_lib_dirs = ['C:\\\\'] # probably not very helpful..." + ] + } + }, + { + "old_path": "numpy/random/mtrand/distributions.c", + "new_path": "numpy/random/mtrand/distributions.c", + "filename": "distributions.c", + "extension": "c", + "change_type": "MODIFY", + "diff": "@@ -50,6 +50,9 @@\n #define max(x,y) ((x>y)?x:y)\n #endif\n \n+#ifndef M_PI\n+#define M_PI 3.14159265358979323846264338328\n+#endif \n /* log-gamma function to support some of these distributions. The \n * algorithm comes from SPECFUN by Shanjie Zhang and Jianming Jin and their\n * book \"Computation of Special Functions\", 1996, John Wiley & Sons, Inc.\n", + "added_lines": 3, + "deleted_lines": 0, + "source_code": "/* Copyright 2005 Robert Kern (robert.kern@gmail.com)\n *\n * Permission is hereby granted, free of charge, to any person obtaining a\n * copy of this software and associated documentation files (the\n * \"Software\"), to deal in the Software without restriction, including\n * without limitation the rights to use, copy, modify, merge, publish,\n * distribute, sublicense, and/or sell copies of the Software, and to\n * permit persons to whom the Software is furnished to do so, subject to\n * the following conditions:\n * \n * The above copyright notice and this permission notice shall be included\n * in all copies or substantial portions of the Software.\n * \n * THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS\n * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF\n * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.\n * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY\n * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,\n * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE\n * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.\n */\n\n/* The implementations of rk_hypergeometric_hyp(), rk_hypergeometric_hrua(),\n * and rk_triangular() were adapted from Ivan Frohne's rv.py which has this \n * license:\n * \n * Copyright 1998 by Ivan Frohne; Wasilla, Alaska, U.S.A.\n * All Rights Reserved\n *\n * Permission to use, copy, modify and distribute this software and its\n * documentation for any purpose, free of charge, is granted subject to the\n * following conditions:\n * The above copyright notice and this permission notice shall be included in\n * all copies or substantial portions of the software.\n *\n * THE SOFTWARE AND DOCUMENTATION IS PROVIDED WITHOUT WARRANTY OF ANY KIND,\n * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO MERCHANTABILITY, FITNESS\n * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHOR\n * OR COPYRIGHT HOLDER BE LIABLE FOR ANY CLAIM OR DAMAGES IN A CONTRACT\n * ACTION, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE\n * SOFTWARE OR ITS DOCUMENTATION.\n */\n\n#include \n#include \"distributions.h\"\n#include \n\n#ifndef min\n#define min(x,y) ((xy)?x:y)\n#endif\n\n#ifndef M_PI\n#define M_PI 3.14159265358979323846264338328\n#endif \n/* log-gamma function to support some of these distributions. The \n * algorithm comes from SPECFUN by Shanjie Zhang and Jianming Jin and their\n * book \"Computation of Special Functions\", 1996, John Wiley & Sons, Inc.\n */\nextern double loggam(double x);\ndouble loggam(double x)\n{\n double x0, x2, xp, gl, gl0;\n long k, n;\n \n static double a[10] = {8.333333333333333e-02,-2.777777777777778e-03,\n 7.936507936507937e-04,-5.952380952380952e-04,\n 8.417508417508418e-04,-1.917526917526918e-03,\n 6.410256410256410e-03,-2.955065359477124e-02,\n 1.796443723688307e-01,-1.39243221690590e+00};\n x0 = x;\n n = 0;\n if ((x == 1.0) || (x == 2.0))\n {\n return 0.0;\n }\n else if (x <= 7.0)\n {\n n = (long)(7 - x);\n x0 = x + n;\n }\n x2 = 1.0/(x0*x0);\n xp = 2*M_PI;\n gl0 = a[9];\n for (k=8; k>=0; k--)\n {\n gl0 *= x2;\n gl0 += a[k];\n }\n gl = gl0/x0 + 0.5*log(xp) + (x0-0.5)*log(x0) - x0;\n if (x <= 7.0)\n {\n for (k=1; k<=n; k++)\n {\n gl -= log(x0-1.0);\n x0 -= 1.0;\n }\n }\n return gl;\n}\n\ndouble rk_normal(rk_state *state, double loc, double scale)\n{\n return loc + scale*rk_gauss(state);\n}\n\ndouble rk_standard_exponential(rk_state *state)\n{\n /* We use -log(1-U) since U is [0, 1) */\n return -log(1.0 - rk_double(state));\n}\n\ndouble rk_exponential(rk_state *state, double scale)\n{\n return scale * rk_standard_exponential(state);\n}\n\ndouble rk_uniform(rk_state *state, double loc, double scale)\n{\n return loc + scale*rk_double(state);\n}\n\ndouble rk_standard_gamma(rk_state *state, double shape)\n{\n double b, c;\n double U, V, X, Y;\n\n if (shape == 1.0)\n {\n return rk_standard_exponential(state);\n }\n else if (shape < 1.0)\n {\n for (;;)\n {\n U = rk_double(state);\n V = rk_standard_exponential(state);\n if (U <= 1.0 - shape)\n {\n X = pow(U, 1./shape);\n if (X <= V)\n {\n return X;\n }\n }\n else\n {\n Y = -log((1-U)/shape);\n X = pow(1.0 - shape + shape*Y, 1./shape);\n if (X <= (V + Y))\n {\n return X;\n }\n }\n }\n }\n else\n {\n b = shape - 1./3.;\n c = 1./sqrt(9*b);\n for (;;)\n {\n do\n {\n X = rk_gauss(state); \n V = 1.0 + c*X;\n } while (V <= 0.0);\n\n V = V*V*V;\n U = rk_double(state);\n if (U < 1.0 - 0.0331*(X*X)*(X*X)) return (b*V);\n if (log(U) < 0.5*X*X + b*(1. - V + log(V))) return (b*V);\n }\n }\n}\n\ndouble rk_gamma(rk_state *state, double shape, double scale)\n{\n return scale * rk_standard_gamma(state, shape);\n}\n\ndouble rk_beta(rk_state *state, double a, double b)\n{\n double Ga, Gb;\n\n if ((a <= 1.0) && (b <= 1.0))\n {\n double U, V, X, Y;\n /* Use Jonk's algorithm */\n\n while (1)\n {\n U = rk_double(state);\n V = rk_double(state);\n X = pow(U, 1.0/a);\n Y = pow(V, 1.0/b);\n\n if ((X + Y) <= 1.0)\n {\n return X;\n }\n }\n }\n else\n {\n Ga = rk_standard_gamma(state, a);\n Gb = rk_standard_gamma(state, b);\n return Ga/(Ga + Gb);\n }\n}\n\ndouble rk_chisquare(rk_state *state, double df)\n{\n return 2.0*rk_standard_gamma(state, df/2.0);\n}\n\ndouble rk_noncentral_chisquare(rk_state *state, double df, double nonc)\n{\n double Chi2, N;\n\n Chi2 = rk_chisquare(state, df-1);\n N = rk_gauss(state) + sqrt(nonc);\n return Chi2 + N*N;\n}\n\ndouble rk_f(rk_state *state, double dfnum, double dfden)\n{\n return rk_chisquare(state, dfnum) / rk_chisquare(state, dfden);\n}\n\ndouble rk_noncentral_f(rk_state *state, double dfnum, double dfden, double nonc)\n{\n return ((rk_noncentral_chisquare(state, dfnum, nonc)*dfden) /\n (rk_chisquare(state, dfden)*dfnum));\n}\n\nlong rk_binomial_btpe(rk_state *state, long n, double p)\n{\n double r,q,fm,p1,xm,xl,xr,c,laml,lamr,p2,p3,p4;\n double a,u,v,s,F,rho,t,A,nrq,x1,x2,f1,f2,z,z2,w,w2,x;\n long m,y,k,i;\n\n if (!(state->has_binomial) || \n (state->nsave != n) ||\n (state->psave != p))\n {\n /* initialize */\n state->nsave = n;\n state->psave = p;\n state->has_binomial = 1;\n state->r = r = min(p, 1.0-p);\n state->q = q = 1.0 - r;\n state->fm = fm = n*r+r;\n state->m = m = (long)floor(state->fm);\n state->p1 = p1 = floor(2.195*sqrt(n*r*q)-4.6*q) + 0.5;\n state->xm = xm = m + 0.5;\n state->xl = xl = xm - p1;\n state->xr = xr = xm + p1;\n state->c = c = 0.134 + 20.5/(15.3 + m);\n a = (fm - xl)/(fm-xl*r);\n state->laml = laml = a*(1.0 + a/2.0);\n a = (xr - fm)/(xr*q);\n state->lamr = lamr = a*(1.0 + a/2.0);\n state->p2 = p2 = p1*(1.0 + 2.0*c);\n state->p3 = p3 = p2 + c/laml;\n state->p4 = p4 = p3 + c/lamr;\n }\n else\n {\n r = state->r;\n q = state->q;\n fm = state->fm;\n m = state->m;\n p1 = state->p1;\n xm = state->xm;\n xl = state->xl;\n xr = state->xr;\n c = state->c;\n laml = state->laml;\n lamr = state->lamr;\n p2 = state->p2;\n p3 = state->p3;\n p4 = state->p4;\n }\n\n /* sigh ... */\n Step10:\n nrq = n*r*q;\n u = rk_double(state)*p4;\n v = rk_double(state);\n if (u > p1) goto Step20;\n y = (long)floor(xm - p1*v + u);\n goto Step60;\n\n Step20:\n if (u > p2) goto Step30;\n x = xl + (u - p1)/c;\n v = v*c + 1.0 - fabs(m - x + 0.5)/p1;\n if (v > 1.0) goto Step10;\n y = (long)floor(x);\n goto Step50;\n\n Step30:\n if (u > p3) goto Step40;\n y = (long)floor(xl + log(v)/laml);\n if (y < 0) goto Step10;\n v = v*(u-p2)*laml;\n goto Step50;\n\n Step40:\n y = (int)floor(xr - log(v)/lamr);\n if (y > n) goto Step10;\n v = v*(u-p3)*lamr;\n\n Step50:\n k = fabs(y - m);\n if ((k > 20) && (k < ((nrq)/2.0 - 1))) goto Step52;\n\n s = r/q;\n a = s*(n+1);\n F = 1.0;\n if (m < y)\n {\n for (i=m; i<=y; i++)\n {\n F *= (a/i - s);\n }\n }\n else if (m > y)\n {\n for (i=y; i<=m; i++)\n {\n F /= (a/i - s);\n }\n }\n else\n {\n if (v > F) goto Step10;\n goto Step60;\n }\n\n Step52:\n rho = (k/(nrq))*((k*(k/3.0 + 0.625) + 0.16666666666666666)/nrq + 0.5);\n t = -k*k/(2*nrq);\n A = log(v);\n if (A < (t - rho)) goto Step60;\n if (A > (t + rho)) goto Step10;\n\n x1 = y+1;\n f1 = m+1;\n z = n+1-m;\n w = n-y+1;\n x2 = x1*x1;\n f2 = f1*f1;\n z2 = z*z;\n w2 = w*w;\n if (A > (xm*log(f1/x1)\n + (n-m+0.5)*log(z/w)\n + (y-m)*log(w*r/(x1*q))\n + (13680.-(462.-(132.-(99.-140./f2)/f2)/f2)/f2)/f1/166320.\n + (13680.-(462.-(132.-(99.-140./z2)/z2)/z2)/z2)/z/166320.\n + (13680.-(462.-(132.-(99.-140./x2)/x2)/x2)/x2)/x1/166320.\n + (13680.-(462.-(132.-(99.-140./w2)/w2)/w2)/w2)/w/166320.))\n {\n goto Step10;\n }\n\n Step60:\n if (p > 0.5)\n {\n y = n - y;\n }\n\n return y;\n}\n\nlong rk_binomial_inversion(rk_state *state, long n, double p)\n{\n double q, qn, np, px, U;\n long X, bound;\n\n if (!(state->has_binomial) || \n (state->nsave != n) ||\n (state->psave != p))\n {\n state->nsave = n;\n state->psave = p;\n state->has_binomial = 1;\n state->q = q = 1.0 - p;\n state->r = qn = exp(n * log(q));\n state->c = np = n*p;\n state->m = bound = min(n, np + 10.0*sqrt(np));\n } else\n {\n q = state->q;\n qn = state->r;\n np = state->c;\n bound = state->m;\n }\n X = 0;\n px = qn;\n U = rk_double(state);\n while (U > px)\n {\n X++;\n if (X > bound) \n {\n X = 0;\n px = qn;\n U = rk_double(state);\n } else \n {\n U -= px;\n px = ((n-X+1) * p * px)/(X*q);\n }\n }\n return X;\n}\n\nlong rk_binomial(rk_state *state, long n, double p)\n{\n double q;\n\n if (p <= 0.5)\n {\n if (p*n <= 30.0)\n {\n return rk_binomial_inversion(state, n, p);\n }\n else\n {\n return rk_binomial_btpe(state, n, p);\n }\n }\n else\n {\n q = 1.0-p;\n if (q*n <= 30.0)\n {\n return n - rk_binomial_inversion(state, n, q);\n }\n else\n {\n return n - rk_binomial_btpe(state, n, q);\n }\n }\n\n}\n\nlong rk_negative_binomial(rk_state *state, long n, double p)\n{\n double Y;\n\n Y = rk_gamma(state, n, (1-p)/p);\n return rk_poisson(state, Y);\n}\n\nlong rk_poisson_mult(rk_state *state, double lam)\n{\n long X;\n double prod, U, enlam;\n\n enlam = exp(-lam);\n X = 0;\n prod = 1.0;\n while (1)\n {\n U = rk_double(state);\n prod *= U;\n if (prod > enlam)\n {\n X += 1;\n }\n else\n {\n return X;\n }\n }\n}\n\n#define LS2PI 0.91893853320467267\n#define TWELFTH 0.083333333333333333333333\nlong rk_poisson_ptrs(rk_state *state, double lam)\n{\n long k;\n double U, V, slam, loglam, a, b, invalpha, vr, us;\n\n slam = sqrt(lam);\n loglam = log(lam);\n b = 0.931 + 2.53*slam;\n a = -0.059 + 0.02483*b;\n invalpha = 1.1239 + 1.1328/(b-3.4);\n vr = 0.9277 - 3.6224/(b-2);\n\n while (1)\n {\n U = rk_double(state) - 0.5;\n V = rk_double(state);\n us = 0.5 - fabs(U);\n k = (long)floor((2*a/us + b)*U + lam + 0.43);\n if ((us >= 0.07) && (V <= vr))\n {\n return k;\n }\n if ((k < 0) ||\n ((us < 0.013) && (V > us)))\n {\n continue;\n }\n if ((log(V) + log(invalpha) - log(a/(us*us)+b)) <=\n (-lam + k*loglam - loggam(k+1)))\n {\n return k;\n }\n\n \n }\n\n}\n\nlong rk_poisson(rk_state *state, double lam)\n{\n if (lam >= 10)\n {\n return rk_poisson_ptrs(state, lam);\n }\n else\n {\n return rk_poisson_mult(state, lam);\n }\n}\n\ndouble rk_standard_cauchy(rk_state *state)\n{\n return rk_gauss(state) / rk_gauss(state);\n}\n\ndouble rk_standard_t(rk_state *state, double df)\n{\n double N, G, X;\n\n N = rk_gauss(state);\n G = rk_standard_gamma(state, df/2);\n X = sqrt(df/2)*N/sqrt(G);\n return X;\n}\n\ndouble rk_vonmises(rk_state *state, double mu, double kappa)\n{\n double r, rho, s;\n double U, V, W, Y, Z;\n double result, mod;\n\n if (kappa < 1e-8)\n {\n return M_PI * (2*rk_double(state)-1);\n }\n else\n {\n r = 1 + sqrt(1 + 4*kappa*kappa);\n rho = (r - sqrt(2*r))/(2*kappa);\n s = (1 + rho*rho)/(2*rho);\n\n while (1)\n {\n U = 2*rk_double(state) - 1;\n V = 2*rk_double(state) - 1;\n Z = cos(M_PI*U);\n W = (1 + s*Z)/(s + Z);\n Y = kappa * (s - W);\n if ((Y*(2-Y) - V >= 0) || (log(Y/V)+1 - Y >= 0))\n {\n break;\n }\n }\n\n if (U < 0)\n {\n result = acos(W);\n }\n else\n {\n result = -acos(W);\n }\n result += mu + M_PI;\n mod = fmod(result, 2*M_PI);\n if (mod && (mod < 0))\n {\n mod += 2*M_PI;\n }\n return mod - M_PI;\n }\n}\n\ndouble rk_pareto(rk_state *state, double a)\n{\n return exp(rk_standard_exponential(state)/a) - 1;\n}\n\ndouble rk_weibull(rk_state *state, double a)\n{\n return pow(rk_standard_exponential(state), 1./a);\n}\n\ndouble rk_power(rk_state *state, double a)\n{\n return pow(1 - exp(-rk_standard_exponential(state)), 1./a);\n}\n\ndouble rk_laplace(rk_state *state, double loc, double scale)\n{\n double U;\n \n U = rk_double(state);\n if (U < 0.5)\n {\n U = loc + scale * log(U + U);\n } else \n {\n U = loc - scale * log(2.0 - U - U);\n }\n return U;\n}\n\ndouble rk_gumbel(rk_state *state, double loc, double scale)\n{\n double U;\n \n U = 1.0 - rk_double(state);\n return loc - scale * log(-log(U));\n}\n\ndouble rk_logistic(rk_state *state, double loc, double scale)\n{\n double U;\n \n U = rk_double(state);\n return loc + scale * log(U/(1.0 - U));\n}\n\ndouble rk_lognormal(rk_state *state, double mean, double sigma)\n{\n return exp(rk_normal(state, mean, sigma));\n}\n\ndouble rk_rayleigh(rk_state *state, double mode)\n{\n return mode*sqrt(-2.0 * log(1.0 - rk_double(state)));\n}\n\ndouble rk_wald(rk_state *state, double mean, double scale)\n{\n double U, X, Y;\n double mu_2l;\n \n mu_2l = mean / (2*scale);\n Y = rk_gauss(state);\n Y = mean*Y*Y;\n X = mean + mu_2l*(Y - sqrt(4*scale*Y + Y*Y));\n U = rk_double(state);\n if (U <= mean/(mean+X))\n {\n return X;\n } else\n {\n return mean*mean/X;\n }\n}\n\nlong rk_zipf(rk_state *state, double a)\n{\n double T, U, V;\n long X;\n double b;\n \n b = pow(2.0, a-1.0);\n do\n {\n U = rk_double(state);\n V = rk_double(state);\n X = (long)floor(pow(U, -1.0/(a-1.0)));\n T = pow(1.0 + 1.0/X, a-1.0); \n } while ((V *X*(T-1.0)/(b-1.0)) > (T/b));\n return X;\n}\n\nlong rk_geometric_search(rk_state *state, double p)\n{\n double U;\n long X;\n double sum, prod, q;\n \n X = 1;\n sum = prod = p;\n q = 1.0 - p;\n U = rk_double(state);\n while (U > sum)\n {\n prod *= q;\n sum += prod;\n X++;\n }\n return X;\n}\n\nlong rk_geometric_inversion(rk_state *state, double p)\n{\n return (long)ceil(log(1.0-rk_double(state))/log(1.0-p));\n}\n\nlong rk_geometric(rk_state *state, double p)\n{\n if (p >= 0.333333333333333333333333)\n {\n return rk_geometric_search(state, p);\n } else\n {\n return rk_geometric_inversion(state, p);\n }\n}\n\nlong rk_hypergeometric_hyp(rk_state *state, long good, long bad, long sample)\n{\n long d1, K, Z;\n double d2, U, Y;\n \n d1 = bad + good - sample;\n d2 = (double)min(bad, good);\n \n Y = d2;\n K = sample;\n while (Y > 0.0)\n {\n U = rk_double(state);\n Y -= (long)floor(U + Y/(d1 + K));\n K--;\n if (K == 0) break;\n }\n Z = (long)(d2 - Y);\n if (bad > good) Z = sample - Z;\n return Z;\n}\n\n/* D1 = 2*sqrt(2/e) */\n/* D2 = 3 - 2*sqrt(3/e) */\n#define D1 1.7155277699214135\n#define D2 0.8989161620588988\nlong rk_hypergeometric_hrua(rk_state *state, long good, long bad, long sample)\n{\n long mingoodbad, maxgoodbad, popsize, m, d9;\n double d4, d5, d6, d7, d8, d10, d11;\n long Z;\n double T, W, X, Y;\n \n mingoodbad = min(good, bad);\n popsize = good + bad;\n maxgoodbad = max(good, bad);\n m = min(sample, popsize - sample);\n d4 = ((double)mingoodbad) / popsize;\n d5 = 1.0 - d4;\n d6 = m*d4 + 0.5;\n d7 = sqrt((popsize - m) * sample * d4 *d5 / (popsize-1) + 0.5);\n d8 = D1*d7 + D2;\n d9 = (long)floor((double)((m+1)*(mingoodbad+1))/(popsize+2));\n d10 = (loggam(d9+1) + loggam(mingoodbad-d9+1) + loggam(m-d9+1) + \n loggam(maxgoodbad-m+d9+1));\n d11 = min(min(m, mingoodbad)+1.0, floor(d6+16*d7));\n /* 16 for 16-decimal-digit precision in D1 and D2 */\n \n while (1)\n {\n X = rk_double(state);\n Y = rk_double(state);\n W = d6 + d8*(Y- 0.5)/X;\n \n /* fast rejection: */\n if ((W < 0.0) || (W >= d11)) continue;\n \n Z = (long)floor(W);\n T = d10 - (loggam(Z+1) + loggam(mingoodbad-Z+1) + loggam(m-Z+1) +\n loggam(maxgoodbad-m+Z+1));\n \n /* fast acceptance: */\n if ((X*(4.0-X)-3.0) <= T) break;\n \n /* fast rejection: */\n if (X*(X-T) >= 1) continue;\n\n if (2.0*log(X) <= T) break; /* acceptance */\n }\n \n /* this is a correction to HRUA* by Ivan Frohne in rv.py */\n if (bad > good) Z = m - Z;\n \n /* another fix from rv.py to allow sample to exceed popsize/2 */\n if (m < sample) Z = bad - Z;\n \n return Z;\n}\n#undef D1\n#undef D2\n\nlong rk_hypergeometric(rk_state *state, long good, long bad, long sample)\n{\n if (sample > 10)\n {\n return rk_hypergeometric_hrua(state, good, bad, sample);\n } else\n {\n return rk_hypergeometric_hyp(state, good, bad, sample);\n }\n}\n\ndouble rk_triangular(rk_state *state, double left, double mode, double right)\n{\n double base, leftbase, ratio, leftprod, rightprod;\n double U;\n \n base = right - left;\n leftbase = mode - left;\n ratio = leftbase / base;\n leftprod = leftbase*base;\n rightprod = (right - mode)*base;\n \n U = rk_double(state);\n if (U <= ratio)\n {\n return left + sqrt(U*leftprod);\n } else \n {\n return right - sqrt((1.0 - U) * rightprod); \n }\n}\n\nlong rk_logseries(rk_state *state, double p)\n{\n double q, r, U, V;\n \n r = log(1.0 - p);\n \n V = rk_double(state);\n if (V >= p) return 1;\n U = rk_double(state);\n q = 1.0 - exp(r*U);\n if (V <= q*q) return (long)floor(1 + log(V)/log(q));\n if (V <= q) return 1;\n return 2;\n}\n", + "source_code_before": "/* Copyright 2005 Robert Kern (robert.kern@gmail.com)\n *\n * Permission is hereby granted, free of charge, to any person obtaining a\n * copy of this software and associated documentation files (the\n * \"Software\"), to deal in the Software without restriction, including\n * without limitation the rights to use, copy, modify, merge, publish,\n * distribute, sublicense, and/or sell copies of the Software, and to\n * permit persons to whom the Software is furnished to do so, subject to\n * the following conditions:\n * \n * The above copyright notice and this permission notice shall be included\n * in all copies or substantial portions of the Software.\n * \n * THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS\n * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF\n * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.\n * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY\n * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,\n * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE\n * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.\n */\n\n/* The implementations of rk_hypergeometric_hyp(), rk_hypergeometric_hrua(),\n * and rk_triangular() were adapted from Ivan Frohne's rv.py which has this \n * license:\n * \n * Copyright 1998 by Ivan Frohne; Wasilla, Alaska, U.S.A.\n * All Rights Reserved\n *\n * Permission to use, copy, modify and distribute this software and its\n * documentation for any purpose, free of charge, is granted subject to the\n * following conditions:\n * The above copyright notice and this permission notice shall be included in\n * all copies or substantial portions of the software.\n *\n * THE SOFTWARE AND DOCUMENTATION IS PROVIDED WITHOUT WARRANTY OF ANY KIND,\n * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO MERCHANTABILITY, FITNESS\n * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHOR\n * OR COPYRIGHT HOLDER BE LIABLE FOR ANY CLAIM OR DAMAGES IN A CONTRACT\n * ACTION, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE\n * SOFTWARE OR ITS DOCUMENTATION.\n */\n\n#include \n#include \"distributions.h\"\n#include \n\n#ifndef min\n#define min(x,y) ((xy)?x:y)\n#endif\n\n/* log-gamma function to support some of these distributions. The \n * algorithm comes from SPECFUN by Shanjie Zhang and Jianming Jin and their\n * book \"Computation of Special Functions\", 1996, John Wiley & Sons, Inc.\n */\nextern double loggam(double x);\ndouble loggam(double x)\n{\n double x0, x2, xp, gl, gl0;\n long k, n;\n \n static double a[10] = {8.333333333333333e-02,-2.777777777777778e-03,\n 7.936507936507937e-04,-5.952380952380952e-04,\n 8.417508417508418e-04,-1.917526917526918e-03,\n 6.410256410256410e-03,-2.955065359477124e-02,\n 1.796443723688307e-01,-1.39243221690590e+00};\n x0 = x;\n n = 0;\n if ((x == 1.0) || (x == 2.0))\n {\n return 0.0;\n }\n else if (x <= 7.0)\n {\n n = (long)(7 - x);\n x0 = x + n;\n }\n x2 = 1.0/(x0*x0);\n xp = 2*M_PI;\n gl0 = a[9];\n for (k=8; k>=0; k--)\n {\n gl0 *= x2;\n gl0 += a[k];\n }\n gl = gl0/x0 + 0.5*log(xp) + (x0-0.5)*log(x0) - x0;\n if (x <= 7.0)\n {\n for (k=1; k<=n; k++)\n {\n gl -= log(x0-1.0);\n x0 -= 1.0;\n }\n }\n return gl;\n}\n\ndouble rk_normal(rk_state *state, double loc, double scale)\n{\n return loc + scale*rk_gauss(state);\n}\n\ndouble rk_standard_exponential(rk_state *state)\n{\n /* We use -log(1-U) since U is [0, 1) */\n return -log(1.0 - rk_double(state));\n}\n\ndouble rk_exponential(rk_state *state, double scale)\n{\n return scale * rk_standard_exponential(state);\n}\n\ndouble rk_uniform(rk_state *state, double loc, double scale)\n{\n return loc + scale*rk_double(state);\n}\n\ndouble rk_standard_gamma(rk_state *state, double shape)\n{\n double b, c;\n double U, V, X, Y;\n\n if (shape == 1.0)\n {\n return rk_standard_exponential(state);\n }\n else if (shape < 1.0)\n {\n for (;;)\n {\n U = rk_double(state);\n V = rk_standard_exponential(state);\n if (U <= 1.0 - shape)\n {\n X = pow(U, 1./shape);\n if (X <= V)\n {\n return X;\n }\n }\n else\n {\n Y = -log((1-U)/shape);\n X = pow(1.0 - shape + shape*Y, 1./shape);\n if (X <= (V + Y))\n {\n return X;\n }\n }\n }\n }\n else\n {\n b = shape - 1./3.;\n c = 1./sqrt(9*b);\n for (;;)\n {\n do\n {\n X = rk_gauss(state); \n V = 1.0 + c*X;\n } while (V <= 0.0);\n\n V = V*V*V;\n U = rk_double(state);\n if (U < 1.0 - 0.0331*(X*X)*(X*X)) return (b*V);\n if (log(U) < 0.5*X*X + b*(1. - V + log(V))) return (b*V);\n }\n }\n}\n\ndouble rk_gamma(rk_state *state, double shape, double scale)\n{\n return scale * rk_standard_gamma(state, shape);\n}\n\ndouble rk_beta(rk_state *state, double a, double b)\n{\n double Ga, Gb;\n\n if ((a <= 1.0) && (b <= 1.0))\n {\n double U, V, X, Y;\n /* Use Jonk's algorithm */\n\n while (1)\n {\n U = rk_double(state);\n V = rk_double(state);\n X = pow(U, 1.0/a);\n Y = pow(V, 1.0/b);\n\n if ((X + Y) <= 1.0)\n {\n return X;\n }\n }\n }\n else\n {\n Ga = rk_standard_gamma(state, a);\n Gb = rk_standard_gamma(state, b);\n return Ga/(Ga + Gb);\n }\n}\n\ndouble rk_chisquare(rk_state *state, double df)\n{\n return 2.0*rk_standard_gamma(state, df/2.0);\n}\n\ndouble rk_noncentral_chisquare(rk_state *state, double df, double nonc)\n{\n double Chi2, N;\n\n Chi2 = rk_chisquare(state, df-1);\n N = rk_gauss(state) + sqrt(nonc);\n return Chi2 + N*N;\n}\n\ndouble rk_f(rk_state *state, double dfnum, double dfden)\n{\n return rk_chisquare(state, dfnum) / rk_chisquare(state, dfden);\n}\n\ndouble rk_noncentral_f(rk_state *state, double dfnum, double dfden, double nonc)\n{\n return ((rk_noncentral_chisquare(state, dfnum, nonc)*dfden) /\n (rk_chisquare(state, dfden)*dfnum));\n}\n\nlong rk_binomial_btpe(rk_state *state, long n, double p)\n{\n double r,q,fm,p1,xm,xl,xr,c,laml,lamr,p2,p3,p4;\n double a,u,v,s,F,rho,t,A,nrq,x1,x2,f1,f2,z,z2,w,w2,x;\n long m,y,k,i;\n\n if (!(state->has_binomial) || \n (state->nsave != n) ||\n (state->psave != p))\n {\n /* initialize */\n state->nsave = n;\n state->psave = p;\n state->has_binomial = 1;\n state->r = r = min(p, 1.0-p);\n state->q = q = 1.0 - r;\n state->fm = fm = n*r+r;\n state->m = m = (long)floor(state->fm);\n state->p1 = p1 = floor(2.195*sqrt(n*r*q)-4.6*q) + 0.5;\n state->xm = xm = m + 0.5;\n state->xl = xl = xm - p1;\n state->xr = xr = xm + p1;\n state->c = c = 0.134 + 20.5/(15.3 + m);\n a = (fm - xl)/(fm-xl*r);\n state->laml = laml = a*(1.0 + a/2.0);\n a = (xr - fm)/(xr*q);\n state->lamr = lamr = a*(1.0 + a/2.0);\n state->p2 = p2 = p1*(1.0 + 2.0*c);\n state->p3 = p3 = p2 + c/laml;\n state->p4 = p4 = p3 + c/lamr;\n }\n else\n {\n r = state->r;\n q = state->q;\n fm = state->fm;\n m = state->m;\n p1 = state->p1;\n xm = state->xm;\n xl = state->xl;\n xr = state->xr;\n c = state->c;\n laml = state->laml;\n lamr = state->lamr;\n p2 = state->p2;\n p3 = state->p3;\n p4 = state->p4;\n }\n\n /* sigh ... */\n Step10:\n nrq = n*r*q;\n u = rk_double(state)*p4;\n v = rk_double(state);\n if (u > p1) goto Step20;\n y = (long)floor(xm - p1*v + u);\n goto Step60;\n\n Step20:\n if (u > p2) goto Step30;\n x = xl + (u - p1)/c;\n v = v*c + 1.0 - fabs(m - x + 0.5)/p1;\n if (v > 1.0) goto Step10;\n y = (long)floor(x);\n goto Step50;\n\n Step30:\n if (u > p3) goto Step40;\n y = (long)floor(xl + log(v)/laml);\n if (y < 0) goto Step10;\n v = v*(u-p2)*laml;\n goto Step50;\n\n Step40:\n y = (int)floor(xr - log(v)/lamr);\n if (y > n) goto Step10;\n v = v*(u-p3)*lamr;\n\n Step50:\n k = fabs(y - m);\n if ((k > 20) && (k < ((nrq)/2.0 - 1))) goto Step52;\n\n s = r/q;\n a = s*(n+1);\n F = 1.0;\n if (m < y)\n {\n for (i=m; i<=y; i++)\n {\n F *= (a/i - s);\n }\n }\n else if (m > y)\n {\n for (i=y; i<=m; i++)\n {\n F /= (a/i - s);\n }\n }\n else\n {\n if (v > F) goto Step10;\n goto Step60;\n }\n\n Step52:\n rho = (k/(nrq))*((k*(k/3.0 + 0.625) + 0.16666666666666666)/nrq + 0.5);\n t = -k*k/(2*nrq);\n A = log(v);\n if (A < (t - rho)) goto Step60;\n if (A > (t + rho)) goto Step10;\n\n x1 = y+1;\n f1 = m+1;\n z = n+1-m;\n w = n-y+1;\n x2 = x1*x1;\n f2 = f1*f1;\n z2 = z*z;\n w2 = w*w;\n if (A > (xm*log(f1/x1)\n + (n-m+0.5)*log(z/w)\n + (y-m)*log(w*r/(x1*q))\n + (13680.-(462.-(132.-(99.-140./f2)/f2)/f2)/f2)/f1/166320.\n + (13680.-(462.-(132.-(99.-140./z2)/z2)/z2)/z2)/z/166320.\n + (13680.-(462.-(132.-(99.-140./x2)/x2)/x2)/x2)/x1/166320.\n + (13680.-(462.-(132.-(99.-140./w2)/w2)/w2)/w2)/w/166320.))\n {\n goto Step10;\n }\n\n Step60:\n if (p > 0.5)\n {\n y = n - y;\n }\n\n return y;\n}\n\nlong rk_binomial_inversion(rk_state *state, long n, double p)\n{\n double q, qn, np, px, U;\n long X, bound;\n\n if (!(state->has_binomial) || \n (state->nsave != n) ||\n (state->psave != p))\n {\n state->nsave = n;\n state->psave = p;\n state->has_binomial = 1;\n state->q = q = 1.0 - p;\n state->r = qn = exp(n * log(q));\n state->c = np = n*p;\n state->m = bound = min(n, np + 10.0*sqrt(np));\n } else\n {\n q = state->q;\n qn = state->r;\n np = state->c;\n bound = state->m;\n }\n X = 0;\n px = qn;\n U = rk_double(state);\n while (U > px)\n {\n X++;\n if (X > bound) \n {\n X = 0;\n px = qn;\n U = rk_double(state);\n } else \n {\n U -= px;\n px = ((n-X+1) * p * px)/(X*q);\n }\n }\n return X;\n}\n\nlong rk_binomial(rk_state *state, long n, double p)\n{\n double q;\n\n if (p <= 0.5)\n {\n if (p*n <= 30.0)\n {\n return rk_binomial_inversion(state, n, p);\n }\n else\n {\n return rk_binomial_btpe(state, n, p);\n }\n }\n else\n {\n q = 1.0-p;\n if (q*n <= 30.0)\n {\n return n - rk_binomial_inversion(state, n, q);\n }\n else\n {\n return n - rk_binomial_btpe(state, n, q);\n }\n }\n\n}\n\nlong rk_negative_binomial(rk_state *state, long n, double p)\n{\n double Y;\n\n Y = rk_gamma(state, n, (1-p)/p);\n return rk_poisson(state, Y);\n}\n\nlong rk_poisson_mult(rk_state *state, double lam)\n{\n long X;\n double prod, U, enlam;\n\n enlam = exp(-lam);\n X = 0;\n prod = 1.0;\n while (1)\n {\n U = rk_double(state);\n prod *= U;\n if (prod > enlam)\n {\n X += 1;\n }\n else\n {\n return X;\n }\n }\n}\n\n#define LS2PI 0.91893853320467267\n#define TWELFTH 0.083333333333333333333333\nlong rk_poisson_ptrs(rk_state *state, double lam)\n{\n long k;\n double U, V, slam, loglam, a, b, invalpha, vr, us;\n\n slam = sqrt(lam);\n loglam = log(lam);\n b = 0.931 + 2.53*slam;\n a = -0.059 + 0.02483*b;\n invalpha = 1.1239 + 1.1328/(b-3.4);\n vr = 0.9277 - 3.6224/(b-2);\n\n while (1)\n {\n U = rk_double(state) - 0.5;\n V = rk_double(state);\n us = 0.5 - fabs(U);\n k = (long)floor((2*a/us + b)*U + lam + 0.43);\n if ((us >= 0.07) && (V <= vr))\n {\n return k;\n }\n if ((k < 0) ||\n ((us < 0.013) && (V > us)))\n {\n continue;\n }\n if ((log(V) + log(invalpha) - log(a/(us*us)+b)) <=\n (-lam + k*loglam - loggam(k+1)))\n {\n return k;\n }\n\n \n }\n\n}\n\nlong rk_poisson(rk_state *state, double lam)\n{\n if (lam >= 10)\n {\n return rk_poisson_ptrs(state, lam);\n }\n else\n {\n return rk_poisson_mult(state, lam);\n }\n}\n\ndouble rk_standard_cauchy(rk_state *state)\n{\n return rk_gauss(state) / rk_gauss(state);\n}\n\ndouble rk_standard_t(rk_state *state, double df)\n{\n double N, G, X;\n\n N = rk_gauss(state);\n G = rk_standard_gamma(state, df/2);\n X = sqrt(df/2)*N/sqrt(G);\n return X;\n}\n\ndouble rk_vonmises(rk_state *state, double mu, double kappa)\n{\n double r, rho, s;\n double U, V, W, Y, Z;\n double result, mod;\n\n if (kappa < 1e-8)\n {\n return M_PI * (2*rk_double(state)-1);\n }\n else\n {\n r = 1 + sqrt(1 + 4*kappa*kappa);\n rho = (r - sqrt(2*r))/(2*kappa);\n s = (1 + rho*rho)/(2*rho);\n\n while (1)\n {\n U = 2*rk_double(state) - 1;\n V = 2*rk_double(state) - 1;\n Z = cos(M_PI*U);\n W = (1 + s*Z)/(s + Z);\n Y = kappa * (s - W);\n if ((Y*(2-Y) - V >= 0) || (log(Y/V)+1 - Y >= 0))\n {\n break;\n }\n }\n\n if (U < 0)\n {\n result = acos(W);\n }\n else\n {\n result = -acos(W);\n }\n result += mu + M_PI;\n mod = fmod(result, 2*M_PI);\n if (mod && (mod < 0))\n {\n mod += 2*M_PI;\n }\n return mod - M_PI;\n }\n}\n\ndouble rk_pareto(rk_state *state, double a)\n{\n return exp(rk_standard_exponential(state)/a) - 1;\n}\n\ndouble rk_weibull(rk_state *state, double a)\n{\n return pow(rk_standard_exponential(state), 1./a);\n}\n\ndouble rk_power(rk_state *state, double a)\n{\n return pow(1 - exp(-rk_standard_exponential(state)), 1./a);\n}\n\ndouble rk_laplace(rk_state *state, double loc, double scale)\n{\n double U;\n \n U = rk_double(state);\n if (U < 0.5)\n {\n U = loc + scale * log(U + U);\n } else \n {\n U = loc - scale * log(2.0 - U - U);\n }\n return U;\n}\n\ndouble rk_gumbel(rk_state *state, double loc, double scale)\n{\n double U;\n \n U = 1.0 - rk_double(state);\n return loc - scale * log(-log(U));\n}\n\ndouble rk_logistic(rk_state *state, double loc, double scale)\n{\n double U;\n \n U = rk_double(state);\n return loc + scale * log(U/(1.0 - U));\n}\n\ndouble rk_lognormal(rk_state *state, double mean, double sigma)\n{\n return exp(rk_normal(state, mean, sigma));\n}\n\ndouble rk_rayleigh(rk_state *state, double mode)\n{\n return mode*sqrt(-2.0 * log(1.0 - rk_double(state)));\n}\n\ndouble rk_wald(rk_state *state, double mean, double scale)\n{\n double U, X, Y;\n double mu_2l;\n \n mu_2l = mean / (2*scale);\n Y = rk_gauss(state);\n Y = mean*Y*Y;\n X = mean + mu_2l*(Y - sqrt(4*scale*Y + Y*Y));\n U = rk_double(state);\n if (U <= mean/(mean+X))\n {\n return X;\n } else\n {\n return mean*mean/X;\n }\n}\n\nlong rk_zipf(rk_state *state, double a)\n{\n double T, U, V;\n long X;\n double b;\n \n b = pow(2.0, a-1.0);\n do\n {\n U = rk_double(state);\n V = rk_double(state);\n X = (long)floor(pow(U, -1.0/(a-1.0)));\n T = pow(1.0 + 1.0/X, a-1.0); \n } while ((V *X*(T-1.0)/(b-1.0)) > (T/b));\n return X;\n}\n\nlong rk_geometric_search(rk_state *state, double p)\n{\n double U;\n long X;\n double sum, prod, q;\n \n X = 1;\n sum = prod = p;\n q = 1.0 - p;\n U = rk_double(state);\n while (U > sum)\n {\n prod *= q;\n sum += prod;\n X++;\n }\n return X;\n}\n\nlong rk_geometric_inversion(rk_state *state, double p)\n{\n return (long)ceil(log(1.0-rk_double(state))/log(1.0-p));\n}\n\nlong rk_geometric(rk_state *state, double p)\n{\n if (p >= 0.333333333333333333333333)\n {\n return rk_geometric_search(state, p);\n } else\n {\n return rk_geometric_inversion(state, p);\n }\n}\n\nlong rk_hypergeometric_hyp(rk_state *state, long good, long bad, long sample)\n{\n long d1, K, Z;\n double d2, U, Y;\n \n d1 = bad + good - sample;\n d2 = (double)min(bad, good);\n \n Y = d2;\n K = sample;\n while (Y > 0.0)\n {\n U = rk_double(state);\n Y -= (long)floor(U + Y/(d1 + K));\n K--;\n if (K == 0) break;\n }\n Z = (long)(d2 - Y);\n if (bad > good) Z = sample - Z;\n return Z;\n}\n\n/* D1 = 2*sqrt(2/e) */\n/* D2 = 3 - 2*sqrt(3/e) */\n#define D1 1.7155277699214135\n#define D2 0.8989161620588988\nlong rk_hypergeometric_hrua(rk_state *state, long good, long bad, long sample)\n{\n long mingoodbad, maxgoodbad, popsize, m, d9;\n double d4, d5, d6, d7, d8, d10, d11;\n long Z;\n double T, W, X, Y;\n \n mingoodbad = min(good, bad);\n popsize = good + bad;\n maxgoodbad = max(good, bad);\n m = min(sample, popsize - sample);\n d4 = ((double)mingoodbad) / popsize;\n d5 = 1.0 - d4;\n d6 = m*d4 + 0.5;\n d7 = sqrt((popsize - m) * sample * d4 *d5 / (popsize-1) + 0.5);\n d8 = D1*d7 + D2;\n d9 = (long)floor((double)((m+1)*(mingoodbad+1))/(popsize+2));\n d10 = (loggam(d9+1) + loggam(mingoodbad-d9+1) + loggam(m-d9+1) + \n loggam(maxgoodbad-m+d9+1));\n d11 = min(min(m, mingoodbad)+1.0, floor(d6+16*d7));\n /* 16 for 16-decimal-digit precision in D1 and D2 */\n \n while (1)\n {\n X = rk_double(state);\n Y = rk_double(state);\n W = d6 + d8*(Y- 0.5)/X;\n \n /* fast rejection: */\n if ((W < 0.0) || (W >= d11)) continue;\n \n Z = (long)floor(W);\n T = d10 - (loggam(Z+1) + loggam(mingoodbad-Z+1) + loggam(m-Z+1) +\n loggam(maxgoodbad-m+Z+1));\n \n /* fast acceptance: */\n if ((X*(4.0-X)-3.0) <= T) break;\n \n /* fast rejection: */\n if (X*(X-T) >= 1) continue;\n\n if (2.0*log(X) <= T) break; /* acceptance */\n }\n \n /* this is a correction to HRUA* by Ivan Frohne in rv.py */\n if (bad > good) Z = m - Z;\n \n /* another fix from rv.py to allow sample to exceed popsize/2 */\n if (m < sample) Z = bad - Z;\n \n return Z;\n}\n#undef D1\n#undef D2\n\nlong rk_hypergeometric(rk_state *state, long good, long bad, long sample)\n{\n if (sample > 10)\n {\n return rk_hypergeometric_hrua(state, good, bad, sample);\n } else\n {\n return rk_hypergeometric_hyp(state, good, bad, sample);\n }\n}\n\ndouble rk_triangular(rk_state *state, double left, double mode, double right)\n{\n double base, leftbase, ratio, leftprod, rightprod;\n double U;\n \n base = right - left;\n leftbase = mode - left;\n ratio = leftbase / base;\n leftprod = leftbase*base;\n rightprod = (right - mode)*base;\n \n U = rk_double(state);\n if (U <= ratio)\n {\n return left + sqrt(U*leftprod);\n } else \n {\n return right - sqrt((1.0 - U) * rightprod); \n }\n}\n\nlong rk_logseries(rk_state *state, double p)\n{\n double q, r, U, V;\n \n r = log(1.0 - p);\n \n V = rk_double(state);\n if (V >= p) return 1;\n U = rk_double(state);\n q = 1.0 - exp(r*U);\n if (V <= q*q) return (long)floor(1 + log(V)/log(q));\n if (V <= q) return 1;\n return 2;\n}\n", + "methods": [ + { + "name": "loggam", + "long_name": "loggam( double x)", + "filename": "distributions.c", + "nloc": 39, + "complexity": 7, + "token_count": 225, + "parameters": [ + "x" + ], + "start_line": 61, + "end_line": 100, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 40, + "top_nesting_level": 0 + }, + { + "name": "rk_normal", + "long_name": "rk_normal( rk_state * state , double loc , double scale)", + "filename": "distributions.c", + "nloc": 4, + "complexity": 1, + "token_count": 24, + "parameters": [ + "state", + "loc", + "scale" + ], + "start_line": 102, + "end_line": 105, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 0 + }, + { + "name": "rk_standard_exponential", + "long_name": "rk_standard_exponential( rk_state * state)", + "filename": "distributions.c", + "nloc": 4, + "complexity": 1, + "token_count": 20, + "parameters": [ + "state" + ], + "start_line": 107, + "end_line": 111, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 5, + "top_nesting_level": 0 + }, + { + "name": "rk_exponential", + "long_name": "rk_exponential( rk_state * state , double scale)", + "filename": "distributions.c", + "nloc": 4, + "complexity": 1, + "token_count": 19, + "parameters": [ + "state", + "scale" + ], + "start_line": 113, + "end_line": 116, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 0 + }, + { + "name": "rk_uniform", + "long_name": "rk_uniform( rk_state * state , double loc , double scale)", + "filename": "distributions.c", + "nloc": 4, + "complexity": 1, + "token_count": 24, + "parameters": [ + "state", + "loc", + "scale" + ], + "start_line": 118, + "end_line": 121, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 0 + }, + { + "name": "rk_standard_gamma", + "long_name": "rk_standard_gamma( rk_state * state , double shape)", + "filename": "distributions.c", + "nloc": 51, + "complexity": 11, + "token_count": 279, + "parameters": [ + "state", + "shape" + ], + "start_line": 123, + "end_line": 175, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 53, + "top_nesting_level": 0 + }, + { + "name": "rk_gamma", + "long_name": "rk_gamma( rk_state * state , double shape , double scale)", + "filename": "distributions.c", + "nloc": 4, + "complexity": 1, + "token_count": 24, + "parameters": [ + "state", + "shape", + "scale" + ], + "start_line": 177, + "end_line": 180, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 0 + }, + { + "name": "rk_beta", + "long_name": "rk_beta( rk_state * state , double a , double b)", + "filename": "distributions.c", + "nloc": 25, + "complexity": 5, + "token_count": 131, + "parameters": [ + "state", + "a", + "b" + ], + "start_line": 182, + "end_line": 210, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 29, + "top_nesting_level": 0 + }, + { + "name": "rk_chisquare", + "long_name": "rk_chisquare( rk_state * state , double df)", + "filename": "distributions.c", + "nloc": 4, + "complexity": 1, + "token_count": 23, + "parameters": [ + "state", + "df" + ], + "start_line": 212, + "end_line": 215, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 0 + }, + { + "name": "rk_noncentral_chisquare", + "long_name": "rk_noncentral_chisquare( rk_state * state , double df , double nonc)", + "filename": "distributions.c", + "nloc": 7, + "complexity": 1, + "token_count": 49, + "parameters": [ + "state", + "df", + "nonc" + ], + "start_line": 217, + "end_line": 224, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 8, + "top_nesting_level": 0 + }, + { + "name": "rk_f", + "long_name": "rk_f( rk_state * state , double dfnum , double dfden)", + "filename": "distributions.c", + "nloc": 4, + "complexity": 1, + "token_count": 29, + "parameters": [ + "state", + "dfnum", + "dfden" + ], + "start_line": 226, + "end_line": 229, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 0 + }, + { + "name": "rk_noncentral_f", + "long_name": "rk_noncentral_f( rk_state * state , double dfnum , double dfden , double nonc)", + "filename": "distributions.c", + "nloc": 5, + "complexity": 1, + "token_count": 44, + "parameters": [ + "state", + "dfnum", + "dfden", + "nonc" + ], + "start_line": 231, + "end_line": 235, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 5, + "top_nesting_level": 0 + }, + { + "name": "rk_binomial_btpe", + "long_name": "rk_binomial_btpe( rk_state * state , long n , double p)", + "filename": "distributions.c", + "nloc": 126, + "complexity": 21, + "token_count": 1119, + "parameters": [ + "state", + "n", + "p" + ], + "start_line": 237, + "end_line": 375, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 139, + "top_nesting_level": 0 + }, + { + "name": "rk_binomial_inversion", + "long_name": "rk_binomial_inversion( rk_state * state , long n , double p)", + "filename": "distributions.c", + "nloc": 41, + "complexity": 6, + "token_count": 239, + "parameters": [ + "state", + "n", + "p" + ], + "start_line": 377, + "end_line": 418, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 42, + "top_nesting_level": 0 + }, + { + "name": "rk_binomial", + "long_name": "rk_binomial( rk_state * state , long n , double p)", + "filename": "distributions.c", + "nloc": 27, + "complexity": 4, + "token_count": 104, + "parameters": [ + "state", + "n", + "p" + ], + "start_line": 420, + "end_line": 448, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 29, + "top_nesting_level": 0 + }, + { + "name": "rk_negative_binomial", + "long_name": "rk_negative_binomial( rk_state * state , long n , double p)", + "filename": "distributions.c", + "nloc": 6, + "complexity": 1, + "token_count": 42, + "parameters": [ + "state", + "n", + "p" + ], + "start_line": 450, + "end_line": 456, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 7, + "top_nesting_level": 0 + }, + { + "name": "rk_poisson_mult", + "long_name": "rk_poisson_mult( rk_state * state , double lam)", + "filename": "distributions.c", + "nloc": 21, + "complexity": 3, + "token_count": 73, + "parameters": [ + "state", + "lam" + ], + "start_line": 458, + "end_line": 479, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 22, + "top_nesting_level": 0 + }, + { + "name": "rk_poisson_ptrs", + "long_name": "rk_poisson_ptrs( rk_state * state , double lam)", + "filename": "distributions.c", + "nloc": 32, + "complexity": 8, + "token_count": 236, + "parameters": [ + "state", + "lam" + ], + "start_line": 483, + "end_line": 519, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 37, + "top_nesting_level": 0 + }, + { + "name": "rk_poisson", + "long_name": "rk_poisson( rk_state * state , double lam)", + "filename": "distributions.c", + "nloc": 11, + "complexity": 2, + "token_count": 38, + "parameters": [ + "state", + "lam" + ], + "start_line": 521, + "end_line": 531, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 11, + "top_nesting_level": 0 + }, + { + "name": "rk_standard_cauchy", + "long_name": "rk_standard_cauchy( rk_state * state)", + "filename": "distributions.c", + "nloc": 4, + "complexity": 1, + "token_count": 19, + "parameters": [ + "state" + ], + "start_line": 533, + "end_line": 536, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 0 + }, + { + "name": "rk_standard_t", + "long_name": "rk_standard_t( rk_state * state , double df)", + "filename": "distributions.c", + "nloc": 8, + "complexity": 1, + "token_count": 55, + "parameters": [ + "state", + "df" + ], + "start_line": 538, + "end_line": 546, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 9, + "top_nesting_level": 0 + }, + { + "name": "rk_vonmises", + "long_name": "rk_vonmises( rk_state * state , double mu , double kappa)", + "filename": "distributions.c", + "nloc": 43, + "complexity": 8, + "token_count": 278, + "parameters": [ + "state", + "mu", + "kappa" + ], + "start_line": 548, + "end_line": 593, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 46, + "top_nesting_level": 0 + }, + { + "name": "rk_pareto", + "long_name": "rk_pareto( rk_state * state , double a)", + "filename": "distributions.c", + "nloc": 4, + "complexity": 1, + "token_count": 24, + "parameters": [ + "state", + "a" + ], + "start_line": 595, + "end_line": 598, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 0 + }, + { + "name": "rk_weibull", + "long_name": "rk_weibull( rk_state * state , double a)", + "filename": "distributions.c", + "nloc": 4, + "complexity": 1, + "token_count": 24, + "parameters": [ + "state", + "a" + ], + "start_line": 600, + "end_line": 603, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 0 + }, + { + "name": "rk_power", + "long_name": "rk_power( rk_state * state , double a)", + "filename": "distributions.c", + "nloc": 4, + "complexity": 1, + "token_count": 30, + "parameters": [ + "state", + "a" + ], + "start_line": 605, + "end_line": 608, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 0 + }, + { + "name": "rk_laplace", + "long_name": "rk_laplace( rk_state * state , double loc , double scale)", + "filename": "distributions.c", + "nloc": 13, + "complexity": 2, + "token_count": 66, + "parameters": [ + "state", + "loc", + "scale" + ], + "start_line": 610, + "end_line": 623, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 14, + "top_nesting_level": 0 + }, + { + "name": "rk_gumbel", + "long_name": "rk_gumbel( rk_state * state , double loc , double scale)", + "filename": "distributions.c", + "nloc": 6, + "complexity": 1, + "token_count": 40, + "parameters": [ + "state", + "loc", + "scale" + ], + "start_line": 625, + "end_line": 631, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 7, + "top_nesting_level": 0 + }, + { + "name": "rk_logistic", + "long_name": "rk_logistic( rk_state * state , double loc , double scale)", + "filename": "distributions.c", + "nloc": 6, + "complexity": 1, + "token_count": 40, + "parameters": [ + "state", + "loc", + "scale" + ], + "start_line": 633, + "end_line": 639, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 7, + "top_nesting_level": 0 + }, + { + "name": "rk_lognormal", + "long_name": "rk_lognormal( rk_state * state , double mean , double sigma)", + "filename": "distributions.c", + "nloc": 4, + "complexity": 1, + "token_count": 27, + "parameters": [ + "state", + "mean", + "sigma" + ], + "start_line": 641, + "end_line": 644, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 0 + }, + { + "name": "rk_rayleigh", + "long_name": "rk_rayleigh( rk_state * state , double mode)", + "filename": "distributions.c", + "nloc": 4, + "complexity": 1, + "token_count": 30, + "parameters": [ + "state", + "mode" + ], + "start_line": 646, + "end_line": 649, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 0 + }, + { + "name": "rk_wald", + "long_name": "rk_wald( rk_state * state , double mean , double scale)", + "filename": "distributions.c", + "nloc": 17, + "complexity": 2, + "token_count": 106, + "parameters": [ + "state", + "mean", + "scale" + ], + "start_line": 651, + "end_line": 668, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 18, + "top_nesting_level": 0 + }, + { + "name": "rk_zipf", + "long_name": "rk_zipf( rk_state * state , double a)", + "filename": "distributions.c", + "nloc": 15, + "complexity": 2, + "token_count": 119, + "parameters": [ + "state", + "a" + ], + "start_line": 670, + "end_line": 685, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 16, + "top_nesting_level": 0 + }, + { + "name": "rk_geometric_search", + "long_name": "rk_geometric_search( rk_state * state , double p)", + "filename": "distributions.c", + "nloc": 17, + "complexity": 2, + "token_count": 70, + "parameters": [ + "state", + "p" + ], + "start_line": 687, + "end_line": 704, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 18, + "top_nesting_level": 0 + }, + { + "name": "rk_geometric_inversion", + "long_name": "rk_geometric_inversion( rk_state * state , double p)", + "filename": "distributions.c", + "nloc": 4, + "complexity": 1, + "token_count": 35, + "parameters": [ + "state", + "p" + ], + "start_line": 706, + "end_line": 709, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 0 + }, + { + "name": "rk_geometric", + "long_name": "rk_geometric( rk_state * state , double p)", + "filename": "distributions.c", + "nloc": 10, + "complexity": 2, + "token_count": 38, + "parameters": [ + "state", + "p" + ], + "start_line": 711, + "end_line": 720, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 10, + "top_nesting_level": 0 + }, + { + "name": "rk_hypergeometric_hyp", + "long_name": "rk_hypergeometric_hyp( rk_state * state , long good , long bad , long sample)", + "filename": "distributions.c", + "nloc": 19, + "complexity": 4, + "token_count": 129, + "parameters": [ + "state", + "good", + "bad", + "sample" + ], + "start_line": 722, + "end_line": 742, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 21, + "top_nesting_level": 0 + }, + { + "name": "rk_hypergeometric_hrua", + "long_name": "rk_hypergeometric_hrua( rk_state * state , long good , long bad , long sample)", + "filename": "distributions.c", + "nloc": 36, + "complexity": 9, + "token_count": 416, + "parameters": [ + "state", + "good", + "bad", + "sample" + ], + "start_line": 748, + "end_line": 799, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 52, + "top_nesting_level": 0 + }, + { + "name": "rk_hypergeometric", + "long_name": "rk_hypergeometric( rk_state * state , long good , long bad , long sample)", + "filename": "distributions.c", + "nloc": 10, + "complexity": 2, + "token_count": 52, + "parameters": [ + "state", + "good", + "bad", + "sample" + ], + "start_line": 803, + "end_line": 812, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 10, + "top_nesting_level": 0 + }, + { + "name": "rk_triangular", + "long_name": "rk_triangular( rk_state * state , double left , double mode , double right)", + "filename": "distributions.c", + "nloc": 18, + "complexity": 2, + "token_count": 107, + "parameters": [ + "state", + "left", + "mode", + "right" + ], + "start_line": 814, + "end_line": 833, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 20, + "top_nesting_level": 0 + }, + { + "name": "rk_logseries", + "long_name": "rk_logseries( rk_state * state , double p)", + "filename": "distributions.c", + "nloc": 12, + "complexity": 4, + "token_count": 102, + "parameters": [ + "state", + "p" + ], + "start_line": 835, + "end_line": 848, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 14, + "top_nesting_level": 0 + } + ], + "methods_before": [ + { + "name": "loggam", + "long_name": "loggam( double x)", + "filename": "distributions.c", + "nloc": 39, + "complexity": 7, + "token_count": 225, + "parameters": [ + "x" + ], + "start_line": 58, + "end_line": 97, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 40, + "top_nesting_level": 0 + }, + { + "name": "rk_normal", + "long_name": "rk_normal( rk_state * state , double loc , double scale)", + "filename": "distributions.c", + "nloc": 4, + "complexity": 1, + "token_count": 24, + "parameters": [ + "state", + "loc", + "scale" + ], + "start_line": 99, + "end_line": 102, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 0 + }, + { + "name": "rk_standard_exponential", + "long_name": "rk_standard_exponential( rk_state * state)", + "filename": "distributions.c", + "nloc": 4, + "complexity": 1, + "token_count": 20, + "parameters": [ + "state" + ], + "start_line": 104, + "end_line": 108, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 5, + "top_nesting_level": 0 + }, + { + "name": "rk_exponential", + "long_name": "rk_exponential( rk_state * state , double scale)", + "filename": "distributions.c", + "nloc": 4, + "complexity": 1, + "token_count": 19, + "parameters": [ + "state", + "scale" + ], + "start_line": 110, + "end_line": 113, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 0 + }, + { + "name": "rk_uniform", + "long_name": "rk_uniform( rk_state * state , double loc , double scale)", + "filename": "distributions.c", + "nloc": 4, + "complexity": 1, + "token_count": 24, + "parameters": [ + "state", + "loc", + "scale" + ], + "start_line": 115, + "end_line": 118, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 0 + }, + { + "name": "rk_standard_gamma", + "long_name": "rk_standard_gamma( rk_state * state , double shape)", + "filename": "distributions.c", + "nloc": 51, + "complexity": 11, + "token_count": 279, + "parameters": [ + "state", + "shape" + ], + "start_line": 120, + "end_line": 172, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 53, + "top_nesting_level": 0 + }, + { + "name": "rk_gamma", + "long_name": "rk_gamma( rk_state * state , double shape , double scale)", + "filename": "distributions.c", + "nloc": 4, + "complexity": 1, + "token_count": 24, + "parameters": [ + "state", + "shape", + "scale" + ], + "start_line": 174, + "end_line": 177, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 0 + }, + { + "name": "rk_beta", + "long_name": "rk_beta( rk_state * state , double a , double b)", + "filename": "distributions.c", + "nloc": 25, + "complexity": 5, + "token_count": 131, + "parameters": [ + "state", + "a", + "b" + ], + "start_line": 179, + "end_line": 207, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 29, + "top_nesting_level": 0 + }, + { + "name": "rk_chisquare", + "long_name": "rk_chisquare( rk_state * state , double df)", + "filename": "distributions.c", + "nloc": 4, + "complexity": 1, + "token_count": 23, + "parameters": [ + "state", + "df" + ], + "start_line": 209, + "end_line": 212, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 0 + }, + { + "name": "rk_noncentral_chisquare", + "long_name": "rk_noncentral_chisquare( rk_state * state , double df , double nonc)", + "filename": "distributions.c", + "nloc": 7, + "complexity": 1, + "token_count": 49, + "parameters": [ + "state", + "df", + "nonc" + ], + "start_line": 214, + "end_line": 221, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 8, + "top_nesting_level": 0 + }, + { + "name": "rk_f", + "long_name": "rk_f( rk_state * state , double dfnum , double dfden)", + "filename": "distributions.c", + "nloc": 4, + "complexity": 1, + "token_count": 29, + "parameters": [ + "state", + "dfnum", + "dfden" + ], + "start_line": 223, + "end_line": 226, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 0 + }, + { + "name": "rk_noncentral_f", + "long_name": "rk_noncentral_f( rk_state * state , double dfnum , double dfden , double nonc)", + "filename": "distributions.c", + "nloc": 5, + "complexity": 1, + "token_count": 44, + "parameters": [ + "state", + "dfnum", + "dfden", + "nonc" + ], + "start_line": 228, + "end_line": 232, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 5, + "top_nesting_level": 0 + }, + { + "name": "rk_binomial_btpe", + "long_name": "rk_binomial_btpe( rk_state * state , long n , double p)", + "filename": "distributions.c", + "nloc": 126, + "complexity": 21, + "token_count": 1119, + "parameters": [ + "state", + "n", + "p" + ], + "start_line": 234, + "end_line": 372, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 139, + "top_nesting_level": 0 + }, + { + "name": "rk_binomial_inversion", + "long_name": "rk_binomial_inversion( rk_state * state , long n , double p)", + "filename": "distributions.c", + "nloc": 41, + "complexity": 6, + "token_count": 239, + "parameters": [ + "state", + "n", + "p" + ], + "start_line": 374, + "end_line": 415, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 42, + "top_nesting_level": 0 + }, + { + "name": "rk_binomial", + "long_name": "rk_binomial( rk_state * state , long n , double p)", + "filename": "distributions.c", + "nloc": 27, + "complexity": 4, + "token_count": 104, + "parameters": [ + "state", + "n", + "p" + ], + "start_line": 417, + "end_line": 445, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 29, + "top_nesting_level": 0 + }, + { + "name": "rk_negative_binomial", + "long_name": "rk_negative_binomial( rk_state * state , long n , double p)", + "filename": "distributions.c", + "nloc": 6, + "complexity": 1, + "token_count": 42, + "parameters": [ + "state", + "n", + "p" + ], + "start_line": 447, + "end_line": 453, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 7, + "top_nesting_level": 0 + }, + { + "name": "rk_poisson_mult", + "long_name": "rk_poisson_mult( rk_state * state , double lam)", + "filename": "distributions.c", + "nloc": 21, + "complexity": 3, + "token_count": 73, + "parameters": [ + "state", + "lam" + ], + "start_line": 455, + "end_line": 476, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 22, + "top_nesting_level": 0 + }, + { + "name": "rk_poisson_ptrs", + "long_name": "rk_poisson_ptrs( rk_state * state , double lam)", + "filename": "distributions.c", + "nloc": 32, + "complexity": 8, + "token_count": 236, + "parameters": [ + "state", + "lam" + ], + "start_line": 480, + "end_line": 516, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 37, + "top_nesting_level": 0 + }, + { + "name": "rk_poisson", + "long_name": "rk_poisson( rk_state * state , double lam)", + "filename": "distributions.c", + "nloc": 11, + "complexity": 2, + "token_count": 38, + "parameters": [ + "state", + "lam" + ], + "start_line": 518, + "end_line": 528, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 11, + "top_nesting_level": 0 + }, + { + "name": "rk_standard_cauchy", + "long_name": "rk_standard_cauchy( rk_state * state)", + "filename": "distributions.c", + "nloc": 4, + "complexity": 1, + "token_count": 19, + "parameters": [ + "state" + ], + "start_line": 530, + "end_line": 533, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 0 + }, + { + "name": "rk_standard_t", + "long_name": "rk_standard_t( rk_state * state , double df)", + "filename": "distributions.c", + "nloc": 8, + "complexity": 1, + "token_count": 55, + "parameters": [ + "state", + "df" + ], + "start_line": 535, + "end_line": 543, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 9, + "top_nesting_level": 0 + }, + { + "name": "rk_vonmises", + "long_name": "rk_vonmises( rk_state * state , double mu , double kappa)", + "filename": "distributions.c", + "nloc": 43, + "complexity": 8, + "token_count": 278, + "parameters": [ + "state", + "mu", + "kappa" + ], + "start_line": 545, + "end_line": 590, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 46, + "top_nesting_level": 0 + }, + { + "name": "rk_pareto", + "long_name": "rk_pareto( rk_state * state , double a)", + "filename": "distributions.c", + "nloc": 4, + "complexity": 1, + "token_count": 24, + "parameters": [ + "state", + "a" + ], + "start_line": 592, + "end_line": 595, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 0 + }, + { + "name": "rk_weibull", + "long_name": "rk_weibull( rk_state * state , double a)", + "filename": "distributions.c", + "nloc": 4, + "complexity": 1, + "token_count": 24, + "parameters": [ + "state", + "a" + ], + "start_line": 597, + "end_line": 600, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 0 + }, + { + "name": "rk_power", + "long_name": "rk_power( rk_state * state , double a)", + "filename": "distributions.c", + "nloc": 4, + "complexity": 1, + "token_count": 30, + "parameters": [ + "state", + "a" + ], + "start_line": 602, + "end_line": 605, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 0 + }, + { + "name": "rk_laplace", + "long_name": "rk_laplace( rk_state * state , double loc , double scale)", + "filename": "distributions.c", + "nloc": 13, + "complexity": 2, + "token_count": 66, + "parameters": [ + "state", + "loc", + "scale" + ], + "start_line": 607, + "end_line": 620, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 14, + "top_nesting_level": 0 + }, + { + "name": "rk_gumbel", + "long_name": "rk_gumbel( rk_state * state , double loc , double scale)", + "filename": "distributions.c", + "nloc": 6, + "complexity": 1, + "token_count": 40, + "parameters": [ + "state", + "loc", + "scale" + ], + "start_line": 622, + "end_line": 628, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 7, + "top_nesting_level": 0 + }, + { + "name": "rk_logistic", + "long_name": "rk_logistic( rk_state * state , double loc , double scale)", + "filename": "distributions.c", + "nloc": 6, + "complexity": 1, + "token_count": 40, + "parameters": [ + "state", + "loc", + "scale" + ], + "start_line": 630, + "end_line": 636, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 7, + "top_nesting_level": 0 + }, + { + "name": "rk_lognormal", + "long_name": "rk_lognormal( rk_state * state , double mean , double sigma)", + "filename": "distributions.c", + "nloc": 4, + "complexity": 1, + "token_count": 27, + "parameters": [ + "state", + "mean", + "sigma" + ], + "start_line": 638, + "end_line": 641, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 0 + }, + { + "name": "rk_rayleigh", + "long_name": "rk_rayleigh( rk_state * state , double mode)", + "filename": "distributions.c", + "nloc": 4, + "complexity": 1, + "token_count": 30, + "parameters": [ + "state", + "mode" + ], + "start_line": 643, + "end_line": 646, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 0 + }, + { + "name": "rk_wald", + "long_name": "rk_wald( rk_state * state , double mean , double scale)", + "filename": "distributions.c", + "nloc": 17, + "complexity": 2, + "token_count": 106, + "parameters": [ + "state", + "mean", + "scale" + ], + "start_line": 648, + "end_line": 665, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 18, + "top_nesting_level": 0 + }, + { + "name": "rk_zipf", + "long_name": "rk_zipf( rk_state * state , double a)", + "filename": "distributions.c", + "nloc": 15, + "complexity": 2, + "token_count": 119, + "parameters": [ + "state", + "a" + ], + "start_line": 667, + "end_line": 682, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 16, + "top_nesting_level": 0 + }, + { + "name": "rk_geometric_search", + "long_name": "rk_geometric_search( rk_state * state , double p)", + "filename": "distributions.c", + "nloc": 17, + "complexity": 2, + "token_count": 70, + "parameters": [ + "state", + "p" + ], + "start_line": 684, + "end_line": 701, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 18, + "top_nesting_level": 0 + }, + { + "name": "rk_geometric_inversion", + "long_name": "rk_geometric_inversion( rk_state * state , double p)", + "filename": "distributions.c", + "nloc": 4, + "complexity": 1, + "token_count": 35, + "parameters": [ + "state", + "p" + ], + "start_line": 703, + "end_line": 706, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 0 + }, + { + "name": "rk_geometric", + "long_name": "rk_geometric( rk_state * state , double p)", + "filename": "distributions.c", + "nloc": 10, + "complexity": 2, + "token_count": 38, + "parameters": [ + "state", + "p" + ], + "start_line": 708, + "end_line": 717, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 10, + "top_nesting_level": 0 + }, + { + "name": "rk_hypergeometric_hyp", + "long_name": "rk_hypergeometric_hyp( rk_state * state , long good , long bad , long sample)", + "filename": "distributions.c", + "nloc": 19, + "complexity": 4, + "token_count": 129, + "parameters": [ + "state", + "good", + "bad", + "sample" + ], + "start_line": 719, + "end_line": 739, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 21, + "top_nesting_level": 0 + }, + { + "name": "rk_hypergeometric_hrua", + "long_name": "rk_hypergeometric_hrua( rk_state * state , long good , long bad , long sample)", + "filename": "distributions.c", + "nloc": 36, + "complexity": 9, + "token_count": 416, + "parameters": [ + "state", + "good", + "bad", + "sample" + ], + "start_line": 745, + "end_line": 796, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 52, + "top_nesting_level": 0 + }, + { + "name": "rk_hypergeometric", + "long_name": "rk_hypergeometric( rk_state * state , long good , long bad , long sample)", + "filename": "distributions.c", + "nloc": 10, + "complexity": 2, + "token_count": 52, + "parameters": [ + "state", + "good", + "bad", + "sample" + ], + "start_line": 800, + "end_line": 809, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 10, + "top_nesting_level": 0 + }, + { + "name": "rk_triangular", + "long_name": "rk_triangular( rk_state * state , double left , double mode , double right)", + "filename": "distributions.c", + "nloc": 18, + "complexity": 2, + "token_count": 107, + "parameters": [ + "state", + "left", + "mode", + "right" + ], + "start_line": 811, + "end_line": 830, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 20, + "top_nesting_level": 0 + }, + { + "name": "rk_logseries", + "long_name": "rk_logseries( rk_state * state , double p)", + "filename": "distributions.c", + "nloc": 12, + "complexity": 4, + "token_count": 102, + "parameters": [ + "state", + "p" + ], + "start_line": 832, + "end_line": 845, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 14, + "top_nesting_level": 0 + } + ], + "changed_methods": [], + "nloc": 681, + "complexity": 126, + "token_count": 4603, + "diff_parsed": { + "added": [ + "#ifndef M_PI", + "#define M_PI 3.14159265358979323846264338328", + "#endif" + ], + "deleted": [] + } + }, + { + "old_path": "numpy/random/setup.py", + "new_path": "numpy/random/setup.py", + "filename": "setup.py", + "extension": "py", + "change_type": "MODIFY", + "diff": "@@ -1,16 +1,31 @@\n \n-from os.path import join\n+from os.path import join, split\n \n def configuration(parent_package='',top_path=None):\n- from numpy.distutils.misc_util import Configuration\n+ from numpy.distutils.misc_util import Configuration, get_mathlibs\n config = Configuration('random',parent_package,top_path)\n \n+ def generate_libraries(ext, build_dir):\n+ config_cmd = config.get_config_cmd()\n+ if top_path is None:\n+ libs = get_mathlibs()\n+ else:\n+ path = join(split(build_dir)[0],'core')\n+ libs = get_mathlibs(path)\n+ tc = testcode_wincrypt()\n+ if config_cmd.try_run(tc):\n+ libs.append('Advapi32')\n+ ext.libraries.extend(libs)\n+ print \"**** got \", libs\n+ return None\n+\n+ libs = []\n # Configure mtrand\n config.add_extension('mtrand',\n sources=[join('mtrand', x) for x in \n ['mtrand.c', 'randomkit.c', 'initarray.c',\n- 'distributions.c']],\n- libraries=['m'],\n+ 'distributions.c']]+[generate_libraries],\n+ libraries=libs,\n depends = [join('mtrand','*.h'),\n join('mtrand','*.pyx'),\n join('mtrand','*.pxi'),\n@@ -19,6 +34,21 @@ def configuration(parent_package='',top_path=None):\n \n return config\n \n+def testcode_wincrypt():\n+ return \"\"\"\\\n+/* check to see if _WIN32 is defined */\n+int main(int argc, char *argv[])\n+{\n+#ifdef _WIN32\n+ return 0;\n+#else\n+#error No _WIN32\n+#endif\n+ return -1;\n+}\n+\"\"\"\n+\n if __name__ == '__main__':\n from numpy.distutils.core import setup\n setup(**configuration(top_path='').todict())\n+\n", + "added_lines": 34, + "deleted_lines": 4, + "source_code": "\nfrom os.path import join, split\n\ndef configuration(parent_package='',top_path=None):\n from numpy.distutils.misc_util import Configuration, get_mathlibs\n config = Configuration('random',parent_package,top_path)\n\n def generate_libraries(ext, build_dir):\n config_cmd = config.get_config_cmd()\n if top_path is None:\n libs = get_mathlibs()\n else:\n path = join(split(build_dir)[0],'core')\n libs = get_mathlibs(path)\n tc = testcode_wincrypt()\n if config_cmd.try_run(tc):\n libs.append('Advapi32')\n ext.libraries.extend(libs)\n print \"**** got \", libs\n return None\n\n libs = []\n # Configure mtrand\n config.add_extension('mtrand',\n sources=[join('mtrand', x) for x in \n ['mtrand.c', 'randomkit.c', 'initarray.c',\n 'distributions.c']]+[generate_libraries],\n libraries=libs,\n depends = [join('mtrand','*.h'),\n join('mtrand','*.pyx'),\n join('mtrand','*.pxi'),\n ]\n )\n \n return config\n\ndef testcode_wincrypt():\n return \"\"\"\\\n/* check to see if _WIN32 is defined */\nint main(int argc, char *argv[])\n{\n#ifdef _WIN32\n return 0;\n#else\n#error No _WIN32\n#endif\n return -1;\n}\n\"\"\"\n\nif __name__ == '__main__':\n from numpy.distutils.core import setup\n setup(**configuration(top_path='').todict())\n\n", + "source_code_before": "\nfrom os.path import join\n\ndef configuration(parent_package='',top_path=None):\n from numpy.distutils.misc_util import Configuration\n config = Configuration('random',parent_package,top_path)\n\n # Configure mtrand\n config.add_extension('mtrand',\n sources=[join('mtrand', x) for x in \n ['mtrand.c', 'randomkit.c', 'initarray.c',\n 'distributions.c']],\n libraries=['m'],\n depends = [join('mtrand','*.h'),\n join('mtrand','*.pyx'),\n join('mtrand','*.pxi'),\n ]\n )\n \n return config\n\nif __name__ == '__main__':\n from numpy.distutils.core import setup\n setup(**configuration(top_path='').todict())\n", + "methods": [ + { + "name": "configuration.generate_libraries", + "long_name": "configuration.generate_libraries( ext , build_dir )", + "filename": "setup.py", + "nloc": 13, + "complexity": 3, + "token_count": 79, + "parameters": [ + "ext", + "build_dir" + ], + "start_line": 8, + "end_line": 20, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 13, + "top_nesting_level": 1 + }, + { + "name": "configuration", + "long_name": "configuration( parent_package = '' , top_path = None )", + "filename": "setup.py", + "nloc": 16, + "complexity": 2, + "token_count": 102, + "parameters": [ + "parent_package", + "top_path" + ], + "start_line": 4, + "end_line": 35, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 32, + "top_nesting_level": 0 + }, + { + "name": "testcode_wincrypt", + "long_name": "testcode_wincrypt( )", + "filename": "setup.py", + "nloc": 13, + "complexity": 1, + "token_count": 6, + "parameters": [], + "start_line": 37, + "end_line": 49, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 13, + "top_nesting_level": 0 + } + ], + "methods_before": [ + { + "name": "configuration", + "long_name": "configuration( parent_package = '' , top_path = None )", + "filename": "setup.py", + "nloc": 14, + "complexity": 2, + "token_count": 92, + "parameters": [ + "parent_package", + "top_path" + ], + "start_line": 4, + "end_line": 20, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 17, + "top_nesting_level": 0 + } + ], + "changed_methods": [ + { + "name": "configuration", + "long_name": "configuration( parent_package = '' , top_path = None )", + "filename": "setup.py", + "nloc": 16, + "complexity": 2, + "token_count": 102, + "parameters": [ + "parent_package", + "top_path" + ], + "start_line": 4, + "end_line": 35, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 32, + "top_nesting_level": 0 + }, + { + "name": "testcode_wincrypt", + "long_name": "testcode_wincrypt( )", + "filename": "setup.py", + "nloc": 13, + "complexity": 1, + "token_count": 6, + "parameters": [], + "start_line": 37, + "end_line": 49, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 13, + "top_nesting_level": 0 + }, + { + "name": "configuration.generate_libraries", + "long_name": "configuration.generate_libraries( ext , build_dir )", + "filename": "setup.py", + "nloc": 13, + "complexity": 3, + "token_count": 79, + "parameters": [ + "ext", + "build_dir" + ], + "start_line": 8, + "end_line": 20, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 13, + "top_nesting_level": 1 + } + ], + "nloc": 45, + "complexity": 6, + "token_count": 223, + "diff_parsed": { + "added": [ + "from os.path import join, split", + " from numpy.distutils.misc_util import Configuration, get_mathlibs", + " def generate_libraries(ext, build_dir):", + " config_cmd = config.get_config_cmd()", + " if top_path is None:", + " libs = get_mathlibs()", + " else:", + " path = join(split(build_dir)[0],'core')", + " libs = get_mathlibs(path)", + " tc = testcode_wincrypt()", + " if config_cmd.try_run(tc):", + " libs.append('Advapi32')", + " ext.libraries.extend(libs)", + " print \"**** got \", libs", + " return None", + "", + " libs = []", + " 'distributions.c']]+[generate_libraries],", + " libraries=libs,", + "def testcode_wincrypt():", + " return \"\"\"\\", + "/* check to see if _WIN32 is defined */", + "int main(int argc, char *argv[])", + "{", + "#ifdef _WIN32", + " return 0;", + "#else", + "#error No _WIN32", + "#endif", + " return -1;", + "}", + "\"\"\"", + "", + "" + ], + "deleted": [ + "from os.path import join", + " from numpy.distutils.misc_util import Configuration", + " 'distributions.c']],", + " libraries=['m']," + ] + } + } + ] + }, + { + "hash": "ddf6e61b8c92311ec3215252aa117fd7fdaaf8ef", + "msg": "Fixed join() -> os.path.join()", + "author": { + "name": "Robert Kern", + "email": "robert.kern@gmail.com" + }, + "committer": { + "name": "Robert Kern", + "email": "robert.kern@gmail.com" + }, + "author_date": "2006-02-09T19:04:18+00:00", + "author_timezone": 0, + "committer_date": "2006-02-09T19:04:18+00:00", + "committer_timezone": 0, + "branches": [ + "main" + ], + "in_main_branch": true, + "merge": false, + "parents": [ + "e5e72a41b507f9d18564aa881c9482c76d399c45" + ], + "project_name": "repo_copy", + "project_path": "/tmp/tmpdjwupkfu/repo_copy", + "deletions": 4, + "insertions": 5, + "lines": 9, + "files": 4, + "dmm_unit_size": 0.0, + "dmm_unit_complexity": 0.0, + "dmm_unit_interfacing": 1.0, + "modified_files": [ + { + "old_path": "numpy/distutils/command/build_ext.py", + "new_path": "numpy/distutils/command/build_ext.py", + "filename": "build_ext.py", + "extension": "py", + "change_type": "MODIFY", + "diff": "@@ -99,6 +99,7 @@ def run(self):\n self.fcompiler.customize_cmd(self)\n self.fcompiler.show_customization()\n else:\n+ print self.fcompiler.get_version()\n self.warn('fcompiler=%s is not available.' % (self.fcompiler.compiler_type))\n self.fcompiler = None\n \n", + "added_lines": 1, + "deleted_lines": 0, + "source_code": "\"\"\" Modified version of build_ext that handles fortran source files.\n\"\"\"\n\nimport os\nimport string\nimport sys\nfrom glob import glob\n\nfrom distutils.dep_util import newer_group\nfrom distutils.command.build_ext import build_ext as old_build_ext\n\nfrom numpy.distutils import log\nfrom numpy.distutils.misc_util import filter_sources, has_f_sources, \\\n has_cxx_sources, get_ext_source_files, all_strings, \\\n get_numpy_include_dirs, is_sequence\nfrom distutils.errors import DistutilsFileError, DistutilsSetupError\n\nclass build_ext (old_build_ext):\n\n description = \"build C/C++/F extensions (compile/link to build directory)\"\n\n user_options = old_build_ext.user_options + [\n ('fcompiler=', None,\n \"specify the Fortran compiler type\"),\n ]\n\n def initialize_options(self):\n old_build_ext.initialize_options(self)\n self.fcompiler = None\n return\n\n def finalize_options(self):\n old_build_ext.finalize_options(self)\n self.set_undefined_options('config_fc',\n ('fcompiler', 'fcompiler'))\n return\n\n def run(self):\n if not self.extensions:\n return\n\n # Make sure that extension sources are complete.\n for ext in self.extensions:\n if not all_strings(ext.sources):\n self.run_command('build_src')\n\n if self.distribution.has_c_libraries():\n build_clib = self.get_finalized_command('build_clib')\n self.library_dirs.append(build_clib.build_clib)\n else:\n build_clib = None\n\n # Not including C libraries to the list of\n # extension libraries automatically to prevent\n # bogus linking commands. Extensions must\n # explicitly specify the C libraries that they use.\n\n # Determine if Fortran compiler is needed.\n if build_clib and build_clib.fcompiler is not None:\n need_f_compiler = 1\n else:\n need_f_compiler = 0\n for ext in self.extensions:\n if has_f_sources(ext.sources):\n need_f_compiler = 1\n break\n if getattr(ext,'language','c') in ['f77','f90']:\n need_f_compiler = 1\n break\n\n # Determine if C++ compiler is needed.\n need_cxx_compiler = 0\n for ext in self.extensions:\n if has_cxx_sources(ext.sources):\n need_cxx_compiler = 1\n break\n if getattr(ext,'language','c')=='c++':\n need_cxx_compiler = 1\n break\n\n from distutils.ccompiler import new_compiler\n self.compiler = new_compiler(compiler=self.compiler,\n verbose=self.verbose,\n dry_run=self.dry_run,\n force=self.force)\n self.compiler.customize(self.distribution,need_cxx=need_cxx_compiler)\n self.compiler.customize_cmd(self)\n self.compiler.show_customization()\n\n # Initialize Fortran/C++ compilers if needed.\n if need_f_compiler:\n from numpy.distutils.fcompiler import new_fcompiler\n self.fcompiler = new_fcompiler(compiler=self.fcompiler,\n verbose=self.verbose,\n dry_run=self.dry_run,\n force=self.force)\n if self.fcompiler.get_version():\n self.fcompiler.customize(self.distribution)\n self.fcompiler.customize_cmd(self)\n self.fcompiler.show_customization()\n else:\n print self.fcompiler.get_version()\n self.warn('fcompiler=%s is not available.' % (self.fcompiler.compiler_type))\n self.fcompiler = None\n\n # Build extensions\n self.build_extensions()\n return\n\n def swig_sources(self, sources):\n # Do nothing. Swig sources have beed handled in build_src command.\n return sources\n\n def build_extension(self, ext):\n sources = ext.sources\n if sources is None or not is_sequence(sources):\n raise DistutilsSetupError, \\\n (\"in 'ext_modules' option (extension '%s'), \" +\n \"'sources' must be present and must be \" +\n \"a list of source filenames\") % ext.name\n sources = list(sources)\n\n if not sources:\n return\n\n fullname = self.get_ext_fullname(ext.name)\n if self.inplace:\n modpath = string.split(fullname, '.')\n package = string.join(modpath[0:-1], '.')\n base = modpath[-1]\n\n build_py = self.get_finalized_command('build_py')\n package_dir = build_py.get_package_dir(package)\n ext_filename = os.path.join(package_dir,\n self.get_ext_filename(base))\n else:\n ext_filename = os.path.join(self.build_lib,\n self.get_ext_filename(fullname))\n depends = sources + ext.depends\n\n if not (self.force or newer_group(depends, ext_filename, 'newer')):\n log.debug(\"skipping '%s' extension (up-to-date)\", ext.name)\n return\n else:\n log.info(\"building '%s' extension\", ext.name)\n\n extra_args = ext.extra_compile_args or []\n macros = ext.define_macros[:]\n for undef in ext.undef_macros:\n macros.append((undef,))\n\n clib_libraries = []\n clib_library_dirs = []\n if self.distribution.libraries:\n for libname,build_info in self.distribution.libraries:\n if libname in ext.libraries:\n macros.extend(build_info.get('macros',[]))\n clib_libraries.extend(build_info.get('libraries',[]))\n clib_library_dirs.extend(build_info.get('library_dirs',[]))\n\n c_sources, cxx_sources, f_sources, fmodule_sources = \\\n filter_sources(ext.sources)\n if self.compiler.compiler_type=='msvc':\n if cxx_sources:\n # Needed to compile kiva.agg._agg extension.\n extra_args.append('/Zm1000')\n # this hack works around the msvc compiler attributes\n # problem, msvc uses its own convention :(\n c_sources += cxx_sources\n cxx_sources = []\n\n\n kws = {'depends':ext.depends}\n output_dir = self.build_temp\n\n include_dirs = ext.include_dirs + get_numpy_include_dirs()\n\n c_objects = []\n if c_sources:\n log.info(\"compiling C sources\")\n c_objects = self.compiler.compile(c_sources,\n output_dir=output_dir,\n macros=macros,\n include_dirs=include_dirs,\n debug=self.debug,\n extra_postargs=extra_args,\n **kws)\n if cxx_sources:\n log.info(\"compiling C++ sources\")\n\n old_compiler = self.compiler.compiler_so[0]\n self.compiler.compiler_so[0] = self.compiler.compiler_cxx[0]\n\n c_objects += self.compiler.compile(cxx_sources,\n output_dir=output_dir,\n macros=macros,\n include_dirs=include_dirs,\n debug=self.debug,\n extra_postargs=extra_args,\n **kws)\n self.compiler.compiler_so[0] = old_compiler\n\n check_for_f90_modules = not not fmodule_sources\n\n if f_sources or fmodule_sources:\n extra_postargs = []\n module_dirs = ext.module_dirs[:]\n\n #if self.fcompiler.compiler_type=='ibm':\n macros = []\n\n if check_for_f90_modules:\n module_build_dir = os.path.join(\\\n self.build_temp,os.path.dirname(\\\n self.get_ext_filename(fullname)))\n\n self.mkpath(module_build_dir)\n if self.fcompiler.module_dir_switch is None:\n existing_modules = glob('*.mod')\n extra_postargs += self.fcompiler.module_options(\\\n module_dirs,module_build_dir)\n\n f_objects = []\n if fmodule_sources:\n log.info(\"compiling Fortran 90 module sources\")\n f_objects = self.fcompiler.compile(fmodule_sources,\n output_dir=self.build_temp,\n macros=macros,\n include_dirs=include_dirs,\n debug=self.debug,\n extra_postargs=extra_postargs,\n depends=ext.depends)\n\n if check_for_f90_modules \\\n and self.fcompiler.module_dir_switch is None:\n for f in glob('*.mod'):\n if f in existing_modules:\n continue\n try:\n self.move_file(f, module_build_dir)\n except DistutilsFileError: # already exists in destination\n os.remove(f)\n\n if f_sources:\n log.info(\"compiling Fortran sources\")\n f_objects += self.fcompiler.compile(f_sources,\n output_dir=self.build_temp,\n macros=macros,\n include_dirs=include_dirs,\n debug=self.debug,\n extra_postargs=extra_postargs,\n depends=ext.depends)\n else:\n f_objects = []\n\n objects = c_objects + f_objects\n\n if ext.extra_objects:\n objects.extend(ext.extra_objects)\n extra_args = ext.extra_link_args or []\n\n try:\n old_linker_so_0 = self.compiler.linker_so[0]\n except:\n pass\n\n use_fortran_linker = getattr(ext,'language','c') in ['f77','f90'] \\\n and self.fcompiler is not None\n c_libraries = []\n c_library_dirs = []\n if use_fortran_linker or f_sources:\n use_fortran_linker = 1\n elif self.distribution.has_c_libraries():\n build_clib = self.get_finalized_command('build_clib')\n f_libs = []\n for (lib_name, build_info) in build_clib.libraries:\n if has_f_sources(build_info.get('sources',[])):\n f_libs.append(lib_name)\n if lib_name in ext.libraries:\n # XXX: how to determine if c_libraries contain\n # fortran compiled sources?\n c_libraries.extend(build_info.get('libraries',[]))\n c_library_dirs.extend(build_info.get('library_dirs',[]))\n for l in ext.libraries:\n if l in f_libs:\n use_fortran_linker = 1\n break\n\n # Always use system linker when using MSVC compiler.\n if self.compiler.compiler_type=='msvc' and use_fortran_linker:\n c_libraries.extend(self.fcompiler.libraries)\n c_library_dirs.extend(self.fcompiler.library_dirs)\n use_fortran_linker = 0\n\n if use_fortran_linker:\n if cxx_sources:\n # XXX: Which linker should be used, Fortran or C++?\n log.warn('mixing Fortran and C++ is untested')\n link = self.fcompiler.link_shared_object\n language = ext.language or self.fcompiler.detect_language(f_sources)\n else:\n link = self.compiler.link_shared_object\n if sys.version[:3]>='2.3':\n language = ext.language or self.compiler.detect_language(sources)\n else:\n language = ext.language\n if cxx_sources:\n self.compiler.linker_so[0] = self.compiler.compiler_cxx[0]\n\n if sys.version[:3]>='2.3':\n kws = {'target_lang':language}\n else:\n kws = {}\n\n link(objects, ext_filename,\n libraries=self.get_libraries(ext) + c_libraries + clib_libraries,\n library_dirs=ext.library_dirs + c_library_dirs + clib_library_dirs,\n runtime_library_dirs=ext.runtime_library_dirs,\n extra_postargs=extra_args,\n export_symbols=self.get_export_symbols(ext),\n debug=self.debug,\n build_temp=self.build_temp,**kws)\n\n try:\n self.compiler.linker_so[0] = old_linker_so_0\n except:\n pass\n\n return\n\n def get_source_files (self):\n self.check_extensions_list(self.extensions)\n filenames = []\n for ext in self.extensions:\n filenames.extend(get_ext_source_files(ext))\n return filenames\n\n def get_outputs (self):\n self.check_extensions_list(self.extensions)\n\n outputs = []\n for ext in self.extensions:\n if not ext.sources:\n continue\n fullname = self.get_ext_fullname(ext.name)\n outputs.append(os.path.join(self.build_lib,\n self.get_ext_filename(fullname)))\n return outputs\n", + "source_code_before": "\"\"\" Modified version of build_ext that handles fortran source files.\n\"\"\"\n\nimport os\nimport string\nimport sys\nfrom glob import glob\n\nfrom distutils.dep_util import newer_group\nfrom distutils.command.build_ext import build_ext as old_build_ext\n\nfrom numpy.distutils import log\nfrom numpy.distutils.misc_util import filter_sources, has_f_sources, \\\n has_cxx_sources, get_ext_source_files, all_strings, \\\n get_numpy_include_dirs, is_sequence\nfrom distutils.errors import DistutilsFileError, DistutilsSetupError\n\nclass build_ext (old_build_ext):\n\n description = \"build C/C++/F extensions (compile/link to build directory)\"\n\n user_options = old_build_ext.user_options + [\n ('fcompiler=', None,\n \"specify the Fortran compiler type\"),\n ]\n\n def initialize_options(self):\n old_build_ext.initialize_options(self)\n self.fcompiler = None\n return\n\n def finalize_options(self):\n old_build_ext.finalize_options(self)\n self.set_undefined_options('config_fc',\n ('fcompiler', 'fcompiler'))\n return\n\n def run(self):\n if not self.extensions:\n return\n\n # Make sure that extension sources are complete.\n for ext in self.extensions:\n if not all_strings(ext.sources):\n self.run_command('build_src')\n\n if self.distribution.has_c_libraries():\n build_clib = self.get_finalized_command('build_clib')\n self.library_dirs.append(build_clib.build_clib)\n else:\n build_clib = None\n\n # Not including C libraries to the list of\n # extension libraries automatically to prevent\n # bogus linking commands. Extensions must\n # explicitly specify the C libraries that they use.\n\n # Determine if Fortran compiler is needed.\n if build_clib and build_clib.fcompiler is not None:\n need_f_compiler = 1\n else:\n need_f_compiler = 0\n for ext in self.extensions:\n if has_f_sources(ext.sources):\n need_f_compiler = 1\n break\n if getattr(ext,'language','c') in ['f77','f90']:\n need_f_compiler = 1\n break\n\n # Determine if C++ compiler is needed.\n need_cxx_compiler = 0\n for ext in self.extensions:\n if has_cxx_sources(ext.sources):\n need_cxx_compiler = 1\n break\n if getattr(ext,'language','c')=='c++':\n need_cxx_compiler = 1\n break\n\n from distutils.ccompiler import new_compiler\n self.compiler = new_compiler(compiler=self.compiler,\n verbose=self.verbose,\n dry_run=self.dry_run,\n force=self.force)\n self.compiler.customize(self.distribution,need_cxx=need_cxx_compiler)\n self.compiler.customize_cmd(self)\n self.compiler.show_customization()\n\n # Initialize Fortran/C++ compilers if needed.\n if need_f_compiler:\n from numpy.distutils.fcompiler import new_fcompiler\n self.fcompiler = new_fcompiler(compiler=self.fcompiler,\n verbose=self.verbose,\n dry_run=self.dry_run,\n force=self.force)\n if self.fcompiler.get_version():\n self.fcompiler.customize(self.distribution)\n self.fcompiler.customize_cmd(self)\n self.fcompiler.show_customization()\n else:\n self.warn('fcompiler=%s is not available.' % (self.fcompiler.compiler_type))\n self.fcompiler = None\n\n # Build extensions\n self.build_extensions()\n return\n\n def swig_sources(self, sources):\n # Do nothing. Swig sources have beed handled in build_src command.\n return sources\n\n def build_extension(self, ext):\n sources = ext.sources\n if sources is None or not is_sequence(sources):\n raise DistutilsSetupError, \\\n (\"in 'ext_modules' option (extension '%s'), \" +\n \"'sources' must be present and must be \" +\n \"a list of source filenames\") % ext.name\n sources = list(sources)\n\n if not sources:\n return\n\n fullname = self.get_ext_fullname(ext.name)\n if self.inplace:\n modpath = string.split(fullname, '.')\n package = string.join(modpath[0:-1], '.')\n base = modpath[-1]\n\n build_py = self.get_finalized_command('build_py')\n package_dir = build_py.get_package_dir(package)\n ext_filename = os.path.join(package_dir,\n self.get_ext_filename(base))\n else:\n ext_filename = os.path.join(self.build_lib,\n self.get_ext_filename(fullname))\n depends = sources + ext.depends\n\n if not (self.force or newer_group(depends, ext_filename, 'newer')):\n log.debug(\"skipping '%s' extension (up-to-date)\", ext.name)\n return\n else:\n log.info(\"building '%s' extension\", ext.name)\n\n extra_args = ext.extra_compile_args or []\n macros = ext.define_macros[:]\n for undef in ext.undef_macros:\n macros.append((undef,))\n\n clib_libraries = []\n clib_library_dirs = []\n if self.distribution.libraries:\n for libname,build_info in self.distribution.libraries:\n if libname in ext.libraries:\n macros.extend(build_info.get('macros',[]))\n clib_libraries.extend(build_info.get('libraries',[]))\n clib_library_dirs.extend(build_info.get('library_dirs',[]))\n\n c_sources, cxx_sources, f_sources, fmodule_sources = \\\n filter_sources(ext.sources)\n if self.compiler.compiler_type=='msvc':\n if cxx_sources:\n # Needed to compile kiva.agg._agg extension.\n extra_args.append('/Zm1000')\n # this hack works around the msvc compiler attributes\n # problem, msvc uses its own convention :(\n c_sources += cxx_sources\n cxx_sources = []\n\n\n kws = {'depends':ext.depends}\n output_dir = self.build_temp\n\n include_dirs = ext.include_dirs + get_numpy_include_dirs()\n\n c_objects = []\n if c_sources:\n log.info(\"compiling C sources\")\n c_objects = self.compiler.compile(c_sources,\n output_dir=output_dir,\n macros=macros,\n include_dirs=include_dirs,\n debug=self.debug,\n extra_postargs=extra_args,\n **kws)\n if cxx_sources:\n log.info(\"compiling C++ sources\")\n\n old_compiler = self.compiler.compiler_so[0]\n self.compiler.compiler_so[0] = self.compiler.compiler_cxx[0]\n\n c_objects += self.compiler.compile(cxx_sources,\n output_dir=output_dir,\n macros=macros,\n include_dirs=include_dirs,\n debug=self.debug,\n extra_postargs=extra_args,\n **kws)\n self.compiler.compiler_so[0] = old_compiler\n\n check_for_f90_modules = not not fmodule_sources\n\n if f_sources or fmodule_sources:\n extra_postargs = []\n module_dirs = ext.module_dirs[:]\n\n #if self.fcompiler.compiler_type=='ibm':\n macros = []\n\n if check_for_f90_modules:\n module_build_dir = os.path.join(\\\n self.build_temp,os.path.dirname(\\\n self.get_ext_filename(fullname)))\n\n self.mkpath(module_build_dir)\n if self.fcompiler.module_dir_switch is None:\n existing_modules = glob('*.mod')\n extra_postargs += self.fcompiler.module_options(\\\n module_dirs,module_build_dir)\n\n f_objects = []\n if fmodule_sources:\n log.info(\"compiling Fortran 90 module sources\")\n f_objects = self.fcompiler.compile(fmodule_sources,\n output_dir=self.build_temp,\n macros=macros,\n include_dirs=include_dirs,\n debug=self.debug,\n extra_postargs=extra_postargs,\n depends=ext.depends)\n\n if check_for_f90_modules \\\n and self.fcompiler.module_dir_switch is None:\n for f in glob('*.mod'):\n if f in existing_modules:\n continue\n try:\n self.move_file(f, module_build_dir)\n except DistutilsFileError: # already exists in destination\n os.remove(f)\n\n if f_sources:\n log.info(\"compiling Fortran sources\")\n f_objects += self.fcompiler.compile(f_sources,\n output_dir=self.build_temp,\n macros=macros,\n include_dirs=include_dirs,\n debug=self.debug,\n extra_postargs=extra_postargs,\n depends=ext.depends)\n else:\n f_objects = []\n\n objects = c_objects + f_objects\n\n if ext.extra_objects:\n objects.extend(ext.extra_objects)\n extra_args = ext.extra_link_args or []\n\n try:\n old_linker_so_0 = self.compiler.linker_so[0]\n except:\n pass\n\n use_fortran_linker = getattr(ext,'language','c') in ['f77','f90'] \\\n and self.fcompiler is not None\n c_libraries = []\n c_library_dirs = []\n if use_fortran_linker or f_sources:\n use_fortran_linker = 1\n elif self.distribution.has_c_libraries():\n build_clib = self.get_finalized_command('build_clib')\n f_libs = []\n for (lib_name, build_info) in build_clib.libraries:\n if has_f_sources(build_info.get('sources',[])):\n f_libs.append(lib_name)\n if lib_name in ext.libraries:\n # XXX: how to determine if c_libraries contain\n # fortran compiled sources?\n c_libraries.extend(build_info.get('libraries',[]))\n c_library_dirs.extend(build_info.get('library_dirs',[]))\n for l in ext.libraries:\n if l in f_libs:\n use_fortran_linker = 1\n break\n\n # Always use system linker when using MSVC compiler.\n if self.compiler.compiler_type=='msvc' and use_fortran_linker:\n c_libraries.extend(self.fcompiler.libraries)\n c_library_dirs.extend(self.fcompiler.library_dirs)\n use_fortran_linker = 0\n\n if use_fortran_linker:\n if cxx_sources:\n # XXX: Which linker should be used, Fortran or C++?\n log.warn('mixing Fortran and C++ is untested')\n link = self.fcompiler.link_shared_object\n language = ext.language or self.fcompiler.detect_language(f_sources)\n else:\n link = self.compiler.link_shared_object\n if sys.version[:3]>='2.3':\n language = ext.language or self.compiler.detect_language(sources)\n else:\n language = ext.language\n if cxx_sources:\n self.compiler.linker_so[0] = self.compiler.compiler_cxx[0]\n\n if sys.version[:3]>='2.3':\n kws = {'target_lang':language}\n else:\n kws = {}\n\n link(objects, ext_filename,\n libraries=self.get_libraries(ext) + c_libraries + clib_libraries,\n library_dirs=ext.library_dirs + c_library_dirs + clib_library_dirs,\n runtime_library_dirs=ext.runtime_library_dirs,\n extra_postargs=extra_args,\n export_symbols=self.get_export_symbols(ext),\n debug=self.debug,\n build_temp=self.build_temp,**kws)\n\n try:\n self.compiler.linker_so[0] = old_linker_so_0\n except:\n pass\n\n return\n\n def get_source_files (self):\n self.check_extensions_list(self.extensions)\n filenames = []\n for ext in self.extensions:\n filenames.extend(get_ext_source_files(ext))\n return filenames\n\n def get_outputs (self):\n self.check_extensions_list(self.extensions)\n\n outputs = []\n for ext in self.extensions:\n if not ext.sources:\n continue\n fullname = self.get_ext_fullname(ext.name)\n outputs.append(os.path.join(self.build_lib,\n self.get_ext_filename(fullname)))\n return outputs\n", + "methods": [ + { + "name": "initialize_options", + "long_name": "initialize_options( self )", + "filename": "build_ext.py", + "nloc": 4, + "complexity": 1, + "token_count": 17, + "parameters": [ + "self" + ], + "start_line": 27, + "end_line": 30, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 1 + }, + { + "name": "finalize_options", + "long_name": "finalize_options( self )", + "filename": "build_ext.py", + "nloc": 5, + "complexity": 1, + "token_count": 24, + "parameters": [ + "self" + ], + "start_line": 32, + "end_line": 36, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 5, + "top_nesting_level": 1 + }, + { + "name": "run", + "long_name": "run( self )", + "filename": "build_ext.py", + "nloc": 54, + "complexity": 15, + "token_count": 336, + "parameters": [ + "self" + ], + "start_line": 38, + "end_line": 108, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 71, + "top_nesting_level": 1 + }, + { + "name": "swig_sources", + "long_name": "swig_sources( self , sources )", + "filename": "build_ext.py", + "nloc": 2, + "complexity": 1, + "token_count": 9, + "parameters": [ + "self", + "sources" + ], + "start_line": 110, + "end_line": 112, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "build_extension", + "long_name": "build_extension( self , ext )", + "filename": "build_ext.py", + "nloc": 177, + "complexity": 49, + "token_count": 1156, + "parameters": [ + "self", + "ext" + ], + "start_line": 114, + "end_line": 329, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 216, + "top_nesting_level": 1 + }, + { + "name": "get_source_files", + "long_name": "get_source_files( self )", + "filename": "build_ext.py", + "nloc": 6, + "complexity": 2, + "token_count": 35, + "parameters": [ + "self" + ], + "start_line": 331, + "end_line": 336, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 6, + "top_nesting_level": 1 + }, + { + "name": "get_outputs", + "long_name": "get_outputs( self )", + "filename": "build_ext.py", + "nloc": 10, + "complexity": 3, + "token_count": 65, + "parameters": [ + "self" + ], + "start_line": 338, + "end_line": 348, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 11, + "top_nesting_level": 1 + } + ], + "methods_before": [ + { + "name": "initialize_options", + "long_name": "initialize_options( self )", + "filename": "build_ext.py", + "nloc": 4, + "complexity": 1, + "token_count": 17, + "parameters": [ + "self" + ], + "start_line": 27, + "end_line": 30, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 1 + }, + { + "name": "finalize_options", + "long_name": "finalize_options( self )", + "filename": "build_ext.py", + "nloc": 5, + "complexity": 1, + "token_count": 24, + "parameters": [ + "self" + ], + "start_line": 32, + "end_line": 36, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 5, + "top_nesting_level": 1 + }, + { + "name": "run", + "long_name": "run( self )", + "filename": "build_ext.py", + "nloc": 53, + "complexity": 15, + "token_count": 328, + "parameters": [ + "self" + ], + "start_line": 38, + "end_line": 107, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 70, + "top_nesting_level": 1 + }, + { + "name": "swig_sources", + "long_name": "swig_sources( self , sources )", + "filename": "build_ext.py", + "nloc": 2, + "complexity": 1, + "token_count": 9, + "parameters": [ + "self", + "sources" + ], + "start_line": 109, + "end_line": 111, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "build_extension", + "long_name": "build_extension( self , ext )", + "filename": "build_ext.py", + "nloc": 177, + "complexity": 49, + "token_count": 1156, + "parameters": [ + "self", + "ext" + ], + "start_line": 113, + "end_line": 328, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 216, + "top_nesting_level": 1 + }, + { + "name": "get_source_files", + "long_name": "get_source_files( self )", + "filename": "build_ext.py", + "nloc": 6, + "complexity": 2, + "token_count": 35, + "parameters": [ + "self" + ], + "start_line": 330, + "end_line": 335, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 6, + "top_nesting_level": 1 + }, + { + "name": "get_outputs", + "long_name": "get_outputs( self )", + "filename": "build_ext.py", + "nloc": 10, + "complexity": 3, + "token_count": 65, + "parameters": [ + "self" + ], + "start_line": 337, + "end_line": 347, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 11, + "top_nesting_level": 1 + } + ], + "changed_methods": [ + { + "name": "run", + "long_name": "run( self )", + "filename": "build_ext.py", + "nloc": 54, + "complexity": 15, + "token_count": 336, + "parameters": [ + "self" + ], + "start_line": 38, + "end_line": 108, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 71, + "top_nesting_level": 1 + } + ], + "nloc": 277, + "complexity": 72, + "token_count": 1737, + "diff_parsed": { + "added": [ + " print self.fcompiler.get_version()" + ], + "deleted": [] + } + }, + { + "old_path": "numpy/distutils/fcompiler/absoft.py", + "new_path": "numpy/distutils/fcompiler/absoft.py", + "filename": "absoft.py", + "extension": "py", + "change_type": "MODIFY", + "diff": "@@ -17,7 +17,7 @@ class AbsoftFCompiler(FCompiler):\n \n compiler_type = 'absoft'\n #version_pattern = r'FORTRAN 77 Compiler (?P[^\\s*,]*).*?Absoft Corp'\n- version_pattern = r'(f90:.*?(Absoft Pro FORTRAN Version|FORTRAN 77 Compiler|Absoft Fortran Compiler Version))'+\\\n+ version_pattern = r'(f90:.*?(Absoft Pro FORTRAN Version|FORTRAN 77 Compiler|Absoft Fortran Compiler Version|Version))'+\\\n r' (?P[^\\s*,]*)(.*?Absoft Corp|)'\n \n # samt5735(8)$ f90 -V -c dummy.f\n@@ -114,7 +114,7 @@ def get_flags_f90(self):\n \"-YCOM_SFX=_\",\"-YEXT_SFX=_\",\"-YEXT_NAMES=LCS\"])\n if self.get_version():\n if self.get_version()>'4.6':\n- opt.extend([\"-YDEALLOC=ALL\"]) \n+ opt.extend([\"-YDEALLOC=ALL\"])\n return opt\n \n def get_flags_fix(self):\n", + "added_lines": 2, + "deleted_lines": 2, + "source_code": "\n# http://www.absoft.com/literature/osxuserguide.pdf\n# http://www.absoft.com/documentation.html\n\n# Notes:\n# - when using -g77 then use -DUNDERSCORE_G77 to compile f2py\n# generated extension modules (works for f2py v2.45.241_1936 and up)\n\nimport os\nimport sys\n\nfrom numpy.distutils.cpuinfo import cpu\nfrom numpy.distutils.fcompiler import FCompiler, dummy_fortran_file\nfrom numpy.distutils.misc_util import cyg2win32\n\nclass AbsoftFCompiler(FCompiler):\n\n compiler_type = 'absoft'\n #version_pattern = r'FORTRAN 77 Compiler (?P[^\\s*,]*).*?Absoft Corp'\n version_pattern = r'(f90:.*?(Absoft Pro FORTRAN Version|FORTRAN 77 Compiler|Absoft Fortran Compiler Version|Version))'+\\\n r' (?P[^\\s*,]*)(.*?Absoft Corp|)'\n\n # samt5735(8)$ f90 -V -c dummy.f\n # f90: Copyright Absoft Corporation 1994-2002; Absoft Pro FORTRAN Version 8.0\n # Note that fink installs g77 as f77, so need to use f90 for detection.\n\n executables = {\n 'version_cmd' : [\"f90\", \"-V -c %(fname)s.f -o %(fname)s.o\" \\\n % {'fname':cyg2win32(dummy_fortran_file())}],\n 'compiler_f77' : [\"f77\"],\n 'compiler_fix' : [\"f90\"],\n 'compiler_f90' : [\"f90\"],\n 'linker_so' : [\"f90\"],\n 'archiver' : [\"ar\", \"-cr\"],\n 'ranlib' : [\"ranlib\"]\n }\n\n if os.name=='nt':\n library_switch = '/out:' #No space after /out:!\n\n module_dir_switch = None\n module_include_switch = '-p'\n\n def get_flags_linker_so(self):\n if os.name=='nt':\n opt = ['/dll']\n # The \"-K shared\" switches are being left in for pre-9.0 versions\n # of Absoft though I don't think versions earlier than 9 can\n # actually be used to build shared libraries. In fact, version\n # 8 of Absoft doesn't recognize \"-K shared\" and will fail.\n elif self.get_version() >= '9.0':\n opt = ['-shared']\n else:\n opt = [\"-K\",\"shared\"]\n return opt\n\n def library_dir_option(self, dir):\n if os.name=='nt':\n return ['-link','/PATH:\"%s\"' % (dir)]\n return \"-L\" + dir\n\n def library_option(self, lib):\n if os.name=='nt':\n return '%s.lib' % (lib)\n return \"-l\" + lib\n\n def get_library_dirs(self):\n opt = FCompiler.get_library_dirs(self)\n d = os.environ.get('ABSOFT')\n if d:\n opt.append(os.path.join(d,'lib'))\n return opt\n\n def get_libraries(self):\n opt = FCompiler.get_libraries(self)\n if self.get_version() >= '8.0':\n\t opt.extend(['f90math','fio','f77math','U77'])\n else:\n opt.extend(['fio','f90math','fmath','U77'])\n if os.name =='nt':\n opt.append('COMDLG32')\n return opt\n\n def get_flags(self):\n opt = FCompiler.get_flags(self)\n if os.name != 'nt':\n opt.extend(['-s'])\n if self.get_version():\n if self.get_version()>='8.2':\n opt.append('-fpic')\n return opt\n\n def get_flags_f77(self):\n opt = FCompiler.get_flags_f77(self)\n opt.extend(['-N22','-N90','-N110'])\n v = self.get_version()\n if os.name == 'nt':\n if v and v>='8.0':\n opt.extend(['-f','-N15'])\n else:\n opt.append('-f')\n if v:\n if v<='4.6':\n opt.append('-B108')\n else:\n # Though -N15 is undocumented, it works with\n # Absoft 8.0 on Linux\n opt.append('-N15')\n return opt\n\n def get_flags_f90(self):\n opt = FCompiler.get_flags_f90(self)\n opt.extend([\"-YCFRL=1\",\"-YCOM_NAMES=LCS\",\"-YCOM_PFX\",\"-YEXT_PFX\",\n \"-YCOM_SFX=_\",\"-YEXT_SFX=_\",\"-YEXT_NAMES=LCS\"])\n if self.get_version():\n if self.get_version()>'4.6':\n opt.extend([\"-YDEALLOC=ALL\"])\n return opt\n\n def get_flags_fix(self):\n opt = FCompiler.get_flags_fix(self)\n opt.extend([\"-YCFRL=1\",\"-YCOM_NAMES=LCS\",\"-YCOM_PFX\",\"-YEXT_PFX\",\n \"-YCOM_SFX=_\",\"-YEXT_SFX=_\",\"-YEXT_NAMES=LCS\"])\n opt.extend([\"-f\",\"fixed\"])\n return opt\n\n def get_flags_opt(self):\n opt = ['-O']\n return opt\n\nif __name__ == '__main__':\n from distutils import log\n log.set_verbosity(2)\n from numpy.distutils.fcompiler import new_fcompiler\n compiler = new_fcompiler(compiler='absoft')\n compiler.customize()\n print compiler.get_version()\n", + "source_code_before": "\n# http://www.absoft.com/literature/osxuserguide.pdf\n# http://www.absoft.com/documentation.html\n\n# Notes:\n# - when using -g77 then use -DUNDERSCORE_G77 to compile f2py\n# generated extension modules (works for f2py v2.45.241_1936 and up)\n\nimport os\nimport sys\n\nfrom numpy.distutils.cpuinfo import cpu\nfrom numpy.distutils.fcompiler import FCompiler, dummy_fortran_file\nfrom numpy.distutils.misc_util import cyg2win32\n\nclass AbsoftFCompiler(FCompiler):\n\n compiler_type = 'absoft'\n #version_pattern = r'FORTRAN 77 Compiler (?P[^\\s*,]*).*?Absoft Corp'\n version_pattern = r'(f90:.*?(Absoft Pro FORTRAN Version|FORTRAN 77 Compiler|Absoft Fortran Compiler Version))'+\\\n r' (?P[^\\s*,]*)(.*?Absoft Corp|)'\n\n # samt5735(8)$ f90 -V -c dummy.f\n # f90: Copyright Absoft Corporation 1994-2002; Absoft Pro FORTRAN Version 8.0\n # Note that fink installs g77 as f77, so need to use f90 for detection.\n\n executables = {\n 'version_cmd' : [\"f90\", \"-V -c %(fname)s.f -o %(fname)s.o\" \\\n % {'fname':cyg2win32(dummy_fortran_file())}],\n 'compiler_f77' : [\"f77\"],\n 'compiler_fix' : [\"f90\"],\n 'compiler_f90' : [\"f90\"],\n 'linker_so' : [\"f90\"],\n 'archiver' : [\"ar\", \"-cr\"],\n 'ranlib' : [\"ranlib\"]\n }\n\n if os.name=='nt':\n library_switch = '/out:' #No space after /out:!\n\n module_dir_switch = None\n module_include_switch = '-p'\n\n def get_flags_linker_so(self):\n if os.name=='nt':\n opt = ['/dll']\n # The \"-K shared\" switches are being left in for pre-9.0 versions\n # of Absoft though I don't think versions earlier than 9 can\n # actually be used to build shared libraries. In fact, version\n # 8 of Absoft doesn't recognize \"-K shared\" and will fail.\n elif self.get_version() >= '9.0':\n opt = ['-shared']\n else:\n opt = [\"-K\",\"shared\"]\n return opt\n\n def library_dir_option(self, dir):\n if os.name=='nt':\n return ['-link','/PATH:\"%s\"' % (dir)]\n return \"-L\" + dir\n\n def library_option(self, lib):\n if os.name=='nt':\n return '%s.lib' % (lib)\n return \"-l\" + lib\n\n def get_library_dirs(self):\n opt = FCompiler.get_library_dirs(self)\n d = os.environ.get('ABSOFT')\n if d:\n opt.append(os.path.join(d,'lib'))\n return opt\n\n def get_libraries(self):\n opt = FCompiler.get_libraries(self)\n if self.get_version() >= '8.0':\n\t opt.extend(['f90math','fio','f77math','U77'])\n else:\n opt.extend(['fio','f90math','fmath','U77'])\n if os.name =='nt':\n opt.append('COMDLG32')\n return opt\n\n def get_flags(self):\n opt = FCompiler.get_flags(self)\n if os.name != 'nt':\n opt.extend(['-s'])\n if self.get_version():\n if self.get_version()>='8.2':\n opt.append('-fpic')\n return opt\n\n def get_flags_f77(self):\n opt = FCompiler.get_flags_f77(self)\n opt.extend(['-N22','-N90','-N110'])\n v = self.get_version()\n if os.name == 'nt':\n if v and v>='8.0':\n opt.extend(['-f','-N15'])\n else:\n opt.append('-f')\n if v:\n if v<='4.6':\n opt.append('-B108')\n else:\n # Though -N15 is undocumented, it works with\n # Absoft 8.0 on Linux\n opt.append('-N15')\n return opt\n\n def get_flags_f90(self):\n opt = FCompiler.get_flags_f90(self)\n opt.extend([\"-YCFRL=1\",\"-YCOM_NAMES=LCS\",\"-YCOM_PFX\",\"-YEXT_PFX\",\n \"-YCOM_SFX=_\",\"-YEXT_SFX=_\",\"-YEXT_NAMES=LCS\"])\n if self.get_version():\n if self.get_version()>'4.6':\n opt.extend([\"-YDEALLOC=ALL\"]) \n return opt\n\n def get_flags_fix(self):\n opt = FCompiler.get_flags_fix(self)\n opt.extend([\"-YCFRL=1\",\"-YCOM_NAMES=LCS\",\"-YCOM_PFX\",\"-YEXT_PFX\",\n \"-YCOM_SFX=_\",\"-YEXT_SFX=_\",\"-YEXT_NAMES=LCS\"])\n opt.extend([\"-f\",\"fixed\"])\n return opt\n\n def get_flags_opt(self):\n opt = ['-O']\n return opt\n\nif __name__ == '__main__':\n from distutils import log\n log.set_verbosity(2)\n from numpy.distutils.fcompiler import new_fcompiler\n compiler = new_fcompiler(compiler='absoft')\n compiler.customize()\n print compiler.get_version()\n", + "methods": [ + { + "name": "get_flags_linker_so", + "long_name": "get_flags_linker_so( self )", + "filename": "absoft.py", + "nloc": 8, + "complexity": 3, + "token_count": 42, + "parameters": [ + "self" + ], + "start_line": 44, + "end_line": 55, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 12, + "top_nesting_level": 1 + }, + { + "name": "library_dir_option", + "long_name": "library_dir_option( self , dir )", + "filename": "absoft.py", + "nloc": 4, + "complexity": 2, + "token_count": 28, + "parameters": [ + "self", + "dir" + ], + "start_line": 57, + "end_line": 60, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 1 + }, + { + "name": "library_option", + "long_name": "library_option( self , lib )", + "filename": "absoft.py", + "nloc": 4, + "complexity": 2, + "token_count": 24, + "parameters": [ + "self", + "lib" + ], + "start_line": 62, + "end_line": 65, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 1 + }, + { + "name": "get_library_dirs", + "long_name": "get_library_dirs( self )", + "filename": "absoft.py", + "nloc": 6, + "complexity": 2, + "token_count": 43, + "parameters": [ + "self" + ], + "start_line": 67, + "end_line": 72, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 6, + "top_nesting_level": 1 + }, + { + "name": "get_libraries", + "long_name": "get_libraries( self )", + "filename": "absoft.py", + "nloc": 9, + "complexity": 3, + "token_count": 67, + "parameters": [ + "self" + ], + "start_line": 74, + "end_line": 82, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 9, + "top_nesting_level": 1 + }, + { + "name": "get_flags", + "long_name": "get_flags( self )", + "filename": "absoft.py", + "nloc": 8, + "complexity": 4, + "token_count": 52, + "parameters": [ + "self" + ], + "start_line": 84, + "end_line": 91, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 8, + "top_nesting_level": 1 + }, + { + "name": "get_flags_f77", + "long_name": "get_flags_f77( self )", + "filename": "absoft.py", + "nloc": 15, + "complexity": 6, + "token_count": 88, + "parameters": [ + "self" + ], + "start_line": 93, + "end_line": 109, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 17, + "top_nesting_level": 1 + }, + { + "name": "get_flags_f90", + "long_name": "get_flags_f90( self )", + "filename": "absoft.py", + "nloc": 8, + "complexity": 3, + "token_count": 59, + "parameters": [ + "self" + ], + "start_line": 111, + "end_line": 118, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 8, + "top_nesting_level": 1 + }, + { + "name": "get_flags_fix", + "long_name": "get_flags_fix( self )", + "filename": "absoft.py", + "nloc": 6, + "complexity": 1, + "token_count": 45, + "parameters": [ + "self" + ], + "start_line": 120, + "end_line": 125, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 6, + "top_nesting_level": 1 + }, + { + "name": "get_flags_opt", + "long_name": "get_flags_opt( self )", + "filename": "absoft.py", + "nloc": 3, + "complexity": 1, + "token_count": 12, + "parameters": [ + "self" + ], + "start_line": 127, + "end_line": 129, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + } + ], + "methods_before": [ + { + "name": "get_flags_linker_so", + "long_name": "get_flags_linker_so( self )", + "filename": "absoft.py", + "nloc": 8, + "complexity": 3, + "token_count": 42, + "parameters": [ + "self" + ], + "start_line": 44, + "end_line": 55, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 12, + "top_nesting_level": 1 + }, + { + "name": "library_dir_option", + "long_name": "library_dir_option( self , dir )", + "filename": "absoft.py", + "nloc": 4, + "complexity": 2, + "token_count": 28, + "parameters": [ + "self", + "dir" + ], + "start_line": 57, + "end_line": 60, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 1 + }, + { + "name": "library_option", + "long_name": "library_option( self , lib )", + "filename": "absoft.py", + "nloc": 4, + "complexity": 2, + "token_count": 24, + "parameters": [ + "self", + "lib" + ], + "start_line": 62, + "end_line": 65, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 1 + }, + { + "name": "get_library_dirs", + "long_name": "get_library_dirs( self )", + "filename": "absoft.py", + "nloc": 6, + "complexity": 2, + "token_count": 43, + "parameters": [ + "self" + ], + "start_line": 67, + "end_line": 72, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 6, + "top_nesting_level": 1 + }, + { + "name": "get_libraries", + "long_name": "get_libraries( self )", + "filename": "absoft.py", + "nloc": 9, + "complexity": 3, + "token_count": 67, + "parameters": [ + "self" + ], + "start_line": 74, + "end_line": 82, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 9, + "top_nesting_level": 1 + }, + { + "name": "get_flags", + "long_name": "get_flags( self )", + "filename": "absoft.py", + "nloc": 8, + "complexity": 4, + "token_count": 52, + "parameters": [ + "self" + ], + "start_line": 84, + "end_line": 91, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 8, + "top_nesting_level": 1 + }, + { + "name": "get_flags_f77", + "long_name": "get_flags_f77( self )", + "filename": "absoft.py", + "nloc": 15, + "complexity": 6, + "token_count": 88, + "parameters": [ + "self" + ], + "start_line": 93, + "end_line": 109, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 17, + "top_nesting_level": 1 + }, + { + "name": "get_flags_f90", + "long_name": "get_flags_f90( self )", + "filename": "absoft.py", + "nloc": 8, + "complexity": 3, + "token_count": 59, + "parameters": [ + "self" + ], + "start_line": 111, + "end_line": 118, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 8, + "top_nesting_level": 1 + }, + { + "name": "get_flags_fix", + "long_name": "get_flags_fix( self )", + "filename": "absoft.py", + "nloc": 6, + "complexity": 1, + "token_count": 45, + "parameters": [ + "self" + ], + "start_line": 120, + "end_line": 125, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 6, + "top_nesting_level": 1 + }, + { + "name": "get_flags_opt", + "long_name": "get_flags_opt( self )", + "filename": "absoft.py", + "nloc": 3, + "complexity": 1, + "token_count": 12, + "parameters": [ + "self" + ], + "start_line": 127, + "end_line": 129, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + } + ], + "changed_methods": [ + { + "name": "get_flags_f90", + "long_name": "get_flags_f90( self )", + "filename": "absoft.py", + "nloc": 8, + "complexity": 3, + "token_count": 59, + "parameters": [ + "self" + ], + "start_line": 111, + "end_line": 118, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 8, + "top_nesting_level": 1 + } + ], + "nloc": 101, + "complexity": 27, + "token_count": 636, + "diff_parsed": { + "added": [ + " version_pattern = r'(f90:.*?(Absoft Pro FORTRAN Version|FORTRAN 77 Compiler|Absoft Fortran Compiler Version|Version))'+\\", + " opt.extend([\"-YDEALLOC=ALL\"])" + ], + "deleted": [ + " version_pattern = r'(f90:.*?(Absoft Pro FORTRAN Version|FORTRAN 77 Compiler|Absoft Fortran Compiler Version))'+\\", + " opt.extend([\"-YDEALLOC=ALL\"])" + ] + } + }, + { + "old_path": "numpy/distutils/fcompiler/gnu.py", + "new_path": "numpy/distutils/fcompiler/gnu.py", + "filename": "gnu.py", + "extension": "py", + "change_type": "MODIFY", + "diff": "@@ -239,6 +239,6 @@ class Gnu95FCompiler(GnuFCompiler):\n log.set_verbosity(2)\n from numpy.distutils.fcompiler import new_fcompiler\n #compiler = new_fcompiler(compiler='gnu')\n- compiler = GnuFCompiler()\n+ compiler = Gnu95FCompiler()\n compiler.customize()\n print compiler.get_version()\n", + "added_lines": 1, + "deleted_lines": 1, + "source_code": "\nimport re\nimport os\nimport sys\nimport warnings\n\nfrom numpy.distutils.cpuinfo import cpu\nfrom numpy.distutils.fcompiler import FCompiler\nfrom numpy.distutils.exec_command import exec_command, find_executable\n\nclass GnuFCompiler(FCompiler):\n\n compiler_type = 'gnu'\n version_pattern = r'GNU Fortran ((\\(GCC[^\\)]*(\\)\\)|\\)))|)\\s*'\\\n '(?P[^\\s*\\)]+)'\n\n # 'g77 --version' results\n # SunOS: GNU Fortran (GCC 3.2) 3.2 20020814 (release)\n # Debian: GNU Fortran (GCC) 3.3.3 20040110 (prerelease) (Debian)\n # GNU Fortran (GCC) 3.3.3 (Debian 20040401)\n # GNU Fortran 0.5.25 20010319 (prerelease)\n # Redhat: GNU Fortran (GCC 3.2.2 20030222 (Red Hat Linux 3.2.2-5)) 3.2.2 20030222 (Red Hat Linux 3.2.2-5)\n\n for fc_exe in map(find_executable,['g77','f77']):\n if os.path.isfile(fc_exe):\n break\n executables = {\n 'version_cmd' : [fc_exe,\"--version\"],\n 'compiler_f77' : [fc_exe,\"-Wall\",\"-fno-second-underscore\"],\n 'compiler_f90' : None,\n 'compiler_fix' : None,\n 'linker_so' : [fc_exe,\"-Wall\"],\n 'archiver' : [\"ar\", \"-cr\"],\n 'ranlib' : [\"ranlib\"],\n 'linker_exe' : [fc_exe,\"-Wall\"]\n }\n module_dir_switch = None\n module_include_switch = None\n\n # Cygwin: f771: warning: -fPIC ignored for target (all code is position independent)\n if os.name != 'nt' and sys.platform!='cygwin':\n pic_flags = ['-fPIC']\n\n g2c = 'g2c'\n\n #def get_linker_so(self):\n # # win32 linking should be handled by standard linker\n # # Darwin g77 cannot be used as a linker.\n # #if re.match(r'(darwin)', sys.platform):\n # # return\n # return FCompiler.get_linker_so(self)\n\n def get_flags_linker_so(self):\n opt = []\n if sys.platform=='darwin':\n target = os.environ.get('MACOSX_DEPLOYMENT_TARGET', None)\n if target is None:\n target = '10.3'\n major, minor = target.split('.')\n if int(minor) < 3:\n minor = '3'\n warnings.warn('Environment variable ' \n 'MACOSX_DEPLOYMENT_TARGET reset to 10.3')\n os.environ['MACOSX_DEPLOYMENT_TARGET'] = '%s.%s' % (major,\n minor)\n\n opt.extend(['-undefined', 'dynamic_lookup', '-bundle'])\n else:\n opt.append(\"-shared\")\n if sys.platform[:5]=='sunos':\n # SunOS often has dynamically loaded symbols defined in the\n # static library libg2c.a The linker doesn't like this. To\n # ignore the problem, use the -mimpure-text flag. It isn't\n # the safest thing, but seems to work. 'man gcc' says:\n # \".. Instead of using -mimpure-text, you should compile all\n # source code with -fpic or -fPIC.\"\n opt.append('-mimpure-text')\n return opt\n\n def get_libgcc_dir(self):\n status, output = exec_command('%s -print-libgcc-file-name' \\\n % (self.compiler_f77[0]),use_tee=0)\n if not status:\n return os.path.dirname(output)\n return\n\n def get_library_dirs(self):\n opt = []\n if sys.platform[:5] != 'linux':\n d = self.get_libgcc_dir()\n if d:\n opt.append(d)\n return opt\n\n def get_libraries(self):\n opt = []\n d = self.get_libgcc_dir()\n if d is not None:\n g2c = self.g2c + '-pic'\n f = self.static_lib_format % (g2c, self.static_lib_extension)\n if not os.path.isfile(os.path.join(d,f)):\n g2c = self.g2c\n else:\n g2c = self.g2c\n \n if sys.platform=='win32':\n opt.append('gcc')\n if g2c is not None:\n opt.append(g2c)\n if sys.platform == 'darwin':\n opt.append('cc_dynamic')\n return opt\n\n def get_flags_debug(self):\n return ['-g']\n\n def get_flags_opt(self):\n if self.get_version()<='3.3.3':\n # With this compiler version building Fortran BLAS/LAPACK\n # with -O3 caused failures in lib.lapack heevr,syevr tests.\n opt = ['-O2']\n else:\n opt = ['-O3']\n opt.append('-funroll-loops')\n return opt\n\n def get_flags_arch(self):\n opt = []\n if sys.platform=='darwin':\n if os.name != 'posix':\n # this should presumably correspond to Apple\n if cpu.is_ppc():\n opt.append('-arch ppc')\n elif cpu.is_i386():\n opt.append('-arch i386')\n for a in '601 602 603 603e 604 604e 620 630 740 7400 7450 750'\\\n '403 505 801 821 823 860'.split():\n if getattr(cpu,'is_ppc%s'%a)():\n opt.append('-mcpu='+a)\n opt.append('-mtune='+a)\n break \n return opt\n march_flag = 1\n # 0.5.25 corresponds to 2.95.x\n if self.get_version() == '0.5.26': # gcc 3.0\n if cpu.is_AthlonK6():\n opt.append('-march=k6')\n elif cpu.is_AthlonK7():\n opt.append('-march=athlon')\n else:\n march_flag = 0\n # Note: gcc 3.2 on win32 has breakage with -march specified\n elif self.get_version() >= '3.1.1' \\\n and not sys.platform=='win32': # gcc >= 3.1.1\n if cpu.is_AthlonK6():\n opt.append('-march=k6')\n elif cpu.is_AthlonK6_2():\n opt.append('-march=k6-2')\n elif cpu.is_AthlonK6_3():\n opt.append('-march=k6-3')\n elif cpu.is_AthlonK7():\n opt.append('-march=athlon')\n elif cpu.is_AthlonMP():\n opt.append('-march=athlon-mp')\n # there's also: athlon-tbird, athlon-4, athlon-xp\n elif cpu.is_Nocona():\n opt.append('-march=nocona')\n elif cpu.is_Prescott():\n opt.append('-march=prescott')\n elif cpu.is_PentiumIV():\n opt.append('-march=pentium4')\n elif cpu.is_PentiumIII():\n opt.append('-march=pentium3')\n elif cpu.is_PentiumII():\n opt.append('-march=pentium2')\n else:\n march_flag = 0\n if self.get_version() >= '3.4' and not march_flag:\n march_flag = 1\n if cpu.is_Opteron():\n opt.append('-march=opteron')\n elif cpu.is_Athlon64():\n opt.append('-march=athlon64')\n else:\n march_flag = 0\n if cpu.has_mmx(): opt.append('-mmmx') \n if self.get_version() > '3.2.2':\n if cpu.has_sse2(): opt.append('-msse2')\n if cpu.has_sse(): opt.append('-msse')\n if self.get_version() >= '3.4':\n if cpu.has_sse3(): opt.append('-msse3')\n if cpu.has_3dnow(): opt.append('-m3dnow')\n else:\n march_flag = 0\n if march_flag:\n pass\n elif cpu.is_i686():\n opt.append('-march=i686')\n elif cpu.is_i586():\n opt.append('-march=i586')\n elif cpu.is_i486():\n opt.append('-march=i486')\n elif cpu.is_i386():\n opt.append('-march=i386')\n if cpu.is_Intel():\n opt.append('-fomit-frame-pointer')\n if cpu.is_32bit():\n opt.append('-malign-double')\n return opt\n\nclass Gnu95FCompiler(GnuFCompiler):\n\n compiler_type = 'gnu95'\n version_pattern = r'GNU Fortran 95 \\(GCC (?P[^\\s*\\)]+)'\n\n # 'gfortran --version' results:\n # Debian: GNU Fortran 95 (GCC 4.0.3 20051023 (prerelease) (Debian 4.0.2-3))\n\n for fc_exe in map(find_executable,['gfortran','f95']):\n if os.path.isfile(fc_exe):\n break\n executables = {\n 'version_cmd' : [fc_exe,\"--version\"],\n 'compiler_f77' : [fc_exe,\"-Wall\",\"-ffixed-form\",\"-fno-second-underscore\"],\n 'compiler_f90' : [fc_exe,\"-Wall\",\"-fno-second-underscore\"],\n 'compiler_fix' : [fc_exe,\"-Wall\",\"-ffixed-form\",\"-fno-second-underscore\"],\n 'linker_so' : [fc_exe,\"-Wall\"],\n 'archiver' : [\"ar\", \"-cr\"],\n 'ranlib' : [\"ranlib\"],\n 'linker_exe' : [fc_exe,\"-Wall\"]\n }\n module_dir_switch = '-J'\n module_include_switch = '-I'\n\n g2c = 'gfortran'\n\nif __name__ == '__main__':\n from distutils import log\n log.set_verbosity(2)\n from numpy.distutils.fcompiler import new_fcompiler\n #compiler = new_fcompiler(compiler='gnu')\n compiler = Gnu95FCompiler()\n compiler.customize()\n print compiler.get_version()\n", + "source_code_before": "\nimport re\nimport os\nimport sys\nimport warnings\n\nfrom numpy.distutils.cpuinfo import cpu\nfrom numpy.distutils.fcompiler import FCompiler\nfrom numpy.distutils.exec_command import exec_command, find_executable\n\nclass GnuFCompiler(FCompiler):\n\n compiler_type = 'gnu'\n version_pattern = r'GNU Fortran ((\\(GCC[^\\)]*(\\)\\)|\\)))|)\\s*'\\\n '(?P[^\\s*\\)]+)'\n\n # 'g77 --version' results\n # SunOS: GNU Fortran (GCC 3.2) 3.2 20020814 (release)\n # Debian: GNU Fortran (GCC) 3.3.3 20040110 (prerelease) (Debian)\n # GNU Fortran (GCC) 3.3.3 (Debian 20040401)\n # GNU Fortran 0.5.25 20010319 (prerelease)\n # Redhat: GNU Fortran (GCC 3.2.2 20030222 (Red Hat Linux 3.2.2-5)) 3.2.2 20030222 (Red Hat Linux 3.2.2-5)\n\n for fc_exe in map(find_executable,['g77','f77']):\n if os.path.isfile(fc_exe):\n break\n executables = {\n 'version_cmd' : [fc_exe,\"--version\"],\n 'compiler_f77' : [fc_exe,\"-Wall\",\"-fno-second-underscore\"],\n 'compiler_f90' : None,\n 'compiler_fix' : None,\n 'linker_so' : [fc_exe,\"-Wall\"],\n 'archiver' : [\"ar\", \"-cr\"],\n 'ranlib' : [\"ranlib\"],\n 'linker_exe' : [fc_exe,\"-Wall\"]\n }\n module_dir_switch = None\n module_include_switch = None\n\n # Cygwin: f771: warning: -fPIC ignored for target (all code is position independent)\n if os.name != 'nt' and sys.platform!='cygwin':\n pic_flags = ['-fPIC']\n\n g2c = 'g2c'\n\n #def get_linker_so(self):\n # # win32 linking should be handled by standard linker\n # # Darwin g77 cannot be used as a linker.\n # #if re.match(r'(darwin)', sys.platform):\n # # return\n # return FCompiler.get_linker_so(self)\n\n def get_flags_linker_so(self):\n opt = []\n if sys.platform=='darwin':\n target = os.environ.get('MACOSX_DEPLOYMENT_TARGET', None)\n if target is None:\n target = '10.3'\n major, minor = target.split('.')\n if int(minor) < 3:\n minor = '3'\n warnings.warn('Environment variable ' \n 'MACOSX_DEPLOYMENT_TARGET reset to 10.3')\n os.environ['MACOSX_DEPLOYMENT_TARGET'] = '%s.%s' % (major,\n minor)\n\n opt.extend(['-undefined', 'dynamic_lookup', '-bundle'])\n else:\n opt.append(\"-shared\")\n if sys.platform[:5]=='sunos':\n # SunOS often has dynamically loaded symbols defined in the\n # static library libg2c.a The linker doesn't like this. To\n # ignore the problem, use the -mimpure-text flag. It isn't\n # the safest thing, but seems to work. 'man gcc' says:\n # \".. Instead of using -mimpure-text, you should compile all\n # source code with -fpic or -fPIC.\"\n opt.append('-mimpure-text')\n return opt\n\n def get_libgcc_dir(self):\n status, output = exec_command('%s -print-libgcc-file-name' \\\n % (self.compiler_f77[0]),use_tee=0)\n if not status:\n return os.path.dirname(output)\n return\n\n def get_library_dirs(self):\n opt = []\n if sys.platform[:5] != 'linux':\n d = self.get_libgcc_dir()\n if d:\n opt.append(d)\n return opt\n\n def get_libraries(self):\n opt = []\n d = self.get_libgcc_dir()\n if d is not None:\n g2c = self.g2c + '-pic'\n f = self.static_lib_format % (g2c, self.static_lib_extension)\n if not os.path.isfile(os.path.join(d,f)):\n g2c = self.g2c\n else:\n g2c = self.g2c\n \n if sys.platform=='win32':\n opt.append('gcc')\n if g2c is not None:\n opt.append(g2c)\n if sys.platform == 'darwin':\n opt.append('cc_dynamic')\n return opt\n\n def get_flags_debug(self):\n return ['-g']\n\n def get_flags_opt(self):\n if self.get_version()<='3.3.3':\n # With this compiler version building Fortran BLAS/LAPACK\n # with -O3 caused failures in lib.lapack heevr,syevr tests.\n opt = ['-O2']\n else:\n opt = ['-O3']\n opt.append('-funroll-loops')\n return opt\n\n def get_flags_arch(self):\n opt = []\n if sys.platform=='darwin':\n if os.name != 'posix':\n # this should presumably correspond to Apple\n if cpu.is_ppc():\n opt.append('-arch ppc')\n elif cpu.is_i386():\n opt.append('-arch i386')\n for a in '601 602 603 603e 604 604e 620 630 740 7400 7450 750'\\\n '403 505 801 821 823 860'.split():\n if getattr(cpu,'is_ppc%s'%a)():\n opt.append('-mcpu='+a)\n opt.append('-mtune='+a)\n break \n return opt\n march_flag = 1\n # 0.5.25 corresponds to 2.95.x\n if self.get_version() == '0.5.26': # gcc 3.0\n if cpu.is_AthlonK6():\n opt.append('-march=k6')\n elif cpu.is_AthlonK7():\n opt.append('-march=athlon')\n else:\n march_flag = 0\n # Note: gcc 3.2 on win32 has breakage with -march specified\n elif self.get_version() >= '3.1.1' \\\n and not sys.platform=='win32': # gcc >= 3.1.1\n if cpu.is_AthlonK6():\n opt.append('-march=k6')\n elif cpu.is_AthlonK6_2():\n opt.append('-march=k6-2')\n elif cpu.is_AthlonK6_3():\n opt.append('-march=k6-3')\n elif cpu.is_AthlonK7():\n opt.append('-march=athlon')\n elif cpu.is_AthlonMP():\n opt.append('-march=athlon-mp')\n # there's also: athlon-tbird, athlon-4, athlon-xp\n elif cpu.is_Nocona():\n opt.append('-march=nocona')\n elif cpu.is_Prescott():\n opt.append('-march=prescott')\n elif cpu.is_PentiumIV():\n opt.append('-march=pentium4')\n elif cpu.is_PentiumIII():\n opt.append('-march=pentium3')\n elif cpu.is_PentiumII():\n opt.append('-march=pentium2')\n else:\n march_flag = 0\n if self.get_version() >= '3.4' and not march_flag:\n march_flag = 1\n if cpu.is_Opteron():\n opt.append('-march=opteron')\n elif cpu.is_Athlon64():\n opt.append('-march=athlon64')\n else:\n march_flag = 0\n if cpu.has_mmx(): opt.append('-mmmx') \n if self.get_version() > '3.2.2':\n if cpu.has_sse2(): opt.append('-msse2')\n if cpu.has_sse(): opt.append('-msse')\n if self.get_version() >= '3.4':\n if cpu.has_sse3(): opt.append('-msse3')\n if cpu.has_3dnow(): opt.append('-m3dnow')\n else:\n march_flag = 0\n if march_flag:\n pass\n elif cpu.is_i686():\n opt.append('-march=i686')\n elif cpu.is_i586():\n opt.append('-march=i586')\n elif cpu.is_i486():\n opt.append('-march=i486')\n elif cpu.is_i386():\n opt.append('-march=i386')\n if cpu.is_Intel():\n opt.append('-fomit-frame-pointer')\n if cpu.is_32bit():\n opt.append('-malign-double')\n return opt\n\nclass Gnu95FCompiler(GnuFCompiler):\n\n compiler_type = 'gnu95'\n version_pattern = r'GNU Fortran 95 \\(GCC (?P[^\\s*\\)]+)'\n\n # 'gfortran --version' results:\n # Debian: GNU Fortran 95 (GCC 4.0.3 20051023 (prerelease) (Debian 4.0.2-3))\n\n for fc_exe in map(find_executable,['gfortran','f95']):\n if os.path.isfile(fc_exe):\n break\n executables = {\n 'version_cmd' : [fc_exe,\"--version\"],\n 'compiler_f77' : [fc_exe,\"-Wall\",\"-ffixed-form\",\"-fno-second-underscore\"],\n 'compiler_f90' : [fc_exe,\"-Wall\",\"-fno-second-underscore\"],\n 'compiler_fix' : [fc_exe,\"-Wall\",\"-ffixed-form\",\"-fno-second-underscore\"],\n 'linker_so' : [fc_exe,\"-Wall\"],\n 'archiver' : [\"ar\", \"-cr\"],\n 'ranlib' : [\"ranlib\"],\n 'linker_exe' : [fc_exe,\"-Wall\"]\n }\n module_dir_switch = '-J'\n module_include_switch = '-I'\n\n g2c = 'gfortran'\n\nif __name__ == '__main__':\n from distutils import log\n log.set_verbosity(2)\n from numpy.distutils.fcompiler import new_fcompiler\n #compiler = new_fcompiler(compiler='gnu')\n compiler = GnuFCompiler()\n compiler.customize()\n print compiler.get_version()\n", + "methods": [ + { + "name": "get_flags_linker_so", + "long_name": "get_flags_linker_so( self )", + "filename": "gnu.py", + "nloc": 19, + "complexity": 5, + "token_count": 117, + "parameters": [ + "self" + ], + "start_line": 53, + "end_line": 78, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 26, + "top_nesting_level": 1 + }, + { + "name": "get_libgcc_dir", + "long_name": "get_libgcc_dir( self )", + "filename": "gnu.py", + "nloc": 6, + "complexity": 2, + "token_count": 41, + "parameters": [ + "self" + ], + "start_line": 80, + "end_line": 85, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 6, + "top_nesting_level": 1 + }, + { + "name": "get_library_dirs", + "long_name": "get_library_dirs( self )", + "filename": "gnu.py", + "nloc": 7, + "complexity": 3, + "token_count": 38, + "parameters": [ + "self" + ], + "start_line": 87, + "end_line": 93, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 7, + "top_nesting_level": 1 + }, + { + "name": "get_libraries", + "long_name": "get_libraries( self )", + "filename": "gnu.py", + "nloc": 17, + "complexity": 6, + "token_count": 114, + "parameters": [ + "self" + ], + "start_line": 95, + "end_line": 112, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 18, + "top_nesting_level": 1 + }, + { + "name": "get_flags_debug", + "long_name": "get_flags_debug( self )", + "filename": "gnu.py", + "nloc": 2, + "complexity": 1, + "token_count": 9, + "parameters": [ + "self" + ], + "start_line": 114, + "end_line": 115, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 1 + }, + { + "name": "get_flags_opt", + "long_name": "get_flags_opt( self )", + "filename": "gnu.py", + "nloc": 7, + "complexity": 2, + "token_count": 34, + "parameters": [ + "self" + ], + "start_line": 117, + "end_line": 125, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 9, + "top_nesting_level": 1 + }, + { + "name": "get_flags_arch", + "long_name": "get_flags_arch( self )", + "filename": "gnu.py", + "nloc": 79, + "complexity": 40, + "token_count": 504, + "parameters": [ + "self" + ], + "start_line": 127, + "end_line": 209, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 83, + "top_nesting_level": 1 + } + ], + "methods_before": [ + { + "name": "get_flags_linker_so", + "long_name": "get_flags_linker_so( self )", + "filename": "gnu.py", + "nloc": 19, + "complexity": 5, + "token_count": 117, + "parameters": [ + "self" + ], + "start_line": 53, + "end_line": 78, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 26, + "top_nesting_level": 1 + }, + { + "name": "get_libgcc_dir", + "long_name": "get_libgcc_dir( self )", + "filename": "gnu.py", + "nloc": 6, + "complexity": 2, + "token_count": 41, + "parameters": [ + "self" + ], + "start_line": 80, + "end_line": 85, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 6, + "top_nesting_level": 1 + }, + { + "name": "get_library_dirs", + "long_name": "get_library_dirs( self )", + "filename": "gnu.py", + "nloc": 7, + "complexity": 3, + "token_count": 38, + "parameters": [ + "self" + ], + "start_line": 87, + "end_line": 93, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 7, + "top_nesting_level": 1 + }, + { + "name": "get_libraries", + "long_name": "get_libraries( self )", + "filename": "gnu.py", + "nloc": 17, + "complexity": 6, + "token_count": 114, + "parameters": [ + "self" + ], + "start_line": 95, + "end_line": 112, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 18, + "top_nesting_level": 1 + }, + { + "name": "get_flags_debug", + "long_name": "get_flags_debug( self )", + "filename": "gnu.py", + "nloc": 2, + "complexity": 1, + "token_count": 9, + "parameters": [ + "self" + ], + "start_line": 114, + "end_line": 115, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 1 + }, + { + "name": "get_flags_opt", + "long_name": "get_flags_opt( self )", + "filename": "gnu.py", + "nloc": 7, + "complexity": 2, + "token_count": 34, + "parameters": [ + "self" + ], + "start_line": 117, + "end_line": 125, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 9, + "top_nesting_level": 1 + }, + { + "name": "get_flags_arch", + "long_name": "get_flags_arch( self )", + "filename": "gnu.py", + "nloc": 79, + "complexity": 40, + "token_count": 504, + "parameters": [ + "self" + ], + "start_line": 127, + "end_line": 209, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 83, + "top_nesting_level": 1 + } + ], + "changed_methods": [], + "nloc": 192, + "complexity": 59, + "token_count": 1185, + "diff_parsed": { + "added": [ + " compiler = Gnu95FCompiler()" + ], + "deleted": [ + " compiler = GnuFCompiler()" + ] + } + }, + { + "old_path": "numpy/distutils/system_info.py", + "new_path": "numpy/distutils/system_info.py", + "filename": "system_info.py", + "extension": "py", + "change_type": "MODIFY", + "diff": "@@ -116,7 +116,7 @@\n \n if sys.platform == 'win32':\n default_lib_dirs = ['C:\\\\',\n- join(distutils.sysconfig.EXEC_PREFIX, 'libs')]\n+ os.path.join(distutils.sysconfig.EXEC_PREFIX, 'libs')]\n default_include_dirs = []\n default_src_dirs = ['.']\n default_x11_lib_dirs = []\n", + "added_lines": 1, + "deleted_lines": 1, + "source_code": "#!/usr/bin/env python\n\"\"\"\nThis file defines a set of system_info classes for getting\ninformation about various resources (libraries, library directories,\ninclude directories, etc.) in the system. Currently, the following\nclasses are available:\n\n atlas_info\n atlas_threads_info\n atlas_blas_info\n atlas_blas_threads_info\n lapack_atlas_info\n blas_info\n lapack_info\n blas_opt_info # usage recommended\n lapack_opt_info # usage recommended\n fftw_info,dfftw_info,sfftw_info\n fftw_threads_info,dfftw_threads_info,sfftw_threads_info\n djbfft_info\n x11_info\n lapack_src_info\n blas_src_info\n numpy_info\n numarray_info\n numpy_info\n boost_python_info\n agg2_info\n wx_info\n gdk_pixbuf_xlib_2_info\n gdk_pixbuf_2_info\n gdk_x11_2_info\n gtkp_x11_2_info\n gtkp_2_info\n xft_info\n freetype2_info\n\nUsage:\n info_dict = get_info()\n where is a string 'atlas','x11','fftw','lapack','blas',\n 'lapack_src', 'blas_src', etc. For a complete list of allowed names,\n see the definition of get_info() function below.\n\n Returned info_dict is a dictionary which is compatible with\n distutils.setup keyword arguments. If info_dict == {}, then the\n asked resource is not available (system_info could not find it).\n\n Several *_info classes specify an environment variable to specify\n the locations of software. When setting the corresponding environment\n variable to 'None' then the software will be ignored, even when it\n is available in system.\n\nGlobal parameters:\n system_info.search_static_first - search static libraries (.a)\n in precedence to shared ones (.so, .sl) if enabled.\n system_info.verbosity - output the results to stdout if enabled.\n\nThe file 'site.cfg' in the same directory as this module is read\nfor configuration options. The format is that used by ConfigParser (i.e.,\nWindows .INI style). The section DEFAULT has options that are the default\nfor each section. The available sections are fftw, atlas, and x11. Appropiate\ndefaults are used if nothing is specified.\n\nThe order of finding the locations of resources is the following:\n 1. environment variable\n 2. section in site.cfg\n 3. DEFAULT section in site.cfg\nOnly the first complete match is returned.\n\nExample:\n----------\n[DEFAULT]\nlibrary_dirs = /usr/lib:/usr/local/lib:/opt/lib\ninclude_dirs = /usr/include:/usr/local/include:/opt/include\nsrc_dirs = /usr/local/src:/opt/src\n# search static libraries (.a) in preference to shared ones (.so)\nsearch_static_first = 0\n\n[fftw]\nfftw_libs = rfftw, fftw\nfftw_opt_libs = rfftw_threaded, fftw_threaded\n# if the above aren't found, look for {s,d}fftw_libs and {s,d}fftw_opt_libs\n\n[atlas]\nlibrary_dirs = /usr/lib/3dnow:/usr/lib/3dnow/atlas\n# for overriding the names of the atlas libraries\natlas_libs = lapack, f77blas, cblas, atlas\n\n[x11]\nlibrary_dirs = /usr/X11R6/lib\ninclude_dirs = /usr/X11R6/include\n----------\n\nAuthors:\n Pearu Peterson , February 2002\n David M. Cooke , April 2002\n\nCopyright 2002 Pearu Peterson all rights reserved,\nPearu Peterson \nPermission to use, modify, and distribute this software is given under the\nterms of the SciPy (BSD style) license. See LICENSE.txt that came with\nthis distribution for specifics.\n\nNO WARRANTY IS EXPRESSED OR IMPLIED. USE AT YOUR OWN RISK.\n\"\"\"\n\nimport sys,os,re\nimport warnings\nfrom distutils.errors import DistutilsError\nfrom glob import glob\nimport ConfigParser\nfrom exec_command import find_executable, exec_command, get_pythonexe\nfrom numpy.distutils.misc_util import is_sequence, is_string\nimport distutils.sysconfig\n\nfrom distutils.sysconfig import get_config_vars\n\nif sys.platform == 'win32':\n default_lib_dirs = ['C:\\\\',\n os.path.join(distutils.sysconfig.EXEC_PREFIX, 'libs')]\n default_include_dirs = []\n default_src_dirs = ['.']\n default_x11_lib_dirs = []\n default_x11_include_dirs = []\nelse:\n default_lib_dirs = ['/usr/local/lib', '/opt/lib', '/usr/lib',\n '/opt/local/lib', '/sw/lib']\n default_include_dirs = ['/usr/local/include',\n '/opt/include', '/usr/include',\n '/opt/local/include', '/sw/include']\n default_src_dirs = ['.','/usr/local/src', '/opt/src','/sw/src']\n default_x11_lib_dirs = ['/usr/X11R6/lib','/usr/X11/lib','/usr/lib']\n default_x11_include_dirs = ['/usr/X11R6/include','/usr/X11/include',\n '/usr/include']\n\nif os.path.join(sys.prefix, 'lib') not in default_lib_dirs:\n default_lib_dirs.insert(0,os.path.join(sys.prefix, 'lib'))\n default_include_dirs.append(os.path.join(sys.prefix, 'include'))\n default_src_dirs.append(os.path.join(sys.prefix, 'src'))\n\ndefault_lib_dirs = filter(os.path.isdir, default_lib_dirs)\ndefault_include_dirs = filter(os.path.isdir, default_include_dirs)\ndefault_src_dirs = filter(os.path.isdir, default_src_dirs)\n\nso_ext = get_config_vars('SO')[0] or ''\n\ndef get_info(name,notfound_action=0):\n \"\"\"\n notfound_action:\n 0 - do nothing\n 1 - display warning message\n 2 - raise error\n \"\"\"\n cl = {'atlas':atlas_info, # use lapack_opt or blas_opt instead\n 'atlas_threads':atlas_threads_info, # ditto\n 'atlas_blas':atlas_blas_info,\n 'atlas_blas_threads':atlas_blas_threads_info,\n 'lapack_atlas':lapack_atlas_info, # use lapack_opt instead\n 'lapack_atlas_threads':lapack_atlas_threads_info, # ditto\n 'mkl':mkl_info,\n 'lapack_mkl':lapack_mkl_info, # use lapack_opt instead\n 'blas_mkl':blas_mkl_info, # use blas_opt instead\n 'x11':x11_info,\n 'fft_opt':fft_opt_info,\n 'fftw':fftw_info,\n 'fftw2':fftw2_info,\n 'fftw3':fftw3_info,\n 'dfftw':dfftw_info,\n 'sfftw':sfftw_info,\n 'fftw_threads':fftw_threads_info,\n 'dfftw_threads':dfftw_threads_info,\n 'sfftw_threads':sfftw_threads_info,\n 'djbfft':djbfft_info,\n 'blas':blas_info, # use blas_opt instead\n 'lapack':lapack_info, # use lapack_opt instead\n 'lapack_src':lapack_src_info,\n 'blas_src':blas_src_info,\n 'numpy':numpy_info,\n 'f2py':f2py_info,\n 'Numeric':Numeric_info,\n 'numarray':numarray_info,\n 'lapack_opt':lapack_opt_info,\n 'blas_opt':blas_opt_info,\n 'boost_python':boost_python_info,\n 'agg2':agg2_info,\n 'wx':wx_info,\n 'gdk_pixbuf_xlib_2':gdk_pixbuf_xlib_2_info,\n 'gdk-pixbuf-xlib-2.0':gdk_pixbuf_xlib_2_info,\n 'gdk_pixbuf_2':gdk_pixbuf_2_info,\n 'gdk-pixbuf-2.0':gdk_pixbuf_2_info,\n 'gdk':gdk_info,\n 'gdk_2':gdk_2_info,\n 'gdk-2.0':gdk_2_info,\n 'gdk_x11_2':gdk_x11_2_info,\n 'gdk-x11-2.0':gdk_x11_2_info,\n 'gtkp_x11_2':gtkp_x11_2_info,\n 'gtk+-x11-2.0':gtkp_x11_2_info,\n 'gtkp_2':gtkp_2_info,\n 'gtk+-2.0':gtkp_2_info,\n 'xft':xft_info,\n 'freetype2':freetype2_info,\n }.get(name.lower(),system_info)\n return cl().get_info(notfound_action)\n\nclass NotFoundError(DistutilsError):\n \"\"\"Some third-party program or library is not found.\"\"\"\n\nclass AtlasNotFoundError(NotFoundError):\n \"\"\"\n Atlas (http://math-atlas.sourceforge.net/) libraries not found.\n Directories to search for the libraries can be specified in the\n numpy/distutils/site.cfg file (section [atlas]) or by setting\n the ATLAS environment variable.\"\"\"\n\nclass LapackNotFoundError(NotFoundError):\n \"\"\"\n Lapack (http://www.netlib.org/lapack/) libraries not found.\n Directories to search for the libraries can be specified in the\n numpy/distutils/site.cfg file (section [lapack]) or by setting\n the LAPACK environment variable.\"\"\"\n\nclass LapackSrcNotFoundError(LapackNotFoundError):\n \"\"\"\n Lapack (http://www.netlib.org/lapack/) sources not found.\n Directories to search for the sources can be specified in the\n numpy/distutils/site.cfg file (section [lapack_src]) or by setting\n the LAPACK_SRC environment variable.\"\"\"\n\nclass BlasNotFoundError(NotFoundError):\n \"\"\"\n Blas (http://www.netlib.org/blas/) libraries not found.\n Directories to search for the libraries can be specified in the\n numpy/distutils/site.cfg file (section [blas]) or by setting\n the BLAS environment variable.\"\"\"\n\nclass BlasSrcNotFoundError(BlasNotFoundError):\n \"\"\"\n Blas (http://www.netlib.org/blas/) sources not found.\n Directories to search for the sources can be specified in the\n numpy/distutils/site.cfg file (section [blas_src]) or by setting\n the BLAS_SRC environment variable.\"\"\"\n\nclass FFTWNotFoundError(NotFoundError):\n \"\"\"\n FFTW (http://www.fftw.org/) libraries not found.\n Directories to search for the libraries can be specified in the\n numpy/distutils/site.cfg file (section [fftw]) or by setting\n the FFTW environment variable.\"\"\"\n\nclass DJBFFTNotFoundError(NotFoundError):\n \"\"\"\n DJBFFT (http://cr.yp.to/djbfft.html) libraries not found.\n Directories to search for the libraries can be specified in the\n numpy/distutils/site.cfg file (section [djbfft]) or by setting\n the DJBFFT environment variable.\"\"\"\n\nclass NumericNotFoundError(NotFoundError):\n \"\"\"\n Numeric (http://www.numpy.org/) module not found.\n Get it from above location, install it, and retry setup.py.\"\"\"\n\nclass X11NotFoundError(NotFoundError):\n \"\"\"X11 libraries not found.\"\"\"\n\nclass system_info:\n\n \"\"\" get_info() is the only public method. Don't use others.\n \"\"\"\n section = 'DEFAULT'\n dir_env_var = None\n search_static_first = 0 # XXX: disabled by default, may disappear in\n # future unless it is proved to be useful.\n verbosity = 1\n saved_results = {}\n\n notfounderror = NotFoundError\n\n def __init__ (self,\n default_lib_dirs=default_lib_dirs,\n default_include_dirs=default_include_dirs,\n verbosity = 1,\n ):\n self.__class__.info = {}\n self.local_prefixes = []\n defaults = {}\n defaults['libraries'] = ''\n defaults['library_dirs'] = os.pathsep.join(default_lib_dirs)\n defaults['include_dirs'] = os.pathsep.join(default_include_dirs)\n defaults['src_dirs'] = os.pathsep.join(default_src_dirs)\n defaults['search_static_first'] = str(self.search_static_first)\n self.cp = ConfigParser.ConfigParser(defaults)\n try:\n f = __file__\n except NameError,msg:\n f = sys.argv[0]\n cf = os.path.join(os.path.split(os.path.abspath(f))[0],\n 'site.cfg')\n self.cp.read([cf])\n if not self.cp.has_section(self.section):\n self.cp.add_section(self.section)\n self.search_static_first = self.cp.getboolean(self.section,\n 'search_static_first')\n assert isinstance(self.search_static_first, int)\n\n def calc_libraries_info(self):\n libs = self.get_libraries()\n dirs = self.get_lib_dirs()\n info = {}\n for lib in libs:\n i = None\n for d in dirs:\n i = self.check_libs(d,[lib])\n if i is not None:\n break\n if i is not None:\n dict_append(info,**i)\n else:\n print 'Library %s was not found. Ignoring' % (lib)\n return info\n\n def set_info(self,**info):\n if info:\n lib_info = self.calc_libraries_info()\n dict_append(info,**lib_info)\n self.saved_results[self.__class__.__name__] = info\n\n def has_info(self):\n return self.saved_results.has_key(self.__class__.__name__)\n\n def get_info(self,notfound_action=0):\n \"\"\" Return a dictonary with items that are compatible\n with numpy.distutils.setup keyword arguments.\n \"\"\"\n flag = 0\n if not self.has_info():\n flag = 1\n if self.verbosity>0:\n print self.__class__.__name__ + ':'\n if hasattr(self, 'calc_info'):\n self.calc_info()\n if notfound_action:\n if not self.has_info():\n if notfound_action==1:\n warnings.warn(self.notfounderror.__doc__)\n elif notfound_action==2:\n raise self.notfounderror,self.notfounderror.__doc__\n else:\n raise ValueError(repr(notfound_action))\n\n if self.verbosity>0:\n if not self.has_info():\n print ' NOT AVAILABLE'\n self.set_info()\n else:\n print ' FOUND:'\n\n res = self.saved_results.get(self.__class__.__name__)\n if self.verbosity>0 and flag:\n for k,v in res.items():\n v = str(v)\n if k=='sources' and len(v)>200: v = v[:60]+' ...\\n... '+v[-60:]\n print ' %s = %s'%(k,v)\n print\n\n return res\n\n def get_paths(self, section, key):\n dirs = self.cp.get(section, key).split(os.pathsep)\n env_var = self.dir_env_var\n if env_var:\n if is_sequence(env_var):\n e0 = env_var[-1]\n for e in env_var:\n if os.environ.has_key(e):\n e0 = e\n break\n if not env_var[0]==e0:\n print 'Setting %s=%s' % (env_var[0],e0)\n env_var = e0\n if env_var and os.environ.has_key(env_var):\n d = os.environ[env_var]\n if d=='None':\n print 'Disabled',self.__class__.__name__,'(%s is None)' \\\n % (self.dir_env_var)\n return []\n if os.path.isfile(d):\n dirs = [os.path.dirname(d)] + dirs\n l = getattr(self,'_lib_names',[])\n if len(l)==1:\n b = os.path.basename(d)\n b = os.path.splitext(b)[0]\n if b[:3]=='lib':\n print 'Replacing _lib_names[0]==%r with %r' \\\n % (self._lib_names[0], b[3:])\n self._lib_names[0] = b[3:]\n else:\n ds = d.split(os.pathsep)\n ds2 = []\n for d in ds:\n if os.path.isdir(d):\n ds2.append(d)\n for dd in ['include','lib']:\n d1 = os.path.join(d,dd)\n if os.path.isdir(d1):\n ds2.append(d1)\n dirs = ds2 + dirs\n default_dirs = self.cp.get('DEFAULT', key).split(os.pathsep)\n dirs.extend(default_dirs)\n ret = []\n [ret.append(d) for d in dirs if os.path.isdir(d) and d not in ret]\n if self.verbosity>1:\n print '(',key,'=',':'.join(ret),')'\n return ret\n\n def get_lib_dirs(self, key='library_dirs'):\n return self.get_paths(self.section, key)\n\n def get_include_dirs(self, key='include_dirs'):\n return self.get_paths(self.section, key)\n\n def get_src_dirs(self, key='src_dirs'):\n return self.get_paths(self.section, key)\n\n def get_libs(self, key, default):\n try:\n libs = self.cp.get(self.section, key)\n except ConfigParser.NoOptionError:\n if not default:\n return []\n if is_string(default):\n return [default]\n return default\n return [b for b in [a.strip() for a in libs.split(',')] if b]\n\n def get_libraries(self, key='libraries'):\n return self.get_libs(key,'')\n\n def check_libs(self,lib_dir,libs,opt_libs =[]):\n \"\"\" If static or shared libraries are available then return\n their info dictionary. \"\"\"\n if self.search_static_first:\n exts = ['.a',so_ext]\n else:\n exts = [so_ext,'.a']\n if sys.platform=='cygwin':\n exts.append('.dll.a')\n for ext in exts:\n info = self._check_libs(lib_dir,libs,opt_libs,[ext])\n if info is not None: return info\n return\n\n def check_libs2(self,lib_dir,libs,opt_libs =[]):\n \"\"\" If static or shared libraries are available then return\n their info dictionary. \"\"\"\n if self.search_static_first:\n exts = ['.a',so_ext]\n else:\n exts = [so_ext,'.a']\n if sys.platform=='cygwin':\n exts.append('.dll.a')\n info = self._check_libs(lib_dir,libs,opt_libs,exts)\n if info is not None: return info\n return\n\n def _lib_list(self, lib_dir, libs, exts):\n assert is_string(lib_dir)\n liblist = []\n for l in libs:\n for ext in exts:\n p = self.combine_paths(lib_dir, 'lib'+l+ext)\n if p:\n assert len(p)==1\n liblist.append(p[0])\n break\n return liblist\n\n def _extract_lib_names(self,libs):\n return [os.path.splitext(os.path.basename(p))[0][3:] \\\n for p in libs]\n\n def _check_libs(self,lib_dir,libs, opt_libs, exts):\n found_libs = self._lib_list(lib_dir, libs, exts)\n if len(found_libs) == len(libs):\n found_libs = self._extract_lib_names(found_libs)\n info = {'libraries' : found_libs, 'library_dirs' : [lib_dir]}\n opt_found_libs = self._lib_list(lib_dir, opt_libs, exts)\n if len(opt_found_libs) == len(opt_libs):\n opt_found_libs = self._extract_lib_names(opt_found_libs)\n info['libraries'].extend(opt_found_libs)\n return info\n\n def combine_paths(self,*args):\n return combine_paths(*args,**{'verbosity':self.verbosity})\n\n\nclass fft_opt_info(system_info):\n\n def calc_info(self):\n info = {}\n fftw_info = get_info('fftw3') or get_info('fftw2') or get_info('dfftw')\n djbfft_info = get_info('djbfft')\n if fftw_info:\n dict_append(info,**fftw_info)\n if djbfft_info:\n dict_append(info,**djbfft_info)\n self.set_info(**info)\n return\n\n\nclass fftw_info(system_info):\n #variables to override\n section = 'fftw'\n dir_env_var = 'FFTW'\n notfounderror = FFTWNotFoundError\n ver_info = [ { 'name':'fftw3',\n 'libs':['fftw3'],\n 'includes':['fftw3.h'],\n 'macros':[('SCIPY_FFTW3_H',None)]},\n { 'name':'fftw2',\n 'libs':['rfftw', 'fftw'],\n 'includes':['fftw.h','rfftw.h'],\n 'macros':[('SCIPY_FFTW_H',None)]}]\n\n def __init__(self):\n system_info.__init__(self)\n\n def calc_ver_info(self,ver_param):\n \"\"\"Returns True on successful version detection, else False\"\"\"\n lib_dirs = self.get_lib_dirs()\n incl_dirs = self.get_include_dirs()\n incl_dir = None\n libs = self.get_libs(self.section+'_libs', ver_param['libs'])\n info = None\n for d in lib_dirs:\n r = self.check_libs(d,libs)\n if r is not None:\n info = r\n break\n if info is not None:\n flag = 0\n for d in incl_dirs:\n if len(self.combine_paths(d,ver_param['includes']))==len(ver_param['includes']):\n dict_append(info,include_dirs=[d])\n flag = 1\n incl_dirs = [d]\n incl_dir = d\n break\n if flag:\n dict_append(info,define_macros=ver_param['macros'])\n else:\n info = None\n if info is not None:\n self.set_info(**info)\n return True\n else:\n if self.verbosity>0:\n print ' %s not found' % (ver_param['name'])\n return False\n\n def calc_info(self):\n for i in self.ver_info:\n if self.calc_ver_info(i):\n break\n\nclass fftw2_info(fftw_info):\n #variables to override\n section = 'fftw'\n dir_env_var = 'FFTW'\n notfounderror = FFTWNotFoundError\n ver_info = [ { 'name':'fftw2',\n 'libs':['rfftw', 'fftw'],\n 'includes':['fftw.h','rfftw.h'],\n 'macros':[('SCIPY_FFTW_H',None)]}\n ]\n\nclass fftw3_info(fftw_info):\n #variables to override\n section = 'fftw3'\n dir_env_var = 'FFTW3'\n notfounderror = FFTWNotFoundError\n ver_info = [ { 'name':'fftw3',\n 'libs':['fftw3'],\n 'includes':['fftw3.h'],\n 'macros':[('SCIPY_FFTW3_H',None)]},\n ]\n\nclass dfftw_info(fftw_info):\n section = 'fftw'\n dir_env_var = 'FFTW'\n ver_info = [ { 'name':'dfftw',\n 'libs':['drfftw','dfftw'],\n 'includes':['dfftw.h','drfftw.h'],\n 'macros':[('SCIPY_DFFTW_H',None)]} ]\n\nclass sfftw_info(fftw_info):\n section = 'fftw'\n dir_env_var = 'FFTW'\n ver_info = [ { 'name':'sfftw',\n 'libs':['srfftw','sfftw'],\n 'includes':['sfftw.h','srfftw.h'],\n 'macros':[('SCIPY_SFFTW_H',None)]} ]\n\nclass fftw_threads_info(fftw_info):\n section = 'fftw'\n dir_env_var = 'FFTW'\n ver_info = [ { 'name':'fftw threads',\n 'libs':['rfftw_threads','fftw_threads'],\n 'includes':['fftw_threads.h','rfftw_threads.h'],\n 'macros':[('SCIPY_FFTW_THREADS_H',None)]} ]\n\nclass dfftw_threads_info(fftw_info):\n section = 'fftw'\n dir_env_var = 'FFTW'\n ver_info = [ { 'name':'dfftw threads',\n 'libs':['drfftw_threads','dfftw_threads'],\n 'includes':['dfftw_threads.h','drfftw_threads.h'],\n 'macros':[('SCIPY_DFFTW_THREADS_H',None)]} ]\n\nclass sfftw_threads_info(fftw_info):\n section = 'fftw'\n dir_env_var = 'FFTW'\n ver_info = [ { 'name':'sfftw threads',\n 'libs':['srfftw_threads','sfftw_threads'],\n 'includes':['sfftw_threads.h','srfftw_threads.h'],\n 'macros':[('SCIPY_SFFTW_THREADS_H',None)]} ]\n\nclass djbfft_info(system_info):\n section = 'djbfft'\n dir_env_var = 'DJBFFT'\n notfounderror = DJBFFTNotFoundError\n\n def get_paths(self, section, key):\n pre_dirs = system_info.get_paths(self, section, key)\n dirs = []\n for d in pre_dirs:\n dirs.extend(self.combine_paths(d,['djbfft'])+[d])\n return [ d for d in dirs if os.path.isdir(d) ]\n\n def calc_info(self):\n lib_dirs = self.get_lib_dirs()\n incl_dirs = self.get_include_dirs()\n info = None\n for d in lib_dirs:\n p = self.combine_paths (d,['djbfft.a'])\n if p:\n info = {'extra_objects':p}\n break\n p = self.combine_paths (d,['libdjbfft.a','libdjbfft'+so_ext])\n if p:\n info = {'libraries':['djbfft'],'library_dirs':[d]}\n break\n if info is None:\n return\n for d in incl_dirs:\n if len(self.combine_paths(d,['fftc8.h','fftfreq.h']))==2:\n dict_append(info,include_dirs=[d],\n define_macros=[('SCIPY_DJBFFT_H',None)])\n self.set_info(**info)\n return\n return\n\nclass mkl_info(system_info):\n section = 'mkl'\n dir_env_var = 'MKL'\n _lib_mkl = ['mkl','vml','guide']\n\n def get_mkl_rootdir(self):\n mklroot = os.environ.get('MKLROOT',None)\n if mklroot is not None:\n return mklroot\n paths = os.environ.get('LD_LIBRARY_PATH','').split(os.pathsep)\n ld_so_conf = '/etc/ld.so.conf'\n if os.path.isfile(ld_so_conf):\n for d in open(ld_so_conf,'r').readlines():\n d = d.strip()\n if d: paths.append(d)\n intel_mkl_dirs = []\n for path in paths:\n path_atoms = path.split(os.sep)\n for m in path_atoms:\n if m.startswith('mkl'):\n d = os.sep.join(path_atoms[:path_atoms.index(m)+2])\n intel_mkl_dirs.append(d)\n break\n for d in paths:\n dirs = glob(os.path.join(d,'mkl','*')) + glob(os.path.join(d,'mkl*'))\n for d in dirs:\n if os.path.isdir(os.path.join(d,'lib')):\n return d\n return None\n\n def __init__(self):\n mklroot = self.get_mkl_rootdir()\n if mklroot is None:\n system_info.__init__(self)\n else:\n from cpuinfo import cpu\n if cpu.is_Itanium():\n plt = '64'\n l = 'mkl_ipf'\n elif cpu.is_Xeon():\n plt = 'em64t'\n l = 'mkl_em64t'\n else:\n plt = '32'\n l = 'mkl_ia32'\n if l not in self._lib_mkl:\n self._lib_mkl.insert(0,l)\n system_info.__init__(self,\n default_lib_dirs=[os.path.join(mklroot,'lib',plt)],\n default_include_dirs=[os.path.join(mklroot,'include')])\n\n def calc_info(self):\n lib_dirs = self.get_lib_dirs()\n incl_dirs = self.get_include_dirs()\n mkl_libs = self.get_libs('mkl_libs',self._lib_mkl)\n mkl = None\n for d in lib_dirs:\n mkl = self.check_libs2(d,mkl_libs)\n if mkl is not None:\n break\n if mkl is None:\n return\n info = {}\n dict_append(info,**mkl)\n dict_append(info,libraries = ['pthread'], include_dirs = incl_dirs)\n self.set_info(**info)\n\nclass lapack_mkl_info(mkl_info):\n\n def calc_info(self):\n mkl = get_info('mkl')\n if not mkl:\n return\n lapack_libs = self.get_libs('lapack_libs',['mkl_lapack'])\n info = {'libraries': lapack_libs}\n dict_append(info,**mkl)\n self.set_info(**info)\n\nclass blas_mkl_info(mkl_info):\n pass\n\nclass atlas_info(system_info):\n section = 'atlas'\n dir_env_var = 'ATLAS'\n _lib_names = ['f77blas','cblas']\n if sys.platform[:7]=='freebsd':\n _lib_atlas = ['atlas_r']\n _lib_lapack = ['alapack_r']\n else:\n _lib_atlas = ['atlas']\n _lib_lapack = ['lapack']\n\n notfounderror = AtlasNotFoundError\n\n def get_paths(self, section, key):\n pre_dirs = system_info.get_paths(self, section, key)\n dirs = []\n for d in pre_dirs:\n dirs.extend(self.combine_paths(d,['atlas*','ATLAS*',\n 'sse','3dnow','sse2'])+[d])\n return [ d for d in dirs if os.path.isdir(d) ]\n\n def calc_info(self):\n lib_dirs = self.get_lib_dirs()\n info = {}\n atlas_libs = self.get_libs('atlas_libs',\n self._lib_names + self._lib_atlas)\n lapack_libs = self.get_libs('lapack_libs',self._lib_lapack)\n atlas = None\n lapack = None\n atlas_1 = None\n for d in lib_dirs:\n atlas = self.check_libs(d,atlas_libs,[])\n lapack_atlas = self.check_libs(d,['lapack_atlas'],[])\n if atlas is not None:\n lib_dirs2 = self.combine_paths(d,['atlas*','ATLAS*'])+[d]\n for d2 in lib_dirs2:\n lapack = self.check_libs(d2,lapack_libs,[])\n if lapack is not None:\n break\n else:\n lapack = None\n if lapack is not None:\n break\n if atlas:\n atlas_1 = atlas\n print self.__class__\n if atlas is None:\n atlas = atlas_1\n if atlas is None:\n return\n include_dirs = self.get_include_dirs()\n h = (self.combine_paths(lib_dirs+include_dirs,'cblas.h') or [None])[0]\n if h:\n h = os.path.dirname(h)\n dict_append(info,include_dirs=[h])\n info['language'] = 'c'\n if lapack is not None:\n dict_append(info,**lapack)\n dict_append(info,**atlas)\n elif 'lapack_atlas' in atlas['libraries']:\n dict_append(info,**atlas)\n dict_append(info,define_macros=[('ATLAS_WITH_LAPACK_ATLAS',None)])\n self.set_info(**info)\n return\n else:\n dict_append(info,**atlas)\n dict_append(info,define_macros=[('ATLAS_WITHOUT_LAPACK',None)])\n message = \"\"\"\n*********************************************************************\n Could not find lapack library within the ATLAS installation.\n*********************************************************************\n\"\"\"\n warnings.warn(message)\n self.set_info(**info)\n return\n\n # Check if lapack library is complete, only warn if it is not.\n lapack_dir = lapack['library_dirs'][0]\n lapack_name = lapack['libraries'][0]\n lapack_lib = None\n for e in ['.a',so_ext]:\n fn = os.path.join(lapack_dir,'lib'+lapack_name+e)\n if os.path.exists(fn):\n lapack_lib = fn\n break\n if lapack_lib is not None:\n sz = os.stat(lapack_lib)[6]\n if sz <= 4000*1024:\n message = \"\"\"\n*********************************************************************\n Lapack library (from ATLAS) is probably incomplete:\n size of %s is %sk (expected >4000k)\n\n Follow the instructions in the KNOWN PROBLEMS section of the file\n numpy/INSTALL.txt.\n*********************************************************************\n\"\"\" % (lapack_lib,sz/1024)\n warnings.warn(message)\n else:\n info['language'] = 'f77'\n\n self.set_info(**info)\n\nclass atlas_blas_info(atlas_info):\n _lib_names = ['f77blas','cblas']\n\n def calc_info(self):\n lib_dirs = self.get_lib_dirs()\n info = {}\n atlas_libs = self.get_libs('atlas_libs',\n self._lib_names + self._lib_atlas)\n atlas = None\n for d in lib_dirs:\n atlas = self.check_libs(d,atlas_libs,[])\n if atlas is not None:\n break\n if atlas is None:\n return\n include_dirs = self.get_include_dirs()\n h = (self.combine_paths(lib_dirs+include_dirs,'cblas.h') or [None])[0]\n if h:\n h = os.path.dirname(h)\n dict_append(info,include_dirs=[h])\n info['language'] = 'c'\n\n dict_append(info,**atlas)\n\n self.set_info(**info)\n return\n\n\nclass atlas_threads_info(atlas_info):\n dir_env_var = ['PTATLAS','ATLAS']\n _lib_names = ['ptf77blas','ptcblas']\n\nclass atlas_blas_threads_info(atlas_blas_info):\n dir_env_var = ['PTATLAS','ATLAS']\n _lib_names = ['ptf77blas','ptcblas']\n\nclass lapack_atlas_info(atlas_info):\n _lib_names = ['lapack_atlas'] + atlas_info._lib_names\n\nclass lapack_atlas_threads_info(atlas_threads_info):\n _lib_names = ['lapack_atlas'] + atlas_threads_info._lib_names\n\nclass lapack_info(system_info):\n section = 'lapack'\n dir_env_var = 'LAPACK'\n _lib_names = ['lapack']\n notfounderror = LapackNotFoundError\n\n def calc_info(self):\n lib_dirs = self.get_lib_dirs()\n\n lapack_libs = self.get_libs('lapack_libs', self._lib_names)\n for d in lib_dirs:\n lapack = self.check_libs(d,lapack_libs,[])\n if lapack is not None:\n info = lapack\n break\n else:\n return\n info['language'] = 'f77'\n self.set_info(**info)\n\nclass lapack_src_info(system_info):\n section = 'lapack_src'\n dir_env_var = 'LAPACK_SRC'\n notfounderror = LapackSrcNotFoundError\n\n def get_paths(self, section, key):\n pre_dirs = system_info.get_paths(self, section, key)\n dirs = []\n for d in pre_dirs:\n dirs.extend([d] + self.combine_paths(d,['LAPACK*/SRC','SRC']))\n return [ d for d in dirs if os.path.isdir(d) ]\n\n def calc_info(self):\n src_dirs = self.get_src_dirs()\n src_dir = ''\n for d in src_dirs:\n if os.path.isfile(os.path.join(d,'dgesv.f')):\n src_dir = d\n break\n if not src_dir:\n #XXX: Get sources from netlib. May be ask first.\n return\n # The following is extracted from LAPACK-3.0/SRC/Makefile\n allaux='''\n ilaenv ieeeck lsame lsamen xerbla\n ''' # *.f\n laux = '''\n bdsdc bdsqr disna labad lacpy ladiv lae2 laebz laed0 laed1\n laed2 laed3 laed4 laed5 laed6 laed7 laed8 laed9 laeda laev2\n lagtf lagts lamch lamrg lanst lapy2 lapy3 larnv larrb larre\n larrf lartg laruv las2 lascl lasd0 lasd1 lasd2 lasd3 lasd4\n lasd5 lasd6 lasd7 lasd8 lasd9 lasda lasdq lasdt laset lasq1\n lasq2 lasq3 lasq4 lasq5 lasq6 lasr lasrt lassq lasv2 pttrf\n stebz stedc steqr sterf\n ''' # [s|d]*.f\n lasrc = '''\n gbbrd gbcon gbequ gbrfs gbsv gbsvx gbtf2 gbtrf gbtrs gebak\n gebal gebd2 gebrd gecon geequ gees geesx geev geevx gegs gegv\n gehd2 gehrd gelq2 gelqf gels gelsd gelss gelsx gelsy geql2\n geqlf geqp3 geqpf geqr2 geqrf gerfs gerq2 gerqf gesc2 gesdd\n gesv gesvd gesvx getc2 getf2 getrf getri getrs ggbak ggbal\n gges ggesx ggev ggevx ggglm gghrd gglse ggqrf ggrqf ggsvd\n ggsvp gtcon gtrfs gtsv gtsvx gttrf gttrs gtts2 hgeqz hsein\n hseqr labrd lacon laein lags2 lagtm lahqr lahrd laic1 lals0\n lalsa lalsd langb lange langt lanhs lansb lansp lansy lantb\n lantp lantr lapll lapmt laqgb laqge laqp2 laqps laqsb laqsp\n laqsy lar1v lar2v larf larfb larfg larft larfx largv larrv\n lartv larz larzb larzt laswp lasyf latbs latdf latps latrd\n latrs latrz latzm lauu2 lauum pbcon pbequ pbrfs pbstf pbsv\n pbsvx pbtf2 pbtrf pbtrs pocon poequ porfs posv posvx potf2\n potrf potri potrs ppcon ppequ pprfs ppsv ppsvx pptrf pptri\n pptrs ptcon pteqr ptrfs ptsv ptsvx pttrs ptts2 spcon sprfs\n spsv spsvx sptrf sptri sptrs stegr stein sycon syrfs sysv\n sysvx sytf2 sytrf sytri sytrs tbcon tbrfs tbtrs tgevc tgex2\n tgexc tgsen tgsja tgsna tgsy2 tgsyl tpcon tprfs tptri tptrs\n trcon trevc trexc trrfs trsen trsna trsyl trti2 trtri trtrs\n tzrqf tzrzf\n ''' # [s|c|d|z]*.f\n sd_lasrc = '''\n laexc lag2 lagv2 laln2 lanv2 laqtr lasy2 opgtr opmtr org2l\n org2r orgbr orghr orgl2 orglq orgql orgqr orgr2 orgrq orgtr\n orm2l orm2r ormbr ormhr orml2 ormlq ormql ormqr ormr2 ormr3\n ormrq ormrz ormtr rscl sbev sbevd sbevx sbgst sbgv sbgvd sbgvx\n sbtrd spev spevd spevx spgst spgv spgvd spgvx sptrd stev stevd\n stevr stevx syev syevd syevr syevx sygs2 sygst sygv sygvd\n sygvx sytd2 sytrd\n ''' # [s|d]*.f\n cz_lasrc = '''\n bdsqr hbev hbevd hbevx hbgst hbgv hbgvd hbgvx hbtrd hecon heev\n heevd heevr heevx hegs2 hegst hegv hegvd hegvx herfs hesv\n hesvx hetd2 hetf2 hetrd hetrf hetri hetrs hpcon hpev hpevd\n hpevx hpgst hpgv hpgvd hpgvx hprfs hpsv hpsvx hptrd hptrf\n hptri hptrs lacgv lacp2 lacpy lacrm lacrt ladiv laed0 laed7\n laed8 laesy laev2 lahef lanhb lanhe lanhp lanht laqhb laqhe\n laqhp larcm larnv lartg lascl laset lasr lassq pttrf rot spmv\n spr stedc steqr symv syr ung2l ung2r ungbr unghr ungl2 unglq\n ungql ungqr ungr2 ungrq ungtr unm2l unm2r unmbr unmhr unml2\n unmlq unmql unmqr unmr2 unmr3 unmrq unmrz unmtr upgtr upmtr\n ''' # [c|z]*.f\n #######\n sclaux = laux + ' econd ' # s*.f\n dzlaux = laux + ' secnd ' # d*.f\n slasrc = lasrc + sd_lasrc # s*.f\n dlasrc = lasrc + sd_lasrc # d*.f\n clasrc = lasrc + cz_lasrc + ' srot srscl ' # c*.f\n zlasrc = lasrc + cz_lasrc + ' drot drscl ' # z*.f\n oclasrc = ' icmax1 scsum1 ' # *.f\n ozlasrc = ' izmax1 dzsum1 ' # *.f\n sources = ['s%s.f'%f for f in (sclaux+slasrc).split()] \\\n + ['d%s.f'%f for f in (dzlaux+dlasrc).split()] \\\n + ['c%s.f'%f for f in (clasrc).split()] \\\n + ['z%s.f'%f for f in (zlasrc).split()] \\\n + ['%s.f'%f for f in (allaux+oclasrc+ozlasrc).split()]\n sources = [os.path.join(src_dir,f) for f in sources]\n #XXX: should we check here actual existence of source files?\n info = {'sources':sources,'language':'f77'}\n self.set_info(**info)\n\natlas_version_c_text = r'''\n/* This file is generated from numpy_distutils/system_info.py */\n#ifdef __CPLUSPLUS__\nextern \"C\" {\n#endif\n#include \"Python.h\"\nstatic PyMethodDef module_methods[] = { {NULL,NULL} };\nDL_EXPORT(void) initatlas_version(void) {\n void ATL_buildinfo(void);\n ATL_buildinfo();\n Py_InitModule(\"atlas_version\", module_methods);\n}\n#ifdef __CPLUSCPLUS__\n}\n#endif\n'''\n\ndef _get_build_temp():\n from distutils.util import get_platform\n plat_specifier = \".%s-%s\" % (get_platform(), sys.version[0:3])\n return os.path.join('build','temp'+plat_specifier)\n\ndef get_atlas_version(**config):\n os.environ['NO_SCIPY_IMPORT']='get_atlas_version'\n from core import Extension, setup\n from misc_util import get_cmd\n import log\n magic = hex(hash(repr(config)))\n def atlas_version_c(extension, build_dir,magic=magic):\n source = os.path.join(build_dir,'atlas_version_%s.c' % (magic))\n if os.path.isfile(source):\n from distutils.dep_util import newer\n if newer(source,__file__):\n return source\n f = open(source,'w')\n f.write(atlas_version_c_text)\n f.close()\n return source\n ext = Extension('atlas_version',\n sources=[atlas_version_c],\n **config)\n build_dir = _get_build_temp()\n extra_args = ['--build-lib',build_dir]\n for a in sys.argv:\n if re.match('[-][-]compiler[=]',a):\n extra_args.append(a)\n import distutils.core\n old_dist = distutils.core._setup_distribution\n distutils.core._setup_distribution = None\n try:\n dist = setup(ext_modules=[ext],\n script_name = 'get_atlas_version',\n script_args = ['build_src','build_ext']+extra_args)\n except Exception,msg:\n print \"##### msg: %s\" % msg\n if not msg:\n msg = \"Unknown Exception\"\n log.warn(msg)\n return None\n distutils.core._setup_distribution = old_dist\n\n from distutils.sysconfig import get_config_var\n so_ext = get_config_var('SO')\n target = os.path.join(build_dir,'atlas_version'+so_ext)\n cmd = [get_pythonexe(),'-c',\n '\"import imp,os;os.environ[\\\\\"NO_SCIPY_IMPORT\\\\\"]='\\\n '\\\\\"system_info.get_atlas_version:load atlas_version\\\\\";'\\\n 'imp.load_dynamic(\\\\\"atlas_version\\\\\",\\\\\"%s\\\\\")\"'\\\n % (os.path.basename(target))]\n s,o = exec_command(cmd,execute_in=os.path.dirname(target),use_tee=0)\n atlas_version = None\n if not s:\n m = re.search(r'ATLAS version (?P\\d+[.]\\d+[.]\\d+)',o)\n if m:\n atlas_version = m.group('version')\n if atlas_version is None:\n if re.search(r'undefined symbol: ATL_buildinfo',o,re.M):\n atlas_version = '3.2.1_pre3.3.6'\n else:\n print 'Command:',' '.join(cmd)\n print 'Status:',s\n print 'Output:',o\n return atlas_version\n\n\nclass lapack_opt_info(system_info):\n\n def calc_info(self):\n\n if sys.platform=='darwin' and not os.environ.get('ATLAS',None):\n args = []\n link_args = []\n if os.path.exists('/System/Library/Frameworks/Accelerate.framework/'):\n args.extend(['-faltivec'])\n link_args.extend(['-Wl,-framework','-Wl,Accelerate'])\n elif os.path.exists('/System/Library/Frameworks/vecLib.framework/'):\n args.extend(['-faltivec'])\n link_args.extend(['-Wl,-framework','-Wl,vecLib'])\n if args:\n self.set_info(extra_compile_args=args,\n extra_link_args=link_args,\n define_macros=[('NO_ATLAS_INFO',3)])\n return\n\n lapack_mkl_info = get_info('lapack_mkl')\n if lapack_mkl_info:\n self.set_info(**lapack_mkl_info)\n return\n\n atlas_info = get_info('atlas_threads')\n if not atlas_info:\n atlas_info = get_info('atlas')\n #atlas_info = {} ## uncomment for testing\n atlas_version = None\n need_lapack = 0\n need_blas = 0\n info = {}\n if atlas_info:\n version_info = atlas_info.copy()\n atlas_version = get_atlas_version(**version_info)\n if not atlas_info.has_key('define_macros'):\n atlas_info['define_macros'] = []\n if atlas_version is None:\n atlas_info['define_macros'].append(('NO_ATLAS_INFO',2))\n else:\n atlas_info['define_macros'].append(('ATLAS_INFO',\n '\"\\\\\"%s\\\\\"\"' % atlas_version))\n\t\tif atlas_version=='3.2.1_pre3.3.6':\n\t\t atlas_info['define_macros'].append(('NO_ATLAS_INFO',4))\n l = atlas_info.get('define_macros',[])\n if ('ATLAS_WITH_LAPACK_ATLAS',None) in l \\\n or ('ATLAS_WITHOUT_LAPACK',None) in l:\n need_lapack = 1\n info = atlas_info\n else:\n warnings.warn(AtlasNotFoundError.__doc__)\n need_blas = 1\n need_lapack = 1\n dict_append(info,define_macros=[('NO_ATLAS_INFO',1)])\n\n if need_lapack:\n lapack_info = get_info('lapack')\n #lapack_info = {} ## uncomment for testing\n if lapack_info:\n dict_append(info,**lapack_info)\n else:\n warnings.warn(LapackNotFoundError.__doc__)\n lapack_src_info = get_info('lapack_src')\n if not lapack_src_info:\n warnings.warn(LapackSrcNotFoundError.__doc__)\n return\n dict_append(info,libraries=[('flapack_src',lapack_src_info)])\n\n if need_blas:\n blas_info = get_info('blas')\n #blas_info = {} ## uncomment for testing\n if blas_info:\n dict_append(info,**blas_info)\n else:\n warnings.warn(BlasNotFoundError.__doc__)\n blas_src_info = get_info('blas_src')\n if not blas_src_info:\n warnings.warn(BlasSrcNotFoundError.__doc__)\n return\n dict_append(info,libraries=[('fblas_src',blas_src_info)])\n\n self.set_info(**info)\n return\n\n\nclass blas_opt_info(system_info):\n\n def calc_info(self):\n\n if sys.platform=='darwin' and not os.environ.get('ATLAS',None):\n args = []\n link_args = []\n if os.path.exists('/System/Library/Frameworks/Accelerate.framework/'):\n args.extend(['-faltivec',\n '-I/System/Library/Frameworks/vecLib.framework/Headers',\n ])\n link_args.extend(['-Wl,-framework','-Wl,Accelerate'])\n elif os.path.exists('/System/Library/Frameworks/vecLib.framework/'):\n args.extend(['-faltivec',\n '-I/System/Library/Frameworks/vecLib.framework/Headers',\n ])\n link_args.extend(['-Wl,-framework','-Wl,vecLib'])\n if args:\n self.set_info(extra_compile_args=args,\n extra_link_args=link_args,\n define_macros=[('NO_ATLAS_INFO',3)])\n return\n\n blas_mkl_info = get_info('blas_mkl')\n if blas_mkl_info:\n self.set_info(**blas_mkl_info)\n return\n\n atlas_info = get_info('atlas_blas_threads')\n if not atlas_info:\n atlas_info = get_info('atlas_blas')\n atlas_version = None\n need_blas = 0\n info = {}\n if atlas_info:\n version_info = atlas_info.copy()\n atlas_version = get_atlas_version(**version_info)\n if not atlas_info.has_key('define_macros'):\n atlas_info['define_macros'] = []\n if atlas_version is None:\n atlas_info['define_macros'].append(('NO_ATLAS_INFO',2))\n else:\n atlas_info['define_macros'].append(('ATLAS_INFO',\n '\"\\\\\"%s\\\\\"\"' % atlas_version))\n info = atlas_info\n else:\n warnings.warn(AtlasNotFoundError.__doc__)\n need_blas = 1\n dict_append(info,define_macros=[('NO_ATLAS_INFO',1)])\n\n if need_blas:\n blas_info = get_info('blas')\n if blas_info:\n dict_append(info,**blas_info)\n else:\n warnings.warn(BlasNotFoundError.__doc__)\n blas_src_info = get_info('blas_src')\n if not blas_src_info:\n warnings.warn(BlasSrcNotFoundError.__doc__)\n return\n dict_append(info,libraries=[('fblas_src',blas_src_info)])\n\n self.set_info(**info)\n return\n\n\nclass blas_info(system_info):\n section = 'blas'\n dir_env_var = 'BLAS'\n _lib_names = ['blas']\n notfounderror = BlasNotFoundError\n\n def calc_info(self):\n lib_dirs = self.get_lib_dirs()\n\n blas_libs = self.get_libs('blas_libs', self._lib_names)\n for d in lib_dirs:\n blas = self.check_libs(d,blas_libs,[])\n if blas is not None:\n info = blas\n break\n else:\n return\n info['language'] = 'f77' # XXX: is it generally true?\n self.set_info(**info)\n\n\nclass blas_src_info(system_info):\n section = 'blas_src'\n dir_env_var = 'BLAS_SRC'\n notfounderror = BlasSrcNotFoundError\n\n def get_paths(self, section, key):\n pre_dirs = system_info.get_paths(self, section, key)\n dirs = []\n for d in pre_dirs:\n dirs.extend([d] + self.combine_paths(d,['blas']))\n return [ d for d in dirs if os.path.isdir(d) ]\n\n def calc_info(self):\n src_dirs = self.get_src_dirs()\n src_dir = ''\n for d in src_dirs:\n if os.path.isfile(os.path.join(d,'daxpy.f')):\n src_dir = d\n break\n if not src_dir:\n #XXX: Get sources from netlib. May be ask first.\n return\n blas1 = '''\n caxpy csscal dnrm2 dzasum saxpy srotg zdotc ccopy cswap drot\n dznrm2 scasum srotm zdotu cdotc dasum drotg icamax scnrm2\n srotmg zdrot cdotu daxpy drotm idamax scopy sscal zdscal crotg\n dcabs1 drotmg isamax sdot sswap zrotg cscal dcopy dscal izamax\n snrm2 zaxpy zscal csrot ddot dswap sasum srot zcopy zswap\n '''\n blas2 = '''\n cgbmv chpmv ctrsv dsymv dtrsv sspr2 strmv zhemv ztpmv cgemv\n chpr dgbmv dsyr lsame ssymv strsv zher ztpsv cgerc chpr2 dgemv\n dsyr2 sgbmv ssyr xerbla zher2 ztrmv cgeru ctbmv dger dtbmv\n sgemv ssyr2 zgbmv zhpmv ztrsv chbmv ctbsv dsbmv dtbsv sger\n stbmv zgemv zhpr chemv ctpmv dspmv dtpmv ssbmv stbsv zgerc\n zhpr2 cher ctpsv dspr dtpsv sspmv stpmv zgeru ztbmv cher2\n ctrmv dspr2 dtrmv sspr stpsv zhbmv ztbsv\n '''\n blas3 = '''\n cgemm csymm ctrsm dsyrk sgemm strmm zhemm zsyr2k chemm csyr2k\n dgemm dtrmm ssymm strsm zher2k zsyrk cher2k csyrk dsymm dtrsm\n ssyr2k zherk ztrmm cherk ctrmm dsyr2k ssyrk zgemm zsymm ztrsm\n '''\n sources = [os.path.join(src_dir,f+'.f') \\\n for f in (blas1+blas2+blas3).split()]\n #XXX: should we check here actual existence of source files?\n info = {'sources':sources,'language':'f77'}\n self.set_info(**info)\n\nclass x11_info(system_info):\n section = 'x11'\n notfounderror = X11NotFoundError\n\n def __init__(self):\n system_info.__init__(self,\n default_lib_dirs=default_x11_lib_dirs,\n default_include_dirs=default_x11_include_dirs)\n\n def calc_info(self):\n if sys.platform in ['win32']:\n return\n lib_dirs = self.get_lib_dirs()\n include_dirs = self.get_include_dirs()\n x11_libs = self.get_libs('x11_libs', ['X11'])\n for lib_dir in lib_dirs:\n info = self.check_libs(lib_dir, x11_libs, [])\n if info is not None:\n break\n else:\n return\n inc_dir = None\n for d in include_dirs:\n if self.combine_paths(d, 'X11/X.h'):\n inc_dir = d\n break\n if inc_dir is not None:\n dict_append(info, include_dirs=[inc_dir])\n self.set_info(**info)\n\nclass _numpy_info(system_info):\n section = 'Numeric'\n modulename = 'Numeric'\n notfounderror = NumericNotFoundError\n\n def __init__(self):\n from distutils.sysconfig import get_python_inc\n include_dirs = []\n try:\n module = __import__(self.modulename)\n prefix = []\n for name in module.__file__.split(os.sep):\n if name=='lib':\n break\n prefix.append(name)\n include_dirs.append(get_python_inc(prefix=os.sep.join(prefix)))\n except ImportError:\n pass\n py_incl_dir = get_python_inc()\n include_dirs.append(py_incl_dir)\n for d in default_include_dirs:\n d = os.path.join(d, os.path.basename(py_incl_dir))\n if d not in include_dirs:\n include_dirs.append(d)\n system_info.__init__(self,\n default_lib_dirs=[],\n default_include_dirs=include_dirs)\n\n def calc_info(self):\n try:\n module = __import__(self.modulename)\n except ImportError:\n return\n info = {}\n macros = []\n for v in ['__version__','version']:\n vrs = getattr(module,v,None)\n if vrs is None:\n continue\n macros = [(self.modulename.upper()+'_VERSION',\n '\"\\\\\"%s\\\\\"\"' % (vrs)),\n (self.modulename.upper(),None)]\n break\n## try:\n## macros.append(\n## (self.modulename.upper()+'_VERSION_HEX',\n## hex(vstr2hex(module.__version__))),\n## )\n## except Exception,msg:\n## print msg\n dict_append(info, define_macros = macros)\n include_dirs = self.get_include_dirs()\n inc_dir = None\n for d in include_dirs:\n if self.combine_paths(d,\n os.path.join(self.modulename,\n 'arrayobject.h')):\n inc_dir = d\n break\n if inc_dir is not None:\n dict_append(info, include_dirs=[inc_dir])\n if info:\n self.set_info(**info)\n return\n\nclass numarray_info(_numpy_info):\n section = 'numarray'\n modulename = 'numarray'\n\nclass Numeric_info(_numpy_info):\n section = 'Numeric'\n modulename = 'Numeric'\n\nclass numpy_info(_numpy_info):\n section = 'numpy'\n modulename = 'numpy'\n\nclass f2py_info(system_info):\n def calc_info(self):\n try:\n import numpy.f2py as f2py\n except ImportError:\n return\n f2py_dir = os.path.join(os.path.dirname(f2py.__file__),'src')\n self.set_info(sources = [os.path.join(f2py_dir,'fortranobject.c')],\n include_dirs = [f2py_dir])\n return\n\nclass boost_python_info(system_info):\n section = 'boost_python'\n dir_env_var = 'BOOST'\n\n def get_paths(self, section, key):\n pre_dirs = system_info.get_paths(self, section, key)\n dirs = []\n for d in pre_dirs:\n dirs.extend([d] + self.combine_paths(d,['boost*']))\n return [ d for d in dirs if os.path.isdir(d) ]\n\n def calc_info(self):\n from distutils.sysconfig import get_python_inc\n src_dirs = self.get_src_dirs()\n src_dir = ''\n for d in src_dirs:\n if os.path.isfile(os.path.join(d,'libs','python','src','module.cpp')):\n src_dir = d\n break\n if not src_dir:\n return\n py_incl_dir = get_python_inc()\n srcs_dir = os.path.join(src_dir,'libs','python','src')\n bpl_srcs = glob(os.path.join(srcs_dir,'*.cpp'))\n bpl_srcs += glob(os.path.join(srcs_dir,'*','*.cpp'))\n info = {'libraries':[('boost_python_src',{'include_dirs':[src_dir,py_incl_dir],\n 'sources':bpl_srcs})],\n 'include_dirs':[src_dir],\n }\n if info:\n self.set_info(**info)\n return\n\nclass agg2_info(system_info):\n section = 'agg2'\n dir_env_var = 'AGG2'\n\n def get_paths(self, section, key):\n pre_dirs = system_info.get_paths(self, section, key)\n dirs = []\n for d in pre_dirs:\n dirs.extend([d] + self.combine_paths(d,['agg2*']))\n return [ d for d in dirs if os.path.isdir(d) ]\n\n def calc_info(self):\n src_dirs = self.get_src_dirs()\n src_dir = ''\n for d in src_dirs:\n if os.path.isfile(os.path.join(d,'src','agg_affine_matrix.cpp')):\n src_dir = d\n break\n if not src_dir:\n return\n if sys.platform=='win32':\n agg2_srcs = glob(os.path.join(src_dir,'src','platform','win32','agg_win32_bmp.cpp'))\n else:\n agg2_srcs = glob(os.path.join(src_dir,'src','*.cpp'))\n agg2_srcs += [os.path.join(src_dir,'src','platform','X11','agg_platform_support.cpp')]\n\n info = {'libraries':[('agg2_src',{'sources':agg2_srcs,\n 'include_dirs':[os.path.join(src_dir,'include')],\n })],\n 'include_dirs':[os.path.join(src_dir,'include')],\n }\n if info:\n self.set_info(**info)\n return\n\nclass _pkg_config_info(system_info):\n section = None\n config_env_var = 'PKG_CONFIG'\n default_config_exe = 'pkg-config'\n append_config_exe = ''\n version_macro_name = None\n release_macro_name = None\n version_flag = '--modversion'\n cflags_flag = '--cflags'\n\n def get_config_exe(self):\n if os.environ.has_key(self.config_env_var):\n return os.environ[self.config_env_var]\n return self.default_config_exe\n def get_config_output(self, config_exe, option):\n s,o = exec_command(config_exe+' '+self.append_config_exe+' '+option,use_tee=0)\n if not s:\n return o\n\n def calc_info(self):\n config_exe = find_executable(self.get_config_exe())\n if not os.path.isfile(config_exe):\n print 'File not found: %s. Cannot determine %s info.' \\\n % (config_exe, self.section)\n return\n info = {}\n macros = []\n libraries = []\n library_dirs = []\n include_dirs = []\n extra_link_args = []\n extra_compile_args = []\n version = self.get_config_output(config_exe,self.version_flag)\n if version:\n macros.append((self.__class__.__name__.split('.')[-1].upper(),\n '\"\\\\\"%s\\\\\"\"' % (version)))\n if self.version_macro_name:\n macros.append((self.version_macro_name+'_%s' % (version.replace('.','_')),None))\n if self.release_macro_name:\n release = self.get_config_output(config_exe,'--release')\n if release:\n macros.append((self.release_macro_name+'_%s' % (release.replace('.','_')),None))\n opts = self.get_config_output(config_exe,'--libs')\n if opts:\n for opt in opts.split():\n if opt[:2]=='-l':\n libraries.append(opt[2:])\n elif opt[:2]=='-L':\n library_dirs.append(opt[2:])\n else:\n extra_link_args.append(opt)\n opts = self.get_config_output(config_exe,self.cflags_flag)\n if opts:\n for opt in opts.split():\n if opt[:2]=='-I':\n include_dirs.append(opt[2:])\n elif opt[:2]=='-D':\n if '=' in opt:\n n,v = opt[2:].split('=')\n macros.append((n,v))\n else:\n macros.append((opt[2:],None))\n else:\n extra_compile_args.append(opt)\n if macros: dict_append(info, define_macros = macros)\n if libraries: dict_append(info, libraries = libraries)\n if library_dirs: dict_append(info, library_dirs = library_dirs)\n if include_dirs: dict_append(info, include_dirs = include_dirs)\n if extra_link_args: dict_append(info, extra_link_args = extra_link_args)\n if extra_compile_args: dict_append(info, extra_compile_args = extra_compile_args)\n if info:\n self.set_info(**info)\n return\n\nclass wx_info(_pkg_config_info):\n section = 'wx'\n config_env_var = 'WX_CONFIG'\n default_config_exe = 'wx-config'\n append_config_exe = ''\n version_macro_name = 'WX_VERSION'\n release_macro_name = 'WX_RELEASE'\n version_flag = '--version'\n cflags_flag = '--cxxflags'\n\nclass gdk_pixbuf_xlib_2_info(_pkg_config_info):\n section = 'gdk_pixbuf_xlib_2'\n append_config_exe = 'gdk-pixbuf-xlib-2.0'\n version_macro_name = 'GDK_PIXBUF_XLIB_VERSION'\n\nclass gdk_pixbuf_2_info(_pkg_config_info):\n section = 'gdk_pixbuf_2'\n append_config_exe = 'gdk-pixbuf-2.0'\n version_macro_name = 'GDK_PIXBUF_VERSION'\n\nclass gdk_x11_2_info(_pkg_config_info):\n section = 'gdk_x11_2'\n append_config_exe = 'gdk-x11-2.0'\n version_macro_name = 'GDK_X11_VERSION'\n\nclass gdk_2_info(_pkg_config_info):\n section = 'gdk_2'\n append_config_exe = 'gdk-2.0'\n version_macro_name = 'GDK_VERSION'\n\nclass gdk_info(_pkg_config_info):\n section = 'gdk'\n append_config_exe = 'gdk'\n version_macro_name = 'GDK_VERSION'\n\nclass gtkp_x11_2_info(_pkg_config_info):\n section = 'gtkp_x11_2'\n append_config_exe = 'gtk+-x11-2.0'\n version_macro_name = 'GTK_X11_VERSION'\n\n\nclass gtkp_2_info(_pkg_config_info):\n section = 'gtkp_2'\n append_config_exe = 'gtk+-2.0'\n version_macro_name = 'GTK_VERSION'\n\nclass xft_info(_pkg_config_info):\n section = 'xft'\n append_config_exe = 'xft'\n version_macro_name = 'XFT_VERSION'\n\nclass freetype2_info(_pkg_config_info):\n section = 'freetype2'\n append_config_exe = 'freetype2'\n version_macro_name = 'FREETYPE2_VERSION'\n\n## def vstr2hex(version):\n## bits = []\n## n = [24,16,8,4,0]\n## r = 0\n## for s in version.split('.'):\n## r |= int(s) << n[0]\n## del n[0]\n## return r\n\n#--------------------------------------------------------------------\n\ndef combine_paths(*args,**kws):\n \"\"\" Return a list of existing paths composed by all combinations of\n items from arguments.\n \"\"\"\n r = []\n for a in args:\n if not a: continue\n if is_string(a):\n a = [a]\n r.append(a)\n args = r\n if not args: return []\n if len(args)==1:\n result = reduce(lambda a,b:a+b,map(glob,args[0]),[])\n elif len (args)==2:\n result = []\n for a0 in args[0]:\n for a1 in args[1]:\n result.extend(glob(os.path.join(a0,a1)))\n else:\n result = combine_paths(*(combine_paths(args[0],args[1])+args[2:]))\n verbosity = kws.get('verbosity',1)\n if verbosity>1 and result:\n print '(','paths:',','.join(result),')'\n return result\n\nlanguage_map = {'c':0,'c++':1,'f77':2,'f90':3}\ninv_language_map = {0:'c',1:'c++',2:'f77',3:'f90'}\ndef dict_append(d,**kws):\n languages = []\n for k,v in kws.items():\n if k=='language':\n languages.append(v)\n continue\n if d.has_key(k):\n if k in ['library_dirs','include_dirs','define_macros']:\n [d[k].append(vv) for vv in v if vv not in d[k]]\n else:\n d[k].extend(v)\n else:\n d[k] = v\n if languages:\n l = inv_language_map[max([language_map.get(l,0) for l in languages])]\n d['language'] = l\n return\n\ndef show_all():\n import system_info\n import pprint\n match_info = re.compile(r'.*?_info').match\n show_only = []\n for n in sys.argv[1:]:\n if n[-5:] != '_info':\n n = n + '_info'\n show_only.append(n)\n show_all = not show_only\n for n in filter(match_info,dir(system_info)):\n if n in ['system_info','get_info']: continue\n if not show_all:\n if n not in show_only: continue\n del show_only[show_only.index(n)]\n c = getattr(system_info,n)()\n c.verbosity = 2\n r = c.get_info()\n if show_only:\n print 'Info classes not defined:',','.join(show_only)\nif __name__ == \"__main__\":\n show_all()\n", + "source_code_before": "#!/usr/bin/env python\n\"\"\"\nThis file defines a set of system_info classes for getting\ninformation about various resources (libraries, library directories,\ninclude directories, etc.) in the system. Currently, the following\nclasses are available:\n\n atlas_info\n atlas_threads_info\n atlas_blas_info\n atlas_blas_threads_info\n lapack_atlas_info\n blas_info\n lapack_info\n blas_opt_info # usage recommended\n lapack_opt_info # usage recommended\n fftw_info,dfftw_info,sfftw_info\n fftw_threads_info,dfftw_threads_info,sfftw_threads_info\n djbfft_info\n x11_info\n lapack_src_info\n blas_src_info\n numpy_info\n numarray_info\n numpy_info\n boost_python_info\n agg2_info\n wx_info\n gdk_pixbuf_xlib_2_info\n gdk_pixbuf_2_info\n gdk_x11_2_info\n gtkp_x11_2_info\n gtkp_2_info\n xft_info\n freetype2_info\n\nUsage:\n info_dict = get_info()\n where is a string 'atlas','x11','fftw','lapack','blas',\n 'lapack_src', 'blas_src', etc. For a complete list of allowed names,\n see the definition of get_info() function below.\n\n Returned info_dict is a dictionary which is compatible with\n distutils.setup keyword arguments. If info_dict == {}, then the\n asked resource is not available (system_info could not find it).\n\n Several *_info classes specify an environment variable to specify\n the locations of software. When setting the corresponding environment\n variable to 'None' then the software will be ignored, even when it\n is available in system.\n\nGlobal parameters:\n system_info.search_static_first - search static libraries (.a)\n in precedence to shared ones (.so, .sl) if enabled.\n system_info.verbosity - output the results to stdout if enabled.\n\nThe file 'site.cfg' in the same directory as this module is read\nfor configuration options. The format is that used by ConfigParser (i.e.,\nWindows .INI style). The section DEFAULT has options that are the default\nfor each section. The available sections are fftw, atlas, and x11. Appropiate\ndefaults are used if nothing is specified.\n\nThe order of finding the locations of resources is the following:\n 1. environment variable\n 2. section in site.cfg\n 3. DEFAULT section in site.cfg\nOnly the first complete match is returned.\n\nExample:\n----------\n[DEFAULT]\nlibrary_dirs = /usr/lib:/usr/local/lib:/opt/lib\ninclude_dirs = /usr/include:/usr/local/include:/opt/include\nsrc_dirs = /usr/local/src:/opt/src\n# search static libraries (.a) in preference to shared ones (.so)\nsearch_static_first = 0\n\n[fftw]\nfftw_libs = rfftw, fftw\nfftw_opt_libs = rfftw_threaded, fftw_threaded\n# if the above aren't found, look for {s,d}fftw_libs and {s,d}fftw_opt_libs\n\n[atlas]\nlibrary_dirs = /usr/lib/3dnow:/usr/lib/3dnow/atlas\n# for overriding the names of the atlas libraries\natlas_libs = lapack, f77blas, cblas, atlas\n\n[x11]\nlibrary_dirs = /usr/X11R6/lib\ninclude_dirs = /usr/X11R6/include\n----------\n\nAuthors:\n Pearu Peterson , February 2002\n David M. Cooke , April 2002\n\nCopyright 2002 Pearu Peterson all rights reserved,\nPearu Peterson \nPermission to use, modify, and distribute this software is given under the\nterms of the SciPy (BSD style) license. See LICENSE.txt that came with\nthis distribution for specifics.\n\nNO WARRANTY IS EXPRESSED OR IMPLIED. USE AT YOUR OWN RISK.\n\"\"\"\n\nimport sys,os,re\nimport warnings\nfrom distutils.errors import DistutilsError\nfrom glob import glob\nimport ConfigParser\nfrom exec_command import find_executable, exec_command, get_pythonexe\nfrom numpy.distutils.misc_util import is_sequence, is_string\nimport distutils.sysconfig\n\nfrom distutils.sysconfig import get_config_vars\n\nif sys.platform == 'win32':\n default_lib_dirs = ['C:\\\\',\n join(distutils.sysconfig.EXEC_PREFIX, 'libs')]\n default_include_dirs = []\n default_src_dirs = ['.']\n default_x11_lib_dirs = []\n default_x11_include_dirs = []\nelse:\n default_lib_dirs = ['/usr/local/lib', '/opt/lib', '/usr/lib',\n '/opt/local/lib', '/sw/lib']\n default_include_dirs = ['/usr/local/include',\n '/opt/include', '/usr/include',\n '/opt/local/include', '/sw/include']\n default_src_dirs = ['.','/usr/local/src', '/opt/src','/sw/src']\n default_x11_lib_dirs = ['/usr/X11R6/lib','/usr/X11/lib','/usr/lib']\n default_x11_include_dirs = ['/usr/X11R6/include','/usr/X11/include',\n '/usr/include']\n\nif os.path.join(sys.prefix, 'lib') not in default_lib_dirs:\n default_lib_dirs.insert(0,os.path.join(sys.prefix, 'lib'))\n default_include_dirs.append(os.path.join(sys.prefix, 'include'))\n default_src_dirs.append(os.path.join(sys.prefix, 'src'))\n\ndefault_lib_dirs = filter(os.path.isdir, default_lib_dirs)\ndefault_include_dirs = filter(os.path.isdir, default_include_dirs)\ndefault_src_dirs = filter(os.path.isdir, default_src_dirs)\n\nso_ext = get_config_vars('SO')[0] or ''\n\ndef get_info(name,notfound_action=0):\n \"\"\"\n notfound_action:\n 0 - do nothing\n 1 - display warning message\n 2 - raise error\n \"\"\"\n cl = {'atlas':atlas_info, # use lapack_opt or blas_opt instead\n 'atlas_threads':atlas_threads_info, # ditto\n 'atlas_blas':atlas_blas_info,\n 'atlas_blas_threads':atlas_blas_threads_info,\n 'lapack_atlas':lapack_atlas_info, # use lapack_opt instead\n 'lapack_atlas_threads':lapack_atlas_threads_info, # ditto\n 'mkl':mkl_info,\n 'lapack_mkl':lapack_mkl_info, # use lapack_opt instead\n 'blas_mkl':blas_mkl_info, # use blas_opt instead\n 'x11':x11_info,\n 'fft_opt':fft_opt_info,\n 'fftw':fftw_info,\n 'fftw2':fftw2_info,\n 'fftw3':fftw3_info,\n 'dfftw':dfftw_info,\n 'sfftw':sfftw_info,\n 'fftw_threads':fftw_threads_info,\n 'dfftw_threads':dfftw_threads_info,\n 'sfftw_threads':sfftw_threads_info,\n 'djbfft':djbfft_info,\n 'blas':blas_info, # use blas_opt instead\n 'lapack':lapack_info, # use lapack_opt instead\n 'lapack_src':lapack_src_info,\n 'blas_src':blas_src_info,\n 'numpy':numpy_info,\n 'f2py':f2py_info,\n 'Numeric':Numeric_info,\n 'numarray':numarray_info,\n 'lapack_opt':lapack_opt_info,\n 'blas_opt':blas_opt_info,\n 'boost_python':boost_python_info,\n 'agg2':agg2_info,\n 'wx':wx_info,\n 'gdk_pixbuf_xlib_2':gdk_pixbuf_xlib_2_info,\n 'gdk-pixbuf-xlib-2.0':gdk_pixbuf_xlib_2_info,\n 'gdk_pixbuf_2':gdk_pixbuf_2_info,\n 'gdk-pixbuf-2.0':gdk_pixbuf_2_info,\n 'gdk':gdk_info,\n 'gdk_2':gdk_2_info,\n 'gdk-2.0':gdk_2_info,\n 'gdk_x11_2':gdk_x11_2_info,\n 'gdk-x11-2.0':gdk_x11_2_info,\n 'gtkp_x11_2':gtkp_x11_2_info,\n 'gtk+-x11-2.0':gtkp_x11_2_info,\n 'gtkp_2':gtkp_2_info,\n 'gtk+-2.0':gtkp_2_info,\n 'xft':xft_info,\n 'freetype2':freetype2_info,\n }.get(name.lower(),system_info)\n return cl().get_info(notfound_action)\n\nclass NotFoundError(DistutilsError):\n \"\"\"Some third-party program or library is not found.\"\"\"\n\nclass AtlasNotFoundError(NotFoundError):\n \"\"\"\n Atlas (http://math-atlas.sourceforge.net/) libraries not found.\n Directories to search for the libraries can be specified in the\n numpy/distutils/site.cfg file (section [atlas]) or by setting\n the ATLAS environment variable.\"\"\"\n\nclass LapackNotFoundError(NotFoundError):\n \"\"\"\n Lapack (http://www.netlib.org/lapack/) libraries not found.\n Directories to search for the libraries can be specified in the\n numpy/distutils/site.cfg file (section [lapack]) or by setting\n the LAPACK environment variable.\"\"\"\n\nclass LapackSrcNotFoundError(LapackNotFoundError):\n \"\"\"\n Lapack (http://www.netlib.org/lapack/) sources not found.\n Directories to search for the sources can be specified in the\n numpy/distutils/site.cfg file (section [lapack_src]) or by setting\n the LAPACK_SRC environment variable.\"\"\"\n\nclass BlasNotFoundError(NotFoundError):\n \"\"\"\n Blas (http://www.netlib.org/blas/) libraries not found.\n Directories to search for the libraries can be specified in the\n numpy/distutils/site.cfg file (section [blas]) or by setting\n the BLAS environment variable.\"\"\"\n\nclass BlasSrcNotFoundError(BlasNotFoundError):\n \"\"\"\n Blas (http://www.netlib.org/blas/) sources not found.\n Directories to search for the sources can be specified in the\n numpy/distutils/site.cfg file (section [blas_src]) or by setting\n the BLAS_SRC environment variable.\"\"\"\n\nclass FFTWNotFoundError(NotFoundError):\n \"\"\"\n FFTW (http://www.fftw.org/) libraries not found.\n Directories to search for the libraries can be specified in the\n numpy/distutils/site.cfg file (section [fftw]) or by setting\n the FFTW environment variable.\"\"\"\n\nclass DJBFFTNotFoundError(NotFoundError):\n \"\"\"\n DJBFFT (http://cr.yp.to/djbfft.html) libraries not found.\n Directories to search for the libraries can be specified in the\n numpy/distutils/site.cfg file (section [djbfft]) or by setting\n the DJBFFT environment variable.\"\"\"\n\nclass NumericNotFoundError(NotFoundError):\n \"\"\"\n Numeric (http://www.numpy.org/) module not found.\n Get it from above location, install it, and retry setup.py.\"\"\"\n\nclass X11NotFoundError(NotFoundError):\n \"\"\"X11 libraries not found.\"\"\"\n\nclass system_info:\n\n \"\"\" get_info() is the only public method. Don't use others.\n \"\"\"\n section = 'DEFAULT'\n dir_env_var = None\n search_static_first = 0 # XXX: disabled by default, may disappear in\n # future unless it is proved to be useful.\n verbosity = 1\n saved_results = {}\n\n notfounderror = NotFoundError\n\n def __init__ (self,\n default_lib_dirs=default_lib_dirs,\n default_include_dirs=default_include_dirs,\n verbosity = 1,\n ):\n self.__class__.info = {}\n self.local_prefixes = []\n defaults = {}\n defaults['libraries'] = ''\n defaults['library_dirs'] = os.pathsep.join(default_lib_dirs)\n defaults['include_dirs'] = os.pathsep.join(default_include_dirs)\n defaults['src_dirs'] = os.pathsep.join(default_src_dirs)\n defaults['search_static_first'] = str(self.search_static_first)\n self.cp = ConfigParser.ConfigParser(defaults)\n try:\n f = __file__\n except NameError,msg:\n f = sys.argv[0]\n cf = os.path.join(os.path.split(os.path.abspath(f))[0],\n 'site.cfg')\n self.cp.read([cf])\n if not self.cp.has_section(self.section):\n self.cp.add_section(self.section)\n self.search_static_first = self.cp.getboolean(self.section,\n 'search_static_first')\n assert isinstance(self.search_static_first, int)\n\n def calc_libraries_info(self):\n libs = self.get_libraries()\n dirs = self.get_lib_dirs()\n info = {}\n for lib in libs:\n i = None\n for d in dirs:\n i = self.check_libs(d,[lib])\n if i is not None:\n break\n if i is not None:\n dict_append(info,**i)\n else:\n print 'Library %s was not found. Ignoring' % (lib)\n return info\n\n def set_info(self,**info):\n if info:\n lib_info = self.calc_libraries_info()\n dict_append(info,**lib_info)\n self.saved_results[self.__class__.__name__] = info\n\n def has_info(self):\n return self.saved_results.has_key(self.__class__.__name__)\n\n def get_info(self,notfound_action=0):\n \"\"\" Return a dictonary with items that are compatible\n with numpy.distutils.setup keyword arguments.\n \"\"\"\n flag = 0\n if not self.has_info():\n flag = 1\n if self.verbosity>0:\n print self.__class__.__name__ + ':'\n if hasattr(self, 'calc_info'):\n self.calc_info()\n if notfound_action:\n if not self.has_info():\n if notfound_action==1:\n warnings.warn(self.notfounderror.__doc__)\n elif notfound_action==2:\n raise self.notfounderror,self.notfounderror.__doc__\n else:\n raise ValueError(repr(notfound_action))\n\n if self.verbosity>0:\n if not self.has_info():\n print ' NOT AVAILABLE'\n self.set_info()\n else:\n print ' FOUND:'\n\n res = self.saved_results.get(self.__class__.__name__)\n if self.verbosity>0 and flag:\n for k,v in res.items():\n v = str(v)\n if k=='sources' and len(v)>200: v = v[:60]+' ...\\n... '+v[-60:]\n print ' %s = %s'%(k,v)\n print\n\n return res\n\n def get_paths(self, section, key):\n dirs = self.cp.get(section, key).split(os.pathsep)\n env_var = self.dir_env_var\n if env_var:\n if is_sequence(env_var):\n e0 = env_var[-1]\n for e in env_var:\n if os.environ.has_key(e):\n e0 = e\n break\n if not env_var[0]==e0:\n print 'Setting %s=%s' % (env_var[0],e0)\n env_var = e0\n if env_var and os.environ.has_key(env_var):\n d = os.environ[env_var]\n if d=='None':\n print 'Disabled',self.__class__.__name__,'(%s is None)' \\\n % (self.dir_env_var)\n return []\n if os.path.isfile(d):\n dirs = [os.path.dirname(d)] + dirs\n l = getattr(self,'_lib_names',[])\n if len(l)==1:\n b = os.path.basename(d)\n b = os.path.splitext(b)[0]\n if b[:3]=='lib':\n print 'Replacing _lib_names[0]==%r with %r' \\\n % (self._lib_names[0], b[3:])\n self._lib_names[0] = b[3:]\n else:\n ds = d.split(os.pathsep)\n ds2 = []\n for d in ds:\n if os.path.isdir(d):\n ds2.append(d)\n for dd in ['include','lib']:\n d1 = os.path.join(d,dd)\n if os.path.isdir(d1):\n ds2.append(d1)\n dirs = ds2 + dirs\n default_dirs = self.cp.get('DEFAULT', key).split(os.pathsep)\n dirs.extend(default_dirs)\n ret = []\n [ret.append(d) for d in dirs if os.path.isdir(d) and d not in ret]\n if self.verbosity>1:\n print '(',key,'=',':'.join(ret),')'\n return ret\n\n def get_lib_dirs(self, key='library_dirs'):\n return self.get_paths(self.section, key)\n\n def get_include_dirs(self, key='include_dirs'):\n return self.get_paths(self.section, key)\n\n def get_src_dirs(self, key='src_dirs'):\n return self.get_paths(self.section, key)\n\n def get_libs(self, key, default):\n try:\n libs = self.cp.get(self.section, key)\n except ConfigParser.NoOptionError:\n if not default:\n return []\n if is_string(default):\n return [default]\n return default\n return [b for b in [a.strip() for a in libs.split(',')] if b]\n\n def get_libraries(self, key='libraries'):\n return self.get_libs(key,'')\n\n def check_libs(self,lib_dir,libs,opt_libs =[]):\n \"\"\" If static or shared libraries are available then return\n their info dictionary. \"\"\"\n if self.search_static_first:\n exts = ['.a',so_ext]\n else:\n exts = [so_ext,'.a']\n if sys.platform=='cygwin':\n exts.append('.dll.a')\n for ext in exts:\n info = self._check_libs(lib_dir,libs,opt_libs,[ext])\n if info is not None: return info\n return\n\n def check_libs2(self,lib_dir,libs,opt_libs =[]):\n \"\"\" If static or shared libraries are available then return\n their info dictionary. \"\"\"\n if self.search_static_first:\n exts = ['.a',so_ext]\n else:\n exts = [so_ext,'.a']\n if sys.platform=='cygwin':\n exts.append('.dll.a')\n info = self._check_libs(lib_dir,libs,opt_libs,exts)\n if info is not None: return info\n return\n\n def _lib_list(self, lib_dir, libs, exts):\n assert is_string(lib_dir)\n liblist = []\n for l in libs:\n for ext in exts:\n p = self.combine_paths(lib_dir, 'lib'+l+ext)\n if p:\n assert len(p)==1\n liblist.append(p[0])\n break\n return liblist\n\n def _extract_lib_names(self,libs):\n return [os.path.splitext(os.path.basename(p))[0][3:] \\\n for p in libs]\n\n def _check_libs(self,lib_dir,libs, opt_libs, exts):\n found_libs = self._lib_list(lib_dir, libs, exts)\n if len(found_libs) == len(libs):\n found_libs = self._extract_lib_names(found_libs)\n info = {'libraries' : found_libs, 'library_dirs' : [lib_dir]}\n opt_found_libs = self._lib_list(lib_dir, opt_libs, exts)\n if len(opt_found_libs) == len(opt_libs):\n opt_found_libs = self._extract_lib_names(opt_found_libs)\n info['libraries'].extend(opt_found_libs)\n return info\n\n def combine_paths(self,*args):\n return combine_paths(*args,**{'verbosity':self.verbosity})\n\n\nclass fft_opt_info(system_info):\n\n def calc_info(self):\n info = {}\n fftw_info = get_info('fftw3') or get_info('fftw2') or get_info('dfftw')\n djbfft_info = get_info('djbfft')\n if fftw_info:\n dict_append(info,**fftw_info)\n if djbfft_info:\n dict_append(info,**djbfft_info)\n self.set_info(**info)\n return\n\n\nclass fftw_info(system_info):\n #variables to override\n section = 'fftw'\n dir_env_var = 'FFTW'\n notfounderror = FFTWNotFoundError\n ver_info = [ { 'name':'fftw3',\n 'libs':['fftw3'],\n 'includes':['fftw3.h'],\n 'macros':[('SCIPY_FFTW3_H',None)]},\n { 'name':'fftw2',\n 'libs':['rfftw', 'fftw'],\n 'includes':['fftw.h','rfftw.h'],\n 'macros':[('SCIPY_FFTW_H',None)]}]\n\n def __init__(self):\n system_info.__init__(self)\n\n def calc_ver_info(self,ver_param):\n \"\"\"Returns True on successful version detection, else False\"\"\"\n lib_dirs = self.get_lib_dirs()\n incl_dirs = self.get_include_dirs()\n incl_dir = None\n libs = self.get_libs(self.section+'_libs', ver_param['libs'])\n info = None\n for d in lib_dirs:\n r = self.check_libs(d,libs)\n if r is not None:\n info = r\n break\n if info is not None:\n flag = 0\n for d in incl_dirs:\n if len(self.combine_paths(d,ver_param['includes']))==len(ver_param['includes']):\n dict_append(info,include_dirs=[d])\n flag = 1\n incl_dirs = [d]\n incl_dir = d\n break\n if flag:\n dict_append(info,define_macros=ver_param['macros'])\n else:\n info = None\n if info is not None:\n self.set_info(**info)\n return True\n else:\n if self.verbosity>0:\n print ' %s not found' % (ver_param['name'])\n return False\n\n def calc_info(self):\n for i in self.ver_info:\n if self.calc_ver_info(i):\n break\n\nclass fftw2_info(fftw_info):\n #variables to override\n section = 'fftw'\n dir_env_var = 'FFTW'\n notfounderror = FFTWNotFoundError\n ver_info = [ { 'name':'fftw2',\n 'libs':['rfftw', 'fftw'],\n 'includes':['fftw.h','rfftw.h'],\n 'macros':[('SCIPY_FFTW_H',None)]}\n ]\n\nclass fftw3_info(fftw_info):\n #variables to override\n section = 'fftw3'\n dir_env_var = 'FFTW3'\n notfounderror = FFTWNotFoundError\n ver_info = [ { 'name':'fftw3',\n 'libs':['fftw3'],\n 'includes':['fftw3.h'],\n 'macros':[('SCIPY_FFTW3_H',None)]},\n ]\n\nclass dfftw_info(fftw_info):\n section = 'fftw'\n dir_env_var = 'FFTW'\n ver_info = [ { 'name':'dfftw',\n 'libs':['drfftw','dfftw'],\n 'includes':['dfftw.h','drfftw.h'],\n 'macros':[('SCIPY_DFFTW_H',None)]} ]\n\nclass sfftw_info(fftw_info):\n section = 'fftw'\n dir_env_var = 'FFTW'\n ver_info = [ { 'name':'sfftw',\n 'libs':['srfftw','sfftw'],\n 'includes':['sfftw.h','srfftw.h'],\n 'macros':[('SCIPY_SFFTW_H',None)]} ]\n\nclass fftw_threads_info(fftw_info):\n section = 'fftw'\n dir_env_var = 'FFTW'\n ver_info = [ { 'name':'fftw threads',\n 'libs':['rfftw_threads','fftw_threads'],\n 'includes':['fftw_threads.h','rfftw_threads.h'],\n 'macros':[('SCIPY_FFTW_THREADS_H',None)]} ]\n\nclass dfftw_threads_info(fftw_info):\n section = 'fftw'\n dir_env_var = 'FFTW'\n ver_info = [ { 'name':'dfftw threads',\n 'libs':['drfftw_threads','dfftw_threads'],\n 'includes':['dfftw_threads.h','drfftw_threads.h'],\n 'macros':[('SCIPY_DFFTW_THREADS_H',None)]} ]\n\nclass sfftw_threads_info(fftw_info):\n section = 'fftw'\n dir_env_var = 'FFTW'\n ver_info = [ { 'name':'sfftw threads',\n 'libs':['srfftw_threads','sfftw_threads'],\n 'includes':['sfftw_threads.h','srfftw_threads.h'],\n 'macros':[('SCIPY_SFFTW_THREADS_H',None)]} ]\n\nclass djbfft_info(system_info):\n section = 'djbfft'\n dir_env_var = 'DJBFFT'\n notfounderror = DJBFFTNotFoundError\n\n def get_paths(self, section, key):\n pre_dirs = system_info.get_paths(self, section, key)\n dirs = []\n for d in pre_dirs:\n dirs.extend(self.combine_paths(d,['djbfft'])+[d])\n return [ d for d in dirs if os.path.isdir(d) ]\n\n def calc_info(self):\n lib_dirs = self.get_lib_dirs()\n incl_dirs = self.get_include_dirs()\n info = None\n for d in lib_dirs:\n p = self.combine_paths (d,['djbfft.a'])\n if p:\n info = {'extra_objects':p}\n break\n p = self.combine_paths (d,['libdjbfft.a','libdjbfft'+so_ext])\n if p:\n info = {'libraries':['djbfft'],'library_dirs':[d]}\n break\n if info is None:\n return\n for d in incl_dirs:\n if len(self.combine_paths(d,['fftc8.h','fftfreq.h']))==2:\n dict_append(info,include_dirs=[d],\n define_macros=[('SCIPY_DJBFFT_H',None)])\n self.set_info(**info)\n return\n return\n\nclass mkl_info(system_info):\n section = 'mkl'\n dir_env_var = 'MKL'\n _lib_mkl = ['mkl','vml','guide']\n\n def get_mkl_rootdir(self):\n mklroot = os.environ.get('MKLROOT',None)\n if mklroot is not None:\n return mklroot\n paths = os.environ.get('LD_LIBRARY_PATH','').split(os.pathsep)\n ld_so_conf = '/etc/ld.so.conf'\n if os.path.isfile(ld_so_conf):\n for d in open(ld_so_conf,'r').readlines():\n d = d.strip()\n if d: paths.append(d)\n intel_mkl_dirs = []\n for path in paths:\n path_atoms = path.split(os.sep)\n for m in path_atoms:\n if m.startswith('mkl'):\n d = os.sep.join(path_atoms[:path_atoms.index(m)+2])\n intel_mkl_dirs.append(d)\n break\n for d in paths:\n dirs = glob(os.path.join(d,'mkl','*')) + glob(os.path.join(d,'mkl*'))\n for d in dirs:\n if os.path.isdir(os.path.join(d,'lib')):\n return d\n return None\n\n def __init__(self):\n mklroot = self.get_mkl_rootdir()\n if mklroot is None:\n system_info.__init__(self)\n else:\n from cpuinfo import cpu\n if cpu.is_Itanium():\n plt = '64'\n l = 'mkl_ipf'\n elif cpu.is_Xeon():\n plt = 'em64t'\n l = 'mkl_em64t'\n else:\n plt = '32'\n l = 'mkl_ia32'\n if l not in self._lib_mkl:\n self._lib_mkl.insert(0,l)\n system_info.__init__(self,\n default_lib_dirs=[os.path.join(mklroot,'lib',plt)],\n default_include_dirs=[os.path.join(mklroot,'include')])\n\n def calc_info(self):\n lib_dirs = self.get_lib_dirs()\n incl_dirs = self.get_include_dirs()\n mkl_libs = self.get_libs('mkl_libs',self._lib_mkl)\n mkl = None\n for d in lib_dirs:\n mkl = self.check_libs2(d,mkl_libs)\n if mkl is not None:\n break\n if mkl is None:\n return\n info = {}\n dict_append(info,**mkl)\n dict_append(info,libraries = ['pthread'], include_dirs = incl_dirs)\n self.set_info(**info)\n\nclass lapack_mkl_info(mkl_info):\n\n def calc_info(self):\n mkl = get_info('mkl')\n if not mkl:\n return\n lapack_libs = self.get_libs('lapack_libs',['mkl_lapack'])\n info = {'libraries': lapack_libs}\n dict_append(info,**mkl)\n self.set_info(**info)\n\nclass blas_mkl_info(mkl_info):\n pass\n\nclass atlas_info(system_info):\n section = 'atlas'\n dir_env_var = 'ATLAS'\n _lib_names = ['f77blas','cblas']\n if sys.platform[:7]=='freebsd':\n _lib_atlas = ['atlas_r']\n _lib_lapack = ['alapack_r']\n else:\n _lib_atlas = ['atlas']\n _lib_lapack = ['lapack']\n\n notfounderror = AtlasNotFoundError\n\n def get_paths(self, section, key):\n pre_dirs = system_info.get_paths(self, section, key)\n dirs = []\n for d in pre_dirs:\n dirs.extend(self.combine_paths(d,['atlas*','ATLAS*',\n 'sse','3dnow','sse2'])+[d])\n return [ d for d in dirs if os.path.isdir(d) ]\n\n def calc_info(self):\n lib_dirs = self.get_lib_dirs()\n info = {}\n atlas_libs = self.get_libs('atlas_libs',\n self._lib_names + self._lib_atlas)\n lapack_libs = self.get_libs('lapack_libs',self._lib_lapack)\n atlas = None\n lapack = None\n atlas_1 = None\n for d in lib_dirs:\n atlas = self.check_libs(d,atlas_libs,[])\n lapack_atlas = self.check_libs(d,['lapack_atlas'],[])\n if atlas is not None:\n lib_dirs2 = self.combine_paths(d,['atlas*','ATLAS*'])+[d]\n for d2 in lib_dirs2:\n lapack = self.check_libs(d2,lapack_libs,[])\n if lapack is not None:\n break\n else:\n lapack = None\n if lapack is not None:\n break\n if atlas:\n atlas_1 = atlas\n print self.__class__\n if atlas is None:\n atlas = atlas_1\n if atlas is None:\n return\n include_dirs = self.get_include_dirs()\n h = (self.combine_paths(lib_dirs+include_dirs,'cblas.h') or [None])[0]\n if h:\n h = os.path.dirname(h)\n dict_append(info,include_dirs=[h])\n info['language'] = 'c'\n if lapack is not None:\n dict_append(info,**lapack)\n dict_append(info,**atlas)\n elif 'lapack_atlas' in atlas['libraries']:\n dict_append(info,**atlas)\n dict_append(info,define_macros=[('ATLAS_WITH_LAPACK_ATLAS',None)])\n self.set_info(**info)\n return\n else:\n dict_append(info,**atlas)\n dict_append(info,define_macros=[('ATLAS_WITHOUT_LAPACK',None)])\n message = \"\"\"\n*********************************************************************\n Could not find lapack library within the ATLAS installation.\n*********************************************************************\n\"\"\"\n warnings.warn(message)\n self.set_info(**info)\n return\n\n # Check if lapack library is complete, only warn if it is not.\n lapack_dir = lapack['library_dirs'][0]\n lapack_name = lapack['libraries'][0]\n lapack_lib = None\n for e in ['.a',so_ext]:\n fn = os.path.join(lapack_dir,'lib'+lapack_name+e)\n if os.path.exists(fn):\n lapack_lib = fn\n break\n if lapack_lib is not None:\n sz = os.stat(lapack_lib)[6]\n if sz <= 4000*1024:\n message = \"\"\"\n*********************************************************************\n Lapack library (from ATLAS) is probably incomplete:\n size of %s is %sk (expected >4000k)\n\n Follow the instructions in the KNOWN PROBLEMS section of the file\n numpy/INSTALL.txt.\n*********************************************************************\n\"\"\" % (lapack_lib,sz/1024)\n warnings.warn(message)\n else:\n info['language'] = 'f77'\n\n self.set_info(**info)\n\nclass atlas_blas_info(atlas_info):\n _lib_names = ['f77blas','cblas']\n\n def calc_info(self):\n lib_dirs = self.get_lib_dirs()\n info = {}\n atlas_libs = self.get_libs('atlas_libs',\n self._lib_names + self._lib_atlas)\n atlas = None\n for d in lib_dirs:\n atlas = self.check_libs(d,atlas_libs,[])\n if atlas is not None:\n break\n if atlas is None:\n return\n include_dirs = self.get_include_dirs()\n h = (self.combine_paths(lib_dirs+include_dirs,'cblas.h') or [None])[0]\n if h:\n h = os.path.dirname(h)\n dict_append(info,include_dirs=[h])\n info['language'] = 'c'\n\n dict_append(info,**atlas)\n\n self.set_info(**info)\n return\n\n\nclass atlas_threads_info(atlas_info):\n dir_env_var = ['PTATLAS','ATLAS']\n _lib_names = ['ptf77blas','ptcblas']\n\nclass atlas_blas_threads_info(atlas_blas_info):\n dir_env_var = ['PTATLAS','ATLAS']\n _lib_names = ['ptf77blas','ptcblas']\n\nclass lapack_atlas_info(atlas_info):\n _lib_names = ['lapack_atlas'] + atlas_info._lib_names\n\nclass lapack_atlas_threads_info(atlas_threads_info):\n _lib_names = ['lapack_atlas'] + atlas_threads_info._lib_names\n\nclass lapack_info(system_info):\n section = 'lapack'\n dir_env_var = 'LAPACK'\n _lib_names = ['lapack']\n notfounderror = LapackNotFoundError\n\n def calc_info(self):\n lib_dirs = self.get_lib_dirs()\n\n lapack_libs = self.get_libs('lapack_libs', self._lib_names)\n for d in lib_dirs:\n lapack = self.check_libs(d,lapack_libs,[])\n if lapack is not None:\n info = lapack\n break\n else:\n return\n info['language'] = 'f77'\n self.set_info(**info)\n\nclass lapack_src_info(system_info):\n section = 'lapack_src'\n dir_env_var = 'LAPACK_SRC'\n notfounderror = LapackSrcNotFoundError\n\n def get_paths(self, section, key):\n pre_dirs = system_info.get_paths(self, section, key)\n dirs = []\n for d in pre_dirs:\n dirs.extend([d] + self.combine_paths(d,['LAPACK*/SRC','SRC']))\n return [ d for d in dirs if os.path.isdir(d) ]\n\n def calc_info(self):\n src_dirs = self.get_src_dirs()\n src_dir = ''\n for d in src_dirs:\n if os.path.isfile(os.path.join(d,'dgesv.f')):\n src_dir = d\n break\n if not src_dir:\n #XXX: Get sources from netlib. May be ask first.\n return\n # The following is extracted from LAPACK-3.0/SRC/Makefile\n allaux='''\n ilaenv ieeeck lsame lsamen xerbla\n ''' # *.f\n laux = '''\n bdsdc bdsqr disna labad lacpy ladiv lae2 laebz laed0 laed1\n laed2 laed3 laed4 laed5 laed6 laed7 laed8 laed9 laeda laev2\n lagtf lagts lamch lamrg lanst lapy2 lapy3 larnv larrb larre\n larrf lartg laruv las2 lascl lasd0 lasd1 lasd2 lasd3 lasd4\n lasd5 lasd6 lasd7 lasd8 lasd9 lasda lasdq lasdt laset lasq1\n lasq2 lasq3 lasq4 lasq5 lasq6 lasr lasrt lassq lasv2 pttrf\n stebz stedc steqr sterf\n ''' # [s|d]*.f\n lasrc = '''\n gbbrd gbcon gbequ gbrfs gbsv gbsvx gbtf2 gbtrf gbtrs gebak\n gebal gebd2 gebrd gecon geequ gees geesx geev geevx gegs gegv\n gehd2 gehrd gelq2 gelqf gels gelsd gelss gelsx gelsy geql2\n geqlf geqp3 geqpf geqr2 geqrf gerfs gerq2 gerqf gesc2 gesdd\n gesv gesvd gesvx getc2 getf2 getrf getri getrs ggbak ggbal\n gges ggesx ggev ggevx ggglm gghrd gglse ggqrf ggrqf ggsvd\n ggsvp gtcon gtrfs gtsv gtsvx gttrf gttrs gtts2 hgeqz hsein\n hseqr labrd lacon laein lags2 lagtm lahqr lahrd laic1 lals0\n lalsa lalsd langb lange langt lanhs lansb lansp lansy lantb\n lantp lantr lapll lapmt laqgb laqge laqp2 laqps laqsb laqsp\n laqsy lar1v lar2v larf larfb larfg larft larfx largv larrv\n lartv larz larzb larzt laswp lasyf latbs latdf latps latrd\n latrs latrz latzm lauu2 lauum pbcon pbequ pbrfs pbstf pbsv\n pbsvx pbtf2 pbtrf pbtrs pocon poequ porfs posv posvx potf2\n potrf potri potrs ppcon ppequ pprfs ppsv ppsvx pptrf pptri\n pptrs ptcon pteqr ptrfs ptsv ptsvx pttrs ptts2 spcon sprfs\n spsv spsvx sptrf sptri sptrs stegr stein sycon syrfs sysv\n sysvx sytf2 sytrf sytri sytrs tbcon tbrfs tbtrs tgevc tgex2\n tgexc tgsen tgsja tgsna tgsy2 tgsyl tpcon tprfs tptri tptrs\n trcon trevc trexc trrfs trsen trsna trsyl trti2 trtri trtrs\n tzrqf tzrzf\n ''' # [s|c|d|z]*.f\n sd_lasrc = '''\n laexc lag2 lagv2 laln2 lanv2 laqtr lasy2 opgtr opmtr org2l\n org2r orgbr orghr orgl2 orglq orgql orgqr orgr2 orgrq orgtr\n orm2l orm2r ormbr ormhr orml2 ormlq ormql ormqr ormr2 ormr3\n ormrq ormrz ormtr rscl sbev sbevd sbevx sbgst sbgv sbgvd sbgvx\n sbtrd spev spevd spevx spgst spgv spgvd spgvx sptrd stev stevd\n stevr stevx syev syevd syevr syevx sygs2 sygst sygv sygvd\n sygvx sytd2 sytrd\n ''' # [s|d]*.f\n cz_lasrc = '''\n bdsqr hbev hbevd hbevx hbgst hbgv hbgvd hbgvx hbtrd hecon heev\n heevd heevr heevx hegs2 hegst hegv hegvd hegvx herfs hesv\n hesvx hetd2 hetf2 hetrd hetrf hetri hetrs hpcon hpev hpevd\n hpevx hpgst hpgv hpgvd hpgvx hprfs hpsv hpsvx hptrd hptrf\n hptri hptrs lacgv lacp2 lacpy lacrm lacrt ladiv laed0 laed7\n laed8 laesy laev2 lahef lanhb lanhe lanhp lanht laqhb laqhe\n laqhp larcm larnv lartg lascl laset lasr lassq pttrf rot spmv\n spr stedc steqr symv syr ung2l ung2r ungbr unghr ungl2 unglq\n ungql ungqr ungr2 ungrq ungtr unm2l unm2r unmbr unmhr unml2\n unmlq unmql unmqr unmr2 unmr3 unmrq unmrz unmtr upgtr upmtr\n ''' # [c|z]*.f\n #######\n sclaux = laux + ' econd ' # s*.f\n dzlaux = laux + ' secnd ' # d*.f\n slasrc = lasrc + sd_lasrc # s*.f\n dlasrc = lasrc + sd_lasrc # d*.f\n clasrc = lasrc + cz_lasrc + ' srot srscl ' # c*.f\n zlasrc = lasrc + cz_lasrc + ' drot drscl ' # z*.f\n oclasrc = ' icmax1 scsum1 ' # *.f\n ozlasrc = ' izmax1 dzsum1 ' # *.f\n sources = ['s%s.f'%f for f in (sclaux+slasrc).split()] \\\n + ['d%s.f'%f for f in (dzlaux+dlasrc).split()] \\\n + ['c%s.f'%f for f in (clasrc).split()] \\\n + ['z%s.f'%f for f in (zlasrc).split()] \\\n + ['%s.f'%f for f in (allaux+oclasrc+ozlasrc).split()]\n sources = [os.path.join(src_dir,f) for f in sources]\n #XXX: should we check here actual existence of source files?\n info = {'sources':sources,'language':'f77'}\n self.set_info(**info)\n\natlas_version_c_text = r'''\n/* This file is generated from numpy_distutils/system_info.py */\n#ifdef __CPLUSPLUS__\nextern \"C\" {\n#endif\n#include \"Python.h\"\nstatic PyMethodDef module_methods[] = { {NULL,NULL} };\nDL_EXPORT(void) initatlas_version(void) {\n void ATL_buildinfo(void);\n ATL_buildinfo();\n Py_InitModule(\"atlas_version\", module_methods);\n}\n#ifdef __CPLUSCPLUS__\n}\n#endif\n'''\n\ndef _get_build_temp():\n from distutils.util import get_platform\n plat_specifier = \".%s-%s\" % (get_platform(), sys.version[0:3])\n return os.path.join('build','temp'+plat_specifier)\n\ndef get_atlas_version(**config):\n os.environ['NO_SCIPY_IMPORT']='get_atlas_version'\n from core import Extension, setup\n from misc_util import get_cmd\n import log\n magic = hex(hash(repr(config)))\n def atlas_version_c(extension, build_dir,magic=magic):\n source = os.path.join(build_dir,'atlas_version_%s.c' % (magic))\n if os.path.isfile(source):\n from distutils.dep_util import newer\n if newer(source,__file__):\n return source\n f = open(source,'w')\n f.write(atlas_version_c_text)\n f.close()\n return source\n ext = Extension('atlas_version',\n sources=[atlas_version_c],\n **config)\n build_dir = _get_build_temp()\n extra_args = ['--build-lib',build_dir]\n for a in sys.argv:\n if re.match('[-][-]compiler[=]',a):\n extra_args.append(a)\n import distutils.core\n old_dist = distutils.core._setup_distribution\n distutils.core._setup_distribution = None\n try:\n dist = setup(ext_modules=[ext],\n script_name = 'get_atlas_version',\n script_args = ['build_src','build_ext']+extra_args)\n except Exception,msg:\n print \"##### msg: %s\" % msg\n if not msg:\n msg = \"Unknown Exception\"\n log.warn(msg)\n return None\n distutils.core._setup_distribution = old_dist\n\n from distutils.sysconfig import get_config_var\n so_ext = get_config_var('SO')\n target = os.path.join(build_dir,'atlas_version'+so_ext)\n cmd = [get_pythonexe(),'-c',\n '\"import imp,os;os.environ[\\\\\"NO_SCIPY_IMPORT\\\\\"]='\\\n '\\\\\"system_info.get_atlas_version:load atlas_version\\\\\";'\\\n 'imp.load_dynamic(\\\\\"atlas_version\\\\\",\\\\\"%s\\\\\")\"'\\\n % (os.path.basename(target))]\n s,o = exec_command(cmd,execute_in=os.path.dirname(target),use_tee=0)\n atlas_version = None\n if not s:\n m = re.search(r'ATLAS version (?P\\d+[.]\\d+[.]\\d+)',o)\n if m:\n atlas_version = m.group('version')\n if atlas_version is None:\n if re.search(r'undefined symbol: ATL_buildinfo',o,re.M):\n atlas_version = '3.2.1_pre3.3.6'\n else:\n print 'Command:',' '.join(cmd)\n print 'Status:',s\n print 'Output:',o\n return atlas_version\n\n\nclass lapack_opt_info(system_info):\n\n def calc_info(self):\n\n if sys.platform=='darwin' and not os.environ.get('ATLAS',None):\n args = []\n link_args = []\n if os.path.exists('/System/Library/Frameworks/Accelerate.framework/'):\n args.extend(['-faltivec'])\n link_args.extend(['-Wl,-framework','-Wl,Accelerate'])\n elif os.path.exists('/System/Library/Frameworks/vecLib.framework/'):\n args.extend(['-faltivec'])\n link_args.extend(['-Wl,-framework','-Wl,vecLib'])\n if args:\n self.set_info(extra_compile_args=args,\n extra_link_args=link_args,\n define_macros=[('NO_ATLAS_INFO',3)])\n return\n\n lapack_mkl_info = get_info('lapack_mkl')\n if lapack_mkl_info:\n self.set_info(**lapack_mkl_info)\n return\n\n atlas_info = get_info('atlas_threads')\n if not atlas_info:\n atlas_info = get_info('atlas')\n #atlas_info = {} ## uncomment for testing\n atlas_version = None\n need_lapack = 0\n need_blas = 0\n info = {}\n if atlas_info:\n version_info = atlas_info.copy()\n atlas_version = get_atlas_version(**version_info)\n if not atlas_info.has_key('define_macros'):\n atlas_info['define_macros'] = []\n if atlas_version is None:\n atlas_info['define_macros'].append(('NO_ATLAS_INFO',2))\n else:\n atlas_info['define_macros'].append(('ATLAS_INFO',\n '\"\\\\\"%s\\\\\"\"' % atlas_version))\n\t\tif atlas_version=='3.2.1_pre3.3.6':\n\t\t atlas_info['define_macros'].append(('NO_ATLAS_INFO',4))\n l = atlas_info.get('define_macros',[])\n if ('ATLAS_WITH_LAPACK_ATLAS',None) in l \\\n or ('ATLAS_WITHOUT_LAPACK',None) in l:\n need_lapack = 1\n info = atlas_info\n else:\n warnings.warn(AtlasNotFoundError.__doc__)\n need_blas = 1\n need_lapack = 1\n dict_append(info,define_macros=[('NO_ATLAS_INFO',1)])\n\n if need_lapack:\n lapack_info = get_info('lapack')\n #lapack_info = {} ## uncomment for testing\n if lapack_info:\n dict_append(info,**lapack_info)\n else:\n warnings.warn(LapackNotFoundError.__doc__)\n lapack_src_info = get_info('lapack_src')\n if not lapack_src_info:\n warnings.warn(LapackSrcNotFoundError.__doc__)\n return\n dict_append(info,libraries=[('flapack_src',lapack_src_info)])\n\n if need_blas:\n blas_info = get_info('blas')\n #blas_info = {} ## uncomment for testing\n if blas_info:\n dict_append(info,**blas_info)\n else:\n warnings.warn(BlasNotFoundError.__doc__)\n blas_src_info = get_info('blas_src')\n if not blas_src_info:\n warnings.warn(BlasSrcNotFoundError.__doc__)\n return\n dict_append(info,libraries=[('fblas_src',blas_src_info)])\n\n self.set_info(**info)\n return\n\n\nclass blas_opt_info(system_info):\n\n def calc_info(self):\n\n if sys.platform=='darwin' and not os.environ.get('ATLAS',None):\n args = []\n link_args = []\n if os.path.exists('/System/Library/Frameworks/Accelerate.framework/'):\n args.extend(['-faltivec',\n '-I/System/Library/Frameworks/vecLib.framework/Headers',\n ])\n link_args.extend(['-Wl,-framework','-Wl,Accelerate'])\n elif os.path.exists('/System/Library/Frameworks/vecLib.framework/'):\n args.extend(['-faltivec',\n '-I/System/Library/Frameworks/vecLib.framework/Headers',\n ])\n link_args.extend(['-Wl,-framework','-Wl,vecLib'])\n if args:\n self.set_info(extra_compile_args=args,\n extra_link_args=link_args,\n define_macros=[('NO_ATLAS_INFO',3)])\n return\n\n blas_mkl_info = get_info('blas_mkl')\n if blas_mkl_info:\n self.set_info(**blas_mkl_info)\n return\n\n atlas_info = get_info('atlas_blas_threads')\n if not atlas_info:\n atlas_info = get_info('atlas_blas')\n atlas_version = None\n need_blas = 0\n info = {}\n if atlas_info:\n version_info = atlas_info.copy()\n atlas_version = get_atlas_version(**version_info)\n if not atlas_info.has_key('define_macros'):\n atlas_info['define_macros'] = []\n if atlas_version is None:\n atlas_info['define_macros'].append(('NO_ATLAS_INFO',2))\n else:\n atlas_info['define_macros'].append(('ATLAS_INFO',\n '\"\\\\\"%s\\\\\"\"' % atlas_version))\n info = atlas_info\n else:\n warnings.warn(AtlasNotFoundError.__doc__)\n need_blas = 1\n dict_append(info,define_macros=[('NO_ATLAS_INFO',1)])\n\n if need_blas:\n blas_info = get_info('blas')\n if blas_info:\n dict_append(info,**blas_info)\n else:\n warnings.warn(BlasNotFoundError.__doc__)\n blas_src_info = get_info('blas_src')\n if not blas_src_info:\n warnings.warn(BlasSrcNotFoundError.__doc__)\n return\n dict_append(info,libraries=[('fblas_src',blas_src_info)])\n\n self.set_info(**info)\n return\n\n\nclass blas_info(system_info):\n section = 'blas'\n dir_env_var = 'BLAS'\n _lib_names = ['blas']\n notfounderror = BlasNotFoundError\n\n def calc_info(self):\n lib_dirs = self.get_lib_dirs()\n\n blas_libs = self.get_libs('blas_libs', self._lib_names)\n for d in lib_dirs:\n blas = self.check_libs(d,blas_libs,[])\n if blas is not None:\n info = blas\n break\n else:\n return\n info['language'] = 'f77' # XXX: is it generally true?\n self.set_info(**info)\n\n\nclass blas_src_info(system_info):\n section = 'blas_src'\n dir_env_var = 'BLAS_SRC'\n notfounderror = BlasSrcNotFoundError\n\n def get_paths(self, section, key):\n pre_dirs = system_info.get_paths(self, section, key)\n dirs = []\n for d in pre_dirs:\n dirs.extend([d] + self.combine_paths(d,['blas']))\n return [ d for d in dirs if os.path.isdir(d) ]\n\n def calc_info(self):\n src_dirs = self.get_src_dirs()\n src_dir = ''\n for d in src_dirs:\n if os.path.isfile(os.path.join(d,'daxpy.f')):\n src_dir = d\n break\n if not src_dir:\n #XXX: Get sources from netlib. May be ask first.\n return\n blas1 = '''\n caxpy csscal dnrm2 dzasum saxpy srotg zdotc ccopy cswap drot\n dznrm2 scasum srotm zdotu cdotc dasum drotg icamax scnrm2\n srotmg zdrot cdotu daxpy drotm idamax scopy sscal zdscal crotg\n dcabs1 drotmg isamax sdot sswap zrotg cscal dcopy dscal izamax\n snrm2 zaxpy zscal csrot ddot dswap sasum srot zcopy zswap\n '''\n blas2 = '''\n cgbmv chpmv ctrsv dsymv dtrsv sspr2 strmv zhemv ztpmv cgemv\n chpr dgbmv dsyr lsame ssymv strsv zher ztpsv cgerc chpr2 dgemv\n dsyr2 sgbmv ssyr xerbla zher2 ztrmv cgeru ctbmv dger dtbmv\n sgemv ssyr2 zgbmv zhpmv ztrsv chbmv ctbsv dsbmv dtbsv sger\n stbmv zgemv zhpr chemv ctpmv dspmv dtpmv ssbmv stbsv zgerc\n zhpr2 cher ctpsv dspr dtpsv sspmv stpmv zgeru ztbmv cher2\n ctrmv dspr2 dtrmv sspr stpsv zhbmv ztbsv\n '''\n blas3 = '''\n cgemm csymm ctrsm dsyrk sgemm strmm zhemm zsyr2k chemm csyr2k\n dgemm dtrmm ssymm strsm zher2k zsyrk cher2k csyrk dsymm dtrsm\n ssyr2k zherk ztrmm cherk ctrmm dsyr2k ssyrk zgemm zsymm ztrsm\n '''\n sources = [os.path.join(src_dir,f+'.f') \\\n for f in (blas1+blas2+blas3).split()]\n #XXX: should we check here actual existence of source files?\n info = {'sources':sources,'language':'f77'}\n self.set_info(**info)\n\nclass x11_info(system_info):\n section = 'x11'\n notfounderror = X11NotFoundError\n\n def __init__(self):\n system_info.__init__(self,\n default_lib_dirs=default_x11_lib_dirs,\n default_include_dirs=default_x11_include_dirs)\n\n def calc_info(self):\n if sys.platform in ['win32']:\n return\n lib_dirs = self.get_lib_dirs()\n include_dirs = self.get_include_dirs()\n x11_libs = self.get_libs('x11_libs', ['X11'])\n for lib_dir in lib_dirs:\n info = self.check_libs(lib_dir, x11_libs, [])\n if info is not None:\n break\n else:\n return\n inc_dir = None\n for d in include_dirs:\n if self.combine_paths(d, 'X11/X.h'):\n inc_dir = d\n break\n if inc_dir is not None:\n dict_append(info, include_dirs=[inc_dir])\n self.set_info(**info)\n\nclass _numpy_info(system_info):\n section = 'Numeric'\n modulename = 'Numeric'\n notfounderror = NumericNotFoundError\n\n def __init__(self):\n from distutils.sysconfig import get_python_inc\n include_dirs = []\n try:\n module = __import__(self.modulename)\n prefix = []\n for name in module.__file__.split(os.sep):\n if name=='lib':\n break\n prefix.append(name)\n include_dirs.append(get_python_inc(prefix=os.sep.join(prefix)))\n except ImportError:\n pass\n py_incl_dir = get_python_inc()\n include_dirs.append(py_incl_dir)\n for d in default_include_dirs:\n d = os.path.join(d, os.path.basename(py_incl_dir))\n if d not in include_dirs:\n include_dirs.append(d)\n system_info.__init__(self,\n default_lib_dirs=[],\n default_include_dirs=include_dirs)\n\n def calc_info(self):\n try:\n module = __import__(self.modulename)\n except ImportError:\n return\n info = {}\n macros = []\n for v in ['__version__','version']:\n vrs = getattr(module,v,None)\n if vrs is None:\n continue\n macros = [(self.modulename.upper()+'_VERSION',\n '\"\\\\\"%s\\\\\"\"' % (vrs)),\n (self.modulename.upper(),None)]\n break\n## try:\n## macros.append(\n## (self.modulename.upper()+'_VERSION_HEX',\n## hex(vstr2hex(module.__version__))),\n## )\n## except Exception,msg:\n## print msg\n dict_append(info, define_macros = macros)\n include_dirs = self.get_include_dirs()\n inc_dir = None\n for d in include_dirs:\n if self.combine_paths(d,\n os.path.join(self.modulename,\n 'arrayobject.h')):\n inc_dir = d\n break\n if inc_dir is not None:\n dict_append(info, include_dirs=[inc_dir])\n if info:\n self.set_info(**info)\n return\n\nclass numarray_info(_numpy_info):\n section = 'numarray'\n modulename = 'numarray'\n\nclass Numeric_info(_numpy_info):\n section = 'Numeric'\n modulename = 'Numeric'\n\nclass numpy_info(_numpy_info):\n section = 'numpy'\n modulename = 'numpy'\n\nclass f2py_info(system_info):\n def calc_info(self):\n try:\n import numpy.f2py as f2py\n except ImportError:\n return\n f2py_dir = os.path.join(os.path.dirname(f2py.__file__),'src')\n self.set_info(sources = [os.path.join(f2py_dir,'fortranobject.c')],\n include_dirs = [f2py_dir])\n return\n\nclass boost_python_info(system_info):\n section = 'boost_python'\n dir_env_var = 'BOOST'\n\n def get_paths(self, section, key):\n pre_dirs = system_info.get_paths(self, section, key)\n dirs = []\n for d in pre_dirs:\n dirs.extend([d] + self.combine_paths(d,['boost*']))\n return [ d for d in dirs if os.path.isdir(d) ]\n\n def calc_info(self):\n from distutils.sysconfig import get_python_inc\n src_dirs = self.get_src_dirs()\n src_dir = ''\n for d in src_dirs:\n if os.path.isfile(os.path.join(d,'libs','python','src','module.cpp')):\n src_dir = d\n break\n if not src_dir:\n return\n py_incl_dir = get_python_inc()\n srcs_dir = os.path.join(src_dir,'libs','python','src')\n bpl_srcs = glob(os.path.join(srcs_dir,'*.cpp'))\n bpl_srcs += glob(os.path.join(srcs_dir,'*','*.cpp'))\n info = {'libraries':[('boost_python_src',{'include_dirs':[src_dir,py_incl_dir],\n 'sources':bpl_srcs})],\n 'include_dirs':[src_dir],\n }\n if info:\n self.set_info(**info)\n return\n\nclass agg2_info(system_info):\n section = 'agg2'\n dir_env_var = 'AGG2'\n\n def get_paths(self, section, key):\n pre_dirs = system_info.get_paths(self, section, key)\n dirs = []\n for d in pre_dirs:\n dirs.extend([d] + self.combine_paths(d,['agg2*']))\n return [ d for d in dirs if os.path.isdir(d) ]\n\n def calc_info(self):\n src_dirs = self.get_src_dirs()\n src_dir = ''\n for d in src_dirs:\n if os.path.isfile(os.path.join(d,'src','agg_affine_matrix.cpp')):\n src_dir = d\n break\n if not src_dir:\n return\n if sys.platform=='win32':\n agg2_srcs = glob(os.path.join(src_dir,'src','platform','win32','agg_win32_bmp.cpp'))\n else:\n agg2_srcs = glob(os.path.join(src_dir,'src','*.cpp'))\n agg2_srcs += [os.path.join(src_dir,'src','platform','X11','agg_platform_support.cpp')]\n\n info = {'libraries':[('agg2_src',{'sources':agg2_srcs,\n 'include_dirs':[os.path.join(src_dir,'include')],\n })],\n 'include_dirs':[os.path.join(src_dir,'include')],\n }\n if info:\n self.set_info(**info)\n return\n\nclass _pkg_config_info(system_info):\n section = None\n config_env_var = 'PKG_CONFIG'\n default_config_exe = 'pkg-config'\n append_config_exe = ''\n version_macro_name = None\n release_macro_name = None\n version_flag = '--modversion'\n cflags_flag = '--cflags'\n\n def get_config_exe(self):\n if os.environ.has_key(self.config_env_var):\n return os.environ[self.config_env_var]\n return self.default_config_exe\n def get_config_output(self, config_exe, option):\n s,o = exec_command(config_exe+' '+self.append_config_exe+' '+option,use_tee=0)\n if not s:\n return o\n\n def calc_info(self):\n config_exe = find_executable(self.get_config_exe())\n if not os.path.isfile(config_exe):\n print 'File not found: %s. Cannot determine %s info.' \\\n % (config_exe, self.section)\n return\n info = {}\n macros = []\n libraries = []\n library_dirs = []\n include_dirs = []\n extra_link_args = []\n extra_compile_args = []\n version = self.get_config_output(config_exe,self.version_flag)\n if version:\n macros.append((self.__class__.__name__.split('.')[-1].upper(),\n '\"\\\\\"%s\\\\\"\"' % (version)))\n if self.version_macro_name:\n macros.append((self.version_macro_name+'_%s' % (version.replace('.','_')),None))\n if self.release_macro_name:\n release = self.get_config_output(config_exe,'--release')\n if release:\n macros.append((self.release_macro_name+'_%s' % (release.replace('.','_')),None))\n opts = self.get_config_output(config_exe,'--libs')\n if opts:\n for opt in opts.split():\n if opt[:2]=='-l':\n libraries.append(opt[2:])\n elif opt[:2]=='-L':\n library_dirs.append(opt[2:])\n else:\n extra_link_args.append(opt)\n opts = self.get_config_output(config_exe,self.cflags_flag)\n if opts:\n for opt in opts.split():\n if opt[:2]=='-I':\n include_dirs.append(opt[2:])\n elif opt[:2]=='-D':\n if '=' in opt:\n n,v = opt[2:].split('=')\n macros.append((n,v))\n else:\n macros.append((opt[2:],None))\n else:\n extra_compile_args.append(opt)\n if macros: dict_append(info, define_macros = macros)\n if libraries: dict_append(info, libraries = libraries)\n if library_dirs: dict_append(info, library_dirs = library_dirs)\n if include_dirs: dict_append(info, include_dirs = include_dirs)\n if extra_link_args: dict_append(info, extra_link_args = extra_link_args)\n if extra_compile_args: dict_append(info, extra_compile_args = extra_compile_args)\n if info:\n self.set_info(**info)\n return\n\nclass wx_info(_pkg_config_info):\n section = 'wx'\n config_env_var = 'WX_CONFIG'\n default_config_exe = 'wx-config'\n append_config_exe = ''\n version_macro_name = 'WX_VERSION'\n release_macro_name = 'WX_RELEASE'\n version_flag = '--version'\n cflags_flag = '--cxxflags'\n\nclass gdk_pixbuf_xlib_2_info(_pkg_config_info):\n section = 'gdk_pixbuf_xlib_2'\n append_config_exe = 'gdk-pixbuf-xlib-2.0'\n version_macro_name = 'GDK_PIXBUF_XLIB_VERSION'\n\nclass gdk_pixbuf_2_info(_pkg_config_info):\n section = 'gdk_pixbuf_2'\n append_config_exe = 'gdk-pixbuf-2.0'\n version_macro_name = 'GDK_PIXBUF_VERSION'\n\nclass gdk_x11_2_info(_pkg_config_info):\n section = 'gdk_x11_2'\n append_config_exe = 'gdk-x11-2.0'\n version_macro_name = 'GDK_X11_VERSION'\n\nclass gdk_2_info(_pkg_config_info):\n section = 'gdk_2'\n append_config_exe = 'gdk-2.0'\n version_macro_name = 'GDK_VERSION'\n\nclass gdk_info(_pkg_config_info):\n section = 'gdk'\n append_config_exe = 'gdk'\n version_macro_name = 'GDK_VERSION'\n\nclass gtkp_x11_2_info(_pkg_config_info):\n section = 'gtkp_x11_2'\n append_config_exe = 'gtk+-x11-2.0'\n version_macro_name = 'GTK_X11_VERSION'\n\n\nclass gtkp_2_info(_pkg_config_info):\n section = 'gtkp_2'\n append_config_exe = 'gtk+-2.0'\n version_macro_name = 'GTK_VERSION'\n\nclass xft_info(_pkg_config_info):\n section = 'xft'\n append_config_exe = 'xft'\n version_macro_name = 'XFT_VERSION'\n\nclass freetype2_info(_pkg_config_info):\n section = 'freetype2'\n append_config_exe = 'freetype2'\n version_macro_name = 'FREETYPE2_VERSION'\n\n## def vstr2hex(version):\n## bits = []\n## n = [24,16,8,4,0]\n## r = 0\n## for s in version.split('.'):\n## r |= int(s) << n[0]\n## del n[0]\n## return r\n\n#--------------------------------------------------------------------\n\ndef combine_paths(*args,**kws):\n \"\"\" Return a list of existing paths composed by all combinations of\n items from arguments.\n \"\"\"\n r = []\n for a in args:\n if not a: continue\n if is_string(a):\n a = [a]\n r.append(a)\n args = r\n if not args: return []\n if len(args)==1:\n result = reduce(lambda a,b:a+b,map(glob,args[0]),[])\n elif len (args)==2:\n result = []\n for a0 in args[0]:\n for a1 in args[1]:\n result.extend(glob(os.path.join(a0,a1)))\n else:\n result = combine_paths(*(combine_paths(args[0],args[1])+args[2:]))\n verbosity = kws.get('verbosity',1)\n if verbosity>1 and result:\n print '(','paths:',','.join(result),')'\n return result\n\nlanguage_map = {'c':0,'c++':1,'f77':2,'f90':3}\ninv_language_map = {0:'c',1:'c++',2:'f77',3:'f90'}\ndef dict_append(d,**kws):\n languages = []\n for k,v in kws.items():\n if k=='language':\n languages.append(v)\n continue\n if d.has_key(k):\n if k in ['library_dirs','include_dirs','define_macros']:\n [d[k].append(vv) for vv in v if vv not in d[k]]\n else:\n d[k].extend(v)\n else:\n d[k] = v\n if languages:\n l = inv_language_map[max([language_map.get(l,0) for l in languages])]\n d['language'] = l\n return\n\ndef show_all():\n import system_info\n import pprint\n match_info = re.compile(r'.*?_info').match\n show_only = []\n for n in sys.argv[1:]:\n if n[-5:] != '_info':\n n = n + '_info'\n show_only.append(n)\n show_all = not show_only\n for n in filter(match_info,dir(system_info)):\n if n in ['system_info','get_info']: continue\n if not show_all:\n if n not in show_only: continue\n del show_only[show_only.index(n)]\n c = getattr(system_info,n)()\n c.verbosity = 2\n r = c.get_info()\n if show_only:\n print 'Info classes not defined:',','.join(show_only)\nif __name__ == \"__main__\":\n show_all()\n", + "methods": [ + { + "name": "get_info", + "long_name": "get_info( name , notfound_action = 0 )", + "filename": "system_info.py", + "nloc": 51, + "complexity": 1, + "token_count": 226, + "parameters": [ + "name", + "notfound_action" + ], + "start_line": 146, + "end_line": 202, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 57, + "top_nesting_level": 0 + }, + { + "name": "__init__", + "long_name": "__init__( self , default_lib_dirs = default_lib_dirs , default_include_dirs = default_include_dirs , verbosity = 1 , )", + "filename": "system_info.py", + "nloc": 26, + "complexity": 3, + "token_count": 207, + "parameters": [ + "self", + "default_lib_dirs", + "default_include_dirs", + "verbosity" + ], + "start_line": 277, + "end_line": 302, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 26, + "top_nesting_level": 1 + }, + { + "name": "calc_libraries_info", + "long_name": "calc_libraries_info( self )", + "filename": "system_info.py", + "nloc": 15, + "complexity": 5, + "token_count": 78, + "parameters": [ + "self" + ], + "start_line": 304, + "end_line": 318, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 15, + "top_nesting_level": 1 + }, + { + "name": "set_info", + "long_name": "set_info( self , ** info )", + "filename": "system_info.py", + "nloc": 5, + "complexity": 2, + "token_count": 37, + "parameters": [ + "self", + "info" + ], + "start_line": 320, + "end_line": 324, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 5, + "top_nesting_level": 1 + }, + { + "name": "has_info", + "long_name": "has_info( self )", + "filename": "system_info.py", + "nloc": 2, + "complexity": 1, + "token_count": 18, + "parameters": [ + "self" + ], + "start_line": 326, + "end_line": 327, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 1 + }, + { + "name": "get_info", + "long_name": "get_info( self , notfound_action = 0 )", + "filename": "system_info.py", + "nloc": 30, + "complexity": 15, + "token_count": 208, + "parameters": [ + "self", + "notfound_action" + ], + "start_line": 329, + "end_line": 364, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 36, + "top_nesting_level": 1 + }, + { + "name": "get_paths", + "long_name": "get_paths( self , section , key )", + "filename": "system_info.py", + "nloc": 47, + "complexity": 20, + "token_count": 399, + "parameters": [ + "self", + "section", + "key" + ], + "start_line": 366, + "end_line": 412, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 47, + "top_nesting_level": 1 + }, + { + "name": "get_lib_dirs", + "long_name": "get_lib_dirs( self , key = 'library_dirs' )", + "filename": "system_info.py", + "nloc": 2, + "complexity": 1, + "token_count": 20, + "parameters": [ + "self", + "key" + ], + "start_line": 414, + "end_line": 415, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 1 + }, + { + "name": "get_include_dirs", + "long_name": "get_include_dirs( self , key = 'include_dirs' )", + "filename": "system_info.py", + "nloc": 2, + "complexity": 1, + "token_count": 20, + "parameters": [ + "self", + "key" + ], + "start_line": 417, + "end_line": 418, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 1 + }, + { + "name": "get_src_dirs", + "long_name": "get_src_dirs( self , key = 'src_dirs' )", + "filename": "system_info.py", + "nloc": 2, + "complexity": 1, + "token_count": 20, + "parameters": [ + "self", + "key" + ], + "start_line": 420, + "end_line": 421, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 1 + }, + { + "name": "get_libs", + "long_name": "get_libs( self , key , default )", + "filename": "system_info.py", + "nloc": 10, + "complexity": 7, + "token_count": 74, + "parameters": [ + "self", + "key", + "default" + ], + "start_line": 423, + "end_line": 432, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 10, + "top_nesting_level": 1 + }, + { + "name": "get_libraries", + "long_name": "get_libraries( self , key = 'libraries' )", + "filename": "system_info.py", + "nloc": 2, + "complexity": 1, + "token_count": 18, + "parameters": [ + "self", + "key" + ], + "start_line": 434, + "end_line": 435, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 1 + }, + { + "name": "check_libs", + "long_name": "check_libs( self , lib_dir , libs , opt_libs = [ ] )", + "filename": "system_info.py", + "nloc": 11, + "complexity": 5, + "token_count": 79, + "parameters": [ + "self", + "lib_dir", + "libs", + "opt_libs" + ], + "start_line": 437, + "end_line": 449, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 13, + "top_nesting_level": 1 + }, + { + "name": "check_libs2", + "long_name": "check_libs2( self , lib_dir , libs , opt_libs = [ ] )", + "filename": "system_info.py", + "nloc": 10, + "complexity": 4, + "token_count": 72, + "parameters": [ + "self", + "lib_dir", + "libs", + "opt_libs" + ], + "start_line": 451, + "end_line": 462, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 12, + "top_nesting_level": 1 + }, + { + "name": "_lib_list", + "long_name": "_lib_list( self , lib_dir , libs , exts )", + "filename": "system_info.py", + "nloc": 11, + "complexity": 4, + "token_count": 66, + "parameters": [ + "self", + "lib_dir", + "libs", + "exts" + ], + "start_line": 464, + "end_line": 474, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 11, + "top_nesting_level": 1 + }, + { + "name": "_extract_lib_names", + "long_name": "_extract_lib_names( self , libs )", + "filename": "system_info.py", + "nloc": 3, + "complexity": 2, + "token_count": 37, + "parameters": [ + "self", + "libs" + ], + "start_line": 476, + "end_line": 478, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "_check_libs", + "long_name": "_check_libs( self , lib_dir , libs , opt_libs , exts )", + "filename": "system_info.py", + "nloc": 10, + "complexity": 3, + "token_count": 99, + "parameters": [ + "self", + "lib_dir", + "libs", + "opt_libs", + "exts" + ], + "start_line": 480, + "end_line": 489, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 10, + "top_nesting_level": 1 + }, + { + "name": "combine_paths", + "long_name": "combine_paths( self , * args )", + "filename": "system_info.py", + "nloc": 2, + "complexity": 1, + "token_count": 23, + "parameters": [ + "self", + "args" + ], + "start_line": 491, + "end_line": 492, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 1 + }, + { + "name": "calc_info", + "long_name": "calc_info( self )", + "filename": "system_info.py", + "nloc": 10, + "complexity": 5, + "token_count": 59, + "parameters": [ + "self" + ], + "start_line": 497, + "end_line": 506, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 10, + "top_nesting_level": 1 + }, + { + "name": "__init__", + "long_name": "__init__( self )", + "filename": "system_info.py", + "nloc": 2, + "complexity": 1, + "token_count": 11, + "parameters": [ + "self" + ], + "start_line": 523, + "end_line": 524, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 1 + }, + { + "name": "calc_ver_info", + "long_name": "calc_ver_info( self , ver_param )", + "filename": "system_info.py", + "nloc": 31, + "complexity": 9, + "token_count": 184, + "parameters": [ + "self", + "ver_param" + ], + "start_line": 526, + "end_line": 557, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 32, + "top_nesting_level": 1 + }, + { + "name": "calc_info", + "long_name": "calc_info( self )", + "filename": "system_info.py", + "nloc": 4, + "complexity": 3, + "token_count": 21, + "parameters": [ + "self" + ], + "start_line": 559, + "end_line": 562, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 1 + }, + { + "name": "get_paths", + "long_name": "get_paths( self , section , key )", + "filename": "system_info.py", + "nloc": 6, + "complexity": 4, + "token_count": 66, + "parameters": [ + "self", + "section", + "key" + ], + "start_line": 631, + "end_line": 636, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 6, + "top_nesting_level": 1 + }, + { + "name": "calc_info", + "long_name": "calc_info( self )", + "filename": "system_info.py", + "nloc": 22, + "complexity": 7, + "token_count": 144, + "parameters": [ + "self" + ], + "start_line": 638, + "end_line": 659, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 22, + "top_nesting_level": 1 + }, + { + "name": "get_mkl_rootdir", + "long_name": "get_mkl_rootdir( self )", + "filename": "system_info.py", + "nloc": 24, + "complexity": 11, + "token_count": 211, + "parameters": [ + "self" + ], + "start_line": 666, + "end_line": 689, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 24, + "top_nesting_level": 1 + }, + { + "name": "__init__", + "long_name": "__init__( self )", + "filename": "system_info.py", + "nloc": 20, + "complexity": 5, + "token_count": 119, + "parameters": [ + "self" + ], + "start_line": 691, + "end_line": 710, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 20, + "top_nesting_level": 1 + }, + { + "name": "calc_info", + "long_name": "calc_info( self )", + "filename": "system_info.py", + "nloc": 15, + "complexity": 4, + "token_count": 94, + "parameters": [ + "self" + ], + "start_line": 712, + "end_line": 726, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 15, + "top_nesting_level": 1 + }, + { + "name": "calc_info", + "long_name": "calc_info( self )", + "filename": "system_info.py", + "nloc": 8, + "complexity": 2, + "token_count": 49, + "parameters": [ + "self" + ], + "start_line": 730, + "end_line": 737, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 8, + "top_nesting_level": 1 + }, + { + "name": "get_paths", + "long_name": "get_paths( self , section , key )", + "filename": "system_info.py", + "nloc": 7, + "complexity": 4, + "token_count": 74, + "parameters": [ + "self", + "section", + "key" + ], + "start_line": 755, + "end_line": 761, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 7, + "top_nesting_level": 1 + }, + { + "name": "calc_info", + "long_name": "calc_info( self )", + "filename": "system_info.py", + "nloc": 78, + "complexity": 17, + "token_count": 441, + "parameters": [ + "self" + ], + "start_line": 763, + "end_line": 843, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 81, + "top_nesting_level": 1 + }, + { + "name": "calc_info", + "long_name": "calc_info( self )", + "filename": "system_info.py", + "nloc": 21, + "complexity": 6, + "token_count": 138, + "parameters": [ + "self" + ], + "start_line": 848, + "end_line": 870, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 23, + "top_nesting_level": 1 + }, + { + "name": "calc_info", + "long_name": "calc_info( self )", + "filename": "system_info.py", + "nloc": 12, + "complexity": 3, + "token_count": 68, + "parameters": [ + "self" + ], + "start_line": 893, + "end_line": 905, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 13, + "top_nesting_level": 1 + }, + { + "name": "get_paths", + "long_name": "get_paths( self , section , key )", + "filename": "system_info.py", + "nloc": 6, + "complexity": 4, + "token_count": 68, + "parameters": [ + "self", + "section", + "key" + ], + "start_line": 912, + "end_line": 917, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 6, + "top_nesting_level": 1 + }, + { + "name": "calc_info", + "long_name": "calc_info( self )", + "filename": "system_info.py", + "nloc": 81, + "complexity": 10, + "token_count": 232, + "parameters": [ + "self" + ], + "start_line": 919, + "end_line": 1003, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 85, + "top_nesting_level": 1 + }, + { + "name": "_get_build_temp", + "long_name": "_get_build_temp( )", + "filename": "system_info.py", + "nloc": 4, + "complexity": 1, + "token_count": 41, + "parameters": [], + "start_line": 1022, + "end_line": 1025, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 0 + }, + { + "name": "get_atlas_version.atlas_version_c", + "long_name": "get_atlas_version.atlas_version_c( extension , build_dir , magic = magic )", + "filename": "system_info.py", + "nloc": 10, + "complexity": 3, + "token_count": 74, + "parameters": [ + "extension", + "build_dir", + "magic" + ], + "start_line": 1033, + "end_line": 1042, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 10, + "top_nesting_level": 1 + }, + { + "name": "get_atlas_version", + "long_name": "get_atlas_version( ** config )", + "filename": "system_info.py", + "nloc": 51, + "complexity": 9, + "token_count": 314, + "parameters": [ + "config" + ], + "start_line": 1027, + "end_line": 1087, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 61, + "top_nesting_level": 0 + }, + { + "name": "calc_info", + "long_name": "calc_info( self )", + "filename": "system_info.py", + "nloc": 72, + "complexity": 20, + "token_count": 443, + "parameters": [ + "self" + ], + "start_line": 1092, + "end_line": 1172, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 81, + "top_nesting_level": 1 + }, + { + "name": "calc_info", + "long_name": "calc_info( self )", + "filename": "system_info.py", + "nloc": 57, + "complexity": 14, + "token_count": 331, + "parameters": [ + "self" + ], + "start_line": 1177, + "end_line": 1238, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 62, + "top_nesting_level": 1 + }, + { + "name": "calc_info", + "long_name": "calc_info( self )", + "filename": "system_info.py", + "nloc": 12, + "complexity": 3, + "token_count": 68, + "parameters": [ + "self" + ], + "start_line": 1247, + "end_line": 1259, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 13, + "top_nesting_level": 1 + }, + { + "name": "get_paths", + "long_name": "get_paths( self , section , key )", + "filename": "system_info.py", + "nloc": 6, + "complexity": 4, + "token_count": 66, + "parameters": [ + "self", + "section", + "key" + ], + "start_line": 1267, + "end_line": 1272, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 6, + "top_nesting_level": 1 + }, + { + "name": "calc_info", + "long_name": "calc_info( self )", + "filename": "system_info.py", + "nloc": 34, + "complexity": 5, + "token_count": 106, + "parameters": [ + "self" + ], + "start_line": 1274, + "end_line": 1309, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 36, + "top_nesting_level": 1 + }, + { + "name": "__init__", + "long_name": "__init__( self )", + "filename": "system_info.py", + "nloc": 4, + "complexity": 1, + "token_count": 19, + "parameters": [ + "self" + ], + "start_line": 1315, + "end_line": 1318, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 1 + }, + { + "name": "calc_info", + "long_name": "calc_info( self )", + "filename": "system_info.py", + "nloc": 20, + "complexity": 7, + "token_count": 114, + "parameters": [ + "self" + ], + "start_line": 1320, + "end_line": 1339, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 20, + "top_nesting_level": 1 + }, + { + "name": "__init__", + "long_name": "__init__( self )", + "filename": "system_info.py", + "nloc": 22, + "complexity": 6, + "token_count": 139, + "parameters": [ + "self" + ], + "start_line": 1346, + "end_line": 1367, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 22, + "top_nesting_level": 1 + }, + { + "name": "calc_info", + "long_name": "calc_info( self )", + "filename": "system_info.py", + "nloc": 29, + "complexity": 8, + "token_count": 161, + "parameters": [ + "self" + ], + "start_line": 1369, + "end_line": 1404, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 36, + "top_nesting_level": 1 + }, + { + "name": "calc_info", + "long_name": "calc_info( self )", + "filename": "system_info.py", + "nloc": 9, + "complexity": 2, + "token_count": 64, + "parameters": [ + "self" + ], + "start_line": 1419, + "end_line": 1427, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 9, + "top_nesting_level": 1 + }, + { + "name": "get_paths", + "long_name": "get_paths( self , section , key )", + "filename": "system_info.py", + "nloc": 6, + "complexity": 4, + "token_count": 66, + "parameters": [ + "self", + "section", + "key" + ], + "start_line": 1433, + "end_line": 1438, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 6, + "top_nesting_level": 1 + }, + { + "name": "calc_info", + "long_name": "calc_info( self )", + "filename": "system_info.py", + "nloc": 21, + "complexity": 5, + "token_count": 156, + "parameters": [ + "self" + ], + "start_line": 1440, + "end_line": 1460, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 21, + "top_nesting_level": 1 + }, + { + "name": "get_paths", + "long_name": "get_paths( self , section , key )", + "filename": "system_info.py", + "nloc": 6, + "complexity": 4, + "token_count": 66, + "parameters": [ + "self", + "section", + "key" + ], + "start_line": 1466, + "end_line": 1471, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 6, + "top_nesting_level": 1 + }, + { + "name": "calc_info", + "long_name": "calc_info( self )", + "filename": "system_info.py", + "nloc": 22, + "complexity": 6, + "token_count": 177, + "parameters": [ + "self" + ], + "start_line": 1473, + "end_line": 1495, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 23, + "top_nesting_level": 1 + }, + { + "name": "get_config_exe", + "long_name": "get_config_exe( self )", + "filename": "system_info.py", + "nloc": 4, + "complexity": 2, + "token_count": 30, + "parameters": [ + "self" + ], + "start_line": 1507, + "end_line": 1510, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 1 + }, + { + "name": "get_config_output", + "long_name": "get_config_output( self , config_exe , option )", + "filename": "system_info.py", + "nloc": 4, + "complexity": 2, + "token_count": 37, + "parameters": [ + "self", + "config_exe", + "option" + ], + "start_line": 1511, + "end_line": 1514, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 1 + }, + { + "name": "calc_info", + "long_name": "calc_info( self )", + "filename": "system_info.py", + "nloc": 54, + "complexity": 22, + "token_count": 435, + "parameters": [ + "self" + ], + "start_line": 1516, + "end_line": 1569, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 54, + "top_nesting_level": 1 + }, + { + "name": "combine_paths", + "long_name": "combine_paths( * args , ** kws )", + "filename": "system_info.py", + "nloc": 22, + "complexity": 11, + "token_count": 191, + "parameters": [ + "args", + "kws" + ], + "start_line": 1638, + "end_line": 1662, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 25, + "top_nesting_level": 0 + }, + { + "name": "dict_append", + "long_name": "dict_append( d , ** kws )", + "filename": "system_info.py", + "nloc": 17, + "complexity": 9, + "token_count": 128, + "parameters": [ + "d", + "kws" + ], + "start_line": 1666, + "end_line": 1682, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 17, + "top_nesting_level": 0 + }, + { + "name": "show_all", + "long_name": "show_all( )", + "filename": "system_info.py", + "nloc": 20, + "complexity": 8, + "token_count": 137, + "parameters": [], + "start_line": 1684, + "end_line": 1703, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 20, + "top_nesting_level": 0 + } + ], + "methods_before": [ + { + "name": "get_info", + "long_name": "get_info( name , notfound_action = 0 )", + "filename": "system_info.py", + "nloc": 51, + "complexity": 1, + "token_count": 226, + "parameters": [ + "name", + "notfound_action" + ], + "start_line": 146, + "end_line": 202, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 57, + "top_nesting_level": 0 + }, + { + "name": "__init__", + "long_name": "__init__( self , default_lib_dirs = default_lib_dirs , default_include_dirs = default_include_dirs , verbosity = 1 , )", + "filename": "system_info.py", + "nloc": 26, + "complexity": 3, + "token_count": 207, + "parameters": [ + "self", + "default_lib_dirs", + "default_include_dirs", + "verbosity" + ], + "start_line": 277, + "end_line": 302, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 26, + "top_nesting_level": 1 + }, + { + "name": "calc_libraries_info", + "long_name": "calc_libraries_info( self )", + "filename": "system_info.py", + "nloc": 15, + "complexity": 5, + "token_count": 78, + "parameters": [ + "self" + ], + "start_line": 304, + "end_line": 318, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 15, + "top_nesting_level": 1 + }, + { + "name": "set_info", + "long_name": "set_info( self , ** info )", + "filename": "system_info.py", + "nloc": 5, + "complexity": 2, + "token_count": 37, + "parameters": [ + "self", + "info" + ], + "start_line": 320, + "end_line": 324, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 5, + "top_nesting_level": 1 + }, + { + "name": "has_info", + "long_name": "has_info( self )", + "filename": "system_info.py", + "nloc": 2, + "complexity": 1, + "token_count": 18, + "parameters": [ + "self" + ], + "start_line": 326, + "end_line": 327, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 1 + }, + { + "name": "get_info", + "long_name": "get_info( self , notfound_action = 0 )", + "filename": "system_info.py", + "nloc": 30, + "complexity": 15, + "token_count": 208, + "parameters": [ + "self", + "notfound_action" + ], + "start_line": 329, + "end_line": 364, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 36, + "top_nesting_level": 1 + }, + { + "name": "get_paths", + "long_name": "get_paths( self , section , key )", + "filename": "system_info.py", + "nloc": 47, + "complexity": 20, + "token_count": 399, + "parameters": [ + "self", + "section", + "key" + ], + "start_line": 366, + "end_line": 412, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 47, + "top_nesting_level": 1 + }, + { + "name": "get_lib_dirs", + "long_name": "get_lib_dirs( self , key = 'library_dirs' )", + "filename": "system_info.py", + "nloc": 2, + "complexity": 1, + "token_count": 20, + "parameters": [ + "self", + "key" + ], + "start_line": 414, + "end_line": 415, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 1 + }, + { + "name": "get_include_dirs", + "long_name": "get_include_dirs( self , key = 'include_dirs' )", + "filename": "system_info.py", + "nloc": 2, + "complexity": 1, + "token_count": 20, + "parameters": [ + "self", + "key" + ], + "start_line": 417, + "end_line": 418, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 1 + }, + { + "name": "get_src_dirs", + "long_name": "get_src_dirs( self , key = 'src_dirs' )", + "filename": "system_info.py", + "nloc": 2, + "complexity": 1, + "token_count": 20, + "parameters": [ + "self", + "key" + ], + "start_line": 420, + "end_line": 421, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 1 + }, + { + "name": "get_libs", + "long_name": "get_libs( self , key , default )", + "filename": "system_info.py", + "nloc": 10, + "complexity": 7, + "token_count": 74, + "parameters": [ + "self", + "key", + "default" + ], + "start_line": 423, + "end_line": 432, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 10, + "top_nesting_level": 1 + }, + { + "name": "get_libraries", + "long_name": "get_libraries( self , key = 'libraries' )", + "filename": "system_info.py", + "nloc": 2, + "complexity": 1, + "token_count": 18, + "parameters": [ + "self", + "key" + ], + "start_line": 434, + "end_line": 435, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 1 + }, + { + "name": "check_libs", + "long_name": "check_libs( self , lib_dir , libs , opt_libs = [ ] )", + "filename": "system_info.py", + "nloc": 11, + "complexity": 5, + "token_count": 79, + "parameters": [ + "self", + "lib_dir", + "libs", + "opt_libs" + ], + "start_line": 437, + "end_line": 449, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 13, + "top_nesting_level": 1 + }, + { + "name": "check_libs2", + "long_name": "check_libs2( self , lib_dir , libs , opt_libs = [ ] )", + "filename": "system_info.py", + "nloc": 10, + "complexity": 4, + "token_count": 72, + "parameters": [ + "self", + "lib_dir", + "libs", + "opt_libs" + ], + "start_line": 451, + "end_line": 462, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 12, + "top_nesting_level": 1 + }, + { + "name": "_lib_list", + "long_name": "_lib_list( self , lib_dir , libs , exts )", + "filename": "system_info.py", + "nloc": 11, + "complexity": 4, + "token_count": 66, + "parameters": [ + "self", + "lib_dir", + "libs", + "exts" + ], + "start_line": 464, + "end_line": 474, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 11, + "top_nesting_level": 1 + }, + { + "name": "_extract_lib_names", + "long_name": "_extract_lib_names( self , libs )", + "filename": "system_info.py", + "nloc": 3, + "complexity": 2, + "token_count": 37, + "parameters": [ + "self", + "libs" + ], + "start_line": 476, + "end_line": 478, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "_check_libs", + "long_name": "_check_libs( self , lib_dir , libs , opt_libs , exts )", + "filename": "system_info.py", + "nloc": 10, + "complexity": 3, + "token_count": 99, + "parameters": [ + "self", + "lib_dir", + "libs", + "opt_libs", + "exts" + ], + "start_line": 480, + "end_line": 489, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 10, + "top_nesting_level": 1 + }, + { + "name": "combine_paths", + "long_name": "combine_paths( self , * args )", + "filename": "system_info.py", + "nloc": 2, + "complexity": 1, + "token_count": 23, + "parameters": [ + "self", + "args" + ], + "start_line": 491, + "end_line": 492, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 1 + }, + { + "name": "calc_info", + "long_name": "calc_info( self )", + "filename": "system_info.py", + "nloc": 10, + "complexity": 5, + "token_count": 59, + "parameters": [ + "self" + ], + "start_line": 497, + "end_line": 506, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 10, + "top_nesting_level": 1 + }, + { + "name": "__init__", + "long_name": "__init__( self )", + "filename": "system_info.py", + "nloc": 2, + "complexity": 1, + "token_count": 11, + "parameters": [ + "self" + ], + "start_line": 523, + "end_line": 524, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 1 + }, + { + "name": "calc_ver_info", + "long_name": "calc_ver_info( self , ver_param )", + "filename": "system_info.py", + "nloc": 31, + "complexity": 9, + "token_count": 184, + "parameters": [ + "self", + "ver_param" + ], + "start_line": 526, + "end_line": 557, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 32, + "top_nesting_level": 1 + }, + { + "name": "calc_info", + "long_name": "calc_info( self )", + "filename": "system_info.py", + "nloc": 4, + "complexity": 3, + "token_count": 21, + "parameters": [ + "self" + ], + "start_line": 559, + "end_line": 562, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 1 + }, + { + "name": "get_paths", + "long_name": "get_paths( self , section , key )", + "filename": "system_info.py", + "nloc": 6, + "complexity": 4, + "token_count": 66, + "parameters": [ + "self", + "section", + "key" + ], + "start_line": 631, + "end_line": 636, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 6, + "top_nesting_level": 1 + }, + { + "name": "calc_info", + "long_name": "calc_info( self )", + "filename": "system_info.py", + "nloc": 22, + "complexity": 7, + "token_count": 144, + "parameters": [ + "self" + ], + "start_line": 638, + "end_line": 659, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 22, + "top_nesting_level": 1 + }, + { + "name": "get_mkl_rootdir", + "long_name": "get_mkl_rootdir( self )", + "filename": "system_info.py", + "nloc": 24, + "complexity": 11, + "token_count": 211, + "parameters": [ + "self" + ], + "start_line": 666, + "end_line": 689, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 24, + "top_nesting_level": 1 + }, + { + "name": "__init__", + "long_name": "__init__( self )", + "filename": "system_info.py", + "nloc": 20, + "complexity": 5, + "token_count": 119, + "parameters": [ + "self" + ], + "start_line": 691, + "end_line": 710, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 20, + "top_nesting_level": 1 + }, + { + "name": "calc_info", + "long_name": "calc_info( self )", + "filename": "system_info.py", + "nloc": 15, + "complexity": 4, + "token_count": 94, + "parameters": [ + "self" + ], + "start_line": 712, + "end_line": 726, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 15, + "top_nesting_level": 1 + }, + { + "name": "calc_info", + "long_name": "calc_info( self )", + "filename": "system_info.py", + "nloc": 8, + "complexity": 2, + "token_count": 49, + "parameters": [ + "self" + ], + "start_line": 730, + "end_line": 737, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 8, + "top_nesting_level": 1 + }, + { + "name": "get_paths", + "long_name": "get_paths( self , section , key )", + "filename": "system_info.py", + "nloc": 7, + "complexity": 4, + "token_count": 74, + "parameters": [ + "self", + "section", + "key" + ], + "start_line": 755, + "end_line": 761, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 7, + "top_nesting_level": 1 + }, + { + "name": "calc_info", + "long_name": "calc_info( self )", + "filename": "system_info.py", + "nloc": 78, + "complexity": 17, + "token_count": 441, + "parameters": [ + "self" + ], + "start_line": 763, + "end_line": 843, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 81, + "top_nesting_level": 1 + }, + { + "name": "calc_info", + "long_name": "calc_info( self )", + "filename": "system_info.py", + "nloc": 21, + "complexity": 6, + "token_count": 138, + "parameters": [ + "self" + ], + "start_line": 848, + "end_line": 870, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 23, + "top_nesting_level": 1 + }, + { + "name": "calc_info", + "long_name": "calc_info( self )", + "filename": "system_info.py", + "nloc": 12, + "complexity": 3, + "token_count": 68, + "parameters": [ + "self" + ], + "start_line": 893, + "end_line": 905, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 13, + "top_nesting_level": 1 + }, + { + "name": "get_paths", + "long_name": "get_paths( self , section , key )", + "filename": "system_info.py", + "nloc": 6, + "complexity": 4, + "token_count": 68, + "parameters": [ + "self", + "section", + "key" + ], + "start_line": 912, + "end_line": 917, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 6, + "top_nesting_level": 1 + }, + { + "name": "calc_info", + "long_name": "calc_info( self )", + "filename": "system_info.py", + "nloc": 81, + "complexity": 10, + "token_count": 232, + "parameters": [ + "self" + ], + "start_line": 919, + "end_line": 1003, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 85, + "top_nesting_level": 1 + }, + { + "name": "_get_build_temp", + "long_name": "_get_build_temp( )", + "filename": "system_info.py", + "nloc": 4, + "complexity": 1, + "token_count": 41, + "parameters": [], + "start_line": 1022, + "end_line": 1025, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 0 + }, + { + "name": "get_atlas_version.atlas_version_c", + "long_name": "get_atlas_version.atlas_version_c( extension , build_dir , magic = magic )", + "filename": "system_info.py", + "nloc": 10, + "complexity": 3, + "token_count": 74, + "parameters": [ + "extension", + "build_dir", + "magic" + ], + "start_line": 1033, + "end_line": 1042, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 10, + "top_nesting_level": 1 + }, + { + "name": "get_atlas_version", + "long_name": "get_atlas_version( ** config )", + "filename": "system_info.py", + "nloc": 51, + "complexity": 9, + "token_count": 314, + "parameters": [ + "config" + ], + "start_line": 1027, + "end_line": 1087, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 61, + "top_nesting_level": 0 + }, + { + "name": "calc_info", + "long_name": "calc_info( self )", + "filename": "system_info.py", + "nloc": 72, + "complexity": 20, + "token_count": 443, + "parameters": [ + "self" + ], + "start_line": 1092, + "end_line": 1172, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 81, + "top_nesting_level": 1 + }, + { + "name": "calc_info", + "long_name": "calc_info( self )", + "filename": "system_info.py", + "nloc": 57, + "complexity": 14, + "token_count": 331, + "parameters": [ + "self" + ], + "start_line": 1177, + "end_line": 1238, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 62, + "top_nesting_level": 1 + }, + { + "name": "calc_info", + "long_name": "calc_info( self )", + "filename": "system_info.py", + "nloc": 12, + "complexity": 3, + "token_count": 68, + "parameters": [ + "self" + ], + "start_line": 1247, + "end_line": 1259, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 13, + "top_nesting_level": 1 + }, + { + "name": "get_paths", + "long_name": "get_paths( self , section , key )", + "filename": "system_info.py", + "nloc": 6, + "complexity": 4, + "token_count": 66, + "parameters": [ + "self", + "section", + "key" + ], + "start_line": 1267, + "end_line": 1272, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 6, + "top_nesting_level": 1 + }, + { + "name": "calc_info", + "long_name": "calc_info( self )", + "filename": "system_info.py", + "nloc": 34, + "complexity": 5, + "token_count": 106, + "parameters": [ + "self" + ], + "start_line": 1274, + "end_line": 1309, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 36, + "top_nesting_level": 1 + }, + { + "name": "__init__", + "long_name": "__init__( self )", + "filename": "system_info.py", + "nloc": 4, + "complexity": 1, + "token_count": 19, + "parameters": [ + "self" + ], + "start_line": 1315, + "end_line": 1318, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 1 + }, + { + "name": "calc_info", + "long_name": "calc_info( self )", + "filename": "system_info.py", + "nloc": 20, + "complexity": 7, + "token_count": 114, + "parameters": [ + "self" + ], + "start_line": 1320, + "end_line": 1339, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 20, + "top_nesting_level": 1 + }, + { + "name": "__init__", + "long_name": "__init__( self )", + "filename": "system_info.py", + "nloc": 22, + "complexity": 6, + "token_count": 139, + "parameters": [ + "self" + ], + "start_line": 1346, + "end_line": 1367, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 22, + "top_nesting_level": 1 + }, + { + "name": "calc_info", + "long_name": "calc_info( self )", + "filename": "system_info.py", + "nloc": 29, + "complexity": 8, + "token_count": 161, + "parameters": [ + "self" + ], + "start_line": 1369, + "end_line": 1404, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 36, + "top_nesting_level": 1 + }, + { + "name": "calc_info", + "long_name": "calc_info( self )", + "filename": "system_info.py", + "nloc": 9, + "complexity": 2, + "token_count": 64, + "parameters": [ + "self" + ], + "start_line": 1419, + "end_line": 1427, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 9, + "top_nesting_level": 1 + }, + { + "name": "get_paths", + "long_name": "get_paths( self , section , key )", + "filename": "system_info.py", + "nloc": 6, + "complexity": 4, + "token_count": 66, + "parameters": [ + "self", + "section", + "key" + ], + "start_line": 1433, + "end_line": 1438, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 6, + "top_nesting_level": 1 + }, + { + "name": "calc_info", + "long_name": "calc_info( self )", + "filename": "system_info.py", + "nloc": 21, + "complexity": 5, + "token_count": 156, + "parameters": [ + "self" + ], + "start_line": 1440, + "end_line": 1460, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 21, + "top_nesting_level": 1 + }, + { + "name": "get_paths", + "long_name": "get_paths( self , section , key )", + "filename": "system_info.py", + "nloc": 6, + "complexity": 4, + "token_count": 66, + "parameters": [ + "self", + "section", + "key" + ], + "start_line": 1466, + "end_line": 1471, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 6, + "top_nesting_level": 1 + }, + { + "name": "calc_info", + "long_name": "calc_info( self )", + "filename": "system_info.py", + "nloc": 22, + "complexity": 6, + "token_count": 177, + "parameters": [ + "self" + ], + "start_line": 1473, + "end_line": 1495, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 23, + "top_nesting_level": 1 + }, + { + "name": "get_config_exe", + "long_name": "get_config_exe( self )", + "filename": "system_info.py", + "nloc": 4, + "complexity": 2, + "token_count": 30, + "parameters": [ + "self" + ], + "start_line": 1507, + "end_line": 1510, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 1 + }, + { + "name": "get_config_output", + "long_name": "get_config_output( self , config_exe , option )", + "filename": "system_info.py", + "nloc": 4, + "complexity": 2, + "token_count": 37, + "parameters": [ + "self", + "config_exe", + "option" + ], + "start_line": 1511, + "end_line": 1514, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 1 + }, + { + "name": "calc_info", + "long_name": "calc_info( self )", + "filename": "system_info.py", + "nloc": 54, + "complexity": 22, + "token_count": 435, + "parameters": [ + "self" + ], + "start_line": 1516, + "end_line": 1569, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 54, + "top_nesting_level": 1 + }, + { + "name": "combine_paths", + "long_name": "combine_paths( * args , ** kws )", + "filename": "system_info.py", + "nloc": 22, + "complexity": 11, + "token_count": 191, + "parameters": [ + "args", + "kws" + ], + "start_line": 1638, + "end_line": 1662, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 25, + "top_nesting_level": 0 + }, + { + "name": "dict_append", + "long_name": "dict_append( d , ** kws )", + "filename": "system_info.py", + "nloc": 17, + "complexity": 9, + "token_count": 128, + "parameters": [ + "d", + "kws" + ], + "start_line": 1666, + "end_line": 1682, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 17, + "top_nesting_level": 0 + }, + { + "name": "show_all", + "long_name": "show_all( )", + "filename": "system_info.py", + "nloc": 20, + "complexity": 8, + "token_count": 137, + "parameters": [], + "start_line": 1684, + "end_line": 1703, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 20, + "top_nesting_level": 0 + } + ], + "changed_methods": [], + "nloc": 1506, + "complexity": 328, + "token_count": 8481, + "diff_parsed": { + "added": [ + " os.path.join(distutils.sysconfig.EXEC_PREFIX, 'libs')]" + ], + "deleted": [ + " join(distutils.sysconfig.EXEC_PREFIX, 'libs')]" + ] + } + } + ] + }, + { + "hash": "f5209cbd46b7d6ad0a0960630189670adb2b3ccb", + "msg": "Back out mistaken commit", + "author": { + "name": "Robert Kern", + "email": "robert.kern@gmail.com" + }, + "committer": { + "name": "Robert Kern", + "email": "robert.kern@gmail.com" + }, + "author_date": "2006-02-09T19:06:53+00:00", + "author_timezone": 0, + "committer_date": "2006-02-09T19:06:53+00:00", + "committer_timezone": 0, + "branches": [ + "main" + ], + "in_main_branch": true, + "merge": false, + "parents": [ + "ddf6e61b8c92311ec3215252aa117fd7fdaaf8ef" + ], + "project_name": "repo_copy", + "project_path": "/tmp/tmpdjwupkfu/repo_copy", + "deletions": 4, + "insertions": 3, + "lines": 7, + "files": 3, + "dmm_unit_size": 1.0, + "dmm_unit_complexity": 1.0, + "dmm_unit_interfacing": 0.0, + "modified_files": [ + { + "old_path": "numpy/distutils/command/build_ext.py", + "new_path": "numpy/distutils/command/build_ext.py", + "filename": "build_ext.py", + "extension": "py", + "change_type": "MODIFY", + "diff": "@@ -99,7 +99,6 @@ def run(self):\n self.fcompiler.customize_cmd(self)\n self.fcompiler.show_customization()\n else:\n- print self.fcompiler.get_version()\n self.warn('fcompiler=%s is not available.' % (self.fcompiler.compiler_type))\n self.fcompiler = None\n \n", + "added_lines": 0, + "deleted_lines": 1, + "source_code": "\"\"\" Modified version of build_ext that handles fortran source files.\n\"\"\"\n\nimport os\nimport string\nimport sys\nfrom glob import glob\n\nfrom distutils.dep_util import newer_group\nfrom distutils.command.build_ext import build_ext as old_build_ext\n\nfrom numpy.distutils import log\nfrom numpy.distutils.misc_util import filter_sources, has_f_sources, \\\n has_cxx_sources, get_ext_source_files, all_strings, \\\n get_numpy_include_dirs, is_sequence\nfrom distutils.errors import DistutilsFileError, DistutilsSetupError\n\nclass build_ext (old_build_ext):\n\n description = \"build C/C++/F extensions (compile/link to build directory)\"\n\n user_options = old_build_ext.user_options + [\n ('fcompiler=', None,\n \"specify the Fortran compiler type\"),\n ]\n\n def initialize_options(self):\n old_build_ext.initialize_options(self)\n self.fcompiler = None\n return\n\n def finalize_options(self):\n old_build_ext.finalize_options(self)\n self.set_undefined_options('config_fc',\n ('fcompiler', 'fcompiler'))\n return\n\n def run(self):\n if not self.extensions:\n return\n\n # Make sure that extension sources are complete.\n for ext in self.extensions:\n if not all_strings(ext.sources):\n self.run_command('build_src')\n\n if self.distribution.has_c_libraries():\n build_clib = self.get_finalized_command('build_clib')\n self.library_dirs.append(build_clib.build_clib)\n else:\n build_clib = None\n\n # Not including C libraries to the list of\n # extension libraries automatically to prevent\n # bogus linking commands. Extensions must\n # explicitly specify the C libraries that they use.\n\n # Determine if Fortran compiler is needed.\n if build_clib and build_clib.fcompiler is not None:\n need_f_compiler = 1\n else:\n need_f_compiler = 0\n for ext in self.extensions:\n if has_f_sources(ext.sources):\n need_f_compiler = 1\n break\n if getattr(ext,'language','c') in ['f77','f90']:\n need_f_compiler = 1\n break\n\n # Determine if C++ compiler is needed.\n need_cxx_compiler = 0\n for ext in self.extensions:\n if has_cxx_sources(ext.sources):\n need_cxx_compiler = 1\n break\n if getattr(ext,'language','c')=='c++':\n need_cxx_compiler = 1\n break\n\n from distutils.ccompiler import new_compiler\n self.compiler = new_compiler(compiler=self.compiler,\n verbose=self.verbose,\n dry_run=self.dry_run,\n force=self.force)\n self.compiler.customize(self.distribution,need_cxx=need_cxx_compiler)\n self.compiler.customize_cmd(self)\n self.compiler.show_customization()\n\n # Initialize Fortran/C++ compilers if needed.\n if need_f_compiler:\n from numpy.distutils.fcompiler import new_fcompiler\n self.fcompiler = new_fcompiler(compiler=self.fcompiler,\n verbose=self.verbose,\n dry_run=self.dry_run,\n force=self.force)\n if self.fcompiler.get_version():\n self.fcompiler.customize(self.distribution)\n self.fcompiler.customize_cmd(self)\n self.fcompiler.show_customization()\n else:\n self.warn('fcompiler=%s is not available.' % (self.fcompiler.compiler_type))\n self.fcompiler = None\n\n # Build extensions\n self.build_extensions()\n return\n\n def swig_sources(self, sources):\n # Do nothing. Swig sources have beed handled in build_src command.\n return sources\n\n def build_extension(self, ext):\n sources = ext.sources\n if sources is None or not is_sequence(sources):\n raise DistutilsSetupError, \\\n (\"in 'ext_modules' option (extension '%s'), \" +\n \"'sources' must be present and must be \" +\n \"a list of source filenames\") % ext.name\n sources = list(sources)\n\n if not sources:\n return\n\n fullname = self.get_ext_fullname(ext.name)\n if self.inplace:\n modpath = string.split(fullname, '.')\n package = string.join(modpath[0:-1], '.')\n base = modpath[-1]\n\n build_py = self.get_finalized_command('build_py')\n package_dir = build_py.get_package_dir(package)\n ext_filename = os.path.join(package_dir,\n self.get_ext_filename(base))\n else:\n ext_filename = os.path.join(self.build_lib,\n self.get_ext_filename(fullname))\n depends = sources + ext.depends\n\n if not (self.force or newer_group(depends, ext_filename, 'newer')):\n log.debug(\"skipping '%s' extension (up-to-date)\", ext.name)\n return\n else:\n log.info(\"building '%s' extension\", ext.name)\n\n extra_args = ext.extra_compile_args or []\n macros = ext.define_macros[:]\n for undef in ext.undef_macros:\n macros.append((undef,))\n\n clib_libraries = []\n clib_library_dirs = []\n if self.distribution.libraries:\n for libname,build_info in self.distribution.libraries:\n if libname in ext.libraries:\n macros.extend(build_info.get('macros',[]))\n clib_libraries.extend(build_info.get('libraries',[]))\n clib_library_dirs.extend(build_info.get('library_dirs',[]))\n\n c_sources, cxx_sources, f_sources, fmodule_sources = \\\n filter_sources(ext.sources)\n if self.compiler.compiler_type=='msvc':\n if cxx_sources:\n # Needed to compile kiva.agg._agg extension.\n extra_args.append('/Zm1000')\n # this hack works around the msvc compiler attributes\n # problem, msvc uses its own convention :(\n c_sources += cxx_sources\n cxx_sources = []\n\n\n kws = {'depends':ext.depends}\n output_dir = self.build_temp\n\n include_dirs = ext.include_dirs + get_numpy_include_dirs()\n\n c_objects = []\n if c_sources:\n log.info(\"compiling C sources\")\n c_objects = self.compiler.compile(c_sources,\n output_dir=output_dir,\n macros=macros,\n include_dirs=include_dirs,\n debug=self.debug,\n extra_postargs=extra_args,\n **kws)\n if cxx_sources:\n log.info(\"compiling C++ sources\")\n\n old_compiler = self.compiler.compiler_so[0]\n self.compiler.compiler_so[0] = self.compiler.compiler_cxx[0]\n\n c_objects += self.compiler.compile(cxx_sources,\n output_dir=output_dir,\n macros=macros,\n include_dirs=include_dirs,\n debug=self.debug,\n extra_postargs=extra_args,\n **kws)\n self.compiler.compiler_so[0] = old_compiler\n\n check_for_f90_modules = not not fmodule_sources\n\n if f_sources or fmodule_sources:\n extra_postargs = []\n module_dirs = ext.module_dirs[:]\n\n #if self.fcompiler.compiler_type=='ibm':\n macros = []\n\n if check_for_f90_modules:\n module_build_dir = os.path.join(\\\n self.build_temp,os.path.dirname(\\\n self.get_ext_filename(fullname)))\n\n self.mkpath(module_build_dir)\n if self.fcompiler.module_dir_switch is None:\n existing_modules = glob('*.mod')\n extra_postargs += self.fcompiler.module_options(\\\n module_dirs,module_build_dir)\n\n f_objects = []\n if fmodule_sources:\n log.info(\"compiling Fortran 90 module sources\")\n f_objects = self.fcompiler.compile(fmodule_sources,\n output_dir=self.build_temp,\n macros=macros,\n include_dirs=include_dirs,\n debug=self.debug,\n extra_postargs=extra_postargs,\n depends=ext.depends)\n\n if check_for_f90_modules \\\n and self.fcompiler.module_dir_switch is None:\n for f in glob('*.mod'):\n if f in existing_modules:\n continue\n try:\n self.move_file(f, module_build_dir)\n except DistutilsFileError: # already exists in destination\n os.remove(f)\n\n if f_sources:\n log.info(\"compiling Fortran sources\")\n f_objects += self.fcompiler.compile(f_sources,\n output_dir=self.build_temp,\n macros=macros,\n include_dirs=include_dirs,\n debug=self.debug,\n extra_postargs=extra_postargs,\n depends=ext.depends)\n else:\n f_objects = []\n\n objects = c_objects + f_objects\n\n if ext.extra_objects:\n objects.extend(ext.extra_objects)\n extra_args = ext.extra_link_args or []\n\n try:\n old_linker_so_0 = self.compiler.linker_so[0]\n except:\n pass\n\n use_fortran_linker = getattr(ext,'language','c') in ['f77','f90'] \\\n and self.fcompiler is not None\n c_libraries = []\n c_library_dirs = []\n if use_fortran_linker or f_sources:\n use_fortran_linker = 1\n elif self.distribution.has_c_libraries():\n build_clib = self.get_finalized_command('build_clib')\n f_libs = []\n for (lib_name, build_info) in build_clib.libraries:\n if has_f_sources(build_info.get('sources',[])):\n f_libs.append(lib_name)\n if lib_name in ext.libraries:\n # XXX: how to determine if c_libraries contain\n # fortran compiled sources?\n c_libraries.extend(build_info.get('libraries',[]))\n c_library_dirs.extend(build_info.get('library_dirs',[]))\n for l in ext.libraries:\n if l in f_libs:\n use_fortran_linker = 1\n break\n\n # Always use system linker when using MSVC compiler.\n if self.compiler.compiler_type=='msvc' and use_fortran_linker:\n c_libraries.extend(self.fcompiler.libraries)\n c_library_dirs.extend(self.fcompiler.library_dirs)\n use_fortran_linker = 0\n\n if use_fortran_linker:\n if cxx_sources:\n # XXX: Which linker should be used, Fortran or C++?\n log.warn('mixing Fortran and C++ is untested')\n link = self.fcompiler.link_shared_object\n language = ext.language or self.fcompiler.detect_language(f_sources)\n else:\n link = self.compiler.link_shared_object\n if sys.version[:3]>='2.3':\n language = ext.language or self.compiler.detect_language(sources)\n else:\n language = ext.language\n if cxx_sources:\n self.compiler.linker_so[0] = self.compiler.compiler_cxx[0]\n\n if sys.version[:3]>='2.3':\n kws = {'target_lang':language}\n else:\n kws = {}\n\n link(objects, ext_filename,\n libraries=self.get_libraries(ext) + c_libraries + clib_libraries,\n library_dirs=ext.library_dirs + c_library_dirs + clib_library_dirs,\n runtime_library_dirs=ext.runtime_library_dirs,\n extra_postargs=extra_args,\n export_symbols=self.get_export_symbols(ext),\n debug=self.debug,\n build_temp=self.build_temp,**kws)\n\n try:\n self.compiler.linker_so[0] = old_linker_so_0\n except:\n pass\n\n return\n\n def get_source_files (self):\n self.check_extensions_list(self.extensions)\n filenames = []\n for ext in self.extensions:\n filenames.extend(get_ext_source_files(ext))\n return filenames\n\n def get_outputs (self):\n self.check_extensions_list(self.extensions)\n\n outputs = []\n for ext in self.extensions:\n if not ext.sources:\n continue\n fullname = self.get_ext_fullname(ext.name)\n outputs.append(os.path.join(self.build_lib,\n self.get_ext_filename(fullname)))\n return outputs\n", + "source_code_before": "\"\"\" Modified version of build_ext that handles fortran source files.\n\"\"\"\n\nimport os\nimport string\nimport sys\nfrom glob import glob\n\nfrom distutils.dep_util import newer_group\nfrom distutils.command.build_ext import build_ext as old_build_ext\n\nfrom numpy.distutils import log\nfrom numpy.distutils.misc_util import filter_sources, has_f_sources, \\\n has_cxx_sources, get_ext_source_files, all_strings, \\\n get_numpy_include_dirs, is_sequence\nfrom distutils.errors import DistutilsFileError, DistutilsSetupError\n\nclass build_ext (old_build_ext):\n\n description = \"build C/C++/F extensions (compile/link to build directory)\"\n\n user_options = old_build_ext.user_options + [\n ('fcompiler=', None,\n \"specify the Fortran compiler type\"),\n ]\n\n def initialize_options(self):\n old_build_ext.initialize_options(self)\n self.fcompiler = None\n return\n\n def finalize_options(self):\n old_build_ext.finalize_options(self)\n self.set_undefined_options('config_fc',\n ('fcompiler', 'fcompiler'))\n return\n\n def run(self):\n if not self.extensions:\n return\n\n # Make sure that extension sources are complete.\n for ext in self.extensions:\n if not all_strings(ext.sources):\n self.run_command('build_src')\n\n if self.distribution.has_c_libraries():\n build_clib = self.get_finalized_command('build_clib')\n self.library_dirs.append(build_clib.build_clib)\n else:\n build_clib = None\n\n # Not including C libraries to the list of\n # extension libraries automatically to prevent\n # bogus linking commands. Extensions must\n # explicitly specify the C libraries that they use.\n\n # Determine if Fortran compiler is needed.\n if build_clib and build_clib.fcompiler is not None:\n need_f_compiler = 1\n else:\n need_f_compiler = 0\n for ext in self.extensions:\n if has_f_sources(ext.sources):\n need_f_compiler = 1\n break\n if getattr(ext,'language','c') in ['f77','f90']:\n need_f_compiler = 1\n break\n\n # Determine if C++ compiler is needed.\n need_cxx_compiler = 0\n for ext in self.extensions:\n if has_cxx_sources(ext.sources):\n need_cxx_compiler = 1\n break\n if getattr(ext,'language','c')=='c++':\n need_cxx_compiler = 1\n break\n\n from distutils.ccompiler import new_compiler\n self.compiler = new_compiler(compiler=self.compiler,\n verbose=self.verbose,\n dry_run=self.dry_run,\n force=self.force)\n self.compiler.customize(self.distribution,need_cxx=need_cxx_compiler)\n self.compiler.customize_cmd(self)\n self.compiler.show_customization()\n\n # Initialize Fortran/C++ compilers if needed.\n if need_f_compiler:\n from numpy.distutils.fcompiler import new_fcompiler\n self.fcompiler = new_fcompiler(compiler=self.fcompiler,\n verbose=self.verbose,\n dry_run=self.dry_run,\n force=self.force)\n if self.fcompiler.get_version():\n self.fcompiler.customize(self.distribution)\n self.fcompiler.customize_cmd(self)\n self.fcompiler.show_customization()\n else:\n print self.fcompiler.get_version()\n self.warn('fcompiler=%s is not available.' % (self.fcompiler.compiler_type))\n self.fcompiler = None\n\n # Build extensions\n self.build_extensions()\n return\n\n def swig_sources(self, sources):\n # Do nothing. Swig sources have beed handled in build_src command.\n return sources\n\n def build_extension(self, ext):\n sources = ext.sources\n if sources is None or not is_sequence(sources):\n raise DistutilsSetupError, \\\n (\"in 'ext_modules' option (extension '%s'), \" +\n \"'sources' must be present and must be \" +\n \"a list of source filenames\") % ext.name\n sources = list(sources)\n\n if not sources:\n return\n\n fullname = self.get_ext_fullname(ext.name)\n if self.inplace:\n modpath = string.split(fullname, '.')\n package = string.join(modpath[0:-1], '.')\n base = modpath[-1]\n\n build_py = self.get_finalized_command('build_py')\n package_dir = build_py.get_package_dir(package)\n ext_filename = os.path.join(package_dir,\n self.get_ext_filename(base))\n else:\n ext_filename = os.path.join(self.build_lib,\n self.get_ext_filename(fullname))\n depends = sources + ext.depends\n\n if not (self.force or newer_group(depends, ext_filename, 'newer')):\n log.debug(\"skipping '%s' extension (up-to-date)\", ext.name)\n return\n else:\n log.info(\"building '%s' extension\", ext.name)\n\n extra_args = ext.extra_compile_args or []\n macros = ext.define_macros[:]\n for undef in ext.undef_macros:\n macros.append((undef,))\n\n clib_libraries = []\n clib_library_dirs = []\n if self.distribution.libraries:\n for libname,build_info in self.distribution.libraries:\n if libname in ext.libraries:\n macros.extend(build_info.get('macros',[]))\n clib_libraries.extend(build_info.get('libraries',[]))\n clib_library_dirs.extend(build_info.get('library_dirs',[]))\n\n c_sources, cxx_sources, f_sources, fmodule_sources = \\\n filter_sources(ext.sources)\n if self.compiler.compiler_type=='msvc':\n if cxx_sources:\n # Needed to compile kiva.agg._agg extension.\n extra_args.append('/Zm1000')\n # this hack works around the msvc compiler attributes\n # problem, msvc uses its own convention :(\n c_sources += cxx_sources\n cxx_sources = []\n\n\n kws = {'depends':ext.depends}\n output_dir = self.build_temp\n\n include_dirs = ext.include_dirs + get_numpy_include_dirs()\n\n c_objects = []\n if c_sources:\n log.info(\"compiling C sources\")\n c_objects = self.compiler.compile(c_sources,\n output_dir=output_dir,\n macros=macros,\n include_dirs=include_dirs,\n debug=self.debug,\n extra_postargs=extra_args,\n **kws)\n if cxx_sources:\n log.info(\"compiling C++ sources\")\n\n old_compiler = self.compiler.compiler_so[0]\n self.compiler.compiler_so[0] = self.compiler.compiler_cxx[0]\n\n c_objects += self.compiler.compile(cxx_sources,\n output_dir=output_dir,\n macros=macros,\n include_dirs=include_dirs,\n debug=self.debug,\n extra_postargs=extra_args,\n **kws)\n self.compiler.compiler_so[0] = old_compiler\n\n check_for_f90_modules = not not fmodule_sources\n\n if f_sources or fmodule_sources:\n extra_postargs = []\n module_dirs = ext.module_dirs[:]\n\n #if self.fcompiler.compiler_type=='ibm':\n macros = []\n\n if check_for_f90_modules:\n module_build_dir = os.path.join(\\\n self.build_temp,os.path.dirname(\\\n self.get_ext_filename(fullname)))\n\n self.mkpath(module_build_dir)\n if self.fcompiler.module_dir_switch is None:\n existing_modules = glob('*.mod')\n extra_postargs += self.fcompiler.module_options(\\\n module_dirs,module_build_dir)\n\n f_objects = []\n if fmodule_sources:\n log.info(\"compiling Fortran 90 module sources\")\n f_objects = self.fcompiler.compile(fmodule_sources,\n output_dir=self.build_temp,\n macros=macros,\n include_dirs=include_dirs,\n debug=self.debug,\n extra_postargs=extra_postargs,\n depends=ext.depends)\n\n if check_for_f90_modules \\\n and self.fcompiler.module_dir_switch is None:\n for f in glob('*.mod'):\n if f in existing_modules:\n continue\n try:\n self.move_file(f, module_build_dir)\n except DistutilsFileError: # already exists in destination\n os.remove(f)\n\n if f_sources:\n log.info(\"compiling Fortran sources\")\n f_objects += self.fcompiler.compile(f_sources,\n output_dir=self.build_temp,\n macros=macros,\n include_dirs=include_dirs,\n debug=self.debug,\n extra_postargs=extra_postargs,\n depends=ext.depends)\n else:\n f_objects = []\n\n objects = c_objects + f_objects\n\n if ext.extra_objects:\n objects.extend(ext.extra_objects)\n extra_args = ext.extra_link_args or []\n\n try:\n old_linker_so_0 = self.compiler.linker_so[0]\n except:\n pass\n\n use_fortran_linker = getattr(ext,'language','c') in ['f77','f90'] \\\n and self.fcompiler is not None\n c_libraries = []\n c_library_dirs = []\n if use_fortran_linker or f_sources:\n use_fortran_linker = 1\n elif self.distribution.has_c_libraries():\n build_clib = self.get_finalized_command('build_clib')\n f_libs = []\n for (lib_name, build_info) in build_clib.libraries:\n if has_f_sources(build_info.get('sources',[])):\n f_libs.append(lib_name)\n if lib_name in ext.libraries:\n # XXX: how to determine if c_libraries contain\n # fortran compiled sources?\n c_libraries.extend(build_info.get('libraries',[]))\n c_library_dirs.extend(build_info.get('library_dirs',[]))\n for l in ext.libraries:\n if l in f_libs:\n use_fortran_linker = 1\n break\n\n # Always use system linker when using MSVC compiler.\n if self.compiler.compiler_type=='msvc' and use_fortran_linker:\n c_libraries.extend(self.fcompiler.libraries)\n c_library_dirs.extend(self.fcompiler.library_dirs)\n use_fortran_linker = 0\n\n if use_fortran_linker:\n if cxx_sources:\n # XXX: Which linker should be used, Fortran or C++?\n log.warn('mixing Fortran and C++ is untested')\n link = self.fcompiler.link_shared_object\n language = ext.language or self.fcompiler.detect_language(f_sources)\n else:\n link = self.compiler.link_shared_object\n if sys.version[:3]>='2.3':\n language = ext.language or self.compiler.detect_language(sources)\n else:\n language = ext.language\n if cxx_sources:\n self.compiler.linker_so[0] = self.compiler.compiler_cxx[0]\n\n if sys.version[:3]>='2.3':\n kws = {'target_lang':language}\n else:\n kws = {}\n\n link(objects, ext_filename,\n libraries=self.get_libraries(ext) + c_libraries + clib_libraries,\n library_dirs=ext.library_dirs + c_library_dirs + clib_library_dirs,\n runtime_library_dirs=ext.runtime_library_dirs,\n extra_postargs=extra_args,\n export_symbols=self.get_export_symbols(ext),\n debug=self.debug,\n build_temp=self.build_temp,**kws)\n\n try:\n self.compiler.linker_so[0] = old_linker_so_0\n except:\n pass\n\n return\n\n def get_source_files (self):\n self.check_extensions_list(self.extensions)\n filenames = []\n for ext in self.extensions:\n filenames.extend(get_ext_source_files(ext))\n return filenames\n\n def get_outputs (self):\n self.check_extensions_list(self.extensions)\n\n outputs = []\n for ext in self.extensions:\n if not ext.sources:\n continue\n fullname = self.get_ext_fullname(ext.name)\n outputs.append(os.path.join(self.build_lib,\n self.get_ext_filename(fullname)))\n return outputs\n", + "methods": [ + { + "name": "initialize_options", + "long_name": "initialize_options( self )", + "filename": "build_ext.py", + "nloc": 4, + "complexity": 1, + "token_count": 17, + "parameters": [ + "self" + ], + "start_line": 27, + "end_line": 30, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 1 + }, + { + "name": "finalize_options", + "long_name": "finalize_options( self )", + "filename": "build_ext.py", + "nloc": 5, + "complexity": 1, + "token_count": 24, + "parameters": [ + "self" + ], + "start_line": 32, + "end_line": 36, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 5, + "top_nesting_level": 1 + }, + { + "name": "run", + "long_name": "run( self )", + "filename": "build_ext.py", + "nloc": 53, + "complexity": 15, + "token_count": 328, + "parameters": [ + "self" + ], + "start_line": 38, + "end_line": 107, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 70, + "top_nesting_level": 1 + }, + { + "name": "swig_sources", + "long_name": "swig_sources( self , sources )", + "filename": "build_ext.py", + "nloc": 2, + "complexity": 1, + "token_count": 9, + "parameters": [ + "self", + "sources" + ], + "start_line": 109, + "end_line": 111, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "build_extension", + "long_name": "build_extension( self , ext )", + "filename": "build_ext.py", + "nloc": 177, + "complexity": 49, + "token_count": 1156, + "parameters": [ + "self", + "ext" + ], + "start_line": 113, + "end_line": 328, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 216, + "top_nesting_level": 1 + }, + { + "name": "get_source_files", + "long_name": "get_source_files( self )", + "filename": "build_ext.py", + "nloc": 6, + "complexity": 2, + "token_count": 35, + "parameters": [ + "self" + ], + "start_line": 330, + "end_line": 335, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 6, + "top_nesting_level": 1 + }, + { + "name": "get_outputs", + "long_name": "get_outputs( self )", + "filename": "build_ext.py", + "nloc": 10, + "complexity": 3, + "token_count": 65, + "parameters": [ + "self" + ], + "start_line": 337, + "end_line": 347, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 11, + "top_nesting_level": 1 + } + ], + "methods_before": [ + { + "name": "initialize_options", + "long_name": "initialize_options( self )", + "filename": "build_ext.py", + "nloc": 4, + "complexity": 1, + "token_count": 17, + "parameters": [ + "self" + ], + "start_line": 27, + "end_line": 30, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 1 + }, + { + "name": "finalize_options", + "long_name": "finalize_options( self )", + "filename": "build_ext.py", + "nloc": 5, + "complexity": 1, + "token_count": 24, + "parameters": [ + "self" + ], + "start_line": 32, + "end_line": 36, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 5, + "top_nesting_level": 1 + }, + { + "name": "run", + "long_name": "run( self )", + "filename": "build_ext.py", + "nloc": 54, + "complexity": 15, + "token_count": 336, + "parameters": [ + "self" + ], + "start_line": 38, + "end_line": 108, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 71, + "top_nesting_level": 1 + }, + { + "name": "swig_sources", + "long_name": "swig_sources( self , sources )", + "filename": "build_ext.py", + "nloc": 2, + "complexity": 1, + "token_count": 9, + "parameters": [ + "self", + "sources" + ], + "start_line": 110, + "end_line": 112, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "build_extension", + "long_name": "build_extension( self , ext )", + "filename": "build_ext.py", + "nloc": 177, + "complexity": 49, + "token_count": 1156, + "parameters": [ + "self", + "ext" + ], + "start_line": 114, + "end_line": 329, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 216, + "top_nesting_level": 1 + }, + { + "name": "get_source_files", + "long_name": "get_source_files( self )", + "filename": "build_ext.py", + "nloc": 6, + "complexity": 2, + "token_count": 35, + "parameters": [ + "self" + ], + "start_line": 331, + "end_line": 336, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 6, + "top_nesting_level": 1 + }, + { + "name": "get_outputs", + "long_name": "get_outputs( self )", + "filename": "build_ext.py", + "nloc": 10, + "complexity": 3, + "token_count": 65, + "parameters": [ + "self" + ], + "start_line": 338, + "end_line": 348, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 11, + "top_nesting_level": 1 + } + ], + "changed_methods": [ + { + "name": "run", + "long_name": "run( self )", + "filename": "build_ext.py", + "nloc": 54, + "complexity": 15, + "token_count": 336, + "parameters": [ + "self" + ], + "start_line": 38, + "end_line": 108, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 71, + "top_nesting_level": 1 + } + ], + "nloc": 276, + "complexity": 72, + "token_count": 1729, + "diff_parsed": { + "added": [], + "deleted": [ + " print self.fcompiler.get_version()" + ] + } + }, + { + "old_path": "numpy/distutils/fcompiler/absoft.py", + "new_path": "numpy/distutils/fcompiler/absoft.py", + "filename": "absoft.py", + "extension": "py", + "change_type": "MODIFY", + "diff": "@@ -17,7 +17,7 @@ class AbsoftFCompiler(FCompiler):\n \n compiler_type = 'absoft'\n #version_pattern = r'FORTRAN 77 Compiler (?P[^\\s*,]*).*?Absoft Corp'\n- version_pattern = r'(f90:.*?(Absoft Pro FORTRAN Version|FORTRAN 77 Compiler|Absoft Fortran Compiler Version|Version))'+\\\n+ version_pattern = r'(f90:.*?(Absoft Pro FORTRAN Version|FORTRAN 77 Compiler|Absoft Fortran Compiler Version))'+\\\n r' (?P[^\\s*,]*)(.*?Absoft Corp|)'\n \n # samt5735(8)$ f90 -V -c dummy.f\n@@ -114,7 +114,7 @@ def get_flags_f90(self):\n \"-YCOM_SFX=_\",\"-YEXT_SFX=_\",\"-YEXT_NAMES=LCS\"])\n if self.get_version():\n if self.get_version()>'4.6':\n- opt.extend([\"-YDEALLOC=ALL\"])\n+ opt.extend([\"-YDEALLOC=ALL\"]) \n return opt\n \n def get_flags_fix(self):\n", + "added_lines": 2, + "deleted_lines": 2, + "source_code": "\n# http://www.absoft.com/literature/osxuserguide.pdf\n# http://www.absoft.com/documentation.html\n\n# Notes:\n# - when using -g77 then use -DUNDERSCORE_G77 to compile f2py\n# generated extension modules (works for f2py v2.45.241_1936 and up)\n\nimport os\nimport sys\n\nfrom numpy.distutils.cpuinfo import cpu\nfrom numpy.distutils.fcompiler import FCompiler, dummy_fortran_file\nfrom numpy.distutils.misc_util import cyg2win32\n\nclass AbsoftFCompiler(FCompiler):\n\n compiler_type = 'absoft'\n #version_pattern = r'FORTRAN 77 Compiler (?P[^\\s*,]*).*?Absoft Corp'\n version_pattern = r'(f90:.*?(Absoft Pro FORTRAN Version|FORTRAN 77 Compiler|Absoft Fortran Compiler Version))'+\\\n r' (?P[^\\s*,]*)(.*?Absoft Corp|)'\n\n # samt5735(8)$ f90 -V -c dummy.f\n # f90: Copyright Absoft Corporation 1994-2002; Absoft Pro FORTRAN Version 8.0\n # Note that fink installs g77 as f77, so need to use f90 for detection.\n\n executables = {\n 'version_cmd' : [\"f90\", \"-V -c %(fname)s.f -o %(fname)s.o\" \\\n % {'fname':cyg2win32(dummy_fortran_file())}],\n 'compiler_f77' : [\"f77\"],\n 'compiler_fix' : [\"f90\"],\n 'compiler_f90' : [\"f90\"],\n 'linker_so' : [\"f90\"],\n 'archiver' : [\"ar\", \"-cr\"],\n 'ranlib' : [\"ranlib\"]\n }\n\n if os.name=='nt':\n library_switch = '/out:' #No space after /out:!\n\n module_dir_switch = None\n module_include_switch = '-p'\n\n def get_flags_linker_so(self):\n if os.name=='nt':\n opt = ['/dll']\n # The \"-K shared\" switches are being left in for pre-9.0 versions\n # of Absoft though I don't think versions earlier than 9 can\n # actually be used to build shared libraries. In fact, version\n # 8 of Absoft doesn't recognize \"-K shared\" and will fail.\n elif self.get_version() >= '9.0':\n opt = ['-shared']\n else:\n opt = [\"-K\",\"shared\"]\n return opt\n\n def library_dir_option(self, dir):\n if os.name=='nt':\n return ['-link','/PATH:\"%s\"' % (dir)]\n return \"-L\" + dir\n\n def library_option(self, lib):\n if os.name=='nt':\n return '%s.lib' % (lib)\n return \"-l\" + lib\n\n def get_library_dirs(self):\n opt = FCompiler.get_library_dirs(self)\n d = os.environ.get('ABSOFT')\n if d:\n opt.append(os.path.join(d,'lib'))\n return opt\n\n def get_libraries(self):\n opt = FCompiler.get_libraries(self)\n if self.get_version() >= '8.0':\n\t opt.extend(['f90math','fio','f77math','U77'])\n else:\n opt.extend(['fio','f90math','fmath','U77'])\n if os.name =='nt':\n opt.append('COMDLG32')\n return opt\n\n def get_flags(self):\n opt = FCompiler.get_flags(self)\n if os.name != 'nt':\n opt.extend(['-s'])\n if self.get_version():\n if self.get_version()>='8.2':\n opt.append('-fpic')\n return opt\n\n def get_flags_f77(self):\n opt = FCompiler.get_flags_f77(self)\n opt.extend(['-N22','-N90','-N110'])\n v = self.get_version()\n if os.name == 'nt':\n if v and v>='8.0':\n opt.extend(['-f','-N15'])\n else:\n opt.append('-f')\n if v:\n if v<='4.6':\n opt.append('-B108')\n else:\n # Though -N15 is undocumented, it works with\n # Absoft 8.0 on Linux\n opt.append('-N15')\n return opt\n\n def get_flags_f90(self):\n opt = FCompiler.get_flags_f90(self)\n opt.extend([\"-YCFRL=1\",\"-YCOM_NAMES=LCS\",\"-YCOM_PFX\",\"-YEXT_PFX\",\n \"-YCOM_SFX=_\",\"-YEXT_SFX=_\",\"-YEXT_NAMES=LCS\"])\n if self.get_version():\n if self.get_version()>'4.6':\n opt.extend([\"-YDEALLOC=ALL\"]) \n return opt\n\n def get_flags_fix(self):\n opt = FCompiler.get_flags_fix(self)\n opt.extend([\"-YCFRL=1\",\"-YCOM_NAMES=LCS\",\"-YCOM_PFX\",\"-YEXT_PFX\",\n \"-YCOM_SFX=_\",\"-YEXT_SFX=_\",\"-YEXT_NAMES=LCS\"])\n opt.extend([\"-f\",\"fixed\"])\n return opt\n\n def get_flags_opt(self):\n opt = ['-O']\n return opt\n\nif __name__ == '__main__':\n from distutils import log\n log.set_verbosity(2)\n from numpy.distutils.fcompiler import new_fcompiler\n compiler = new_fcompiler(compiler='absoft')\n compiler.customize()\n print compiler.get_version()\n", + "source_code_before": "\n# http://www.absoft.com/literature/osxuserguide.pdf\n# http://www.absoft.com/documentation.html\n\n# Notes:\n# - when using -g77 then use -DUNDERSCORE_G77 to compile f2py\n# generated extension modules (works for f2py v2.45.241_1936 and up)\n\nimport os\nimport sys\n\nfrom numpy.distutils.cpuinfo import cpu\nfrom numpy.distutils.fcompiler import FCompiler, dummy_fortran_file\nfrom numpy.distutils.misc_util import cyg2win32\n\nclass AbsoftFCompiler(FCompiler):\n\n compiler_type = 'absoft'\n #version_pattern = r'FORTRAN 77 Compiler (?P[^\\s*,]*).*?Absoft Corp'\n version_pattern = r'(f90:.*?(Absoft Pro FORTRAN Version|FORTRAN 77 Compiler|Absoft Fortran Compiler Version|Version))'+\\\n r' (?P[^\\s*,]*)(.*?Absoft Corp|)'\n\n # samt5735(8)$ f90 -V -c dummy.f\n # f90: Copyright Absoft Corporation 1994-2002; Absoft Pro FORTRAN Version 8.0\n # Note that fink installs g77 as f77, so need to use f90 for detection.\n\n executables = {\n 'version_cmd' : [\"f90\", \"-V -c %(fname)s.f -o %(fname)s.o\" \\\n % {'fname':cyg2win32(dummy_fortran_file())}],\n 'compiler_f77' : [\"f77\"],\n 'compiler_fix' : [\"f90\"],\n 'compiler_f90' : [\"f90\"],\n 'linker_so' : [\"f90\"],\n 'archiver' : [\"ar\", \"-cr\"],\n 'ranlib' : [\"ranlib\"]\n }\n\n if os.name=='nt':\n library_switch = '/out:' #No space after /out:!\n\n module_dir_switch = None\n module_include_switch = '-p'\n\n def get_flags_linker_so(self):\n if os.name=='nt':\n opt = ['/dll']\n # The \"-K shared\" switches are being left in for pre-9.0 versions\n # of Absoft though I don't think versions earlier than 9 can\n # actually be used to build shared libraries. In fact, version\n # 8 of Absoft doesn't recognize \"-K shared\" and will fail.\n elif self.get_version() >= '9.0':\n opt = ['-shared']\n else:\n opt = [\"-K\",\"shared\"]\n return opt\n\n def library_dir_option(self, dir):\n if os.name=='nt':\n return ['-link','/PATH:\"%s\"' % (dir)]\n return \"-L\" + dir\n\n def library_option(self, lib):\n if os.name=='nt':\n return '%s.lib' % (lib)\n return \"-l\" + lib\n\n def get_library_dirs(self):\n opt = FCompiler.get_library_dirs(self)\n d = os.environ.get('ABSOFT')\n if d:\n opt.append(os.path.join(d,'lib'))\n return opt\n\n def get_libraries(self):\n opt = FCompiler.get_libraries(self)\n if self.get_version() >= '8.0':\n\t opt.extend(['f90math','fio','f77math','U77'])\n else:\n opt.extend(['fio','f90math','fmath','U77'])\n if os.name =='nt':\n opt.append('COMDLG32')\n return opt\n\n def get_flags(self):\n opt = FCompiler.get_flags(self)\n if os.name != 'nt':\n opt.extend(['-s'])\n if self.get_version():\n if self.get_version()>='8.2':\n opt.append('-fpic')\n return opt\n\n def get_flags_f77(self):\n opt = FCompiler.get_flags_f77(self)\n opt.extend(['-N22','-N90','-N110'])\n v = self.get_version()\n if os.name == 'nt':\n if v and v>='8.0':\n opt.extend(['-f','-N15'])\n else:\n opt.append('-f')\n if v:\n if v<='4.6':\n opt.append('-B108')\n else:\n # Though -N15 is undocumented, it works with\n # Absoft 8.0 on Linux\n opt.append('-N15')\n return opt\n\n def get_flags_f90(self):\n opt = FCompiler.get_flags_f90(self)\n opt.extend([\"-YCFRL=1\",\"-YCOM_NAMES=LCS\",\"-YCOM_PFX\",\"-YEXT_PFX\",\n \"-YCOM_SFX=_\",\"-YEXT_SFX=_\",\"-YEXT_NAMES=LCS\"])\n if self.get_version():\n if self.get_version()>'4.6':\n opt.extend([\"-YDEALLOC=ALL\"])\n return opt\n\n def get_flags_fix(self):\n opt = FCompiler.get_flags_fix(self)\n opt.extend([\"-YCFRL=1\",\"-YCOM_NAMES=LCS\",\"-YCOM_PFX\",\"-YEXT_PFX\",\n \"-YCOM_SFX=_\",\"-YEXT_SFX=_\",\"-YEXT_NAMES=LCS\"])\n opt.extend([\"-f\",\"fixed\"])\n return opt\n\n def get_flags_opt(self):\n opt = ['-O']\n return opt\n\nif __name__ == '__main__':\n from distutils import log\n log.set_verbosity(2)\n from numpy.distutils.fcompiler import new_fcompiler\n compiler = new_fcompiler(compiler='absoft')\n compiler.customize()\n print compiler.get_version()\n", + "methods": [ + { + "name": "get_flags_linker_so", + "long_name": "get_flags_linker_so( self )", + "filename": "absoft.py", + "nloc": 8, + "complexity": 3, + "token_count": 42, + "parameters": [ + "self" + ], + "start_line": 44, + "end_line": 55, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 12, + "top_nesting_level": 1 + }, + { + "name": "library_dir_option", + "long_name": "library_dir_option( self , dir )", + "filename": "absoft.py", + "nloc": 4, + "complexity": 2, + "token_count": 28, + "parameters": [ + "self", + "dir" + ], + "start_line": 57, + "end_line": 60, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 1 + }, + { + "name": "library_option", + "long_name": "library_option( self , lib )", + "filename": "absoft.py", + "nloc": 4, + "complexity": 2, + "token_count": 24, + "parameters": [ + "self", + "lib" + ], + "start_line": 62, + "end_line": 65, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 1 + }, + { + "name": "get_library_dirs", + "long_name": "get_library_dirs( self )", + "filename": "absoft.py", + "nloc": 6, + "complexity": 2, + "token_count": 43, + "parameters": [ + "self" + ], + "start_line": 67, + "end_line": 72, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 6, + "top_nesting_level": 1 + }, + { + "name": "get_libraries", + "long_name": "get_libraries( self )", + "filename": "absoft.py", + "nloc": 9, + "complexity": 3, + "token_count": 67, + "parameters": [ + "self" + ], + "start_line": 74, + "end_line": 82, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 9, + "top_nesting_level": 1 + }, + { + "name": "get_flags", + "long_name": "get_flags( self )", + "filename": "absoft.py", + "nloc": 8, + "complexity": 4, + "token_count": 52, + "parameters": [ + "self" + ], + "start_line": 84, + "end_line": 91, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 8, + "top_nesting_level": 1 + }, + { + "name": "get_flags_f77", + "long_name": "get_flags_f77( self )", + "filename": "absoft.py", + "nloc": 15, + "complexity": 6, + "token_count": 88, + "parameters": [ + "self" + ], + "start_line": 93, + "end_line": 109, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 17, + "top_nesting_level": 1 + }, + { + "name": "get_flags_f90", + "long_name": "get_flags_f90( self )", + "filename": "absoft.py", + "nloc": 8, + "complexity": 3, + "token_count": 59, + "parameters": [ + "self" + ], + "start_line": 111, + "end_line": 118, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 8, + "top_nesting_level": 1 + }, + { + "name": "get_flags_fix", + "long_name": "get_flags_fix( self )", + "filename": "absoft.py", + "nloc": 6, + "complexity": 1, + "token_count": 45, + "parameters": [ + "self" + ], + "start_line": 120, + "end_line": 125, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 6, + "top_nesting_level": 1 + }, + { + "name": "get_flags_opt", + "long_name": "get_flags_opt( self )", + "filename": "absoft.py", + "nloc": 3, + "complexity": 1, + "token_count": 12, + "parameters": [ + "self" + ], + "start_line": 127, + "end_line": 129, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + } + ], + "methods_before": [ + { + "name": "get_flags_linker_so", + "long_name": "get_flags_linker_so( self )", + "filename": "absoft.py", + "nloc": 8, + "complexity": 3, + "token_count": 42, + "parameters": [ + "self" + ], + "start_line": 44, + "end_line": 55, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 12, + "top_nesting_level": 1 + }, + { + "name": "library_dir_option", + "long_name": "library_dir_option( self , dir )", + "filename": "absoft.py", + "nloc": 4, + "complexity": 2, + "token_count": 28, + "parameters": [ + "self", + "dir" + ], + "start_line": 57, + "end_line": 60, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 1 + }, + { + "name": "library_option", + "long_name": "library_option( self , lib )", + "filename": "absoft.py", + "nloc": 4, + "complexity": 2, + "token_count": 24, + "parameters": [ + "self", + "lib" + ], + "start_line": 62, + "end_line": 65, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 1 + }, + { + "name": "get_library_dirs", + "long_name": "get_library_dirs( self )", + "filename": "absoft.py", + "nloc": 6, + "complexity": 2, + "token_count": 43, + "parameters": [ + "self" + ], + "start_line": 67, + "end_line": 72, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 6, + "top_nesting_level": 1 + }, + { + "name": "get_libraries", + "long_name": "get_libraries( self )", + "filename": "absoft.py", + "nloc": 9, + "complexity": 3, + "token_count": 67, + "parameters": [ + "self" + ], + "start_line": 74, + "end_line": 82, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 9, + "top_nesting_level": 1 + }, + { + "name": "get_flags", + "long_name": "get_flags( self )", + "filename": "absoft.py", + "nloc": 8, + "complexity": 4, + "token_count": 52, + "parameters": [ + "self" + ], + "start_line": 84, + "end_line": 91, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 8, + "top_nesting_level": 1 + }, + { + "name": "get_flags_f77", + "long_name": "get_flags_f77( self )", + "filename": "absoft.py", + "nloc": 15, + "complexity": 6, + "token_count": 88, + "parameters": [ + "self" + ], + "start_line": 93, + "end_line": 109, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 17, + "top_nesting_level": 1 + }, + { + "name": "get_flags_f90", + "long_name": "get_flags_f90( self )", + "filename": "absoft.py", + "nloc": 8, + "complexity": 3, + "token_count": 59, + "parameters": [ + "self" + ], + "start_line": 111, + "end_line": 118, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 8, + "top_nesting_level": 1 + }, + { + "name": "get_flags_fix", + "long_name": "get_flags_fix( self )", + "filename": "absoft.py", + "nloc": 6, + "complexity": 1, + "token_count": 45, + "parameters": [ + "self" + ], + "start_line": 120, + "end_line": 125, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 6, + "top_nesting_level": 1 + }, + { + "name": "get_flags_opt", + "long_name": "get_flags_opt( self )", + "filename": "absoft.py", + "nloc": 3, + "complexity": 1, + "token_count": 12, + "parameters": [ + "self" + ], + "start_line": 127, + "end_line": 129, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + } + ], + "changed_methods": [ + { + "name": "get_flags_f90", + "long_name": "get_flags_f90( self )", + "filename": "absoft.py", + "nloc": 8, + "complexity": 3, + "token_count": 59, + "parameters": [ + "self" + ], + "start_line": 111, + "end_line": 118, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 8, + "top_nesting_level": 1 + } + ], + "nloc": 101, + "complexity": 27, + "token_count": 636, + "diff_parsed": { + "added": [ + " version_pattern = r'(f90:.*?(Absoft Pro FORTRAN Version|FORTRAN 77 Compiler|Absoft Fortran Compiler Version))'+\\", + " opt.extend([\"-YDEALLOC=ALL\"])" + ], + "deleted": [ + " version_pattern = r'(f90:.*?(Absoft Pro FORTRAN Version|FORTRAN 77 Compiler|Absoft Fortran Compiler Version|Version))'+\\", + " opt.extend([\"-YDEALLOC=ALL\"])" + ] + } + }, + { + "old_path": "numpy/distutils/fcompiler/gnu.py", + "new_path": "numpy/distutils/fcompiler/gnu.py", + "filename": "gnu.py", + "extension": "py", + "change_type": "MODIFY", + "diff": "@@ -239,6 +239,6 @@ class Gnu95FCompiler(GnuFCompiler):\n log.set_verbosity(2)\n from numpy.distutils.fcompiler import new_fcompiler\n #compiler = new_fcompiler(compiler='gnu')\n- compiler = Gnu95FCompiler()\n+ compiler = GnuFCompiler()\n compiler.customize()\n print compiler.get_version()\n", + "added_lines": 1, + "deleted_lines": 1, + "source_code": "\nimport re\nimport os\nimport sys\nimport warnings\n\nfrom numpy.distutils.cpuinfo import cpu\nfrom numpy.distutils.fcompiler import FCompiler\nfrom numpy.distutils.exec_command import exec_command, find_executable\n\nclass GnuFCompiler(FCompiler):\n\n compiler_type = 'gnu'\n version_pattern = r'GNU Fortran ((\\(GCC[^\\)]*(\\)\\)|\\)))|)\\s*'\\\n '(?P[^\\s*\\)]+)'\n\n # 'g77 --version' results\n # SunOS: GNU Fortran (GCC 3.2) 3.2 20020814 (release)\n # Debian: GNU Fortran (GCC) 3.3.3 20040110 (prerelease) (Debian)\n # GNU Fortran (GCC) 3.3.3 (Debian 20040401)\n # GNU Fortran 0.5.25 20010319 (prerelease)\n # Redhat: GNU Fortran (GCC 3.2.2 20030222 (Red Hat Linux 3.2.2-5)) 3.2.2 20030222 (Red Hat Linux 3.2.2-5)\n\n for fc_exe in map(find_executable,['g77','f77']):\n if os.path.isfile(fc_exe):\n break\n executables = {\n 'version_cmd' : [fc_exe,\"--version\"],\n 'compiler_f77' : [fc_exe,\"-Wall\",\"-fno-second-underscore\"],\n 'compiler_f90' : None,\n 'compiler_fix' : None,\n 'linker_so' : [fc_exe,\"-Wall\"],\n 'archiver' : [\"ar\", \"-cr\"],\n 'ranlib' : [\"ranlib\"],\n 'linker_exe' : [fc_exe,\"-Wall\"]\n }\n module_dir_switch = None\n module_include_switch = None\n\n # Cygwin: f771: warning: -fPIC ignored for target (all code is position independent)\n if os.name != 'nt' and sys.platform!='cygwin':\n pic_flags = ['-fPIC']\n\n g2c = 'g2c'\n\n #def get_linker_so(self):\n # # win32 linking should be handled by standard linker\n # # Darwin g77 cannot be used as a linker.\n # #if re.match(r'(darwin)', sys.platform):\n # # return\n # return FCompiler.get_linker_so(self)\n\n def get_flags_linker_so(self):\n opt = []\n if sys.platform=='darwin':\n target = os.environ.get('MACOSX_DEPLOYMENT_TARGET', None)\n if target is None:\n target = '10.3'\n major, minor = target.split('.')\n if int(minor) < 3:\n minor = '3'\n warnings.warn('Environment variable ' \n 'MACOSX_DEPLOYMENT_TARGET reset to 10.3')\n os.environ['MACOSX_DEPLOYMENT_TARGET'] = '%s.%s' % (major,\n minor)\n\n opt.extend(['-undefined', 'dynamic_lookup', '-bundle'])\n else:\n opt.append(\"-shared\")\n if sys.platform[:5]=='sunos':\n # SunOS often has dynamically loaded symbols defined in the\n # static library libg2c.a The linker doesn't like this. To\n # ignore the problem, use the -mimpure-text flag. It isn't\n # the safest thing, but seems to work. 'man gcc' says:\n # \".. Instead of using -mimpure-text, you should compile all\n # source code with -fpic or -fPIC.\"\n opt.append('-mimpure-text')\n return opt\n\n def get_libgcc_dir(self):\n status, output = exec_command('%s -print-libgcc-file-name' \\\n % (self.compiler_f77[0]),use_tee=0)\n if not status:\n return os.path.dirname(output)\n return\n\n def get_library_dirs(self):\n opt = []\n if sys.platform[:5] != 'linux':\n d = self.get_libgcc_dir()\n if d:\n opt.append(d)\n return opt\n\n def get_libraries(self):\n opt = []\n d = self.get_libgcc_dir()\n if d is not None:\n g2c = self.g2c + '-pic'\n f = self.static_lib_format % (g2c, self.static_lib_extension)\n if not os.path.isfile(os.path.join(d,f)):\n g2c = self.g2c\n else:\n g2c = self.g2c\n \n if sys.platform=='win32':\n opt.append('gcc')\n if g2c is not None:\n opt.append(g2c)\n if sys.platform == 'darwin':\n opt.append('cc_dynamic')\n return opt\n\n def get_flags_debug(self):\n return ['-g']\n\n def get_flags_opt(self):\n if self.get_version()<='3.3.3':\n # With this compiler version building Fortran BLAS/LAPACK\n # with -O3 caused failures in lib.lapack heevr,syevr tests.\n opt = ['-O2']\n else:\n opt = ['-O3']\n opt.append('-funroll-loops')\n return opt\n\n def get_flags_arch(self):\n opt = []\n if sys.platform=='darwin':\n if os.name != 'posix':\n # this should presumably correspond to Apple\n if cpu.is_ppc():\n opt.append('-arch ppc')\n elif cpu.is_i386():\n opt.append('-arch i386')\n for a in '601 602 603 603e 604 604e 620 630 740 7400 7450 750'\\\n '403 505 801 821 823 860'.split():\n if getattr(cpu,'is_ppc%s'%a)():\n opt.append('-mcpu='+a)\n opt.append('-mtune='+a)\n break \n return opt\n march_flag = 1\n # 0.5.25 corresponds to 2.95.x\n if self.get_version() == '0.5.26': # gcc 3.0\n if cpu.is_AthlonK6():\n opt.append('-march=k6')\n elif cpu.is_AthlonK7():\n opt.append('-march=athlon')\n else:\n march_flag = 0\n # Note: gcc 3.2 on win32 has breakage with -march specified\n elif self.get_version() >= '3.1.1' \\\n and not sys.platform=='win32': # gcc >= 3.1.1\n if cpu.is_AthlonK6():\n opt.append('-march=k6')\n elif cpu.is_AthlonK6_2():\n opt.append('-march=k6-2')\n elif cpu.is_AthlonK6_3():\n opt.append('-march=k6-3')\n elif cpu.is_AthlonK7():\n opt.append('-march=athlon')\n elif cpu.is_AthlonMP():\n opt.append('-march=athlon-mp')\n # there's also: athlon-tbird, athlon-4, athlon-xp\n elif cpu.is_Nocona():\n opt.append('-march=nocona')\n elif cpu.is_Prescott():\n opt.append('-march=prescott')\n elif cpu.is_PentiumIV():\n opt.append('-march=pentium4')\n elif cpu.is_PentiumIII():\n opt.append('-march=pentium3')\n elif cpu.is_PentiumII():\n opt.append('-march=pentium2')\n else:\n march_flag = 0\n if self.get_version() >= '3.4' and not march_flag:\n march_flag = 1\n if cpu.is_Opteron():\n opt.append('-march=opteron')\n elif cpu.is_Athlon64():\n opt.append('-march=athlon64')\n else:\n march_flag = 0\n if cpu.has_mmx(): opt.append('-mmmx') \n if self.get_version() > '3.2.2':\n if cpu.has_sse2(): opt.append('-msse2')\n if cpu.has_sse(): opt.append('-msse')\n if self.get_version() >= '3.4':\n if cpu.has_sse3(): opt.append('-msse3')\n if cpu.has_3dnow(): opt.append('-m3dnow')\n else:\n march_flag = 0\n if march_flag:\n pass\n elif cpu.is_i686():\n opt.append('-march=i686')\n elif cpu.is_i586():\n opt.append('-march=i586')\n elif cpu.is_i486():\n opt.append('-march=i486')\n elif cpu.is_i386():\n opt.append('-march=i386')\n if cpu.is_Intel():\n opt.append('-fomit-frame-pointer')\n if cpu.is_32bit():\n opt.append('-malign-double')\n return opt\n\nclass Gnu95FCompiler(GnuFCompiler):\n\n compiler_type = 'gnu95'\n version_pattern = r'GNU Fortran 95 \\(GCC (?P[^\\s*\\)]+)'\n\n # 'gfortran --version' results:\n # Debian: GNU Fortran 95 (GCC 4.0.3 20051023 (prerelease) (Debian 4.0.2-3))\n\n for fc_exe in map(find_executable,['gfortran','f95']):\n if os.path.isfile(fc_exe):\n break\n executables = {\n 'version_cmd' : [fc_exe,\"--version\"],\n 'compiler_f77' : [fc_exe,\"-Wall\",\"-ffixed-form\",\"-fno-second-underscore\"],\n 'compiler_f90' : [fc_exe,\"-Wall\",\"-fno-second-underscore\"],\n 'compiler_fix' : [fc_exe,\"-Wall\",\"-ffixed-form\",\"-fno-second-underscore\"],\n 'linker_so' : [fc_exe,\"-Wall\"],\n 'archiver' : [\"ar\", \"-cr\"],\n 'ranlib' : [\"ranlib\"],\n 'linker_exe' : [fc_exe,\"-Wall\"]\n }\n module_dir_switch = '-J'\n module_include_switch = '-I'\n\n g2c = 'gfortran'\n\nif __name__ == '__main__':\n from distutils import log\n log.set_verbosity(2)\n from numpy.distutils.fcompiler import new_fcompiler\n #compiler = new_fcompiler(compiler='gnu')\n compiler = GnuFCompiler()\n compiler.customize()\n print compiler.get_version()\n", + "source_code_before": "\nimport re\nimport os\nimport sys\nimport warnings\n\nfrom numpy.distutils.cpuinfo import cpu\nfrom numpy.distutils.fcompiler import FCompiler\nfrom numpy.distutils.exec_command import exec_command, find_executable\n\nclass GnuFCompiler(FCompiler):\n\n compiler_type = 'gnu'\n version_pattern = r'GNU Fortran ((\\(GCC[^\\)]*(\\)\\)|\\)))|)\\s*'\\\n '(?P[^\\s*\\)]+)'\n\n # 'g77 --version' results\n # SunOS: GNU Fortran (GCC 3.2) 3.2 20020814 (release)\n # Debian: GNU Fortran (GCC) 3.3.3 20040110 (prerelease) (Debian)\n # GNU Fortran (GCC) 3.3.3 (Debian 20040401)\n # GNU Fortran 0.5.25 20010319 (prerelease)\n # Redhat: GNU Fortran (GCC 3.2.2 20030222 (Red Hat Linux 3.2.2-5)) 3.2.2 20030222 (Red Hat Linux 3.2.2-5)\n\n for fc_exe in map(find_executable,['g77','f77']):\n if os.path.isfile(fc_exe):\n break\n executables = {\n 'version_cmd' : [fc_exe,\"--version\"],\n 'compiler_f77' : [fc_exe,\"-Wall\",\"-fno-second-underscore\"],\n 'compiler_f90' : None,\n 'compiler_fix' : None,\n 'linker_so' : [fc_exe,\"-Wall\"],\n 'archiver' : [\"ar\", \"-cr\"],\n 'ranlib' : [\"ranlib\"],\n 'linker_exe' : [fc_exe,\"-Wall\"]\n }\n module_dir_switch = None\n module_include_switch = None\n\n # Cygwin: f771: warning: -fPIC ignored for target (all code is position independent)\n if os.name != 'nt' and sys.platform!='cygwin':\n pic_flags = ['-fPIC']\n\n g2c = 'g2c'\n\n #def get_linker_so(self):\n # # win32 linking should be handled by standard linker\n # # Darwin g77 cannot be used as a linker.\n # #if re.match(r'(darwin)', sys.platform):\n # # return\n # return FCompiler.get_linker_so(self)\n\n def get_flags_linker_so(self):\n opt = []\n if sys.platform=='darwin':\n target = os.environ.get('MACOSX_DEPLOYMENT_TARGET', None)\n if target is None:\n target = '10.3'\n major, minor = target.split('.')\n if int(minor) < 3:\n minor = '3'\n warnings.warn('Environment variable ' \n 'MACOSX_DEPLOYMENT_TARGET reset to 10.3')\n os.environ['MACOSX_DEPLOYMENT_TARGET'] = '%s.%s' % (major,\n minor)\n\n opt.extend(['-undefined', 'dynamic_lookup', '-bundle'])\n else:\n opt.append(\"-shared\")\n if sys.platform[:5]=='sunos':\n # SunOS often has dynamically loaded symbols defined in the\n # static library libg2c.a The linker doesn't like this. To\n # ignore the problem, use the -mimpure-text flag. It isn't\n # the safest thing, but seems to work. 'man gcc' says:\n # \".. Instead of using -mimpure-text, you should compile all\n # source code with -fpic or -fPIC.\"\n opt.append('-mimpure-text')\n return opt\n\n def get_libgcc_dir(self):\n status, output = exec_command('%s -print-libgcc-file-name' \\\n % (self.compiler_f77[0]),use_tee=0)\n if not status:\n return os.path.dirname(output)\n return\n\n def get_library_dirs(self):\n opt = []\n if sys.platform[:5] != 'linux':\n d = self.get_libgcc_dir()\n if d:\n opt.append(d)\n return opt\n\n def get_libraries(self):\n opt = []\n d = self.get_libgcc_dir()\n if d is not None:\n g2c = self.g2c + '-pic'\n f = self.static_lib_format % (g2c, self.static_lib_extension)\n if not os.path.isfile(os.path.join(d,f)):\n g2c = self.g2c\n else:\n g2c = self.g2c\n \n if sys.platform=='win32':\n opt.append('gcc')\n if g2c is not None:\n opt.append(g2c)\n if sys.platform == 'darwin':\n opt.append('cc_dynamic')\n return opt\n\n def get_flags_debug(self):\n return ['-g']\n\n def get_flags_opt(self):\n if self.get_version()<='3.3.3':\n # With this compiler version building Fortran BLAS/LAPACK\n # with -O3 caused failures in lib.lapack heevr,syevr tests.\n opt = ['-O2']\n else:\n opt = ['-O3']\n opt.append('-funroll-loops')\n return opt\n\n def get_flags_arch(self):\n opt = []\n if sys.platform=='darwin':\n if os.name != 'posix':\n # this should presumably correspond to Apple\n if cpu.is_ppc():\n opt.append('-arch ppc')\n elif cpu.is_i386():\n opt.append('-arch i386')\n for a in '601 602 603 603e 604 604e 620 630 740 7400 7450 750'\\\n '403 505 801 821 823 860'.split():\n if getattr(cpu,'is_ppc%s'%a)():\n opt.append('-mcpu='+a)\n opt.append('-mtune='+a)\n break \n return opt\n march_flag = 1\n # 0.5.25 corresponds to 2.95.x\n if self.get_version() == '0.5.26': # gcc 3.0\n if cpu.is_AthlonK6():\n opt.append('-march=k6')\n elif cpu.is_AthlonK7():\n opt.append('-march=athlon')\n else:\n march_flag = 0\n # Note: gcc 3.2 on win32 has breakage with -march specified\n elif self.get_version() >= '3.1.1' \\\n and not sys.platform=='win32': # gcc >= 3.1.1\n if cpu.is_AthlonK6():\n opt.append('-march=k6')\n elif cpu.is_AthlonK6_2():\n opt.append('-march=k6-2')\n elif cpu.is_AthlonK6_3():\n opt.append('-march=k6-3')\n elif cpu.is_AthlonK7():\n opt.append('-march=athlon')\n elif cpu.is_AthlonMP():\n opt.append('-march=athlon-mp')\n # there's also: athlon-tbird, athlon-4, athlon-xp\n elif cpu.is_Nocona():\n opt.append('-march=nocona')\n elif cpu.is_Prescott():\n opt.append('-march=prescott')\n elif cpu.is_PentiumIV():\n opt.append('-march=pentium4')\n elif cpu.is_PentiumIII():\n opt.append('-march=pentium3')\n elif cpu.is_PentiumII():\n opt.append('-march=pentium2')\n else:\n march_flag = 0\n if self.get_version() >= '3.4' and not march_flag:\n march_flag = 1\n if cpu.is_Opteron():\n opt.append('-march=opteron')\n elif cpu.is_Athlon64():\n opt.append('-march=athlon64')\n else:\n march_flag = 0\n if cpu.has_mmx(): opt.append('-mmmx') \n if self.get_version() > '3.2.2':\n if cpu.has_sse2(): opt.append('-msse2')\n if cpu.has_sse(): opt.append('-msse')\n if self.get_version() >= '3.4':\n if cpu.has_sse3(): opt.append('-msse3')\n if cpu.has_3dnow(): opt.append('-m3dnow')\n else:\n march_flag = 0\n if march_flag:\n pass\n elif cpu.is_i686():\n opt.append('-march=i686')\n elif cpu.is_i586():\n opt.append('-march=i586')\n elif cpu.is_i486():\n opt.append('-march=i486')\n elif cpu.is_i386():\n opt.append('-march=i386')\n if cpu.is_Intel():\n opt.append('-fomit-frame-pointer')\n if cpu.is_32bit():\n opt.append('-malign-double')\n return opt\n\nclass Gnu95FCompiler(GnuFCompiler):\n\n compiler_type = 'gnu95'\n version_pattern = r'GNU Fortran 95 \\(GCC (?P[^\\s*\\)]+)'\n\n # 'gfortran --version' results:\n # Debian: GNU Fortran 95 (GCC 4.0.3 20051023 (prerelease) (Debian 4.0.2-3))\n\n for fc_exe in map(find_executable,['gfortran','f95']):\n if os.path.isfile(fc_exe):\n break\n executables = {\n 'version_cmd' : [fc_exe,\"--version\"],\n 'compiler_f77' : [fc_exe,\"-Wall\",\"-ffixed-form\",\"-fno-second-underscore\"],\n 'compiler_f90' : [fc_exe,\"-Wall\",\"-fno-second-underscore\"],\n 'compiler_fix' : [fc_exe,\"-Wall\",\"-ffixed-form\",\"-fno-second-underscore\"],\n 'linker_so' : [fc_exe,\"-Wall\"],\n 'archiver' : [\"ar\", \"-cr\"],\n 'ranlib' : [\"ranlib\"],\n 'linker_exe' : [fc_exe,\"-Wall\"]\n }\n module_dir_switch = '-J'\n module_include_switch = '-I'\n\n g2c = 'gfortran'\n\nif __name__ == '__main__':\n from distutils import log\n log.set_verbosity(2)\n from numpy.distutils.fcompiler import new_fcompiler\n #compiler = new_fcompiler(compiler='gnu')\n compiler = Gnu95FCompiler()\n compiler.customize()\n print compiler.get_version()\n", + "methods": [ + { + "name": "get_flags_linker_so", + "long_name": "get_flags_linker_so( self )", + "filename": "gnu.py", + "nloc": 19, + "complexity": 5, + "token_count": 117, + "parameters": [ + "self" + ], + "start_line": 53, + "end_line": 78, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 26, + "top_nesting_level": 1 + }, + { + "name": "get_libgcc_dir", + "long_name": "get_libgcc_dir( self )", + "filename": "gnu.py", + "nloc": 6, + "complexity": 2, + "token_count": 41, + "parameters": [ + "self" + ], + "start_line": 80, + "end_line": 85, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 6, + "top_nesting_level": 1 + }, + { + "name": "get_library_dirs", + "long_name": "get_library_dirs( self )", + "filename": "gnu.py", + "nloc": 7, + "complexity": 3, + "token_count": 38, + "parameters": [ + "self" + ], + "start_line": 87, + "end_line": 93, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 7, + "top_nesting_level": 1 + }, + { + "name": "get_libraries", + "long_name": "get_libraries( self )", + "filename": "gnu.py", + "nloc": 17, + "complexity": 6, + "token_count": 114, + "parameters": [ + "self" + ], + "start_line": 95, + "end_line": 112, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 18, + "top_nesting_level": 1 + }, + { + "name": "get_flags_debug", + "long_name": "get_flags_debug( self )", + "filename": "gnu.py", + "nloc": 2, + "complexity": 1, + "token_count": 9, + "parameters": [ + "self" + ], + "start_line": 114, + "end_line": 115, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 1 + }, + { + "name": "get_flags_opt", + "long_name": "get_flags_opt( self )", + "filename": "gnu.py", + "nloc": 7, + "complexity": 2, + "token_count": 34, + "parameters": [ + "self" + ], + "start_line": 117, + "end_line": 125, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 9, + "top_nesting_level": 1 + }, + { + "name": "get_flags_arch", + "long_name": "get_flags_arch( self )", + "filename": "gnu.py", + "nloc": 79, + "complexity": 40, + "token_count": 504, + "parameters": [ + "self" + ], + "start_line": 127, + "end_line": 209, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 83, + "top_nesting_level": 1 + } + ], + "methods_before": [ + { + "name": "get_flags_linker_so", + "long_name": "get_flags_linker_so( self )", + "filename": "gnu.py", + "nloc": 19, + "complexity": 5, + "token_count": 117, + "parameters": [ + "self" + ], + "start_line": 53, + "end_line": 78, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 26, + "top_nesting_level": 1 + }, + { + "name": "get_libgcc_dir", + "long_name": "get_libgcc_dir( self )", + "filename": "gnu.py", + "nloc": 6, + "complexity": 2, + "token_count": 41, + "parameters": [ + "self" + ], + "start_line": 80, + "end_line": 85, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 6, + "top_nesting_level": 1 + }, + { + "name": "get_library_dirs", + "long_name": "get_library_dirs( self )", + "filename": "gnu.py", + "nloc": 7, + "complexity": 3, + "token_count": 38, + "parameters": [ + "self" + ], + "start_line": 87, + "end_line": 93, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 7, + "top_nesting_level": 1 + }, + { + "name": "get_libraries", + "long_name": "get_libraries( self )", + "filename": "gnu.py", + "nloc": 17, + "complexity": 6, + "token_count": 114, + "parameters": [ + "self" + ], + "start_line": 95, + "end_line": 112, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 18, + "top_nesting_level": 1 + }, + { + "name": "get_flags_debug", + "long_name": "get_flags_debug( self )", + "filename": "gnu.py", + "nloc": 2, + "complexity": 1, + "token_count": 9, + "parameters": [ + "self" + ], + "start_line": 114, + "end_line": 115, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 1 + }, + { + "name": "get_flags_opt", + "long_name": "get_flags_opt( self )", + "filename": "gnu.py", + "nloc": 7, + "complexity": 2, + "token_count": 34, + "parameters": [ + "self" + ], + "start_line": 117, + "end_line": 125, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 9, + "top_nesting_level": 1 + }, + { + "name": "get_flags_arch", + "long_name": "get_flags_arch( self )", + "filename": "gnu.py", + "nloc": 79, + "complexity": 40, + "token_count": 504, + "parameters": [ + "self" + ], + "start_line": 127, + "end_line": 209, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 83, + "top_nesting_level": 1 + } + ], + "changed_methods": [], + "nloc": 192, + "complexity": 59, + "token_count": 1185, + "diff_parsed": { + "added": [ + " compiler = GnuFCompiler()" + ], + "deleted": [ + " compiler = Gnu95FCompiler()" + ] + } + } + ] + }, + { + "hash": "d99b73b34ffc1778e9ff2423b56a8994d0e9be78", + "msg": "Change accuracy of fill and more _WIN32 fixes.", + "author": { + "name": "Travis Oliphant", + "email": "oliphant@enthought.com" + }, + "committer": { + "name": "Travis Oliphant", + "email": "oliphant@enthought.com" + }, + "author_date": "2006-02-09T20:50:33+00:00", + "author_timezone": 0, + "committer_date": "2006-02-09T20:50:33+00:00", + "committer_timezone": 0, + "branches": [ + "main" + ], + "in_main_branch": true, + "merge": false, + "parents": [ + "f5209cbd46b7d6ad0a0960630189670adb2b3ccb" + ], + "project_name": "repo_copy", + "project_path": "/tmp/tmpdjwupkfu/repo_copy", + "deletions": 21, + "insertions": 12, + "lines": 33, + "files": 4, + "dmm_unit_size": 0.0, + "dmm_unit_complexity": 0.0, + "dmm_unit_interfacing": null, + "modified_files": [ + { + "old_path": "numpy/core/setup.py", + "new_path": "numpy/core/setup.py", + "filename": "setup.py", + "extension": "py", + "change_type": "MODIFY", + "diff": "@@ -8,7 +8,7 @@\n \n def 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+ from numpy.distutils.system_info import get_info, default_lib_dirs\n \n config = Configuration('core',parent_package,top_path)\n local_dir = config.local_path\n@@ -31,7 +31,8 @@ def generate_config_h(ext, build_dir):\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+ result = config_cmd.try_run(tc,include_dirs=[python_include],\n+ library_dirs = default_lib_dirs)\n if not result:\n raise \"ERROR: Failed to test configuration\"\n moredefs = []\n", + "added_lines": 3, + "deleted_lines": 2, + "source_code": "\nimport imp\nimport os\nimport sys\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, default_lib_dirs\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 library_dirs = default_lib_dirs)\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 sys.version[:3] < '2.4':\n kws_args['headers'].append('stdlib.h')\n if config_cmd.check_func('strtod', **kws_args):\n moredefs.append(('PyOS_ascii_strtod', 'strtod'))\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('src','ucsnarrow.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\nimport sys\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 sys.version[:3] < '2.4':\n kws_args['headers'].append('stdlib.h')\n if config_cmd.check_func('strtod', **kws_args):\n moredefs.append(('PyOS_ascii_strtod', 'strtod'))\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('src','ucsnarrow.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": 75, + "complexity": 24, + "token_count": 560, + "parameters": [ + "ext", + "build_dir" + ], + "start_line": 25, + "end_line": 108, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 84, + "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": 111, + "end_line": 123, + "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": 110, + "end_line": 124, + "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": 131, + "end_line": 139, + "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": 194, + "end_line": 197, + "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": 76, + "complexity": 1, + "token_count": 459, + "parameters": [ + "parent_package", + "top_path" + ], + "start_line": 9, + "end_line": 212, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 204, + "top_nesting_level": 0 + }, + { + "name": "testcode_mathlib", + "long_name": "testcode_mathlib( )", + "filename": "setup.py", + "nloc": 9, + "complexity": 1, + "token_count": 6, + "parameters": [], + "start_line": 214, + "end_line": 222, + "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": 225, + "end_line": 287, + "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": 74, + "complexity": 24, + "token_count": 556, + "parameters": [ + "ext", + "build_dir" + ], + "start_line": 25, + "end_line": 107, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 83, + "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": 110, + "end_line": 122, + "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": 109, + "end_line": 123, + "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": 130, + "end_line": 138, + "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": 193, + "end_line": 196, + "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": 76, + "complexity": 1, + "token_count": 457, + "parameters": [ + "parent_package", + "top_path" + ], + "start_line": 9, + "end_line": 211, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 203, + "top_nesting_level": 0 + }, + { + "name": "testcode_mathlib", + "long_name": "testcode_mathlib( )", + "filename": "setup.py", + "nloc": 9, + "complexity": 1, + "token_count": 6, + "parameters": [], + "start_line": 213, + "end_line": 221, + "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": 224, + "end_line": 286, + "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": 76, + "complexity": 1, + "token_count": 459, + "parameters": [ + "parent_package", + "top_path" + ], + "start_line": 9, + "end_line": 212, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 204, + "top_nesting_level": 0 + }, + { + "name": "configuration.generate_config_h", + "long_name": "configuration.generate_config_h( ext , build_dir )", + "filename": "setup.py", + "nloc": 75, + "complexity": 24, + "token_count": 560, + "parameters": [ + "ext", + "build_dir" + ], + "start_line": 25, + "end_line": 108, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 84, + "top_nesting_level": 1 + } + ], + "nloc": 253, + "complexity": 37, + "token_count": 1405, + "diff_parsed": { + "added": [ + " from numpy.distutils.system_info import get_info, default_lib_dirs", + " result = config_cmd.try_run(tc,include_dirs=[python_include],", + " library_dirs = default_lib_dirs)" + ], + "deleted": [ + " from numpy.distutils.system_info import get_info", + " result = config_cmd.try_run(tc,include_dirs=[python_include])" + ] + } + }, + { + "old_path": "numpy/core/src/arraytypes.inc.src", + "new_path": "numpy/core/src/arraytypes.inc.src", + "filename": "arraytypes.inc.src", + "extension": "src", + "change_type": "MODIFY", + "diff": "@@ -1648,17 +1648,13 @@ OBJECT_fill(PyObject **buffer, intp length, void *ignored)\n static void\n @NAME@_fill(@typ@ *buffer, intp length, void *ignored)\n {\n-\t@typ@ *buffermax;\n+\tregister intp i;\n \t@typ@ start = buffer[0];\n \t@typ@ delta = buffer[1];\n \tdelta -= start;\n-\tstart += (delta + delta);\n-\tbuffermax = buffer + length;\n \tbuffer += 2;\n-\twhile(buffer < buffermax) {\n-\t\t*buffer = start;\n-\t\tstart += delta;\n-\t\tbuffer++;\n+\tfor (i=2; ireal;\n \tstart.imag = buffer->imag;\n@@ -1680,16 +1676,10 @@ static void\n \tdelta.imag = buffer[1].imag;\n \tdelta.real -= start.real;\n \tdelta.imag -= start.imag;\n-\tstart.real += (delta.real + delta.real);\n-\tstart.imag += (delta.imag + delta.imag);\n-\tbuffermax = buffer + length;\n \tbuffer += 2;\n-\twhile (buffer < buffermax) {\n-\t\tbuffer->real = start.real;\n-\t\tbuffer->imag = start.imag; \n-\t\tstart.real += delta.real;\n-\t\tstart.imag += delta.imag;\n-\t\tbuffer++;\n+\tfor (i=2; ireal = start.real + i*delta.real;\n+\t\tbuffer->imag = start.imag + i*delta.imag;\n \t}\n }\n /**end repeat**/\n", + "added_lines": 7, + "deleted_lines": 17, + "source_code": "/* -*- c -*- */\n\n/**begin repeat\n#name=UnsignedLong,UnsignedLongLong,LongLong#\n#type=ulong,ulonglong,longlong#\n */\nstatic @type@\nMyPyLong_As@name@(PyObject *vv)\n{\n\t@type@ ret;\n\n\tif (!PyLong_Check(vv)) {\n\t\tPyObject *mylong;\n\t\tmylong = PyNumber_Long(vv);\n\t\tif (mylong == NULL) return (@type@) -1;\n\t\tvv = mylong;\n\t}\n\telse Py_INCREF(vv);\n\n\tret = PyLong_As@name@(vv);\n\tPy_DECREF(vv);\n\treturn ret;\n}\n/**end repeat**/\n\n\nstatic double \n_getNAN(void) {\n#ifdef NAN\n return NAN;\n#else\n static double nan=0;\n \n if (nan == 0) {\n\t\tdouble mul = 1e100;\n\t\tdouble tmp = 0.0;\n\t\tdouble pinf=0;\n pinf = mul;\n for (;;) {\n pinf *= mul;\n if (pinf == tmp) break;\n tmp = pinf;\n }\n nan = pinf / pinf;\n }\n return nan;\n#endif\n}\n\nstatic double\nMyPyFloat_AsDouble(PyObject *obj)\n{\n if (obj == Py_None) return _getNAN();\n return PyFloat_AsDouble(obj); \n}\n\n\n/****************** getitem and setitem **********************/\n\n/**begin repeat\n\n#TYP=BOOL,BYTE,UBYTE,SHORT,USHORT,INT,LONG,UINT,ULONG,LONGLONG,ULONGLONG,FLOAT,DOUBLE#\n#func1=PyBool_FromLong, PyInt_FromLong*6, PyLong_FromUnsignedLong*2, PyLong_FromLongLong, PyLong_FromUnsignedLongLong, PyFloat_FromDouble*2#\n#func2=PyObject_IsTrue, PyInt_AsLong*6, MyPyLong_AsUnsignedLong*2, MyPyLong_AsLongLong, MyPyLong_AsUnsignedLongLong, MyPyFloat_AsDouble*2#\n#typ=Bool, byte, ubyte, short, ushort, int, long, uint, ulong, longlong, ulonglong, float, double#\n#typ1=long*7, ulong*2, longlong, ulonglong, float, double#\n#kind=Bool, Byte, UByte, Short, UShort, Int, Long, UInt, ULong, LongLong, ULongLong, Float, Double#\n*/\n\nstatic PyObject * \n@TYP@_getitem(char *ip, PyArrayObject *ap) {\n @typ@ t1;\n\n\tif ((ap==NULL) || PyArray_ISBEHAVED_RO(ap)) {\n t1 = *((@typ@ *)ip);\n return @func1@((@typ1@)t1);\n\t}\n\telse {\n ap->descr->f->copyswap(&t1, ip, !PyArray_ISNOTSWAPPED(ap),\n\t\t\t\t ap->descr->elsize);\n return @func1@((@typ1@)t1);\n\t}\n}\n\nstatic int \n@TYP@_setitem(PyObject *op, char *ov, PyArrayObject *ap) {\n @typ@ temp; /* ensures alignment */\n\n if (PyArray_IsScalar(op, @kind@)) {\n temp = ((Py@kind@ScalarObject *)op)->obval;\n }\n else {\n temp = (@typ@)@func2@(op);\n }\n if (PyErr_Occurred()) return -1;\n if (ap == NULL || PyArray_ISBEHAVED(ap)) \n *((@typ@ *)ov)=temp;\n else {\n ap->descr->f->copyswap(ov, &temp, !PyArray_ISNOTSWAPPED(ap), \n\t\t\t\t ap->descr->elsize);\n }\n \n return 0;\n}\n\n/**end repeat**/\n\n\n/**begin repeat \n\n#TYP=CFLOAT,CDOUBLE#\n#typ=float, double#\n*/\n\nstatic PyObject * \n@TYP@_getitem(char *ip, PyArrayObject *ap) {\n @typ@ t1, t2;\n\n if ((ap==NULL) || PyArray_ISBEHAVED_RO(ap)) { \n return PyComplex_FromDoubles((double)((@typ@ *)ip)[0], \n (double)((@typ@ *)ip)[1]);\n }\n else {\n\t\tint size = sizeof(@typ@);\n\t\tBool swap = !PyArray_ISNOTSWAPPED(ap);\n copy_and_swap(&t1, ip, size, 1, 0, swap);\n copy_and_swap(&t2, ip+size, size, 1, 0, swap);\n return PyComplex_FromDoubles((double)t1, (double)t2);\n }\n}\n/**end repeat**/\n\n/**begin repeat \n\n#TYP=CFLOAT, CDOUBLE, CLONGDOUBLE#\n#typ=float, double, longdouble#\n#kind=CFloat, CDouble, CLongDouble#\n*/\nstatic int \n@TYP@_setitem(PyObject *op, char *ov, PyArrayObject *ap) \n{\n Py_complex oop;\n PyObject *op2;\n c@typ@ temp;\n\tint rsize;\n \n if (!(PyArray_IsScalar(op, @kind@))) {\n if (PyArray_Check(op) && (PyArray_NDIM(op)==0)) {\n op2 = ((PyArrayObject *)op)->descr->f->getitem \\\n (((PyArrayObject *)op)->data, \n (PyArrayObject *)op);\n\t\t}\n\t\telse { \n op2 = op; Py_INCREF(op);\n }\n if (op2 == Py_None) {\n oop.real = oop.imag = _getNAN();\n }\n else {\n oop = PyComplex_AsCComplex (op2);\n }\n Py_DECREF(op2);\n if (PyErr_Occurred()) return -1;\n temp.real = (@typ@) oop.real;\n temp.imag = (@typ@) oop.imag; \n }\n\telse {\n temp = ((Py@kind@ScalarObject *)op)->obval;\n }\n\t\n memcpy(ov, &temp, ap->descr->elsize);\n if (!PyArray_ISNOTSWAPPED(ap))\n byte_swap_vector(ov, 2, sizeof(@typ@));\n\t\n\trsize = sizeof(@typ@);\n\tcopy_and_swap(ov, &temp, rsize, 2, rsize, !PyArray_ISNOTSWAPPED(ap));\n return 0;\n}\n/**end repeat**/\n\nstatic PyObject * \nLONGDOUBLE_getitem(char *ip, PyArrayObject *ap) \n{\n return PyArray_Scalar(ip, ap->descr, NULL);\n}\n\nstatic int \nLONGDOUBLE_setitem(PyObject *op, char *ov, PyArrayObject *ap) {\n longdouble temp; /* ensures alignment */\n\n if (PyArray_IsScalar(op, LongDouble)) {\n temp = ((PyLongDoubleScalarObject *)op)->obval;\n }\n else {\n if (op == Py_None) temp = (longdouble)_getNAN();\n else temp = (longdouble)PyFloat_AsDouble(op);\n }\n if (PyErr_Occurred()) return -1;\n if (ap == NULL || PyArray_ISBEHAVED(ap)) \n *((longdouble *)ov)=temp;\n else {\n copy_and_swap(ov, &temp, ap->descr->elsize, 1, 0,\n !PyArray_ISNOTSWAPPED(ap));\n }\n \n return 0;\n}\n\nstatic PyObject * \nCLONGDOUBLE_getitem(char *ip, PyArrayObject *ap) \n{\n return PyArray_Scalar(ip, ap->descr, NULL);\n}\n\n\n/* UNICODE */\nstatic PyObject * \nUNICODE_getitem(char *ip, PyArrayObject *ap) \n{\n\tPyObject *obj;\n\tint mysize;\n\tPyArray_UCS4 *dptr;\n\n\tmysize = ap->descr->elsize >> 2;\n\tdptr = (PyArray_UCS4 *)ip + mysize-1;\n\twhile(mysize > 0 && *dptr-- == 0) mysize--;\n\tif (!PyArray_ISNOTSWAPPED(ap) && (obj != NULL)) {\n\t\tbyte_swap_vector(PyArray_BYTES(ap), mysize, 4);\n\t}\n#ifdef Py_UNICODE_WIDE\n\tobj = PyUnicode_FromUnicode((const PyArray_UCS4 *)ip, mysize);\n#else\n\t/* create new empty unicode object of length mysize*2 */\n\tobj = MyPyUnicode_New(mysize*2);\n\tif (obj == NULL) return obj;\n\tmysize = PyUCS2Buffer_FromUCS4(((PyUnicodeObject *)obj)->str, \n\t\t\t\t (PyArray_UCS4 *)ip, mysize);\n\t/* reset length of unicode object to ucs2size */\n\tif (MyPyUnicode_Resize((PyUnicodeObject *)obj, mysize) < 0) {\n\t\tPy_DECREF(obj);\n\t\treturn NULL;\n\t}\n#endif\n\n\treturn obj;\n}\n\nstatic int \nUNICODE_setitem(PyObject *op, char *ov, PyArrayObject *ap) \n{\n PyObject *temp;\n\tPy_UNICODE *ptr;\n\tint datalen;\n\n\tif ((temp=PyObject_Unicode(op)) == NULL) return -1;\n\tptr = PyUnicode_AS_UNICODE(temp);\n\tif ((ptr == NULL) || (PyErr_Occurred())) {\n\t\tPy_DECREF(temp);\n\t\treturn -1;\n\t}\n\tdatalen = PyUnicode_GET_DATA_SIZE(temp);\n\n#ifdef Py_UNICODE_WIDE\n\tmemcpy(ov, ptr, MIN(ap->descr->elsize, datalen));\n#else\n datalen = PyUCS2Buffer_AsUCS4(ptr, (PyArray_UCS4 *)ov, datalen >> 1,\n\t\t\t\t ap->descr->elsize >> 2);\n\tdatalen <<= 2;\n#endif\n\t/* Fill in the rest of the space with 0 */\n\tif (ap->descr->elsize > datalen) {\n\t\tmemset(ov + datalen, 0, (ap->descr->elsize - datalen));\n\t}\n\t\n\tif (!PyArray_ISNOTSWAPPED(ap)) \n\t\tbyte_swap_vector(ov, ap->descr->elsize >> 2, 4);\n\tPy_DECREF(temp);\n\treturn 0;\n}\n\n/* STRING -- can handle both NULL-terminated and not NULL-terminated cases */\nstatic PyObject * \nSTRING_getitem(char *ip, PyArrayObject *ap) \n{\n\tif (ip[ap->descr->elsize-1])\n\t\treturn PyString_FromStringAndSize(ip,ap->descr->elsize);\n\telse\n\t\treturn PyString_FromString(ip);\n}\n\nstatic int \nSTRING_setitem(PyObject *op, char *ov, PyArrayObject *ap) \n{\n\tchar *ptr;\n\tint len;\n\tPyObject *temp=PyObject_Str(op);\n\t\n\tif (temp == NULL) return -1;\n\t\n\tif (PyString_AsStringAndSize(temp, &ptr, &len) == -1) {\n\t\tPy_DECREF(temp);\n\t\treturn -1;\n\t}\n\tmemcpy(ov, ptr, MIN(ap->descr->elsize,len));\n\tif (ap->descr->elsize > len) {\n\t\tmemset(ov + len, 0, (ap->descr->elsize - len));\n\t}\n\tPy_DECREF(temp);\n\treturn 0;\n}\n\n/* OBJECT */\n\nstatic PyObject * \nOBJECT_getitem(char *ip, PyArrayObject *ap) \n{\n\tPy_INCREF(*(PyObject **)ip);\n\treturn *(PyObject **)ip;\n}\n\nstatic int \nOBJECT_setitem(PyObject *op, char *ov, PyArrayObject *ap) \n{\n\tPy_XDECREF(*(PyObject **)ov);\n\tPy_INCREF(op);\n\t*(PyObject **)ov = op;\n\treturn PyErr_Occurred() ? -1:0;\n}\n\n/* VOID */\n\nstatic PyObject *\nVOID_getitem(char *ip, PyArrayObject *ap)\n{\n PyObject *u=NULL;\n\tPyArray_Descr* descr;\n int itemsize;\n\n\tdescr = ap->descr;\n\tif (descr->fields && descr->fields != Py_None) {\n\t\tPyObject *key;\n\t\tPyObject *names;\n\t\tint i, n;\n\t\tPyObject *ret;\n\t\tPyObject *tup, *title;\n\t\tPyArray_Descr *new;\n\t\tint offset;\n\t\tint savedflags;\n\n\t\t/* get the names from the fields dictionary*/\n\t\tkey = PyInt_FromLong(-1);\n\t\tnames = PyDict_GetItem(descr->fields, key);\n\t\tPy_DECREF(key);\n\t\tif (!names) goto finish;\n\t\tn = PyList_GET_SIZE(names);\n\t\tret = PyTuple_New(n);\n\t\tsavedflags = ap->flags;\n\t\tfor (i=0; ifields, key);\n\t\t\tif (!PyArg_ParseTuple(tup, \"Oi|O\", &new, &offset, \n\t\t\t\t\t &title)) {\n\t\t\t\tPy_DECREF(ret); \n\t\t\t\tap->descr = descr;\n\t\t\t\treturn NULL;\n\t\t\t}\n\t\t\tap->descr = new;\n\t\t\t/* update alignment based on offset */\n\t\t\tif ((new->alignment > 1) &&\t\t\t\\\n\t\t\t ((((intp)(ip+offset)) % new->alignment) != 0))\n\t\t\t\tap->flags &= ~ALIGNED;\n\t\t\telse\n\t\t\t\tap->flags |= ALIGNED;\n\n\t\t\tPyTuple_SET_ITEM(ret, i,\t\t\t\\\n\t\t\t\t\t new->f->getitem(ip+offset, ap));\n\t\t\tap->flags = savedflags;\n\t\t}\n\t\tap->descr = descr;\n\t\treturn ret;\n\t}\n\n\tif (descr->subarray) {\n\t\t/* return an array of the basic type */\n\t\tPyArray_Dims shape={NULL,-1};\n\t\tPyObject *ret;\n\t\tif (!(PyArray_IntpConverter(descr->subarray->shape, \n\t\t\t\t\t &shape))) {\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\treturn NULL;\n\t\t}\n Py_INCREF(descr->subarray->base);\n\t\tret = PyArray_NewFromDescr(&PyArray_Type,\n\t\t\t\t\t descr->subarray->base,\n\t\t\t\t\t shape.len, shape.ptr,\n\t\t\t\t\t NULL, ip, ap->flags, NULL);\n\t\tPyDimMem_FREE(shape.ptr);\n\t\tif (!ret) return NULL;\n\t\tPyArray_BASE(ret) = (PyObject *)ap;\n\t\tPy_INCREF(ap);\n\t\tPyArray_UpdateFlags((PyArrayObject *)ret, UPDATE_ALL_FLAGS);\n\t\treturn ret;\n\t}\n\n finish:\n\titemsize=ap->descr->elsize;\n\tif (PyArray_ISWRITEABLE(ap))\n\t\tu = PyBuffer_FromReadWriteMemory(ip, itemsize);\n\telse\n\t\tu = PyBuffer_FromMemory(ip, itemsize);\n\tif (u==NULL) goto fail;\n\n\t/* default is to return buffer object pointing to current item */\n\t/* a view of it */\n\treturn u; \n\t\n fail:\n return NULL;\n}\n\n\n\nstatic int PyArray_CopyObject(PyArrayObject *, PyObject *);\n\nstatic int\nVOID_setitem(PyObject *op, char *ip, PyArrayObject *ap)\n{\n\tPyArray_Descr* descr;\n int itemsize=ap->descr->elsize;\n\tint res;\n\n\tdescr = ap->descr;\n\tif (descr->fields && (descr->fields != Py_None) && \\\n\t PyTuple_Check(op)) {\n\t\tPyObject *key;\n\t\tPyObject *names;\n\t\tint i, n;\n\t\tPyObject *tup, *title;\n\t\tPyArray_Descr *new;\n\t\tint offset;\n\t\tint savedflags;\n\t\tres = -1;\n\t\t/* get the names from the fields dictionary*/\n\t\tkey = PyInt_FromLong(-1);\n\t\tnames = PyDict_GetItem(descr->fields, key);\n\t\tPy_DECREF(key);\n\t\tif (!names) goto finish;\n\t\tn = PyList_GET_SIZE(names);\n\t\tif (PyTuple_GET_SIZE(op) != n) {\n\t\t\tPyErr_SetString(PyExc_ValueError, \n\t\t\t\t\t\"size of tuple must match\"\\\n\t\t\t\t\t\"number of fields.\");\n\t\t\treturn -1;\n\t\t}\n\t\tsavedflags = ap->flags;\n\t\tfor (i=0; ifields, key);\n\t\t\tif (!PyArg_ParseTuple(tup, \"Oi|O\", &new, &offset, \n\t\t\t\t\t &title)) {\n\t\t\t\tap->descr = descr;\n\t\t\t\treturn -1;\n\t\t\t}\n\t\t\tap->descr = new;\n\t\t\t/* remember to update alignment flags */\n\t\t\tif ((new->alignment > 1) &&\t\t\t\\\n\t\t\t ((((intp)(ip+offset)) % new->alignment) != 0))\n\t\t\t\tap->flags &= ~ALIGNED;\n\t\t\telse\n\t\t\t\tap->flags |= ALIGNED;\n\n\t\t\tres = new->f->setitem(PyTuple_GET_ITEM(op, i),\n\t\t\t\t\t ip+offset, ap);\n\t\t\tap->flags = savedflags;\n\t\t\tif (res < 0) break;\n\t\t}\n\t\tap->descr = descr;\n\t\treturn res;\n\t}\n\n\tif (descr->subarray) {\n\t\t/* copy into an array of the same basic type */\n\t\tPyArray_Dims shape={NULL,-1};\n\t\tPyObject *ret;\n\t\tif (!(PyArray_IntpConverter(descr->subarray->shape, \n\t\t\t\t\t &shape))) {\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\treturn -1;\n\t\t}\n Py_INCREF(descr->subarray->base);\n\t\tret = PyArray_NewFromDescr(&PyArray_Type,\n\t\t\t\t\t descr->subarray->base,\n\t\t\t\t\t shape.len, shape.ptr,\n\t\t\t\t\t NULL, ip, ap->flags, NULL);\n\t\tPyDimMem_FREE(shape.ptr);\n\t\tif (!ret) return -1;\n\t\tPyArray_BASE(ret) = (PyObject *)ap;\n\t\tPy_INCREF(ap);\n\t\tPyArray_UpdateFlags((PyArrayObject *)ret, UPDATE_ALL_FLAGS);\n\t\tres = PyArray_CopyObject((PyArrayObject *)ret, op);\n\t\tPy_DECREF(ret);\n\t\treturn res;\n\t}\n\n finish:\n\t/* Default is to use buffer interface to set item */\n\t{\n\t\tconst void *buffer;\n\t\tint buflen;\n\t\tres = PyObject_AsReadBuffer(op, &buffer, &buflen);\n\t\tif (res == -1) goto fail;\n\t\tmemcpy(ip, buffer, MIN(buflen, itemsize));\n }\n\treturn 0;\n\n fail:\n return -1; \n}\n\n\n/****************** XXX_to_YYY *******************************/ \n\n/* Assumes contiguous, and aligned, from and to */\n\n\n/**begin repeat\n#to=(BYTE,UBYTE,SHORT,USHORT,INT,UINT,LONG,ULONG,LONGLONG,ULONGLONG,FLOAT,DOUBLE,LONGDOUBLE)*16#\n#from=BYTE*13,UBYTE*13,SHORT*13,USHORT*13,INT*13,UINT*13,LONG*13,ULONG*13,LONGLONG*13,ULONGLONG*13,FLOAT*13,DOUBLE*13,LONGDOUBLE*13,CFLOAT*13,CDOUBLE*13,CLONGDOUBLE*13#\n#totyp=(byte, ubyte, short, ushort, int, uint, long, ulong, longlong, ulonglong, float, double, longdouble)*16#\n#fromtyp=byte*13, ubyte*13, short*13, ushort*13, int*13, uint*13, long*13, ulong*13, longlong*13, ulonglong*13, float*13, double*13, longdouble*13, float*13, double*13, longdouble*13#\n#incr= ip++*169,ip+=2*39#\n*/\nstatic void \n@from@_to_@to@(@fromtyp@ *ip, @totyp@ *op, intp n, PyArrayObject *aip, \n\t PyArrayObject *aop) {\n\tregister intp i; \n\tfor(i=0;idescr->elsize*3, 1#\n*/\nstatic void \n@from@_to_OBJECT(@fromtyp@ *ip, PyObject **op, intp n, PyArrayObject *aip,\n\t\t PyArrayObject *aop)\n{\n\tregister intp i; \n\tint skip=@skip@;\n\tfor(i=0;idescr->elsize*3#\n*/\nstatic void \nOBJECT_to_@to@(PyObject **ip, @totyp@ *op, intp n, PyArrayObject *aip,\n\t\t PyArrayObject *aop)\n{\n\tregister intp i; \n\tint skip=@skip@;\n\tfor(i=0;idescr->elsize*3)*3#\n#convert=1*17,0*3,1*17,0*3,0*20#\n#convstr=(Int*9,Long*2,Float*3,Complex*3,Tuple*3)*3#\n*/\nstatic void\n@from@_to_@to@(@fromtyp@ *ip, @totyp@ *op, intp n, PyArrayObject *aip, \n\t PyArrayObject *aop)\n{\n\tregister intp i;\n\tPyObject *temp=NULL;\n\tint skip=aip->descr->elsize;\n\tint oskip=@oskip@;\n\tfor(i=0; idescr->elsize;\n\tfor(i=0; i= 0x02040000) || defined(PyOS_ascii_strtod)\nstatic int\n@fname@_fromstr(char *str, @type@ *ip, char **endptr, void *ignore)\n{\n\tdouble result;\n\n\tresult = PyOS_ascii_strtod(str, endptr);\n\t*ip = (@type@) result;\n\treturn 0;\n}\n#else\n#define @fname@_fromstr NULL\n#endif\n/**end repeat**/\n\n\n\n/**begin repeat\n#fname=BOOL,CFLOAT,CDOUBLE,CLONGDOUBLE,OBJECT,STRING,UNICODE,VOID#\n*/\n#define @fname@_fromstr NULL\n/**end repeat**/\n\n\n/****************** copyswapn *************************************/\n\n/**begin repeat\n\n#fname=SHORT,USHORT,INT,UINT,LONG,ULONG,LONGLONG,ULONGLONG,FLOAT,DOUBLE,LONGDOUBLE#\n#fsize=SHORT,SHORT,INT,INT,LONG,LONG,LONGLONG,LONGLONG,FLOAT,DOUBLE,LONGDOUBLE#\n#type=short,ushort,int,uint,long,ulong,longlong,ulonglong,float,double,longdouble#\n*/\nstatic void\n@fname@_copyswapn (void *dst, void *src, intp n, int swap, int itemsize)\n{\n\tif (src != NULL) /* copy first if needed */\n\t\tmemcpy(dst, src, n*sizeof(@type@));\n\n\tif (swap) {\n\t\tregister char *a, *b, c;\n\t\tfor (a = (char *)dst; n>0; n--) {\n#if SIZEOF_@fsize@ == 2\n\t\t\tb = a + 1;\n\t\t\tc = *a; *a++ = *b; *b = c;\n\t\t\ta += 1;\n#elif SIZEOF_@fsize@ == 4\n\t\t\tb = a + 3;\n c = *a; *a++ = *b; *b-- = c;\n c = *a; *a++ = *b; *b = c;\n\t\t\ta += 2;\n#elif SIZEOF_@fsize@ == 8\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\t\t\ta += 4;\n#elif SIZEOF_@fsize@ == 10\n b = a + 9;\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 c = *a; *a++ = *b; *b = c;\n\t\t\ta += 5;\n#elif SIZEOF_@fsize@ == 12\n b = a + 11;\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 c = *a; *a++ = *b; *b-- = c;\n c = *a; *a++ = *b; *b = c;\n\t\t\ta += 6;\n#elif SIZEOF_@fsize@ == 16\n b = a + 15;\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 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\t\t\ta += 8;\n#else\n\t\t\tregister int i, nn;\n b = a + (SIZEOF_@fsize@-1);\n\t\t\tnn = SIZEOF_@fsize@ / 2;\n for (i=0; i0; nn--) {\n#if SIZEOF_@fsize@ == 4\n\t\t\tb = a + 3;\n c = *a; *a++ = *b; *b-- = c;\n c = *a; *a++ = *b; *b = c;\n\t\t\ta += 2;\n#elif SIZEOF_@fsize@ == 8\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\t\t\ta += 4;\n#elif SIZEOF_@fsize@ == 10\n b = a + 9;\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 c = *a; *a++ = *b; *b = c;\n\t\t\ta += 5;\n#elif SIZEOF_@fsize@ == 12\n b = a + 11;\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 c = *a; *a++ = *b; *b-- = c;\n c = *a; *a++ = *b; *b = c;\n\t\t\ta += 6;\n#elif SIZEOF_@fsize@ == 16\n b = a + 15;\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 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\t\t\ta += 8;\n#else\n\t\t\tregister int i, kn;\n\n b = a + (SIZEOF_@fsize@-1);\n\t\t\tkn = SIZEOF_@fsize@ / 2;\n for (i=0; i0; n--) {\n\t\t\tb = a + 3;\n\t\t\tc=*a; *a++ = *b; *b-- = c;\n\t\t\tc=*a; *a++ = *b; *b-- = c;\n\t\t\ta += 1;\n\t\t}\n\t}\n}\n\n\nstatic void\nOBJECT_copyswap (PyObject **dst, PyObject **src, int swap, int itemsize)\n{\n OBJECT_copyswapn(dst, src, 1, swap, itemsize);\n}\n\nstatic void\nSTRING_copyswap (char *dst, char *src, int swap, int itemsize)\n{\n\tif (src != NULL) \n\t\tmemcpy(dst, src, itemsize);\n\t\n}\n\n/* ignore swap */\nstatic void\nVOID_copyswap (char *dst, char *src, int swap, int itemsize)\n{\n\tif (src != NULL) \n\t\tmemcpy(dst, src, itemsize);\t\n\treturn;\n}\n\nstatic void\nUNICODE_copyswap (char *dst, char *src, int swap, int itemsize)\n{\n\n\tif (src != NULL) \n\t\tmemcpy(dst, src, itemsize);\n\t\n\tif (swap) {\n\t\tregister char *a, *b, c;\n a = (char *)dst;\n b = a + 3;\n\t\tc=*a; *a++ = *b; *b-- = c;\n\t\tc=*a; *a++ = *b; *b-- = c;\n\t}\n}\n\n\n/****************** nonzero **********************************/\n\n/**begin repeat\n#fname=BOOL,BYTE,UBYTE,SHORT,USHORT,INT,UINT,LONG,ULONG,LONGLONG,ULONGLONG,FLOAT,DOUBLE,LONGDOUBLE#\n#type=Bool, byte, ubyte, short, ushort, int, uint, long, ulong, longlong, ulonglong, float, double, longdouble#\n*/\nstatic Bool \n@fname@_nonzero (@type@ *ip, PyArrayObject *ap)\n{\n\t@type@ t1;\n\tif (ap==NULL || PyArray_ISBEHAVED_RO(ap))\n\t\treturn (Bool) (*ip != 0);\n\telse {\n\t\t/* don't worry about swap, since we are just testing\n\t\t whether or not equal to 0 */\n\t\tmemcpy(&t1, ip, sizeof(@type@));\n\t\treturn (Bool) (t1 != 0);\n\t}\n}\n/**end repeat**/\n\n/**begin repeat\n#fname=CFLOAT,CDOUBLE,CLONGDOUBLE#\n#type=cfloat, cdouble, clongdouble#\n*/\nstatic Bool \n@fname@_nonzero (@type@ *ip, PyArrayObject *ap)\n{\n\t@type@ t1;\n\tif (ap==NULL || PyArray_ISBEHAVED_RO(ap))\n\t\treturn (Bool) ((ip->real != 0) || (ip->imag != 0));\n\telse {\n\t\t/* don't worry about swap, since we are just testing\n\t\t whether or not equal to 0 */\n\t\tmemcpy(&t1, ip, sizeof(@type@));\n\t\treturn (Bool) ((t1.real != 0) || (t1.imag != 0));\n\t}\n}\n/**end repeat**/\n\n\n\n#define WHITESPACE \" \\t\\n\\r\\v\\f\"\n#define WHITELEN 6\n\nstatic Bool\nPy_STRING_ISSPACE(char ch) \n{\n\tchar white[] = WHITESPACE;\n\tint j;\n\tBool space=FALSE;\n\tfor (j=0; jdescr->elsize;\n\tint i;\n\tBool nonz = FALSE;\n\n\tfor (i=0; idescr->elsize >> 2;\n\tint i;\n\tBool nonz = FALSE;\n\tchar *buffer=NULL;\t\n\n\tif ((!PyArray_ISNOTSWAPPED(ap)) || \\\n\t (!PyArray_ISALIGNED(ap))) {\n\t\tbuffer = _pya_malloc(ap->descr->elsize);\n\t\tif (buffer == NULL) {\n\t\t\treturn nonz;\n\t\t}\n\t\tmemcpy(buffer, ip, ap->descr->elsize);\n\t\tif (!PyArray_ISNOTSWAPPED(ap)) {\n\t\t\tbyte_swap_vector(buffer, len, 4);\n\t\t}\n\t\tip = (PyArray_UCS4 *)buffer;\n\t}\n\n\tfor (i=0; idescr->elsize;\n\tBool nonz = FALSE;\n\t\n\tfor (i=0; idescr->elsize);\n}\n\n/* taken from Python */\nstatic int \nUNICODE_compare(register PyArray_UCS4 *ip1, register PyArray_UCS4 *ip2, \n\t\tPyArrayObject *ap)\n{\n register int itemsize=ap->descr->elsize;\n\tregister PyArray_UCS4 c1, c2;\n\n\tif (itemsize < 0) return 0;\n\t\n\twhile(itemsize-- > 0) {\n\t\tc1 = *ip1++;\n\t\tc2 = *ip2++;\n\t\t\n\t\tif (c1 != c2) \n\t\t\treturn (c1 < c2) ? -1 : 1;\n\t}\n\treturn 0;\n}\n\n/* possibly redefine compare in terms of fields and subarrays if any */\n\n/* as it is, it compares raw-bytes as it they were strings */\n#define VOID_compare STRING_compare\n\n/****************** argfunc **********************************/\n\n/**begin repeat\n\n#fname= BOOL,BYTE, UBYTE, SHORT, USHORT, INT, UINT, LONG, ULONG, LONGLONG, ULONGLONG, FLOAT, DOUBLE, LONGDOUBLE, CFLOAT, CDOUBLE, CLONGDOUBLE#\n#type= Bool, byte, ubyte, short, ushort, int, uint, long, ulong, longlong, ulonglong, float, double, longdouble, float, double, longdouble#\n#incr= ip++*14, ip+=2*3#\n*/\n\nstatic int\n@fname@_argmax(@type@ *ip, intp n, intp *max_ind, PyArrayObject *aip)\n{\n\tregister intp i;\n\t@type@ mp=*ip;\n\t*max_ind=0;\n\tfor (i=1; i mp) {\n\t\t\tmp = *ip;\n\t\t\t*max_ind = i;\n\t\t}\n\t}\n\treturn 0;\n}\n\n/**end repeat**/\n\nstatic int \nOBJECT_argmax(PyObject **ip, intp n, intp *max_ind, PyArrayObject *aip) \n{\n\tregister intp i; \n\tPyObject *mp=ip[0]; *max_ind=0;\n\tfor(i=1; i 0) { \n\t\t\tmp = *ip; \n\t\t\t*max_ind=i;\n\t\t} \n\t} \n\treturn 0;\n}\n\n/**begin repeat\n\n#fname= STRING, UNICODE#\n#type= char, PyArray_UCS4#\n\n*/\nstatic int \n@fname@_argmax(@type@ *ip, intp n, intp *max_ind, PyArrayObject *aip) \n{\n\tregister intp i; \n\tint elsize = aip->descr->elsize;\n\t@type@ *mp = (@type@ *)_pya_malloc(elsize);\n\t\n\tif (mp==NULL) return 0;\n\tmemcpy(mp, ip, elsize);\n\t*max_ind = 0;\n\tfor(i=1; i 0) { \n\t\t\tmemcpy(mp, ip, elsize);\n\t\t\t*max_ind=i;\n\t\t} \n\t} \n\t_pya_free(mp);\n\treturn 0;\n}\n\n/**end repeat**/\n\n#define VOID_argmax NULL\n\nstatic void\nBOOL_dot(char *ip1, intp is1, char *ip2, intp is2, char *op, intp n, \n void *ignore)\n{\n\tregister Bool tmp=FALSE;\n\tregister intp i;\n\tfor(i=0;ireal;\n\tstart.imag = buffer->imag;\n\tdelta.real = buffer[1].real;\n\tdelta.imag = buffer[1].imag;\n\tdelta.real -= start.real;\n\tdelta.imag -= start.imag;\n\tbuffer += 2;\n\tfor (i=2; ireal = start.real + i*delta.real;\n\t\tbuffer->imag = start.imag + i*delta.imag;\n\t}\n}\n/**end repeat**/\n\n\n#define _ALIGN(type) offsetof(struct {char c; type v;},v)\n\n/**begin repeat\n\n#from= VOID, STRING, UNICODE#\n#align= char, char, PyArray_UCS4#\n#NAME= Void, String, Unicode#\n#endian= |, |, =#\n*/\n\nstatic PyArray_ArrFuncs _Py@NAME@_ArrFuncs = {\n\t{\n\t\t(PyArray_VectorUnaryFunc*)@from@_to_BOOL, \n\t\t(PyArray_VectorUnaryFunc*)@from@_to_BYTE, \n\t\t(PyArray_VectorUnaryFunc*)@from@_to_UBYTE, \n\t\t(PyArray_VectorUnaryFunc*)@from@_to_SHORT, \n\t\t(PyArray_VectorUnaryFunc*)@from@_to_USHORT, \n\t\t(PyArray_VectorUnaryFunc*)@from@_to_INT, \n\t\t(PyArray_VectorUnaryFunc*)@from@_to_UINT, \n\t\t(PyArray_VectorUnaryFunc*)@from@_to_LONG,\n\t\t(PyArray_VectorUnaryFunc*)@from@_to_ULONG, \n\t\t(PyArray_VectorUnaryFunc*)@from@_to_LONGLONG, \n\t\t(PyArray_VectorUnaryFunc*)@from@_to_ULONGLONG, \n\t\t(PyArray_VectorUnaryFunc*)@from@_to_FLOAT, \n\t\t(PyArray_VectorUnaryFunc*)@from@_to_DOUBLE, \n\t\t(PyArray_VectorUnaryFunc*)@from@_to_LONGDOUBLE, \n\t\t(PyArray_VectorUnaryFunc*)@from@_to_CFLOAT, \n\t\t(PyArray_VectorUnaryFunc*)@from@_to_CDOUBLE, \n\t\t(PyArray_VectorUnaryFunc*)@from@_to_CLONGDOUBLE, \n\t\t(PyArray_VectorUnaryFunc*)@from@_to_OBJECT, \n\t\t(PyArray_VectorUnaryFunc*)@from@_to_STRING, \n\t\t(PyArray_VectorUnaryFunc*)@from@_to_UNICODE, \n\t\t(PyArray_VectorUnaryFunc*)@from@_to_VOID\n\t},\n\t(PyArray_GetItemFunc*)@from@_getitem, \n\t(PyArray_SetItemFunc*)@from@_setitem,\n\t(PyArray_CopySwapNFunc*)@from@_copyswapn,\n\t(PyArray_CopySwapFunc*)@from@_copyswap,\n\t(PyArray_CompareFunc*)@from@_compare, \n\t(PyArray_ArgFunc*)@from@_argmax,\n\t(PyArray_DotFunc*)NULL, \n\t(PyArray_ScanFunc*)@from@_scan,\n\t(PyArray_FromStrFunc*)@from@_fromstr,\n\t(PyArray_NonzeroFunc*)@from@_nonzero,\n\t(PyArray_FillFunc*)NULL,\n\t{\n\t\tNULL, NULL, NULL, NULL\n\t},\n\t{\n\t\tNULL, NULL, NULL, NULL\n\t}\n};\n\nstatic PyArray_Descr @from@_Descr = { \n\tPyObject_HEAD_INIT(&PyArrayDescr_Type)\n\t&Py@NAME@ArrType_Type,\n\tPyArray_@from@LTR,\n\tPyArray_@from@LTR,\n\t'@endian@', 0,\n\tPyArray_@from@, 0,\n\t_ALIGN(@align@),\n\tNULL,\n\tNULL,\n\t&_Py@NAME@_ArrFuncs,\n};\n\n/**end repeat**/\n\n\n/**begin repeat\n\n#from= BOOL,BYTE,UBYTE,SHORT,USHORT,INT,UINT,LONG,ULONG,LONGLONG,ULONGLONG,FLOAT,DOUBLE,LONGDOUBLE,CFLOAT,CDOUBLE,CLONGDOUBLE,OBJECT#\n#num= 1*14,2*3,1#\n#fromtyp= Bool, byte, ubyte, short, ushort, int, uint, long, ulong, longlong, ulonglong, float, double, longdouble, float, double, longdouble, PyObject *#\n#NAME= Bool, Byte, UByte, Short, UShort, Int, UInt, Long, ULong, LongLong, ULongLong, Float, Double, LongDouble, CFloat, CDouble, CLongDouble, Object#\n#kind= GENBOOL, SIGNED, UNSIGNED, SIGNED, UNSIGNED, SIGNED, UNSIGNED, SIGNED, UNSIGNED, SIGNED, UNSIGNED, FLOATING, FLOATING, FLOATING, COMPLEX, COMPLEX, COMPLEX, OBJECT#\n#endian= |*3, =*14, |#\n#isobject= 0*17,1#\n*/\n\nstatic PyArray_ArrFuncs _Py@NAME@_ArrFuncs = {\n\t{\n\t\t(PyArray_VectorUnaryFunc*)@from@_to_BOOL, \n\t\t(PyArray_VectorUnaryFunc*)@from@_to_BYTE,\n\t\t(PyArray_VectorUnaryFunc*)@from@_to_UBYTE, \n\t\t(PyArray_VectorUnaryFunc*)@from@_to_SHORT, \n\t\t(PyArray_VectorUnaryFunc*)@from@_to_USHORT, \n\t\t(PyArray_VectorUnaryFunc*)@from@_to_INT, \n\t\t(PyArray_VectorUnaryFunc*)@from@_to_UINT, \n\t\t(PyArray_VectorUnaryFunc*)@from@_to_LONG,\n\t\t(PyArray_VectorUnaryFunc*)@from@_to_ULONG, \n\t\t(PyArray_VectorUnaryFunc*)@from@_to_LONGLONG, \n\t\t(PyArray_VectorUnaryFunc*)@from@_to_ULONGLONG, \n\t\t(PyArray_VectorUnaryFunc*)@from@_to_FLOAT, \n\t\t(PyArray_VectorUnaryFunc*)@from@_to_DOUBLE, \n\t\t(PyArray_VectorUnaryFunc*)@from@_to_LONGDOUBLE, \n\t\t(PyArray_VectorUnaryFunc*)@from@_to_CFLOAT, \n\t\t(PyArray_VectorUnaryFunc*)@from@_to_CDOUBLE, \n\t\t(PyArray_VectorUnaryFunc*)@from@_to_CLONGDOUBLE, \n\t\t(PyArray_VectorUnaryFunc*)@from@_to_OBJECT, \n\t\t(PyArray_VectorUnaryFunc*)@from@_to_STRING, \n\t\t(PyArray_VectorUnaryFunc*)@from@_to_UNICODE, \n\t\t(PyArray_VectorUnaryFunc*)@from@_to_VOID\n\t},\n\t(PyArray_GetItemFunc*)@from@_getitem, \n\t(PyArray_SetItemFunc*)@from@_setitem,\n\t(PyArray_CopySwapNFunc*)@from@_copyswapn,\n\t(PyArray_CopySwapFunc*)@from@_copyswap,\n\t(PyArray_CompareFunc*)@from@_compare, \n\t(PyArray_ArgFunc*)@from@_argmax,\n\t(PyArray_DotFunc*)@from@_dot, \n\t(PyArray_ScanFunc*)@from@_scan,\n\t(PyArray_FromStrFunc*)@from@_fromstr,\n\t(PyArray_NonzeroFunc*)@from@_nonzero,\n\t(PyArray_FillFunc*)@from@_fill,\n\t{\n\t\tNULL, NULL, NULL, NULL\n\t},\n\t{\n\t\tNULL, NULL, NULL, NULL\n\t}\n};\n\nstatic PyArray_Descr @from@_Descr = { \n\tPyObject_HEAD_INIT(&PyArrayDescr_Type)\n\t&Py@NAME@ArrType_Type,\n\tPyArray_@kind@LTR,\n\tPyArray_@from@LTR,\n\t'@endian@', @isobject@,\n\tPyArray_@from@, \n\t@num@*sizeof(@fromtyp@), \n\t_ALIGN(@fromtyp@),\n\tNULL,\n\tNULL,\n\t&_Py@NAME@_ArrFuncs,\n};\n\n/**end repeat**/\n\n#define _MAX_LETTER 128\nstatic char _letter_to_num[_MAX_LETTER];\n\nstatic PyArray_Descr *_builtin_descrs[] = {\n\t&BOOL_Descr,\n\t&BYTE_Descr,\n\t&UBYTE_Descr,\n\t&SHORT_Descr, \n\t&USHORT_Descr, \n\t&INT_Descr, \n\t&UINT_Descr, \n\t&LONG_Descr, \n\t&ULONG_Descr,\n\t&LONGLONG_Descr,\n\t&ULONGLONG_Descr,\n\t&FLOAT_Descr, \n\t&DOUBLE_Descr,\n\t&LONGDOUBLE_Descr,\n\t&CFLOAT_Descr, \n\t&CDOUBLE_Descr, \n\t&CLONGDOUBLE_Descr,\n\t&OBJECT_Descr, \n\t&STRING_Descr, \n\t&UNICODE_Descr,\n\t&VOID_Descr,\n};\n\n/*OBJECT_API\n Get the PyArray_Descr structure for a type.\n*/\nstatic PyArray_Descr *\nPyArray_DescrFromType(int type)\n{\n\tPyArray_Descr *ret=NULL;\n\n\tif (type < PyArray_NTYPES) {\n\t\tret = _builtin_descrs[type];\n\t}\n\telse if (type == PyArray_NOTYPE) {\n\t\t/* This needs to not raise an error so\n\t\t that PyArray_DescrFromType(PyArray_NOTYPE)\n\t\t works for backwards-compatible C-API \n\t\t*/\t\t\n\t\treturn NULL;\n\t}\n\telse if PyTypeNum_ISUSERDEF(type) {\n\t\tret = userdescrs[type-PyArray_USERDEF];\n\t} \n\telse {\n\t\tint num=PyArray_NTYPES;\n\t\tif (type < _MAX_LETTER) \n\t\t\tnum = (int) _letter_to_num[type];\n\t\tif (num >= PyArray_NTYPES)\n\t\t\tret = NULL;\n\t\telse\n\t\t\tret = _builtin_descrs[num];\n\t}\n\tif (ret==NULL) {\n\t\tPyErr_SetString(PyExc_ValueError, \n\t\t\t\t\"Invalid data-type for array\"); \n\t}\n\telse Py_INCREF(ret);\n\treturn ret;\n}\n\n\nstatic int\nset_typeinfo(PyObject *dict)\n{\n\tPyObject *infodict, *s;\n\tint i;\n\n\tfor (i=0; i<_MAX_LETTER; i++) {\n\t\t_letter_to_num[i] = PyArray_NTYPES;\n\t}\n\n/**begin repeat\n#name=BOOL,BYTE,UBYTE,SHORT,USHORT,INT,UINT,INTP,UINTP,LONG,ULONG,LONGLONG,ULONGLONG,FLOAT,DOUBLE,LONGDOUBLE,CFLOAT,CDOUBLE,CLONGDOUBLE,OBJECT,STRING,UNICODE,VOID#\n*/\n\t_letter_to_num[PyArray_@name@LTR] = PyArray_@name@;\n/**end repeat**/\n\t_letter_to_num[PyArray_STRINGLTR2] = PyArray_STRING;\n\n/**begin repeat\n#name=BOOL,BYTE,UBYTE,SHORT,USHORT,INT,UINT,LONG,ULONG,LONGLONG,ULONGLONG,FLOAT,DOUBLE,LONGDOUBLE,CFLOAT,CDOUBLE,CLONGDOUBLE,OBJECT,STRING,UNICODE,VOID#\n*/\n\t@name@_Descr.fields = Py_None;\n/**end repeat**/\n\t\n\t/* Set a dictionary with type information */\n\tinfodict = PyDict_New();\n\tif (infodict == NULL) return -1;\n\n#define BITSOF_INTP CHAR_BIT*SIZEOF_PY_INTPTR_T\n#define BITSOF_BYTE CHAR_BIT\n\n/**begin repeat \n\n#name=BOOL,BYTE,UBYTE,SHORT,USHORT,INT,UINT,INTP,UINTP,LONG,ULONG,LONGLONG,ULONGLONG#\n#uname=BOOL,BYTE*2,SHORT*2,INT*2,INTP*2,LONG*2,LONGLONG*2#\n#Name=Bool,Byte,UByte,Short,UShort,Int,UInt,Intp,UIntp,Long,ULong,LongLong,ULongLong#\n#type=Bool,byte,ubyte,short,ushort,int,uint,intp,uintp,long,ulong,longlong,ulonglong#\n#max=1,MAX_BYTE,MAX_UBYTE,MAX_SHORT,MAX_USHORT,MAX_INT,PyLong_FromUnsignedLong(MAX_UINT),PyLong_FromLongLong((longlong) MAX_INTP),PyLong_FromUnsignedLongLong((ulonglong) MAX_UINTP),MAX_LONG,PyLong_FromUnsignedLong((unsigned long) MAX_ULONG),PyLong_FromLongLong((longlong) MAX_LONGLONG), PyLong_FromUnsignedLongLong((ulonglong) MAX_ULONGLONG)#\n#min=0,MIN_BYTE,0,MIN_SHORT,0,MIN_INT,0,PyLong_FromLongLong((longlong) MIN_INTP),0,MIN_LONG,0,PyLong_FromLongLong((longlong) MIN_LONGLONG),0#\n#cx=i*6,N,N,N,l,N,N,N#\n#cn=i*7,N,i,l,i,N,i#\n*/\n \tPyDict_SetItemString(infodict, \"@name@\", \n\t\t\t s=Py_BuildValue(\"ciii@cx@@cn@O\", \n\t\t\t\t\t PyArray_@name@LTR, \n\t\t\t\t\t PyArray_@name@,\n\t\t\t\t\t BITSOF_@uname@,\n\t\t\t\t\t _ALIGN(@type@),\n\t\t\t\t\t @max@, @min@,\n\t\t\t\t (PyObject *)&Py@Name@ArrType_Type));\n\tPy_DECREF(s); \n/**end repeat**/\n\n#define BITSOF_CFLOAT 2*BITSOF_FLOAT\n#define BITSOF_CDOUBLE 2*BITSOF_DOUBLE\n#define BITSOF_CLONGDOUBLE 2*BITSOF_LONGDOUBLE\n\n/**begin repeat\n\n#type=float,double,longdouble,cfloat,cdouble,clongdouble#\n#name=FLOAT, DOUBLE, LONGDOUBLE, CFLOAT, CDOUBLE, CLONGDOUBLE#\n#Name=Float,Double,LongDouble,CFloat,CDouble,CLongDouble#\n*/\n \tPyDict_SetItemString(infodict, \"@name@\", \n\t\t\t s=Py_BuildValue(\"ciiiO\", PyArray_@name@LTR, \n\t\t\t\t\t PyArray_@name@, BITSOF_@name@,\n\t\t\t\t\t _ALIGN(@type@),\n (PyObject *)\\\n &Py@Name@ArrType_Type));\n\tPy_DECREF(s);\n/**end repeat**/\n\t\n\tPyDict_SetItemString(infodict, \"OBJECT\", \n\t\t\t s=Py_BuildValue(\"ciiiO\", PyArray_OBJECTLTR, \n\t\t\t\t\t PyArray_OBJECT, \n\t\t\t\t\t sizeof(PyObject *)*CHAR_BIT,\n\t\t\t\t\t _ALIGN(PyObject *),\n (PyObject *)\\\n &PyObjectArrType_Type));\n\tPy_DECREF(s);\n\tPyDict_SetItemString(infodict, \"STRING\", \n\t\t\t s=Py_BuildValue(\"ciiiO\", PyArray_STRINGLTR, \n\t\t\t\t\t PyArray_STRING, 0,\n\t\t\t\t\t _ALIGN(char),\n (PyObject *)\\\n &PyStringArrType_Type));\n\tPy_DECREF(s);\n\tPyDict_SetItemString(infodict, \"UNICODE\", \n\t\t\t s=Py_BuildValue(\"ciiiO\", PyArray_UNICODELTR, \n\t\t\t\t\t PyArray_UNICODE, 0,\n\t\t\t\t\t _ALIGN(PyArray_UCS4),\n (PyObject *)\\\n &PyUnicodeArrType_Type));\t\n\tPy_DECREF(s);\n\tPyDict_SetItemString(infodict, \"VOID\", \n\t\t\t s=Py_BuildValue(\"ciiiO\", PyArray_VOIDLTR, \n\t\t\t\t\t PyArray_VOID, 0,\n\t\t\t\t\t _ALIGN(char),\n (PyObject *)\\\n &PyVoidArrType_Type));\t\n\tPy_DECREF(s);\n\n#define SETTYPE(name) \\\n Py_INCREF(&Py##name##ArrType_Type); \\\n PyDict_SetItemString(infodict, #name, \\\n (PyObject *)&Py##name##ArrType_Type);\n\n SETTYPE(Generic)\n SETTYPE(Number)\n SETTYPE(Integer)\n\tSETTYPE(Inexact)\n SETTYPE(SignedInteger)\n SETTYPE(UnsignedInteger)\n SETTYPE(Floating)\n SETTYPE(ComplexFloating)\n SETTYPE(Flexible)\n SETTYPE(Character)\n\n#undef SETTYPE \t\n\n\tPyDict_SetItemString(dict, \"typeinfo\", infodict);\n\tPy_DECREF(infodict);\n\treturn 0;\n}\n\n#undef _MAX_LETTER\n\n", + "source_code_before": "/* -*- c -*- */\n\n/**begin repeat\n#name=UnsignedLong,UnsignedLongLong,LongLong#\n#type=ulong,ulonglong,longlong#\n */\nstatic @type@\nMyPyLong_As@name@(PyObject *vv)\n{\n\t@type@ ret;\n\n\tif (!PyLong_Check(vv)) {\n\t\tPyObject *mylong;\n\t\tmylong = PyNumber_Long(vv);\n\t\tif (mylong == NULL) return (@type@) -1;\n\t\tvv = mylong;\n\t}\n\telse Py_INCREF(vv);\n\n\tret = PyLong_As@name@(vv);\n\tPy_DECREF(vv);\n\treturn ret;\n}\n/**end repeat**/\n\n\nstatic double \n_getNAN(void) {\n#ifdef NAN\n return NAN;\n#else\n static double nan=0;\n \n if (nan == 0) {\n\t\tdouble mul = 1e100;\n\t\tdouble tmp = 0.0;\n\t\tdouble pinf=0;\n pinf = mul;\n for (;;) {\n pinf *= mul;\n if (pinf == tmp) break;\n tmp = pinf;\n }\n nan = pinf / pinf;\n }\n return nan;\n#endif\n}\n\nstatic double\nMyPyFloat_AsDouble(PyObject *obj)\n{\n if (obj == Py_None) return _getNAN();\n return PyFloat_AsDouble(obj); \n}\n\n\n/****************** getitem and setitem **********************/\n\n/**begin repeat\n\n#TYP=BOOL,BYTE,UBYTE,SHORT,USHORT,INT,LONG,UINT,ULONG,LONGLONG,ULONGLONG,FLOAT,DOUBLE#\n#func1=PyBool_FromLong, PyInt_FromLong*6, PyLong_FromUnsignedLong*2, PyLong_FromLongLong, PyLong_FromUnsignedLongLong, PyFloat_FromDouble*2#\n#func2=PyObject_IsTrue, PyInt_AsLong*6, MyPyLong_AsUnsignedLong*2, MyPyLong_AsLongLong, MyPyLong_AsUnsignedLongLong, MyPyFloat_AsDouble*2#\n#typ=Bool, byte, ubyte, short, ushort, int, long, uint, ulong, longlong, ulonglong, float, double#\n#typ1=long*7, ulong*2, longlong, ulonglong, float, double#\n#kind=Bool, Byte, UByte, Short, UShort, Int, Long, UInt, ULong, LongLong, ULongLong, Float, Double#\n*/\n\nstatic PyObject * \n@TYP@_getitem(char *ip, PyArrayObject *ap) {\n @typ@ t1;\n\n\tif ((ap==NULL) || PyArray_ISBEHAVED_RO(ap)) {\n t1 = *((@typ@ *)ip);\n return @func1@((@typ1@)t1);\n\t}\n\telse {\n ap->descr->f->copyswap(&t1, ip, !PyArray_ISNOTSWAPPED(ap),\n\t\t\t\t ap->descr->elsize);\n return @func1@((@typ1@)t1);\n\t}\n}\n\nstatic int \n@TYP@_setitem(PyObject *op, char *ov, PyArrayObject *ap) {\n @typ@ temp; /* ensures alignment */\n\n if (PyArray_IsScalar(op, @kind@)) {\n temp = ((Py@kind@ScalarObject *)op)->obval;\n }\n else {\n temp = (@typ@)@func2@(op);\n }\n if (PyErr_Occurred()) return -1;\n if (ap == NULL || PyArray_ISBEHAVED(ap)) \n *((@typ@ *)ov)=temp;\n else {\n ap->descr->f->copyswap(ov, &temp, !PyArray_ISNOTSWAPPED(ap), \n\t\t\t\t ap->descr->elsize);\n }\n \n return 0;\n}\n\n/**end repeat**/\n\n\n/**begin repeat \n\n#TYP=CFLOAT,CDOUBLE#\n#typ=float, double#\n*/\n\nstatic PyObject * \n@TYP@_getitem(char *ip, PyArrayObject *ap) {\n @typ@ t1, t2;\n\n if ((ap==NULL) || PyArray_ISBEHAVED_RO(ap)) { \n return PyComplex_FromDoubles((double)((@typ@ *)ip)[0], \n (double)((@typ@ *)ip)[1]);\n }\n else {\n\t\tint size = sizeof(@typ@);\n\t\tBool swap = !PyArray_ISNOTSWAPPED(ap);\n copy_and_swap(&t1, ip, size, 1, 0, swap);\n copy_and_swap(&t2, ip+size, size, 1, 0, swap);\n return PyComplex_FromDoubles((double)t1, (double)t2);\n }\n}\n/**end repeat**/\n\n/**begin repeat \n\n#TYP=CFLOAT, CDOUBLE, CLONGDOUBLE#\n#typ=float, double, longdouble#\n#kind=CFloat, CDouble, CLongDouble#\n*/\nstatic int \n@TYP@_setitem(PyObject *op, char *ov, PyArrayObject *ap) \n{\n Py_complex oop;\n PyObject *op2;\n c@typ@ temp;\n\tint rsize;\n \n if (!(PyArray_IsScalar(op, @kind@))) {\n if (PyArray_Check(op) && (PyArray_NDIM(op)==0)) {\n op2 = ((PyArrayObject *)op)->descr->f->getitem \\\n (((PyArrayObject *)op)->data, \n (PyArrayObject *)op);\n\t\t}\n\t\telse { \n op2 = op; Py_INCREF(op);\n }\n if (op2 == Py_None) {\n oop.real = oop.imag = _getNAN();\n }\n else {\n oop = PyComplex_AsCComplex (op2);\n }\n Py_DECREF(op2);\n if (PyErr_Occurred()) return -1;\n temp.real = (@typ@) oop.real;\n temp.imag = (@typ@) oop.imag; \n }\n\telse {\n temp = ((Py@kind@ScalarObject *)op)->obval;\n }\n\t\n memcpy(ov, &temp, ap->descr->elsize);\n if (!PyArray_ISNOTSWAPPED(ap))\n byte_swap_vector(ov, 2, sizeof(@typ@));\n\t\n\trsize = sizeof(@typ@);\n\tcopy_and_swap(ov, &temp, rsize, 2, rsize, !PyArray_ISNOTSWAPPED(ap));\n return 0;\n}\n/**end repeat**/\n\nstatic PyObject * \nLONGDOUBLE_getitem(char *ip, PyArrayObject *ap) \n{\n return PyArray_Scalar(ip, ap->descr, NULL);\n}\n\nstatic int \nLONGDOUBLE_setitem(PyObject *op, char *ov, PyArrayObject *ap) {\n longdouble temp; /* ensures alignment */\n\n if (PyArray_IsScalar(op, LongDouble)) {\n temp = ((PyLongDoubleScalarObject *)op)->obval;\n }\n else {\n if (op == Py_None) temp = (longdouble)_getNAN();\n else temp = (longdouble)PyFloat_AsDouble(op);\n }\n if (PyErr_Occurred()) return -1;\n if (ap == NULL || PyArray_ISBEHAVED(ap)) \n *((longdouble *)ov)=temp;\n else {\n copy_and_swap(ov, &temp, ap->descr->elsize, 1, 0,\n !PyArray_ISNOTSWAPPED(ap));\n }\n \n return 0;\n}\n\nstatic PyObject * \nCLONGDOUBLE_getitem(char *ip, PyArrayObject *ap) \n{\n return PyArray_Scalar(ip, ap->descr, NULL);\n}\n\n\n/* UNICODE */\nstatic PyObject * \nUNICODE_getitem(char *ip, PyArrayObject *ap) \n{\n\tPyObject *obj;\n\tint mysize;\n\tPyArray_UCS4 *dptr;\n\n\tmysize = ap->descr->elsize >> 2;\n\tdptr = (PyArray_UCS4 *)ip + mysize-1;\n\twhile(mysize > 0 && *dptr-- == 0) mysize--;\n\tif (!PyArray_ISNOTSWAPPED(ap) && (obj != NULL)) {\n\t\tbyte_swap_vector(PyArray_BYTES(ap), mysize, 4);\n\t}\n#ifdef Py_UNICODE_WIDE\n\tobj = PyUnicode_FromUnicode((const PyArray_UCS4 *)ip, mysize);\n#else\n\t/* create new empty unicode object of length mysize*2 */\n\tobj = MyPyUnicode_New(mysize*2);\n\tif (obj == NULL) return obj;\n\tmysize = PyUCS2Buffer_FromUCS4(((PyUnicodeObject *)obj)->str, \n\t\t\t\t (PyArray_UCS4 *)ip, mysize);\n\t/* reset length of unicode object to ucs2size */\n\tif (MyPyUnicode_Resize((PyUnicodeObject *)obj, mysize) < 0) {\n\t\tPy_DECREF(obj);\n\t\treturn NULL;\n\t}\n#endif\n\n\treturn obj;\n}\n\nstatic int \nUNICODE_setitem(PyObject *op, char *ov, PyArrayObject *ap) \n{\n PyObject *temp;\n\tPy_UNICODE *ptr;\n\tint datalen;\n\n\tif ((temp=PyObject_Unicode(op)) == NULL) return -1;\n\tptr = PyUnicode_AS_UNICODE(temp);\n\tif ((ptr == NULL) || (PyErr_Occurred())) {\n\t\tPy_DECREF(temp);\n\t\treturn -1;\n\t}\n\tdatalen = PyUnicode_GET_DATA_SIZE(temp);\n\n#ifdef Py_UNICODE_WIDE\n\tmemcpy(ov, ptr, MIN(ap->descr->elsize, datalen));\n#else\n datalen = PyUCS2Buffer_AsUCS4(ptr, (PyArray_UCS4 *)ov, datalen >> 1,\n\t\t\t\t ap->descr->elsize >> 2);\n\tdatalen <<= 2;\n#endif\n\t/* Fill in the rest of the space with 0 */\n\tif (ap->descr->elsize > datalen) {\n\t\tmemset(ov + datalen, 0, (ap->descr->elsize - datalen));\n\t}\n\t\n\tif (!PyArray_ISNOTSWAPPED(ap)) \n\t\tbyte_swap_vector(ov, ap->descr->elsize >> 2, 4);\n\tPy_DECREF(temp);\n\treturn 0;\n}\n\n/* STRING -- can handle both NULL-terminated and not NULL-terminated cases */\nstatic PyObject * \nSTRING_getitem(char *ip, PyArrayObject *ap) \n{\n\tif (ip[ap->descr->elsize-1])\n\t\treturn PyString_FromStringAndSize(ip,ap->descr->elsize);\n\telse\n\t\treturn PyString_FromString(ip);\n}\n\nstatic int \nSTRING_setitem(PyObject *op, char *ov, PyArrayObject *ap) \n{\n\tchar *ptr;\n\tint len;\n\tPyObject *temp=PyObject_Str(op);\n\t\n\tif (temp == NULL) return -1;\n\t\n\tif (PyString_AsStringAndSize(temp, &ptr, &len) == -1) {\n\t\tPy_DECREF(temp);\n\t\treturn -1;\n\t}\n\tmemcpy(ov, ptr, MIN(ap->descr->elsize,len));\n\tif (ap->descr->elsize > len) {\n\t\tmemset(ov + len, 0, (ap->descr->elsize - len));\n\t}\n\tPy_DECREF(temp);\n\treturn 0;\n}\n\n/* OBJECT */\n\nstatic PyObject * \nOBJECT_getitem(char *ip, PyArrayObject *ap) \n{\n\tPy_INCREF(*(PyObject **)ip);\n\treturn *(PyObject **)ip;\n}\n\nstatic int \nOBJECT_setitem(PyObject *op, char *ov, PyArrayObject *ap) \n{\n\tPy_XDECREF(*(PyObject **)ov);\n\tPy_INCREF(op);\n\t*(PyObject **)ov = op;\n\treturn PyErr_Occurred() ? -1:0;\n}\n\n/* VOID */\n\nstatic PyObject *\nVOID_getitem(char *ip, PyArrayObject *ap)\n{\n PyObject *u=NULL;\n\tPyArray_Descr* descr;\n int itemsize;\n\n\tdescr = ap->descr;\n\tif (descr->fields && descr->fields != Py_None) {\n\t\tPyObject *key;\n\t\tPyObject *names;\n\t\tint i, n;\n\t\tPyObject *ret;\n\t\tPyObject *tup, *title;\n\t\tPyArray_Descr *new;\n\t\tint offset;\n\t\tint savedflags;\n\n\t\t/* get the names from the fields dictionary*/\n\t\tkey = PyInt_FromLong(-1);\n\t\tnames = PyDict_GetItem(descr->fields, key);\n\t\tPy_DECREF(key);\n\t\tif (!names) goto finish;\n\t\tn = PyList_GET_SIZE(names);\n\t\tret = PyTuple_New(n);\n\t\tsavedflags = ap->flags;\n\t\tfor (i=0; ifields, key);\n\t\t\tif (!PyArg_ParseTuple(tup, \"Oi|O\", &new, &offset, \n\t\t\t\t\t &title)) {\n\t\t\t\tPy_DECREF(ret); \n\t\t\t\tap->descr = descr;\n\t\t\t\treturn NULL;\n\t\t\t}\n\t\t\tap->descr = new;\n\t\t\t/* update alignment based on offset */\n\t\t\tif ((new->alignment > 1) &&\t\t\t\\\n\t\t\t ((((intp)(ip+offset)) % new->alignment) != 0))\n\t\t\t\tap->flags &= ~ALIGNED;\n\t\t\telse\n\t\t\t\tap->flags |= ALIGNED;\n\n\t\t\tPyTuple_SET_ITEM(ret, i,\t\t\t\\\n\t\t\t\t\t new->f->getitem(ip+offset, ap));\n\t\t\tap->flags = savedflags;\n\t\t}\n\t\tap->descr = descr;\n\t\treturn ret;\n\t}\n\n\tif (descr->subarray) {\n\t\t/* return an array of the basic type */\n\t\tPyArray_Dims shape={NULL,-1};\n\t\tPyObject *ret;\n\t\tif (!(PyArray_IntpConverter(descr->subarray->shape, \n\t\t\t\t\t &shape))) {\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\treturn NULL;\n\t\t}\n Py_INCREF(descr->subarray->base);\n\t\tret = PyArray_NewFromDescr(&PyArray_Type,\n\t\t\t\t\t descr->subarray->base,\n\t\t\t\t\t shape.len, shape.ptr,\n\t\t\t\t\t NULL, ip, ap->flags, NULL);\n\t\tPyDimMem_FREE(shape.ptr);\n\t\tif (!ret) return NULL;\n\t\tPyArray_BASE(ret) = (PyObject *)ap;\n\t\tPy_INCREF(ap);\n\t\tPyArray_UpdateFlags((PyArrayObject *)ret, UPDATE_ALL_FLAGS);\n\t\treturn ret;\n\t}\n\n finish:\n\titemsize=ap->descr->elsize;\n\tif (PyArray_ISWRITEABLE(ap))\n\t\tu = PyBuffer_FromReadWriteMemory(ip, itemsize);\n\telse\n\t\tu = PyBuffer_FromMemory(ip, itemsize);\n\tif (u==NULL) goto fail;\n\n\t/* default is to return buffer object pointing to current item */\n\t/* a view of it */\n\treturn u; \n\t\n fail:\n return NULL;\n}\n\n\n\nstatic int PyArray_CopyObject(PyArrayObject *, PyObject *);\n\nstatic int\nVOID_setitem(PyObject *op, char *ip, PyArrayObject *ap)\n{\n\tPyArray_Descr* descr;\n int itemsize=ap->descr->elsize;\n\tint res;\n\n\tdescr = ap->descr;\n\tif (descr->fields && (descr->fields != Py_None) && \\\n\t PyTuple_Check(op)) {\n\t\tPyObject *key;\n\t\tPyObject *names;\n\t\tint i, n;\n\t\tPyObject *tup, *title;\n\t\tPyArray_Descr *new;\n\t\tint offset;\n\t\tint savedflags;\n\t\tres = -1;\n\t\t/* get the names from the fields dictionary*/\n\t\tkey = PyInt_FromLong(-1);\n\t\tnames = PyDict_GetItem(descr->fields, key);\n\t\tPy_DECREF(key);\n\t\tif (!names) goto finish;\n\t\tn = PyList_GET_SIZE(names);\n\t\tif (PyTuple_GET_SIZE(op) != n) {\n\t\t\tPyErr_SetString(PyExc_ValueError, \n\t\t\t\t\t\"size of tuple must match\"\\\n\t\t\t\t\t\"number of fields.\");\n\t\t\treturn -1;\n\t\t}\n\t\tsavedflags = ap->flags;\n\t\tfor (i=0; ifields, key);\n\t\t\tif (!PyArg_ParseTuple(tup, \"Oi|O\", &new, &offset, \n\t\t\t\t\t &title)) {\n\t\t\t\tap->descr = descr;\n\t\t\t\treturn -1;\n\t\t\t}\n\t\t\tap->descr = new;\n\t\t\t/* remember to update alignment flags */\n\t\t\tif ((new->alignment > 1) &&\t\t\t\\\n\t\t\t ((((intp)(ip+offset)) % new->alignment) != 0))\n\t\t\t\tap->flags &= ~ALIGNED;\n\t\t\telse\n\t\t\t\tap->flags |= ALIGNED;\n\n\t\t\tres = new->f->setitem(PyTuple_GET_ITEM(op, i),\n\t\t\t\t\t ip+offset, ap);\n\t\t\tap->flags = savedflags;\n\t\t\tif (res < 0) break;\n\t\t}\n\t\tap->descr = descr;\n\t\treturn res;\n\t}\n\n\tif (descr->subarray) {\n\t\t/* copy into an array of the same basic type */\n\t\tPyArray_Dims shape={NULL,-1};\n\t\tPyObject *ret;\n\t\tif (!(PyArray_IntpConverter(descr->subarray->shape, \n\t\t\t\t\t &shape))) {\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\treturn -1;\n\t\t}\n Py_INCREF(descr->subarray->base);\n\t\tret = PyArray_NewFromDescr(&PyArray_Type,\n\t\t\t\t\t descr->subarray->base,\n\t\t\t\t\t shape.len, shape.ptr,\n\t\t\t\t\t NULL, ip, ap->flags, NULL);\n\t\tPyDimMem_FREE(shape.ptr);\n\t\tif (!ret) return -1;\n\t\tPyArray_BASE(ret) = (PyObject *)ap;\n\t\tPy_INCREF(ap);\n\t\tPyArray_UpdateFlags((PyArrayObject *)ret, UPDATE_ALL_FLAGS);\n\t\tres = PyArray_CopyObject((PyArrayObject *)ret, op);\n\t\tPy_DECREF(ret);\n\t\treturn res;\n\t}\n\n finish:\n\t/* Default is to use buffer interface to set item */\n\t{\n\t\tconst void *buffer;\n\t\tint buflen;\n\t\tres = PyObject_AsReadBuffer(op, &buffer, &buflen);\n\t\tif (res == -1) goto fail;\n\t\tmemcpy(ip, buffer, MIN(buflen, itemsize));\n }\n\treturn 0;\n\n fail:\n return -1; \n}\n\n\n/****************** XXX_to_YYY *******************************/ \n\n/* Assumes contiguous, and aligned, from and to */\n\n\n/**begin repeat\n#to=(BYTE,UBYTE,SHORT,USHORT,INT,UINT,LONG,ULONG,LONGLONG,ULONGLONG,FLOAT,DOUBLE,LONGDOUBLE)*16#\n#from=BYTE*13,UBYTE*13,SHORT*13,USHORT*13,INT*13,UINT*13,LONG*13,ULONG*13,LONGLONG*13,ULONGLONG*13,FLOAT*13,DOUBLE*13,LONGDOUBLE*13,CFLOAT*13,CDOUBLE*13,CLONGDOUBLE*13#\n#totyp=(byte, ubyte, short, ushort, int, uint, long, ulong, longlong, ulonglong, float, double, longdouble)*16#\n#fromtyp=byte*13, ubyte*13, short*13, ushort*13, int*13, uint*13, long*13, ulong*13, longlong*13, ulonglong*13, float*13, double*13, longdouble*13, float*13, double*13, longdouble*13#\n#incr= ip++*169,ip+=2*39#\n*/\nstatic void \n@from@_to_@to@(@fromtyp@ *ip, @totyp@ *op, intp n, PyArrayObject *aip, \n\t PyArrayObject *aop) {\n\tregister intp i; \n\tfor(i=0;idescr->elsize*3, 1#\n*/\nstatic void \n@from@_to_OBJECT(@fromtyp@ *ip, PyObject **op, intp n, PyArrayObject *aip,\n\t\t PyArrayObject *aop)\n{\n\tregister intp i; \n\tint skip=@skip@;\n\tfor(i=0;idescr->elsize*3#\n*/\nstatic void \nOBJECT_to_@to@(PyObject **ip, @totyp@ *op, intp n, PyArrayObject *aip,\n\t\t PyArrayObject *aop)\n{\n\tregister intp i; \n\tint skip=@skip@;\n\tfor(i=0;idescr->elsize*3)*3#\n#convert=1*17,0*3,1*17,0*3,0*20#\n#convstr=(Int*9,Long*2,Float*3,Complex*3,Tuple*3)*3#\n*/\nstatic void\n@from@_to_@to@(@fromtyp@ *ip, @totyp@ *op, intp n, PyArrayObject *aip, \n\t PyArrayObject *aop)\n{\n\tregister intp i;\n\tPyObject *temp=NULL;\n\tint skip=aip->descr->elsize;\n\tint oskip=@oskip@;\n\tfor(i=0; idescr->elsize;\n\tfor(i=0; i= 0x02040000) || defined(PyOS_ascii_strtod)\nstatic int\n@fname@_fromstr(char *str, @type@ *ip, char **endptr, void *ignore)\n{\n\tdouble result;\n\n\tresult = PyOS_ascii_strtod(str, endptr);\n\t*ip = (@type@) result;\n\treturn 0;\n}\n#else\n#define @fname@_fromstr NULL\n#endif\n/**end repeat**/\n\n\n\n/**begin repeat\n#fname=BOOL,CFLOAT,CDOUBLE,CLONGDOUBLE,OBJECT,STRING,UNICODE,VOID#\n*/\n#define @fname@_fromstr NULL\n/**end repeat**/\n\n\n/****************** copyswapn *************************************/\n\n/**begin repeat\n\n#fname=SHORT,USHORT,INT,UINT,LONG,ULONG,LONGLONG,ULONGLONG,FLOAT,DOUBLE,LONGDOUBLE#\n#fsize=SHORT,SHORT,INT,INT,LONG,LONG,LONGLONG,LONGLONG,FLOAT,DOUBLE,LONGDOUBLE#\n#type=short,ushort,int,uint,long,ulong,longlong,ulonglong,float,double,longdouble#\n*/\nstatic void\n@fname@_copyswapn (void *dst, void *src, intp n, int swap, int itemsize)\n{\n\tif (src != NULL) /* copy first if needed */\n\t\tmemcpy(dst, src, n*sizeof(@type@));\n\n\tif (swap) {\n\t\tregister char *a, *b, c;\n\t\tfor (a = (char *)dst; n>0; n--) {\n#if SIZEOF_@fsize@ == 2\n\t\t\tb = a + 1;\n\t\t\tc = *a; *a++ = *b; *b = c;\n\t\t\ta += 1;\n#elif SIZEOF_@fsize@ == 4\n\t\t\tb = a + 3;\n c = *a; *a++ = *b; *b-- = c;\n c = *a; *a++ = *b; *b = c;\n\t\t\ta += 2;\n#elif SIZEOF_@fsize@ == 8\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\t\t\ta += 4;\n#elif SIZEOF_@fsize@ == 10\n b = a + 9;\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 c = *a; *a++ = *b; *b = c;\n\t\t\ta += 5;\n#elif SIZEOF_@fsize@ == 12\n b = a + 11;\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 c = *a; *a++ = *b; *b-- = c;\n c = *a; *a++ = *b; *b = c;\n\t\t\ta += 6;\n#elif SIZEOF_@fsize@ == 16\n b = a + 15;\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 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\t\t\ta += 8;\n#else\n\t\t\tregister int i, nn;\n b = a + (SIZEOF_@fsize@-1);\n\t\t\tnn = SIZEOF_@fsize@ / 2;\n for (i=0; i0; nn--) {\n#if SIZEOF_@fsize@ == 4\n\t\t\tb = a + 3;\n c = *a; *a++ = *b; *b-- = c;\n c = *a; *a++ = *b; *b = c;\n\t\t\ta += 2;\n#elif SIZEOF_@fsize@ == 8\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\t\t\ta += 4;\n#elif SIZEOF_@fsize@ == 10\n b = a + 9;\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 c = *a; *a++ = *b; *b = c;\n\t\t\ta += 5;\n#elif SIZEOF_@fsize@ == 12\n b = a + 11;\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 c = *a; *a++ = *b; *b-- = c;\n c = *a; *a++ = *b; *b = c;\n\t\t\ta += 6;\n#elif SIZEOF_@fsize@ == 16\n b = a + 15;\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 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\t\t\ta += 8;\n#else\n\t\t\tregister int i, kn;\n\n b = a + (SIZEOF_@fsize@-1);\n\t\t\tkn = SIZEOF_@fsize@ / 2;\n for (i=0; i0; n--) {\n\t\t\tb = a + 3;\n\t\t\tc=*a; *a++ = *b; *b-- = c;\n\t\t\tc=*a; *a++ = *b; *b-- = c;\n\t\t\ta += 1;\n\t\t}\n\t}\n}\n\n\nstatic void\nOBJECT_copyswap (PyObject **dst, PyObject **src, int swap, int itemsize)\n{\n OBJECT_copyswapn(dst, src, 1, swap, itemsize);\n}\n\nstatic void\nSTRING_copyswap (char *dst, char *src, int swap, int itemsize)\n{\n\tif (src != NULL) \n\t\tmemcpy(dst, src, itemsize);\n\t\n}\n\n/* ignore swap */\nstatic void\nVOID_copyswap (char *dst, char *src, int swap, int itemsize)\n{\n\tif (src != NULL) \n\t\tmemcpy(dst, src, itemsize);\t\n\treturn;\n}\n\nstatic void\nUNICODE_copyswap (char *dst, char *src, int swap, int itemsize)\n{\n\n\tif (src != NULL) \n\t\tmemcpy(dst, src, itemsize);\n\t\n\tif (swap) {\n\t\tregister char *a, *b, c;\n a = (char *)dst;\n b = a + 3;\n\t\tc=*a; *a++ = *b; *b-- = c;\n\t\tc=*a; *a++ = *b; *b-- = c;\n\t}\n}\n\n\n/****************** nonzero **********************************/\n\n/**begin repeat\n#fname=BOOL,BYTE,UBYTE,SHORT,USHORT,INT,UINT,LONG,ULONG,LONGLONG,ULONGLONG,FLOAT,DOUBLE,LONGDOUBLE#\n#type=Bool, byte, ubyte, short, ushort, int, uint, long, ulong, longlong, ulonglong, float, double, longdouble#\n*/\nstatic Bool \n@fname@_nonzero (@type@ *ip, PyArrayObject *ap)\n{\n\t@type@ t1;\n\tif (ap==NULL || PyArray_ISBEHAVED_RO(ap))\n\t\treturn (Bool) (*ip != 0);\n\telse {\n\t\t/* don't worry about swap, since we are just testing\n\t\t whether or not equal to 0 */\n\t\tmemcpy(&t1, ip, sizeof(@type@));\n\t\treturn (Bool) (t1 != 0);\n\t}\n}\n/**end repeat**/\n\n/**begin repeat\n#fname=CFLOAT,CDOUBLE,CLONGDOUBLE#\n#type=cfloat, cdouble, clongdouble#\n*/\nstatic Bool \n@fname@_nonzero (@type@ *ip, PyArrayObject *ap)\n{\n\t@type@ t1;\n\tif (ap==NULL || PyArray_ISBEHAVED_RO(ap))\n\t\treturn (Bool) ((ip->real != 0) || (ip->imag != 0));\n\telse {\n\t\t/* don't worry about swap, since we are just testing\n\t\t whether or not equal to 0 */\n\t\tmemcpy(&t1, ip, sizeof(@type@));\n\t\treturn (Bool) ((t1.real != 0) || (t1.imag != 0));\n\t}\n}\n/**end repeat**/\n\n\n\n#define WHITESPACE \" \\t\\n\\r\\v\\f\"\n#define WHITELEN 6\n\nstatic Bool\nPy_STRING_ISSPACE(char ch) \n{\n\tchar white[] = WHITESPACE;\n\tint j;\n\tBool space=FALSE;\n\tfor (j=0; jdescr->elsize;\n\tint i;\n\tBool nonz = FALSE;\n\n\tfor (i=0; idescr->elsize >> 2;\n\tint i;\n\tBool nonz = FALSE;\n\tchar *buffer=NULL;\t\n\n\tif ((!PyArray_ISNOTSWAPPED(ap)) || \\\n\t (!PyArray_ISALIGNED(ap))) {\n\t\tbuffer = _pya_malloc(ap->descr->elsize);\n\t\tif (buffer == NULL) {\n\t\t\treturn nonz;\n\t\t}\n\t\tmemcpy(buffer, ip, ap->descr->elsize);\n\t\tif (!PyArray_ISNOTSWAPPED(ap)) {\n\t\t\tbyte_swap_vector(buffer, len, 4);\n\t\t}\n\t\tip = (PyArray_UCS4 *)buffer;\n\t}\n\n\tfor (i=0; idescr->elsize;\n\tBool nonz = FALSE;\n\t\n\tfor (i=0; idescr->elsize);\n}\n\n/* taken from Python */\nstatic int \nUNICODE_compare(register PyArray_UCS4 *ip1, register PyArray_UCS4 *ip2, \n\t\tPyArrayObject *ap)\n{\n register int itemsize=ap->descr->elsize;\n\tregister PyArray_UCS4 c1, c2;\n\n\tif (itemsize < 0) return 0;\n\t\n\twhile(itemsize-- > 0) {\n\t\tc1 = *ip1++;\n\t\tc2 = *ip2++;\n\t\t\n\t\tif (c1 != c2) \n\t\t\treturn (c1 < c2) ? -1 : 1;\n\t}\n\treturn 0;\n}\n\n/* possibly redefine compare in terms of fields and subarrays if any */\n\n/* as it is, it compares raw-bytes as it they were strings */\n#define VOID_compare STRING_compare\n\n/****************** argfunc **********************************/\n\n/**begin repeat\n\n#fname= BOOL,BYTE, UBYTE, SHORT, USHORT, INT, UINT, LONG, ULONG, LONGLONG, ULONGLONG, FLOAT, DOUBLE, LONGDOUBLE, CFLOAT, CDOUBLE, CLONGDOUBLE#\n#type= Bool, byte, ubyte, short, ushort, int, uint, long, ulong, longlong, ulonglong, float, double, longdouble, float, double, longdouble#\n#incr= ip++*14, ip+=2*3#\n*/\n\nstatic int\n@fname@_argmax(@type@ *ip, intp n, intp *max_ind, PyArrayObject *aip)\n{\n\tregister intp i;\n\t@type@ mp=*ip;\n\t*max_ind=0;\n\tfor (i=1; i mp) {\n\t\t\tmp = *ip;\n\t\t\t*max_ind = i;\n\t\t}\n\t}\n\treturn 0;\n}\n\n/**end repeat**/\n\nstatic int \nOBJECT_argmax(PyObject **ip, intp n, intp *max_ind, PyArrayObject *aip) \n{\n\tregister intp i; \n\tPyObject *mp=ip[0]; *max_ind=0;\n\tfor(i=1; i 0) { \n\t\t\tmp = *ip; \n\t\t\t*max_ind=i;\n\t\t} \n\t} \n\treturn 0;\n}\n\n/**begin repeat\n\n#fname= STRING, UNICODE#\n#type= char, PyArray_UCS4#\n\n*/\nstatic int \n@fname@_argmax(@type@ *ip, intp n, intp *max_ind, PyArrayObject *aip) \n{\n\tregister intp i; \n\tint elsize = aip->descr->elsize;\n\t@type@ *mp = (@type@ *)_pya_malloc(elsize);\n\t\n\tif (mp==NULL) return 0;\n\tmemcpy(mp, ip, elsize);\n\t*max_ind = 0;\n\tfor(i=1; i 0) { \n\t\t\tmemcpy(mp, ip, elsize);\n\t\t\t*max_ind=i;\n\t\t} \n\t} \n\t_pya_free(mp);\n\treturn 0;\n}\n\n/**end repeat**/\n\n#define VOID_argmax NULL\n\nstatic void\nBOOL_dot(char *ip1, intp is1, char *ip2, intp is2, char *op, intp n, \n void *ignore)\n{\n\tregister Bool tmp=FALSE;\n\tregister intp i;\n\tfor(i=0;ireal;\n\tstart.imag = buffer->imag;\n\tdelta.real = buffer[1].real;\n\tdelta.imag = buffer[1].imag;\n\tdelta.real -= start.real;\n\tdelta.imag -= start.imag;\n\tstart.real += (delta.real + delta.real);\n\tstart.imag += (delta.imag + delta.imag);\n\tbuffermax = buffer + length;\n\tbuffer += 2;\n\twhile (buffer < buffermax) {\n\t\tbuffer->real = start.real;\n\t\tbuffer->imag = start.imag; \n\t\tstart.real += delta.real;\n\t\tstart.imag += delta.imag;\n\t\tbuffer++;\n\t}\n}\n/**end repeat**/\n\n\n#define _ALIGN(type) offsetof(struct {char c; type v;},v)\n\n/**begin repeat\n\n#from= VOID, STRING, UNICODE#\n#align= char, char, PyArray_UCS4#\n#NAME= Void, String, Unicode#\n#endian= |, |, =#\n*/\n\nstatic PyArray_ArrFuncs _Py@NAME@_ArrFuncs = {\n\t{\n\t\t(PyArray_VectorUnaryFunc*)@from@_to_BOOL, \n\t\t(PyArray_VectorUnaryFunc*)@from@_to_BYTE, \n\t\t(PyArray_VectorUnaryFunc*)@from@_to_UBYTE, \n\t\t(PyArray_VectorUnaryFunc*)@from@_to_SHORT, \n\t\t(PyArray_VectorUnaryFunc*)@from@_to_USHORT, \n\t\t(PyArray_VectorUnaryFunc*)@from@_to_INT, \n\t\t(PyArray_VectorUnaryFunc*)@from@_to_UINT, \n\t\t(PyArray_VectorUnaryFunc*)@from@_to_LONG,\n\t\t(PyArray_VectorUnaryFunc*)@from@_to_ULONG, \n\t\t(PyArray_VectorUnaryFunc*)@from@_to_LONGLONG, \n\t\t(PyArray_VectorUnaryFunc*)@from@_to_ULONGLONG, \n\t\t(PyArray_VectorUnaryFunc*)@from@_to_FLOAT, \n\t\t(PyArray_VectorUnaryFunc*)@from@_to_DOUBLE, \n\t\t(PyArray_VectorUnaryFunc*)@from@_to_LONGDOUBLE, \n\t\t(PyArray_VectorUnaryFunc*)@from@_to_CFLOAT, \n\t\t(PyArray_VectorUnaryFunc*)@from@_to_CDOUBLE, \n\t\t(PyArray_VectorUnaryFunc*)@from@_to_CLONGDOUBLE, \n\t\t(PyArray_VectorUnaryFunc*)@from@_to_OBJECT, \n\t\t(PyArray_VectorUnaryFunc*)@from@_to_STRING, \n\t\t(PyArray_VectorUnaryFunc*)@from@_to_UNICODE, \n\t\t(PyArray_VectorUnaryFunc*)@from@_to_VOID\n\t},\n\t(PyArray_GetItemFunc*)@from@_getitem, \n\t(PyArray_SetItemFunc*)@from@_setitem,\n\t(PyArray_CopySwapNFunc*)@from@_copyswapn,\n\t(PyArray_CopySwapFunc*)@from@_copyswap,\n\t(PyArray_CompareFunc*)@from@_compare, \n\t(PyArray_ArgFunc*)@from@_argmax,\n\t(PyArray_DotFunc*)NULL, \n\t(PyArray_ScanFunc*)@from@_scan,\n\t(PyArray_FromStrFunc*)@from@_fromstr,\n\t(PyArray_NonzeroFunc*)@from@_nonzero,\n\t(PyArray_FillFunc*)NULL,\n\t{\n\t\tNULL, NULL, NULL, NULL\n\t},\n\t{\n\t\tNULL, NULL, NULL, NULL\n\t}\n};\n\nstatic PyArray_Descr @from@_Descr = { \n\tPyObject_HEAD_INIT(&PyArrayDescr_Type)\n\t&Py@NAME@ArrType_Type,\n\tPyArray_@from@LTR,\n\tPyArray_@from@LTR,\n\t'@endian@', 0,\n\tPyArray_@from@, 0,\n\t_ALIGN(@align@),\n\tNULL,\n\tNULL,\n\t&_Py@NAME@_ArrFuncs,\n};\n\n/**end repeat**/\n\n\n/**begin repeat\n\n#from= BOOL,BYTE,UBYTE,SHORT,USHORT,INT,UINT,LONG,ULONG,LONGLONG,ULONGLONG,FLOAT,DOUBLE,LONGDOUBLE,CFLOAT,CDOUBLE,CLONGDOUBLE,OBJECT#\n#num= 1*14,2*3,1#\n#fromtyp= Bool, byte, ubyte, short, ushort, int, uint, long, ulong, longlong, ulonglong, float, double, longdouble, float, double, longdouble, PyObject *#\n#NAME= Bool, Byte, UByte, Short, UShort, Int, UInt, Long, ULong, LongLong, ULongLong, Float, Double, LongDouble, CFloat, CDouble, CLongDouble, Object#\n#kind= GENBOOL, SIGNED, UNSIGNED, SIGNED, UNSIGNED, SIGNED, UNSIGNED, SIGNED, UNSIGNED, SIGNED, UNSIGNED, FLOATING, FLOATING, FLOATING, COMPLEX, COMPLEX, COMPLEX, OBJECT#\n#endian= |*3, =*14, |#\n#isobject= 0*17,1#\n*/\n\nstatic PyArray_ArrFuncs _Py@NAME@_ArrFuncs = {\n\t{\n\t\t(PyArray_VectorUnaryFunc*)@from@_to_BOOL, \n\t\t(PyArray_VectorUnaryFunc*)@from@_to_BYTE,\n\t\t(PyArray_VectorUnaryFunc*)@from@_to_UBYTE, \n\t\t(PyArray_VectorUnaryFunc*)@from@_to_SHORT, \n\t\t(PyArray_VectorUnaryFunc*)@from@_to_USHORT, \n\t\t(PyArray_VectorUnaryFunc*)@from@_to_INT, \n\t\t(PyArray_VectorUnaryFunc*)@from@_to_UINT, \n\t\t(PyArray_VectorUnaryFunc*)@from@_to_LONG,\n\t\t(PyArray_VectorUnaryFunc*)@from@_to_ULONG, \n\t\t(PyArray_VectorUnaryFunc*)@from@_to_LONGLONG, \n\t\t(PyArray_VectorUnaryFunc*)@from@_to_ULONGLONG, \n\t\t(PyArray_VectorUnaryFunc*)@from@_to_FLOAT, \n\t\t(PyArray_VectorUnaryFunc*)@from@_to_DOUBLE, \n\t\t(PyArray_VectorUnaryFunc*)@from@_to_LONGDOUBLE, \n\t\t(PyArray_VectorUnaryFunc*)@from@_to_CFLOAT, \n\t\t(PyArray_VectorUnaryFunc*)@from@_to_CDOUBLE, \n\t\t(PyArray_VectorUnaryFunc*)@from@_to_CLONGDOUBLE, \n\t\t(PyArray_VectorUnaryFunc*)@from@_to_OBJECT, \n\t\t(PyArray_VectorUnaryFunc*)@from@_to_STRING, \n\t\t(PyArray_VectorUnaryFunc*)@from@_to_UNICODE, \n\t\t(PyArray_VectorUnaryFunc*)@from@_to_VOID\n\t},\n\t(PyArray_GetItemFunc*)@from@_getitem, \n\t(PyArray_SetItemFunc*)@from@_setitem,\n\t(PyArray_CopySwapNFunc*)@from@_copyswapn,\n\t(PyArray_CopySwapFunc*)@from@_copyswap,\n\t(PyArray_CompareFunc*)@from@_compare, \n\t(PyArray_ArgFunc*)@from@_argmax,\n\t(PyArray_DotFunc*)@from@_dot, \n\t(PyArray_ScanFunc*)@from@_scan,\n\t(PyArray_FromStrFunc*)@from@_fromstr,\n\t(PyArray_NonzeroFunc*)@from@_nonzero,\n\t(PyArray_FillFunc*)@from@_fill,\n\t{\n\t\tNULL, NULL, NULL, NULL\n\t},\n\t{\n\t\tNULL, NULL, NULL, NULL\n\t}\n};\n\nstatic PyArray_Descr @from@_Descr = { \n\tPyObject_HEAD_INIT(&PyArrayDescr_Type)\n\t&Py@NAME@ArrType_Type,\n\tPyArray_@kind@LTR,\n\tPyArray_@from@LTR,\n\t'@endian@', @isobject@,\n\tPyArray_@from@, \n\t@num@*sizeof(@fromtyp@), \n\t_ALIGN(@fromtyp@),\n\tNULL,\n\tNULL,\n\t&_Py@NAME@_ArrFuncs,\n};\n\n/**end repeat**/\n\n#define _MAX_LETTER 128\nstatic char _letter_to_num[_MAX_LETTER];\n\nstatic PyArray_Descr *_builtin_descrs[] = {\n\t&BOOL_Descr,\n\t&BYTE_Descr,\n\t&UBYTE_Descr,\n\t&SHORT_Descr, \n\t&USHORT_Descr, \n\t&INT_Descr, \n\t&UINT_Descr, \n\t&LONG_Descr, \n\t&ULONG_Descr,\n\t&LONGLONG_Descr,\n\t&ULONGLONG_Descr,\n\t&FLOAT_Descr, \n\t&DOUBLE_Descr,\n\t&LONGDOUBLE_Descr,\n\t&CFLOAT_Descr, \n\t&CDOUBLE_Descr, \n\t&CLONGDOUBLE_Descr,\n\t&OBJECT_Descr, \n\t&STRING_Descr, \n\t&UNICODE_Descr,\n\t&VOID_Descr,\n};\n\n/*OBJECT_API\n Get the PyArray_Descr structure for a type.\n*/\nstatic PyArray_Descr *\nPyArray_DescrFromType(int type)\n{\n\tPyArray_Descr *ret=NULL;\n\n\tif (type < PyArray_NTYPES) {\n\t\tret = _builtin_descrs[type];\n\t}\n\telse if (type == PyArray_NOTYPE) {\n\t\t/* This needs to not raise an error so\n\t\t that PyArray_DescrFromType(PyArray_NOTYPE)\n\t\t works for backwards-compatible C-API \n\t\t*/\t\t\n\t\treturn NULL;\n\t}\n\telse if PyTypeNum_ISUSERDEF(type) {\n\t\tret = userdescrs[type-PyArray_USERDEF];\n\t} \n\telse {\n\t\tint num=PyArray_NTYPES;\n\t\tif (type < _MAX_LETTER) \n\t\t\tnum = (int) _letter_to_num[type];\n\t\tif (num >= PyArray_NTYPES)\n\t\t\tret = NULL;\n\t\telse\n\t\t\tret = _builtin_descrs[num];\n\t}\n\tif (ret==NULL) {\n\t\tPyErr_SetString(PyExc_ValueError, \n\t\t\t\t\"Invalid data-type for array\"); \n\t}\n\telse Py_INCREF(ret);\n\treturn ret;\n}\n\n\nstatic int\nset_typeinfo(PyObject *dict)\n{\n\tPyObject *infodict, *s;\n\tint i;\n\n\tfor (i=0; i<_MAX_LETTER; i++) {\n\t\t_letter_to_num[i] = PyArray_NTYPES;\n\t}\n\n/**begin repeat\n#name=BOOL,BYTE,UBYTE,SHORT,USHORT,INT,UINT,INTP,UINTP,LONG,ULONG,LONGLONG,ULONGLONG,FLOAT,DOUBLE,LONGDOUBLE,CFLOAT,CDOUBLE,CLONGDOUBLE,OBJECT,STRING,UNICODE,VOID#\n*/\n\t_letter_to_num[PyArray_@name@LTR] = PyArray_@name@;\n/**end repeat**/\n\t_letter_to_num[PyArray_STRINGLTR2] = PyArray_STRING;\n\n/**begin repeat\n#name=BOOL,BYTE,UBYTE,SHORT,USHORT,INT,UINT,LONG,ULONG,LONGLONG,ULONGLONG,FLOAT,DOUBLE,LONGDOUBLE,CFLOAT,CDOUBLE,CLONGDOUBLE,OBJECT,STRING,UNICODE,VOID#\n*/\n\t@name@_Descr.fields = Py_None;\n/**end repeat**/\n\t\n\t/* Set a dictionary with type information */\n\tinfodict = PyDict_New();\n\tif (infodict == NULL) return -1;\n\n#define BITSOF_INTP CHAR_BIT*SIZEOF_PY_INTPTR_T\n#define BITSOF_BYTE CHAR_BIT\n\n/**begin repeat \n\n#name=BOOL,BYTE,UBYTE,SHORT,USHORT,INT,UINT,INTP,UINTP,LONG,ULONG,LONGLONG,ULONGLONG#\n#uname=BOOL,BYTE*2,SHORT*2,INT*2,INTP*2,LONG*2,LONGLONG*2#\n#Name=Bool,Byte,UByte,Short,UShort,Int,UInt,Intp,UIntp,Long,ULong,LongLong,ULongLong#\n#type=Bool,byte,ubyte,short,ushort,int,uint,intp,uintp,long,ulong,longlong,ulonglong#\n#max=1,MAX_BYTE,MAX_UBYTE,MAX_SHORT,MAX_USHORT,MAX_INT,PyLong_FromUnsignedLong(MAX_UINT),PyLong_FromLongLong((longlong) MAX_INTP),PyLong_FromUnsignedLongLong((ulonglong) MAX_UINTP),MAX_LONG,PyLong_FromUnsignedLong((unsigned long) MAX_ULONG),PyLong_FromLongLong((longlong) MAX_LONGLONG), PyLong_FromUnsignedLongLong((ulonglong) MAX_ULONGLONG)#\n#min=0,MIN_BYTE,0,MIN_SHORT,0,MIN_INT,0,PyLong_FromLongLong((longlong) MIN_INTP),0,MIN_LONG,0,PyLong_FromLongLong((longlong) MIN_LONGLONG),0#\n#cx=i*6,N,N,N,l,N,N,N#\n#cn=i*7,N,i,l,i,N,i#\n*/\n \tPyDict_SetItemString(infodict, \"@name@\", \n\t\t\t s=Py_BuildValue(\"ciii@cx@@cn@O\", \n\t\t\t\t\t PyArray_@name@LTR, \n\t\t\t\t\t PyArray_@name@,\n\t\t\t\t\t BITSOF_@uname@,\n\t\t\t\t\t _ALIGN(@type@),\n\t\t\t\t\t @max@, @min@,\n\t\t\t\t (PyObject *)&Py@Name@ArrType_Type));\n\tPy_DECREF(s); \n/**end repeat**/\n\n#define BITSOF_CFLOAT 2*BITSOF_FLOAT\n#define BITSOF_CDOUBLE 2*BITSOF_DOUBLE\n#define BITSOF_CLONGDOUBLE 2*BITSOF_LONGDOUBLE\n\n/**begin repeat\n\n#type=float,double,longdouble,cfloat,cdouble,clongdouble#\n#name=FLOAT, DOUBLE, LONGDOUBLE, CFLOAT, CDOUBLE, CLONGDOUBLE#\n#Name=Float,Double,LongDouble,CFloat,CDouble,CLongDouble#\n*/\n \tPyDict_SetItemString(infodict, \"@name@\", \n\t\t\t s=Py_BuildValue(\"ciiiO\", PyArray_@name@LTR, \n\t\t\t\t\t PyArray_@name@, BITSOF_@name@,\n\t\t\t\t\t _ALIGN(@type@),\n (PyObject *)\\\n &Py@Name@ArrType_Type));\n\tPy_DECREF(s);\n/**end repeat**/\n\t\n\tPyDict_SetItemString(infodict, \"OBJECT\", \n\t\t\t s=Py_BuildValue(\"ciiiO\", PyArray_OBJECTLTR, \n\t\t\t\t\t PyArray_OBJECT, \n\t\t\t\t\t sizeof(PyObject *)*CHAR_BIT,\n\t\t\t\t\t _ALIGN(PyObject *),\n (PyObject *)\\\n &PyObjectArrType_Type));\n\tPy_DECREF(s);\n\tPyDict_SetItemString(infodict, \"STRING\", \n\t\t\t s=Py_BuildValue(\"ciiiO\", PyArray_STRINGLTR, \n\t\t\t\t\t PyArray_STRING, 0,\n\t\t\t\t\t _ALIGN(char),\n (PyObject *)\\\n &PyStringArrType_Type));\n\tPy_DECREF(s);\n\tPyDict_SetItemString(infodict, \"UNICODE\", \n\t\t\t s=Py_BuildValue(\"ciiiO\", PyArray_UNICODELTR, \n\t\t\t\t\t PyArray_UNICODE, 0,\n\t\t\t\t\t _ALIGN(PyArray_UCS4),\n (PyObject *)\\\n &PyUnicodeArrType_Type));\t\n\tPy_DECREF(s);\n\tPyDict_SetItemString(infodict, \"VOID\", \n\t\t\t s=Py_BuildValue(\"ciiiO\", PyArray_VOIDLTR, \n\t\t\t\t\t PyArray_VOID, 0,\n\t\t\t\t\t _ALIGN(char),\n (PyObject *)\\\n &PyVoidArrType_Type));\t\n\tPy_DECREF(s);\n\n#define SETTYPE(name) \\\n Py_INCREF(&Py##name##ArrType_Type); \\\n PyDict_SetItemString(infodict, #name, \\\n (PyObject *)&Py##name##ArrType_Type);\n\n SETTYPE(Generic)\n SETTYPE(Number)\n SETTYPE(Integer)\n\tSETTYPE(Inexact)\n SETTYPE(SignedInteger)\n SETTYPE(UnsignedInteger)\n SETTYPE(Floating)\n SETTYPE(ComplexFloating)\n SETTYPE(Flexible)\n SETTYPE(Character)\n\n#undef SETTYPE \t\n\n\tPyDict_SetItemString(dict, \"typeinfo\", infodict);\n\tPy_DECREF(infodict);\n\treturn 0;\n}\n\n#undef _MAX_LETTER\n\n", + "methods": [], + "methods_before": [], + "changed_methods": [], + "nloc": null, + "complexity": null, + "token_count": null, + "diff_parsed": { + "added": [ + "\tregister intp i;", + "\tfor (i=2; ireal = start.real + i*delta.real;", + "\t\tbuffer->imag = start.imag + i*delta.imag;" + ], + "deleted": [ + "\t@typ@ *buffermax;", + "\tstart += (delta + delta);", + "\tbuffermax = buffer + length;", + "\twhile(buffer < buffermax) {", + "\t\t*buffer = start;", + "\t\tstart += delta;", + "\t\tbuffer++;", + "\t@typ@ *buffermax;", + "\tstart.real += (delta.real + delta.real);", + "\tstart.imag += (delta.imag + delta.imag);", + "\tbuffermax = buffer + length;", + "\twhile (buffer < buffermax) {", + "\t\tbuffer->real = start.real;", + "\t\tbuffer->imag = start.imag;", + "\t\tstart.real += delta.real;", + "\t\tstart.imag += delta.imag;", + "\t\tbuffer++;" + ] + } + }, + { + "old_path": "numpy/distutils/system_info.py", + "new_path": "numpy/distutils/system_info.py", + "filename": "system_info.py", + "extension": "py", + "change_type": "MODIFY", + "diff": "@@ -116,7 +116,8 @@\n \n if sys.platform == 'win32':\n default_lib_dirs = ['C:\\\\',\n- os.path.join(distutils.sysconfig.EXEC_PREFIX, 'libs')]\n+ os.path.join(distutils.sysconfig.EXEC_PREFIX,\n+ 'libs')]\n default_include_dirs = []\n default_src_dirs = ['.']\n default_x11_lib_dirs = []\n", + "added_lines": 2, + "deleted_lines": 1, + "source_code": "#!/usr/bin/env python\n\"\"\"\nThis file defines a set of system_info classes for getting\ninformation about various resources (libraries, library directories,\ninclude directories, etc.) in the system. Currently, the following\nclasses are available:\n\n atlas_info\n atlas_threads_info\n atlas_blas_info\n atlas_blas_threads_info\n lapack_atlas_info\n blas_info\n lapack_info\n blas_opt_info # usage recommended\n lapack_opt_info # usage recommended\n fftw_info,dfftw_info,sfftw_info\n fftw_threads_info,dfftw_threads_info,sfftw_threads_info\n djbfft_info\n x11_info\n lapack_src_info\n blas_src_info\n numpy_info\n numarray_info\n numpy_info\n boost_python_info\n agg2_info\n wx_info\n gdk_pixbuf_xlib_2_info\n gdk_pixbuf_2_info\n gdk_x11_2_info\n gtkp_x11_2_info\n gtkp_2_info\n xft_info\n freetype2_info\n\nUsage:\n info_dict = get_info()\n where is a string 'atlas','x11','fftw','lapack','blas',\n 'lapack_src', 'blas_src', etc. For a complete list of allowed names,\n see the definition of get_info() function below.\n\n Returned info_dict is a dictionary which is compatible with\n distutils.setup keyword arguments. If info_dict == {}, then the\n asked resource is not available (system_info could not find it).\n\n Several *_info classes specify an environment variable to specify\n the locations of software. When setting the corresponding environment\n variable to 'None' then the software will be ignored, even when it\n is available in system.\n\nGlobal parameters:\n system_info.search_static_first - search static libraries (.a)\n in precedence to shared ones (.so, .sl) if enabled.\n system_info.verbosity - output the results to stdout if enabled.\n\nThe file 'site.cfg' in the same directory as this module is read\nfor configuration options. The format is that used by ConfigParser (i.e.,\nWindows .INI style). The section DEFAULT has options that are the default\nfor each section. The available sections are fftw, atlas, and x11. Appropiate\ndefaults are used if nothing is specified.\n\nThe order of finding the locations of resources is the following:\n 1. environment variable\n 2. section in site.cfg\n 3. DEFAULT section in site.cfg\nOnly the first complete match is returned.\n\nExample:\n----------\n[DEFAULT]\nlibrary_dirs = /usr/lib:/usr/local/lib:/opt/lib\ninclude_dirs = /usr/include:/usr/local/include:/opt/include\nsrc_dirs = /usr/local/src:/opt/src\n# search static libraries (.a) in preference to shared ones (.so)\nsearch_static_first = 0\n\n[fftw]\nfftw_libs = rfftw, fftw\nfftw_opt_libs = rfftw_threaded, fftw_threaded\n# if the above aren't found, look for {s,d}fftw_libs and {s,d}fftw_opt_libs\n\n[atlas]\nlibrary_dirs = /usr/lib/3dnow:/usr/lib/3dnow/atlas\n# for overriding the names of the atlas libraries\natlas_libs = lapack, f77blas, cblas, atlas\n\n[x11]\nlibrary_dirs = /usr/X11R6/lib\ninclude_dirs = /usr/X11R6/include\n----------\n\nAuthors:\n Pearu Peterson , February 2002\n David M. Cooke , April 2002\n\nCopyright 2002 Pearu Peterson all rights reserved,\nPearu Peterson \nPermission to use, modify, and distribute this software is given under the\nterms of the SciPy (BSD style) license. See LICENSE.txt that came with\nthis distribution for specifics.\n\nNO WARRANTY IS EXPRESSED OR IMPLIED. USE AT YOUR OWN RISK.\n\"\"\"\n\nimport sys,os,re\nimport warnings\nfrom distutils.errors import DistutilsError\nfrom glob import glob\nimport ConfigParser\nfrom exec_command import find_executable, exec_command, get_pythonexe\nfrom numpy.distutils.misc_util import is_sequence, is_string\nimport distutils.sysconfig\n\nfrom distutils.sysconfig import get_config_vars\n\nif sys.platform == 'win32':\n default_lib_dirs = ['C:\\\\',\n os.path.join(distutils.sysconfig.EXEC_PREFIX,\n 'libs')]\n default_include_dirs = []\n default_src_dirs = ['.']\n default_x11_lib_dirs = []\n default_x11_include_dirs = []\nelse:\n default_lib_dirs = ['/usr/local/lib', '/opt/lib', '/usr/lib',\n '/opt/local/lib', '/sw/lib']\n default_include_dirs = ['/usr/local/include',\n '/opt/include', '/usr/include',\n '/opt/local/include', '/sw/include']\n default_src_dirs = ['.','/usr/local/src', '/opt/src','/sw/src']\n default_x11_lib_dirs = ['/usr/X11R6/lib','/usr/X11/lib','/usr/lib']\n default_x11_include_dirs = ['/usr/X11R6/include','/usr/X11/include',\n '/usr/include']\n\nif os.path.join(sys.prefix, 'lib') not in default_lib_dirs:\n default_lib_dirs.insert(0,os.path.join(sys.prefix, 'lib'))\n default_include_dirs.append(os.path.join(sys.prefix, 'include'))\n default_src_dirs.append(os.path.join(sys.prefix, 'src'))\n\ndefault_lib_dirs = filter(os.path.isdir, default_lib_dirs)\ndefault_include_dirs = filter(os.path.isdir, default_include_dirs)\ndefault_src_dirs = filter(os.path.isdir, default_src_dirs)\n\nso_ext = get_config_vars('SO')[0] or ''\n\ndef get_info(name,notfound_action=0):\n \"\"\"\n notfound_action:\n 0 - do nothing\n 1 - display warning message\n 2 - raise error\n \"\"\"\n cl = {'atlas':atlas_info, # use lapack_opt or blas_opt instead\n 'atlas_threads':atlas_threads_info, # ditto\n 'atlas_blas':atlas_blas_info,\n 'atlas_blas_threads':atlas_blas_threads_info,\n 'lapack_atlas':lapack_atlas_info, # use lapack_opt instead\n 'lapack_atlas_threads':lapack_atlas_threads_info, # ditto\n 'mkl':mkl_info,\n 'lapack_mkl':lapack_mkl_info, # use lapack_opt instead\n 'blas_mkl':blas_mkl_info, # use blas_opt instead\n 'x11':x11_info,\n 'fft_opt':fft_opt_info,\n 'fftw':fftw_info,\n 'fftw2':fftw2_info,\n 'fftw3':fftw3_info,\n 'dfftw':dfftw_info,\n 'sfftw':sfftw_info,\n 'fftw_threads':fftw_threads_info,\n 'dfftw_threads':dfftw_threads_info,\n 'sfftw_threads':sfftw_threads_info,\n 'djbfft':djbfft_info,\n 'blas':blas_info, # use blas_opt instead\n 'lapack':lapack_info, # use lapack_opt instead\n 'lapack_src':lapack_src_info,\n 'blas_src':blas_src_info,\n 'numpy':numpy_info,\n 'f2py':f2py_info,\n 'Numeric':Numeric_info,\n 'numarray':numarray_info,\n 'lapack_opt':lapack_opt_info,\n 'blas_opt':blas_opt_info,\n 'boost_python':boost_python_info,\n 'agg2':agg2_info,\n 'wx':wx_info,\n 'gdk_pixbuf_xlib_2':gdk_pixbuf_xlib_2_info,\n 'gdk-pixbuf-xlib-2.0':gdk_pixbuf_xlib_2_info,\n 'gdk_pixbuf_2':gdk_pixbuf_2_info,\n 'gdk-pixbuf-2.0':gdk_pixbuf_2_info,\n 'gdk':gdk_info,\n 'gdk_2':gdk_2_info,\n 'gdk-2.0':gdk_2_info,\n 'gdk_x11_2':gdk_x11_2_info,\n 'gdk-x11-2.0':gdk_x11_2_info,\n 'gtkp_x11_2':gtkp_x11_2_info,\n 'gtk+-x11-2.0':gtkp_x11_2_info,\n 'gtkp_2':gtkp_2_info,\n 'gtk+-2.0':gtkp_2_info,\n 'xft':xft_info,\n 'freetype2':freetype2_info,\n }.get(name.lower(),system_info)\n return cl().get_info(notfound_action)\n\nclass NotFoundError(DistutilsError):\n \"\"\"Some third-party program or library is not found.\"\"\"\n\nclass AtlasNotFoundError(NotFoundError):\n \"\"\"\n Atlas (http://math-atlas.sourceforge.net/) libraries not found.\n Directories to search for the libraries can be specified in the\n numpy/distutils/site.cfg file (section [atlas]) or by setting\n the ATLAS environment variable.\"\"\"\n\nclass LapackNotFoundError(NotFoundError):\n \"\"\"\n Lapack (http://www.netlib.org/lapack/) libraries not found.\n Directories to search for the libraries can be specified in the\n numpy/distutils/site.cfg file (section [lapack]) or by setting\n the LAPACK environment variable.\"\"\"\n\nclass LapackSrcNotFoundError(LapackNotFoundError):\n \"\"\"\n Lapack (http://www.netlib.org/lapack/) sources not found.\n Directories to search for the sources can be specified in the\n numpy/distutils/site.cfg file (section [lapack_src]) or by setting\n the LAPACK_SRC environment variable.\"\"\"\n\nclass BlasNotFoundError(NotFoundError):\n \"\"\"\n Blas (http://www.netlib.org/blas/) libraries not found.\n Directories to search for the libraries can be specified in the\n numpy/distutils/site.cfg file (section [blas]) or by setting\n the BLAS environment variable.\"\"\"\n\nclass BlasSrcNotFoundError(BlasNotFoundError):\n \"\"\"\n Blas (http://www.netlib.org/blas/) sources not found.\n Directories to search for the sources can be specified in the\n numpy/distutils/site.cfg file (section [blas_src]) or by setting\n the BLAS_SRC environment variable.\"\"\"\n\nclass FFTWNotFoundError(NotFoundError):\n \"\"\"\n FFTW (http://www.fftw.org/) libraries not found.\n Directories to search for the libraries can be specified in the\n numpy/distutils/site.cfg file (section [fftw]) or by setting\n the FFTW environment variable.\"\"\"\n\nclass DJBFFTNotFoundError(NotFoundError):\n \"\"\"\n DJBFFT (http://cr.yp.to/djbfft.html) libraries not found.\n Directories to search for the libraries can be specified in the\n numpy/distutils/site.cfg file (section [djbfft]) or by setting\n the DJBFFT environment variable.\"\"\"\n\nclass NumericNotFoundError(NotFoundError):\n \"\"\"\n Numeric (http://www.numpy.org/) module not found.\n Get it from above location, install it, and retry setup.py.\"\"\"\n\nclass X11NotFoundError(NotFoundError):\n \"\"\"X11 libraries not found.\"\"\"\n\nclass system_info:\n\n \"\"\" get_info() is the only public method. Don't use others.\n \"\"\"\n section = 'DEFAULT'\n dir_env_var = None\n search_static_first = 0 # XXX: disabled by default, may disappear in\n # future unless it is proved to be useful.\n verbosity = 1\n saved_results = {}\n\n notfounderror = NotFoundError\n\n def __init__ (self,\n default_lib_dirs=default_lib_dirs,\n default_include_dirs=default_include_dirs,\n verbosity = 1,\n ):\n self.__class__.info = {}\n self.local_prefixes = []\n defaults = {}\n defaults['libraries'] = ''\n defaults['library_dirs'] = os.pathsep.join(default_lib_dirs)\n defaults['include_dirs'] = os.pathsep.join(default_include_dirs)\n defaults['src_dirs'] = os.pathsep.join(default_src_dirs)\n defaults['search_static_first'] = str(self.search_static_first)\n self.cp = ConfigParser.ConfigParser(defaults)\n try:\n f = __file__\n except NameError,msg:\n f = sys.argv[0]\n cf = os.path.join(os.path.split(os.path.abspath(f))[0],\n 'site.cfg')\n self.cp.read([cf])\n if not self.cp.has_section(self.section):\n self.cp.add_section(self.section)\n self.search_static_first = self.cp.getboolean(self.section,\n 'search_static_first')\n assert isinstance(self.search_static_first, int)\n\n def calc_libraries_info(self):\n libs = self.get_libraries()\n dirs = self.get_lib_dirs()\n info = {}\n for lib in libs:\n i = None\n for d in dirs:\n i = self.check_libs(d,[lib])\n if i is not None:\n break\n if i is not None:\n dict_append(info,**i)\n else:\n print 'Library %s was not found. Ignoring' % (lib)\n return info\n\n def set_info(self,**info):\n if info:\n lib_info = self.calc_libraries_info()\n dict_append(info,**lib_info)\n self.saved_results[self.__class__.__name__] = info\n\n def has_info(self):\n return self.saved_results.has_key(self.__class__.__name__)\n\n def get_info(self,notfound_action=0):\n \"\"\" Return a dictonary with items that are compatible\n with numpy.distutils.setup keyword arguments.\n \"\"\"\n flag = 0\n if not self.has_info():\n flag = 1\n if self.verbosity>0:\n print self.__class__.__name__ + ':'\n if hasattr(self, 'calc_info'):\n self.calc_info()\n if notfound_action:\n if not self.has_info():\n if notfound_action==1:\n warnings.warn(self.notfounderror.__doc__)\n elif notfound_action==2:\n raise self.notfounderror,self.notfounderror.__doc__\n else:\n raise ValueError(repr(notfound_action))\n\n if self.verbosity>0:\n if not self.has_info():\n print ' NOT AVAILABLE'\n self.set_info()\n else:\n print ' FOUND:'\n\n res = self.saved_results.get(self.__class__.__name__)\n if self.verbosity>0 and flag:\n for k,v in res.items():\n v = str(v)\n if k=='sources' and len(v)>200: v = v[:60]+' ...\\n... '+v[-60:]\n print ' %s = %s'%(k,v)\n print\n\n return res\n\n def get_paths(self, section, key):\n dirs = self.cp.get(section, key).split(os.pathsep)\n env_var = self.dir_env_var\n if env_var:\n if is_sequence(env_var):\n e0 = env_var[-1]\n for e in env_var:\n if os.environ.has_key(e):\n e0 = e\n break\n if not env_var[0]==e0:\n print 'Setting %s=%s' % (env_var[0],e0)\n env_var = e0\n if env_var and os.environ.has_key(env_var):\n d = os.environ[env_var]\n if d=='None':\n print 'Disabled',self.__class__.__name__,'(%s is None)' \\\n % (self.dir_env_var)\n return []\n if os.path.isfile(d):\n dirs = [os.path.dirname(d)] + dirs\n l = getattr(self,'_lib_names',[])\n if len(l)==1:\n b = os.path.basename(d)\n b = os.path.splitext(b)[0]\n if b[:3]=='lib':\n print 'Replacing _lib_names[0]==%r with %r' \\\n % (self._lib_names[0], b[3:])\n self._lib_names[0] = b[3:]\n else:\n ds = d.split(os.pathsep)\n ds2 = []\n for d in ds:\n if os.path.isdir(d):\n ds2.append(d)\n for dd in ['include','lib']:\n d1 = os.path.join(d,dd)\n if os.path.isdir(d1):\n ds2.append(d1)\n dirs = ds2 + dirs\n default_dirs = self.cp.get('DEFAULT', key).split(os.pathsep)\n dirs.extend(default_dirs)\n ret = []\n [ret.append(d) for d in dirs if os.path.isdir(d) and d not in ret]\n if self.verbosity>1:\n print '(',key,'=',':'.join(ret),')'\n return ret\n\n def get_lib_dirs(self, key='library_dirs'):\n return self.get_paths(self.section, key)\n\n def get_include_dirs(self, key='include_dirs'):\n return self.get_paths(self.section, key)\n\n def get_src_dirs(self, key='src_dirs'):\n return self.get_paths(self.section, key)\n\n def get_libs(self, key, default):\n try:\n libs = self.cp.get(self.section, key)\n except ConfigParser.NoOptionError:\n if not default:\n return []\n if is_string(default):\n return [default]\n return default\n return [b for b in [a.strip() for a in libs.split(',')] if b]\n\n def get_libraries(self, key='libraries'):\n return self.get_libs(key,'')\n\n def check_libs(self,lib_dir,libs,opt_libs =[]):\n \"\"\" If static or shared libraries are available then return\n their info dictionary. \"\"\"\n if self.search_static_first:\n exts = ['.a',so_ext]\n else:\n exts = [so_ext,'.a']\n if sys.platform=='cygwin':\n exts.append('.dll.a')\n for ext in exts:\n info = self._check_libs(lib_dir,libs,opt_libs,[ext])\n if info is not None: return info\n return\n\n def check_libs2(self,lib_dir,libs,opt_libs =[]):\n \"\"\" If static or shared libraries are available then return\n their info dictionary. \"\"\"\n if self.search_static_first:\n exts = ['.a',so_ext]\n else:\n exts = [so_ext,'.a']\n if sys.platform=='cygwin':\n exts.append('.dll.a')\n info = self._check_libs(lib_dir,libs,opt_libs,exts)\n if info is not None: return info\n return\n\n def _lib_list(self, lib_dir, libs, exts):\n assert is_string(lib_dir)\n liblist = []\n for l in libs:\n for ext in exts:\n p = self.combine_paths(lib_dir, 'lib'+l+ext)\n if p:\n assert len(p)==1\n liblist.append(p[0])\n break\n return liblist\n\n def _extract_lib_names(self,libs):\n return [os.path.splitext(os.path.basename(p))[0][3:] \\\n for p in libs]\n\n def _check_libs(self,lib_dir,libs, opt_libs, exts):\n found_libs = self._lib_list(lib_dir, libs, exts)\n if len(found_libs) == len(libs):\n found_libs = self._extract_lib_names(found_libs)\n info = {'libraries' : found_libs, 'library_dirs' : [lib_dir]}\n opt_found_libs = self._lib_list(lib_dir, opt_libs, exts)\n if len(opt_found_libs) == len(opt_libs):\n opt_found_libs = self._extract_lib_names(opt_found_libs)\n info['libraries'].extend(opt_found_libs)\n return info\n\n def combine_paths(self,*args):\n return combine_paths(*args,**{'verbosity':self.verbosity})\n\n\nclass fft_opt_info(system_info):\n\n def calc_info(self):\n info = {}\n fftw_info = get_info('fftw3') or get_info('fftw2') or get_info('dfftw')\n djbfft_info = get_info('djbfft')\n if fftw_info:\n dict_append(info,**fftw_info)\n if djbfft_info:\n dict_append(info,**djbfft_info)\n self.set_info(**info)\n return\n\n\nclass fftw_info(system_info):\n #variables to override\n section = 'fftw'\n dir_env_var = 'FFTW'\n notfounderror = FFTWNotFoundError\n ver_info = [ { 'name':'fftw3',\n 'libs':['fftw3'],\n 'includes':['fftw3.h'],\n 'macros':[('SCIPY_FFTW3_H',None)]},\n { 'name':'fftw2',\n 'libs':['rfftw', 'fftw'],\n 'includes':['fftw.h','rfftw.h'],\n 'macros':[('SCIPY_FFTW_H',None)]}]\n\n def __init__(self):\n system_info.__init__(self)\n\n def calc_ver_info(self,ver_param):\n \"\"\"Returns True on successful version detection, else False\"\"\"\n lib_dirs = self.get_lib_dirs()\n incl_dirs = self.get_include_dirs()\n incl_dir = None\n libs = self.get_libs(self.section+'_libs', ver_param['libs'])\n info = None\n for d in lib_dirs:\n r = self.check_libs(d,libs)\n if r is not None:\n info = r\n break\n if info is not None:\n flag = 0\n for d in incl_dirs:\n if len(self.combine_paths(d,ver_param['includes']))==len(ver_param['includes']):\n dict_append(info,include_dirs=[d])\n flag = 1\n incl_dirs = [d]\n incl_dir = d\n break\n if flag:\n dict_append(info,define_macros=ver_param['macros'])\n else:\n info = None\n if info is not None:\n self.set_info(**info)\n return True\n else:\n if self.verbosity>0:\n print ' %s not found' % (ver_param['name'])\n return False\n\n def calc_info(self):\n for i in self.ver_info:\n if self.calc_ver_info(i):\n break\n\nclass fftw2_info(fftw_info):\n #variables to override\n section = 'fftw'\n dir_env_var = 'FFTW'\n notfounderror = FFTWNotFoundError\n ver_info = [ { 'name':'fftw2',\n 'libs':['rfftw', 'fftw'],\n 'includes':['fftw.h','rfftw.h'],\n 'macros':[('SCIPY_FFTW_H',None)]}\n ]\n\nclass fftw3_info(fftw_info):\n #variables to override\n section = 'fftw3'\n dir_env_var = 'FFTW3'\n notfounderror = FFTWNotFoundError\n ver_info = [ { 'name':'fftw3',\n 'libs':['fftw3'],\n 'includes':['fftw3.h'],\n 'macros':[('SCIPY_FFTW3_H',None)]},\n ]\n\nclass dfftw_info(fftw_info):\n section = 'fftw'\n dir_env_var = 'FFTW'\n ver_info = [ { 'name':'dfftw',\n 'libs':['drfftw','dfftw'],\n 'includes':['dfftw.h','drfftw.h'],\n 'macros':[('SCIPY_DFFTW_H',None)]} ]\n\nclass sfftw_info(fftw_info):\n section = 'fftw'\n dir_env_var = 'FFTW'\n ver_info = [ { 'name':'sfftw',\n 'libs':['srfftw','sfftw'],\n 'includes':['sfftw.h','srfftw.h'],\n 'macros':[('SCIPY_SFFTW_H',None)]} ]\n\nclass fftw_threads_info(fftw_info):\n section = 'fftw'\n dir_env_var = 'FFTW'\n ver_info = [ { 'name':'fftw threads',\n 'libs':['rfftw_threads','fftw_threads'],\n 'includes':['fftw_threads.h','rfftw_threads.h'],\n 'macros':[('SCIPY_FFTW_THREADS_H',None)]} ]\n\nclass dfftw_threads_info(fftw_info):\n section = 'fftw'\n dir_env_var = 'FFTW'\n ver_info = [ { 'name':'dfftw threads',\n 'libs':['drfftw_threads','dfftw_threads'],\n 'includes':['dfftw_threads.h','drfftw_threads.h'],\n 'macros':[('SCIPY_DFFTW_THREADS_H',None)]} ]\n\nclass sfftw_threads_info(fftw_info):\n section = 'fftw'\n dir_env_var = 'FFTW'\n ver_info = [ { 'name':'sfftw threads',\n 'libs':['srfftw_threads','sfftw_threads'],\n 'includes':['sfftw_threads.h','srfftw_threads.h'],\n 'macros':[('SCIPY_SFFTW_THREADS_H',None)]} ]\n\nclass djbfft_info(system_info):\n section = 'djbfft'\n dir_env_var = 'DJBFFT'\n notfounderror = DJBFFTNotFoundError\n\n def get_paths(self, section, key):\n pre_dirs = system_info.get_paths(self, section, key)\n dirs = []\n for d in pre_dirs:\n dirs.extend(self.combine_paths(d,['djbfft'])+[d])\n return [ d for d in dirs if os.path.isdir(d) ]\n\n def calc_info(self):\n lib_dirs = self.get_lib_dirs()\n incl_dirs = self.get_include_dirs()\n info = None\n for d in lib_dirs:\n p = self.combine_paths (d,['djbfft.a'])\n if p:\n info = {'extra_objects':p}\n break\n p = self.combine_paths (d,['libdjbfft.a','libdjbfft'+so_ext])\n if p:\n info = {'libraries':['djbfft'],'library_dirs':[d]}\n break\n if info is None:\n return\n for d in incl_dirs:\n if len(self.combine_paths(d,['fftc8.h','fftfreq.h']))==2:\n dict_append(info,include_dirs=[d],\n define_macros=[('SCIPY_DJBFFT_H',None)])\n self.set_info(**info)\n return\n return\n\nclass mkl_info(system_info):\n section = 'mkl'\n dir_env_var = 'MKL'\n _lib_mkl = ['mkl','vml','guide']\n\n def get_mkl_rootdir(self):\n mklroot = os.environ.get('MKLROOT',None)\n if mklroot is not None:\n return mklroot\n paths = os.environ.get('LD_LIBRARY_PATH','').split(os.pathsep)\n ld_so_conf = '/etc/ld.so.conf'\n if os.path.isfile(ld_so_conf):\n for d in open(ld_so_conf,'r').readlines():\n d = d.strip()\n if d: paths.append(d)\n intel_mkl_dirs = []\n for path in paths:\n path_atoms = path.split(os.sep)\n for m in path_atoms:\n if m.startswith('mkl'):\n d = os.sep.join(path_atoms[:path_atoms.index(m)+2])\n intel_mkl_dirs.append(d)\n break\n for d in paths:\n dirs = glob(os.path.join(d,'mkl','*')) + glob(os.path.join(d,'mkl*'))\n for d in dirs:\n if os.path.isdir(os.path.join(d,'lib')):\n return d\n return None\n\n def __init__(self):\n mklroot = self.get_mkl_rootdir()\n if mklroot is None:\n system_info.__init__(self)\n else:\n from cpuinfo import cpu\n if cpu.is_Itanium():\n plt = '64'\n l = 'mkl_ipf'\n elif cpu.is_Xeon():\n plt = 'em64t'\n l = 'mkl_em64t'\n else:\n plt = '32'\n l = 'mkl_ia32'\n if l not in self._lib_mkl:\n self._lib_mkl.insert(0,l)\n system_info.__init__(self,\n default_lib_dirs=[os.path.join(mklroot,'lib',plt)],\n default_include_dirs=[os.path.join(mklroot,'include')])\n\n def calc_info(self):\n lib_dirs = self.get_lib_dirs()\n incl_dirs = self.get_include_dirs()\n mkl_libs = self.get_libs('mkl_libs',self._lib_mkl)\n mkl = None\n for d in lib_dirs:\n mkl = self.check_libs2(d,mkl_libs)\n if mkl is not None:\n break\n if mkl is None:\n return\n info = {}\n dict_append(info,**mkl)\n dict_append(info,libraries = ['pthread'], include_dirs = incl_dirs)\n self.set_info(**info)\n\nclass lapack_mkl_info(mkl_info):\n\n def calc_info(self):\n mkl = get_info('mkl')\n if not mkl:\n return\n lapack_libs = self.get_libs('lapack_libs',['mkl_lapack'])\n info = {'libraries': lapack_libs}\n dict_append(info,**mkl)\n self.set_info(**info)\n\nclass blas_mkl_info(mkl_info):\n pass\n\nclass atlas_info(system_info):\n section = 'atlas'\n dir_env_var = 'ATLAS'\n _lib_names = ['f77blas','cblas']\n if sys.platform[:7]=='freebsd':\n _lib_atlas = ['atlas_r']\n _lib_lapack = ['alapack_r']\n else:\n _lib_atlas = ['atlas']\n _lib_lapack = ['lapack']\n\n notfounderror = AtlasNotFoundError\n\n def get_paths(self, section, key):\n pre_dirs = system_info.get_paths(self, section, key)\n dirs = []\n for d in pre_dirs:\n dirs.extend(self.combine_paths(d,['atlas*','ATLAS*',\n 'sse','3dnow','sse2'])+[d])\n return [ d for d in dirs if os.path.isdir(d) ]\n\n def calc_info(self):\n lib_dirs = self.get_lib_dirs()\n info = {}\n atlas_libs = self.get_libs('atlas_libs',\n self._lib_names + self._lib_atlas)\n lapack_libs = self.get_libs('lapack_libs',self._lib_lapack)\n atlas = None\n lapack = None\n atlas_1 = None\n for d in lib_dirs:\n atlas = self.check_libs(d,atlas_libs,[])\n lapack_atlas = self.check_libs(d,['lapack_atlas'],[])\n if atlas is not None:\n lib_dirs2 = self.combine_paths(d,['atlas*','ATLAS*'])+[d]\n for d2 in lib_dirs2:\n lapack = self.check_libs(d2,lapack_libs,[])\n if lapack is not None:\n break\n else:\n lapack = None\n if lapack is not None:\n break\n if atlas:\n atlas_1 = atlas\n print self.__class__\n if atlas is None:\n atlas = atlas_1\n if atlas is None:\n return\n include_dirs = self.get_include_dirs()\n h = (self.combine_paths(lib_dirs+include_dirs,'cblas.h') or [None])[0]\n if h:\n h = os.path.dirname(h)\n dict_append(info,include_dirs=[h])\n info['language'] = 'c'\n if lapack is not None:\n dict_append(info,**lapack)\n dict_append(info,**atlas)\n elif 'lapack_atlas' in atlas['libraries']:\n dict_append(info,**atlas)\n dict_append(info,define_macros=[('ATLAS_WITH_LAPACK_ATLAS',None)])\n self.set_info(**info)\n return\n else:\n dict_append(info,**atlas)\n dict_append(info,define_macros=[('ATLAS_WITHOUT_LAPACK',None)])\n message = \"\"\"\n*********************************************************************\n Could not find lapack library within the ATLAS installation.\n*********************************************************************\n\"\"\"\n warnings.warn(message)\n self.set_info(**info)\n return\n\n # Check if lapack library is complete, only warn if it is not.\n lapack_dir = lapack['library_dirs'][0]\n lapack_name = lapack['libraries'][0]\n lapack_lib = None\n for e in ['.a',so_ext]:\n fn = os.path.join(lapack_dir,'lib'+lapack_name+e)\n if os.path.exists(fn):\n lapack_lib = fn\n break\n if lapack_lib is not None:\n sz = os.stat(lapack_lib)[6]\n if sz <= 4000*1024:\n message = \"\"\"\n*********************************************************************\n Lapack library (from ATLAS) is probably incomplete:\n size of %s is %sk (expected >4000k)\n\n Follow the instructions in the KNOWN PROBLEMS section of the file\n numpy/INSTALL.txt.\n*********************************************************************\n\"\"\" % (lapack_lib,sz/1024)\n warnings.warn(message)\n else:\n info['language'] = 'f77'\n\n self.set_info(**info)\n\nclass atlas_blas_info(atlas_info):\n _lib_names = ['f77blas','cblas']\n\n def calc_info(self):\n lib_dirs = self.get_lib_dirs()\n info = {}\n atlas_libs = self.get_libs('atlas_libs',\n self._lib_names + self._lib_atlas)\n atlas = None\n for d in lib_dirs:\n atlas = self.check_libs(d,atlas_libs,[])\n if atlas is not None:\n break\n if atlas is None:\n return\n include_dirs = self.get_include_dirs()\n h = (self.combine_paths(lib_dirs+include_dirs,'cblas.h') or [None])[0]\n if h:\n h = os.path.dirname(h)\n dict_append(info,include_dirs=[h])\n info['language'] = 'c'\n\n dict_append(info,**atlas)\n\n self.set_info(**info)\n return\n\n\nclass atlas_threads_info(atlas_info):\n dir_env_var = ['PTATLAS','ATLAS']\n _lib_names = ['ptf77blas','ptcblas']\n\nclass atlas_blas_threads_info(atlas_blas_info):\n dir_env_var = ['PTATLAS','ATLAS']\n _lib_names = ['ptf77blas','ptcblas']\n\nclass lapack_atlas_info(atlas_info):\n _lib_names = ['lapack_atlas'] + atlas_info._lib_names\n\nclass lapack_atlas_threads_info(atlas_threads_info):\n _lib_names = ['lapack_atlas'] + atlas_threads_info._lib_names\n\nclass lapack_info(system_info):\n section = 'lapack'\n dir_env_var = 'LAPACK'\n _lib_names = ['lapack']\n notfounderror = LapackNotFoundError\n\n def calc_info(self):\n lib_dirs = self.get_lib_dirs()\n\n lapack_libs = self.get_libs('lapack_libs', self._lib_names)\n for d in lib_dirs:\n lapack = self.check_libs(d,lapack_libs,[])\n if lapack is not None:\n info = lapack\n break\n else:\n return\n info['language'] = 'f77'\n self.set_info(**info)\n\nclass lapack_src_info(system_info):\n section = 'lapack_src'\n dir_env_var = 'LAPACK_SRC'\n notfounderror = LapackSrcNotFoundError\n\n def get_paths(self, section, key):\n pre_dirs = system_info.get_paths(self, section, key)\n dirs = []\n for d in pre_dirs:\n dirs.extend([d] + self.combine_paths(d,['LAPACK*/SRC','SRC']))\n return [ d for d in dirs if os.path.isdir(d) ]\n\n def calc_info(self):\n src_dirs = self.get_src_dirs()\n src_dir = ''\n for d in src_dirs:\n if os.path.isfile(os.path.join(d,'dgesv.f')):\n src_dir = d\n break\n if not src_dir:\n #XXX: Get sources from netlib. May be ask first.\n return\n # The following is extracted from LAPACK-3.0/SRC/Makefile\n allaux='''\n ilaenv ieeeck lsame lsamen xerbla\n ''' # *.f\n laux = '''\n bdsdc bdsqr disna labad lacpy ladiv lae2 laebz laed0 laed1\n laed2 laed3 laed4 laed5 laed6 laed7 laed8 laed9 laeda laev2\n lagtf lagts lamch lamrg lanst lapy2 lapy3 larnv larrb larre\n larrf lartg laruv las2 lascl lasd0 lasd1 lasd2 lasd3 lasd4\n lasd5 lasd6 lasd7 lasd8 lasd9 lasda lasdq lasdt laset lasq1\n lasq2 lasq3 lasq4 lasq5 lasq6 lasr lasrt lassq lasv2 pttrf\n stebz stedc steqr sterf\n ''' # [s|d]*.f\n lasrc = '''\n gbbrd gbcon gbequ gbrfs gbsv gbsvx gbtf2 gbtrf gbtrs gebak\n gebal gebd2 gebrd gecon geequ gees geesx geev geevx gegs gegv\n gehd2 gehrd gelq2 gelqf gels gelsd gelss gelsx gelsy geql2\n geqlf geqp3 geqpf geqr2 geqrf gerfs gerq2 gerqf gesc2 gesdd\n gesv gesvd gesvx getc2 getf2 getrf getri getrs ggbak ggbal\n gges ggesx ggev ggevx ggglm gghrd gglse ggqrf ggrqf ggsvd\n ggsvp gtcon gtrfs gtsv gtsvx gttrf gttrs gtts2 hgeqz hsein\n hseqr labrd lacon laein lags2 lagtm lahqr lahrd laic1 lals0\n lalsa lalsd langb lange langt lanhs lansb lansp lansy lantb\n lantp lantr lapll lapmt laqgb laqge laqp2 laqps laqsb laqsp\n laqsy lar1v lar2v larf larfb larfg larft larfx largv larrv\n lartv larz larzb larzt laswp lasyf latbs latdf latps latrd\n latrs latrz latzm lauu2 lauum pbcon pbequ pbrfs pbstf pbsv\n pbsvx pbtf2 pbtrf pbtrs pocon poequ porfs posv posvx potf2\n potrf potri potrs ppcon ppequ pprfs ppsv ppsvx pptrf pptri\n pptrs ptcon pteqr ptrfs ptsv ptsvx pttrs ptts2 spcon sprfs\n spsv spsvx sptrf sptri sptrs stegr stein sycon syrfs sysv\n sysvx sytf2 sytrf sytri sytrs tbcon tbrfs tbtrs tgevc tgex2\n tgexc tgsen tgsja tgsna tgsy2 tgsyl tpcon tprfs tptri tptrs\n trcon trevc trexc trrfs trsen trsna trsyl trti2 trtri trtrs\n tzrqf tzrzf\n ''' # [s|c|d|z]*.f\n sd_lasrc = '''\n laexc lag2 lagv2 laln2 lanv2 laqtr lasy2 opgtr opmtr org2l\n org2r orgbr orghr orgl2 orglq orgql orgqr orgr2 orgrq orgtr\n orm2l orm2r ormbr ormhr orml2 ormlq ormql ormqr ormr2 ormr3\n ormrq ormrz ormtr rscl sbev sbevd sbevx sbgst sbgv sbgvd sbgvx\n sbtrd spev spevd spevx spgst spgv spgvd spgvx sptrd stev stevd\n stevr stevx syev syevd syevr syevx sygs2 sygst sygv sygvd\n sygvx sytd2 sytrd\n ''' # [s|d]*.f\n cz_lasrc = '''\n bdsqr hbev hbevd hbevx hbgst hbgv hbgvd hbgvx hbtrd hecon heev\n heevd heevr heevx hegs2 hegst hegv hegvd hegvx herfs hesv\n hesvx hetd2 hetf2 hetrd hetrf hetri hetrs hpcon hpev hpevd\n hpevx hpgst hpgv hpgvd hpgvx hprfs hpsv hpsvx hptrd hptrf\n hptri hptrs lacgv lacp2 lacpy lacrm lacrt ladiv laed0 laed7\n laed8 laesy laev2 lahef lanhb lanhe lanhp lanht laqhb laqhe\n laqhp larcm larnv lartg lascl laset lasr lassq pttrf rot spmv\n spr stedc steqr symv syr ung2l ung2r ungbr unghr ungl2 unglq\n ungql ungqr ungr2 ungrq ungtr unm2l unm2r unmbr unmhr unml2\n unmlq unmql unmqr unmr2 unmr3 unmrq unmrz unmtr upgtr upmtr\n ''' # [c|z]*.f\n #######\n sclaux = laux + ' econd ' # s*.f\n dzlaux = laux + ' secnd ' # d*.f\n slasrc = lasrc + sd_lasrc # s*.f\n dlasrc = lasrc + sd_lasrc # d*.f\n clasrc = lasrc + cz_lasrc + ' srot srscl ' # c*.f\n zlasrc = lasrc + cz_lasrc + ' drot drscl ' # z*.f\n oclasrc = ' icmax1 scsum1 ' # *.f\n ozlasrc = ' izmax1 dzsum1 ' # *.f\n sources = ['s%s.f'%f for f in (sclaux+slasrc).split()] \\\n + ['d%s.f'%f for f in (dzlaux+dlasrc).split()] \\\n + ['c%s.f'%f for f in (clasrc).split()] \\\n + ['z%s.f'%f for f in (zlasrc).split()] \\\n + ['%s.f'%f for f in (allaux+oclasrc+ozlasrc).split()]\n sources = [os.path.join(src_dir,f) for f in sources]\n #XXX: should we check here actual existence of source files?\n info = {'sources':sources,'language':'f77'}\n self.set_info(**info)\n\natlas_version_c_text = r'''\n/* This file is generated from numpy_distutils/system_info.py */\n#ifdef __CPLUSPLUS__\nextern \"C\" {\n#endif\n#include \"Python.h\"\nstatic PyMethodDef module_methods[] = { {NULL,NULL} };\nDL_EXPORT(void) initatlas_version(void) {\n void ATL_buildinfo(void);\n ATL_buildinfo();\n Py_InitModule(\"atlas_version\", module_methods);\n}\n#ifdef __CPLUSCPLUS__\n}\n#endif\n'''\n\ndef _get_build_temp():\n from distutils.util import get_platform\n plat_specifier = \".%s-%s\" % (get_platform(), sys.version[0:3])\n return os.path.join('build','temp'+plat_specifier)\n\ndef get_atlas_version(**config):\n os.environ['NO_SCIPY_IMPORT']='get_atlas_version'\n from core import Extension, setup\n from misc_util import get_cmd\n import log\n magic = hex(hash(repr(config)))\n def atlas_version_c(extension, build_dir,magic=magic):\n source = os.path.join(build_dir,'atlas_version_%s.c' % (magic))\n if os.path.isfile(source):\n from distutils.dep_util import newer\n if newer(source,__file__):\n return source\n f = open(source,'w')\n f.write(atlas_version_c_text)\n f.close()\n return source\n ext = Extension('atlas_version',\n sources=[atlas_version_c],\n **config)\n build_dir = _get_build_temp()\n extra_args = ['--build-lib',build_dir]\n for a in sys.argv:\n if re.match('[-][-]compiler[=]',a):\n extra_args.append(a)\n import distutils.core\n old_dist = distutils.core._setup_distribution\n distutils.core._setup_distribution = None\n try:\n dist = setup(ext_modules=[ext],\n script_name = 'get_atlas_version',\n script_args = ['build_src','build_ext']+extra_args)\n except Exception,msg:\n print \"##### msg: %s\" % msg\n if not msg:\n msg = \"Unknown Exception\"\n log.warn(msg)\n return None\n distutils.core._setup_distribution = old_dist\n\n from distutils.sysconfig import get_config_var\n so_ext = get_config_var('SO')\n target = os.path.join(build_dir,'atlas_version'+so_ext)\n cmd = [get_pythonexe(),'-c',\n '\"import imp,os;os.environ[\\\\\"NO_SCIPY_IMPORT\\\\\"]='\\\n '\\\\\"system_info.get_atlas_version:load atlas_version\\\\\";'\\\n 'imp.load_dynamic(\\\\\"atlas_version\\\\\",\\\\\"%s\\\\\")\"'\\\n % (os.path.basename(target))]\n s,o = exec_command(cmd,execute_in=os.path.dirname(target),use_tee=0)\n atlas_version = None\n if not s:\n m = re.search(r'ATLAS version (?P\\d+[.]\\d+[.]\\d+)',o)\n if m:\n atlas_version = m.group('version')\n if atlas_version is None:\n if re.search(r'undefined symbol: ATL_buildinfo',o,re.M):\n atlas_version = '3.2.1_pre3.3.6'\n else:\n print 'Command:',' '.join(cmd)\n print 'Status:',s\n print 'Output:',o\n return atlas_version\n\n\nclass lapack_opt_info(system_info):\n\n def calc_info(self):\n\n if sys.platform=='darwin' and not os.environ.get('ATLAS',None):\n args = []\n link_args = []\n if os.path.exists('/System/Library/Frameworks/Accelerate.framework/'):\n args.extend(['-faltivec'])\n link_args.extend(['-Wl,-framework','-Wl,Accelerate'])\n elif os.path.exists('/System/Library/Frameworks/vecLib.framework/'):\n args.extend(['-faltivec'])\n link_args.extend(['-Wl,-framework','-Wl,vecLib'])\n if args:\n self.set_info(extra_compile_args=args,\n extra_link_args=link_args,\n define_macros=[('NO_ATLAS_INFO',3)])\n return\n\n lapack_mkl_info = get_info('lapack_mkl')\n if lapack_mkl_info:\n self.set_info(**lapack_mkl_info)\n return\n\n atlas_info = get_info('atlas_threads')\n if not atlas_info:\n atlas_info = get_info('atlas')\n #atlas_info = {} ## uncomment for testing\n atlas_version = None\n need_lapack = 0\n need_blas = 0\n info = {}\n if atlas_info:\n version_info = atlas_info.copy()\n atlas_version = get_atlas_version(**version_info)\n if not atlas_info.has_key('define_macros'):\n atlas_info['define_macros'] = []\n if atlas_version is None:\n atlas_info['define_macros'].append(('NO_ATLAS_INFO',2))\n else:\n atlas_info['define_macros'].append(('ATLAS_INFO',\n '\"\\\\\"%s\\\\\"\"' % atlas_version))\n\t\tif atlas_version=='3.2.1_pre3.3.6':\n\t\t atlas_info['define_macros'].append(('NO_ATLAS_INFO',4))\n l = atlas_info.get('define_macros',[])\n if ('ATLAS_WITH_LAPACK_ATLAS',None) in l \\\n or ('ATLAS_WITHOUT_LAPACK',None) in l:\n need_lapack = 1\n info = atlas_info\n else:\n warnings.warn(AtlasNotFoundError.__doc__)\n need_blas = 1\n need_lapack = 1\n dict_append(info,define_macros=[('NO_ATLAS_INFO',1)])\n\n if need_lapack:\n lapack_info = get_info('lapack')\n #lapack_info = {} ## uncomment for testing\n if lapack_info:\n dict_append(info,**lapack_info)\n else:\n warnings.warn(LapackNotFoundError.__doc__)\n lapack_src_info = get_info('lapack_src')\n if not lapack_src_info:\n warnings.warn(LapackSrcNotFoundError.__doc__)\n return\n dict_append(info,libraries=[('flapack_src',lapack_src_info)])\n\n if need_blas:\n blas_info = get_info('blas')\n #blas_info = {} ## uncomment for testing\n if blas_info:\n dict_append(info,**blas_info)\n else:\n warnings.warn(BlasNotFoundError.__doc__)\n blas_src_info = get_info('blas_src')\n if not blas_src_info:\n warnings.warn(BlasSrcNotFoundError.__doc__)\n return\n dict_append(info,libraries=[('fblas_src',blas_src_info)])\n\n self.set_info(**info)\n return\n\n\nclass blas_opt_info(system_info):\n\n def calc_info(self):\n\n if sys.platform=='darwin' and not os.environ.get('ATLAS',None):\n args = []\n link_args = []\n if os.path.exists('/System/Library/Frameworks/Accelerate.framework/'):\n args.extend(['-faltivec',\n '-I/System/Library/Frameworks/vecLib.framework/Headers',\n ])\n link_args.extend(['-Wl,-framework','-Wl,Accelerate'])\n elif os.path.exists('/System/Library/Frameworks/vecLib.framework/'):\n args.extend(['-faltivec',\n '-I/System/Library/Frameworks/vecLib.framework/Headers',\n ])\n link_args.extend(['-Wl,-framework','-Wl,vecLib'])\n if args:\n self.set_info(extra_compile_args=args,\n extra_link_args=link_args,\n define_macros=[('NO_ATLAS_INFO',3)])\n return\n\n blas_mkl_info = get_info('blas_mkl')\n if blas_mkl_info:\n self.set_info(**blas_mkl_info)\n return\n\n atlas_info = get_info('atlas_blas_threads')\n if not atlas_info:\n atlas_info = get_info('atlas_blas')\n atlas_version = None\n need_blas = 0\n info = {}\n if atlas_info:\n version_info = atlas_info.copy()\n atlas_version = get_atlas_version(**version_info)\n if not atlas_info.has_key('define_macros'):\n atlas_info['define_macros'] = []\n if atlas_version is None:\n atlas_info['define_macros'].append(('NO_ATLAS_INFO',2))\n else:\n atlas_info['define_macros'].append(('ATLAS_INFO',\n '\"\\\\\"%s\\\\\"\"' % atlas_version))\n info = atlas_info\n else:\n warnings.warn(AtlasNotFoundError.__doc__)\n need_blas = 1\n dict_append(info,define_macros=[('NO_ATLAS_INFO',1)])\n\n if need_blas:\n blas_info = get_info('blas')\n if blas_info:\n dict_append(info,**blas_info)\n else:\n warnings.warn(BlasNotFoundError.__doc__)\n blas_src_info = get_info('blas_src')\n if not blas_src_info:\n warnings.warn(BlasSrcNotFoundError.__doc__)\n return\n dict_append(info,libraries=[('fblas_src',blas_src_info)])\n\n self.set_info(**info)\n return\n\n\nclass blas_info(system_info):\n section = 'blas'\n dir_env_var = 'BLAS'\n _lib_names = ['blas']\n notfounderror = BlasNotFoundError\n\n def calc_info(self):\n lib_dirs = self.get_lib_dirs()\n\n blas_libs = self.get_libs('blas_libs', self._lib_names)\n for d in lib_dirs:\n blas = self.check_libs(d,blas_libs,[])\n if blas is not None:\n info = blas\n break\n else:\n return\n info['language'] = 'f77' # XXX: is it generally true?\n self.set_info(**info)\n\n\nclass blas_src_info(system_info):\n section = 'blas_src'\n dir_env_var = 'BLAS_SRC'\n notfounderror = BlasSrcNotFoundError\n\n def get_paths(self, section, key):\n pre_dirs = system_info.get_paths(self, section, key)\n dirs = []\n for d in pre_dirs:\n dirs.extend([d] + self.combine_paths(d,['blas']))\n return [ d for d in dirs if os.path.isdir(d) ]\n\n def calc_info(self):\n src_dirs = self.get_src_dirs()\n src_dir = ''\n for d in src_dirs:\n if os.path.isfile(os.path.join(d,'daxpy.f')):\n src_dir = d\n break\n if not src_dir:\n #XXX: Get sources from netlib. May be ask first.\n return\n blas1 = '''\n caxpy csscal dnrm2 dzasum saxpy srotg zdotc ccopy cswap drot\n dznrm2 scasum srotm zdotu cdotc dasum drotg icamax scnrm2\n srotmg zdrot cdotu daxpy drotm idamax scopy sscal zdscal crotg\n dcabs1 drotmg isamax sdot sswap zrotg cscal dcopy dscal izamax\n snrm2 zaxpy zscal csrot ddot dswap sasum srot zcopy zswap\n '''\n blas2 = '''\n cgbmv chpmv ctrsv dsymv dtrsv sspr2 strmv zhemv ztpmv cgemv\n chpr dgbmv dsyr lsame ssymv strsv zher ztpsv cgerc chpr2 dgemv\n dsyr2 sgbmv ssyr xerbla zher2 ztrmv cgeru ctbmv dger dtbmv\n sgemv ssyr2 zgbmv zhpmv ztrsv chbmv ctbsv dsbmv dtbsv sger\n stbmv zgemv zhpr chemv ctpmv dspmv dtpmv ssbmv stbsv zgerc\n zhpr2 cher ctpsv dspr dtpsv sspmv stpmv zgeru ztbmv cher2\n ctrmv dspr2 dtrmv sspr stpsv zhbmv ztbsv\n '''\n blas3 = '''\n cgemm csymm ctrsm dsyrk sgemm strmm zhemm zsyr2k chemm csyr2k\n dgemm dtrmm ssymm strsm zher2k zsyrk cher2k csyrk dsymm dtrsm\n ssyr2k zherk ztrmm cherk ctrmm dsyr2k ssyrk zgemm zsymm ztrsm\n '''\n sources = [os.path.join(src_dir,f+'.f') \\\n for f in (blas1+blas2+blas3).split()]\n #XXX: should we check here actual existence of source files?\n info = {'sources':sources,'language':'f77'}\n self.set_info(**info)\n\nclass x11_info(system_info):\n section = 'x11'\n notfounderror = X11NotFoundError\n\n def __init__(self):\n system_info.__init__(self,\n default_lib_dirs=default_x11_lib_dirs,\n default_include_dirs=default_x11_include_dirs)\n\n def calc_info(self):\n if sys.platform in ['win32']:\n return\n lib_dirs = self.get_lib_dirs()\n include_dirs = self.get_include_dirs()\n x11_libs = self.get_libs('x11_libs', ['X11'])\n for lib_dir in lib_dirs:\n info = self.check_libs(lib_dir, x11_libs, [])\n if info is not None:\n break\n else:\n return\n inc_dir = None\n for d in include_dirs:\n if self.combine_paths(d, 'X11/X.h'):\n inc_dir = d\n break\n if inc_dir is not None:\n dict_append(info, include_dirs=[inc_dir])\n self.set_info(**info)\n\nclass _numpy_info(system_info):\n section = 'Numeric'\n modulename = 'Numeric'\n notfounderror = NumericNotFoundError\n\n def __init__(self):\n from distutils.sysconfig import get_python_inc\n include_dirs = []\n try:\n module = __import__(self.modulename)\n prefix = []\n for name in module.__file__.split(os.sep):\n if name=='lib':\n break\n prefix.append(name)\n include_dirs.append(get_python_inc(prefix=os.sep.join(prefix)))\n except ImportError:\n pass\n py_incl_dir = get_python_inc()\n include_dirs.append(py_incl_dir)\n for d in default_include_dirs:\n d = os.path.join(d, os.path.basename(py_incl_dir))\n if d not in include_dirs:\n include_dirs.append(d)\n system_info.__init__(self,\n default_lib_dirs=[],\n default_include_dirs=include_dirs)\n\n def calc_info(self):\n try:\n module = __import__(self.modulename)\n except ImportError:\n return\n info = {}\n macros = []\n for v in ['__version__','version']:\n vrs = getattr(module,v,None)\n if vrs is None:\n continue\n macros = [(self.modulename.upper()+'_VERSION',\n '\"\\\\\"%s\\\\\"\"' % (vrs)),\n (self.modulename.upper(),None)]\n break\n## try:\n## macros.append(\n## (self.modulename.upper()+'_VERSION_HEX',\n## hex(vstr2hex(module.__version__))),\n## )\n## except Exception,msg:\n## print msg\n dict_append(info, define_macros = macros)\n include_dirs = self.get_include_dirs()\n inc_dir = None\n for d in include_dirs:\n if self.combine_paths(d,\n os.path.join(self.modulename,\n 'arrayobject.h')):\n inc_dir = d\n break\n if inc_dir is not None:\n dict_append(info, include_dirs=[inc_dir])\n if info:\n self.set_info(**info)\n return\n\nclass numarray_info(_numpy_info):\n section = 'numarray'\n modulename = 'numarray'\n\nclass Numeric_info(_numpy_info):\n section = 'Numeric'\n modulename = 'Numeric'\n\nclass numpy_info(_numpy_info):\n section = 'numpy'\n modulename = 'numpy'\n\nclass f2py_info(system_info):\n def calc_info(self):\n try:\n import numpy.f2py as f2py\n except ImportError:\n return\n f2py_dir = os.path.join(os.path.dirname(f2py.__file__),'src')\n self.set_info(sources = [os.path.join(f2py_dir,'fortranobject.c')],\n include_dirs = [f2py_dir])\n return\n\nclass boost_python_info(system_info):\n section = 'boost_python'\n dir_env_var = 'BOOST'\n\n def get_paths(self, section, key):\n pre_dirs = system_info.get_paths(self, section, key)\n dirs = []\n for d in pre_dirs:\n dirs.extend([d] + self.combine_paths(d,['boost*']))\n return [ d for d in dirs if os.path.isdir(d) ]\n\n def calc_info(self):\n from distutils.sysconfig import get_python_inc\n src_dirs = self.get_src_dirs()\n src_dir = ''\n for d in src_dirs:\n if os.path.isfile(os.path.join(d,'libs','python','src','module.cpp')):\n src_dir = d\n break\n if not src_dir:\n return\n py_incl_dir = get_python_inc()\n srcs_dir = os.path.join(src_dir,'libs','python','src')\n bpl_srcs = glob(os.path.join(srcs_dir,'*.cpp'))\n bpl_srcs += glob(os.path.join(srcs_dir,'*','*.cpp'))\n info = {'libraries':[('boost_python_src',{'include_dirs':[src_dir,py_incl_dir],\n 'sources':bpl_srcs})],\n 'include_dirs':[src_dir],\n }\n if info:\n self.set_info(**info)\n return\n\nclass agg2_info(system_info):\n section = 'agg2'\n dir_env_var = 'AGG2'\n\n def get_paths(self, section, key):\n pre_dirs = system_info.get_paths(self, section, key)\n dirs = []\n for d in pre_dirs:\n dirs.extend([d] + self.combine_paths(d,['agg2*']))\n return [ d for d in dirs if os.path.isdir(d) ]\n\n def calc_info(self):\n src_dirs = self.get_src_dirs()\n src_dir = ''\n for d in src_dirs:\n if os.path.isfile(os.path.join(d,'src','agg_affine_matrix.cpp')):\n src_dir = d\n break\n if not src_dir:\n return\n if sys.platform=='win32':\n agg2_srcs = glob(os.path.join(src_dir,'src','platform','win32','agg_win32_bmp.cpp'))\n else:\n agg2_srcs = glob(os.path.join(src_dir,'src','*.cpp'))\n agg2_srcs += [os.path.join(src_dir,'src','platform','X11','agg_platform_support.cpp')]\n\n info = {'libraries':[('agg2_src',{'sources':agg2_srcs,\n 'include_dirs':[os.path.join(src_dir,'include')],\n })],\n 'include_dirs':[os.path.join(src_dir,'include')],\n }\n if info:\n self.set_info(**info)\n return\n\nclass _pkg_config_info(system_info):\n section = None\n config_env_var = 'PKG_CONFIG'\n default_config_exe = 'pkg-config'\n append_config_exe = ''\n version_macro_name = None\n release_macro_name = None\n version_flag = '--modversion'\n cflags_flag = '--cflags'\n\n def get_config_exe(self):\n if os.environ.has_key(self.config_env_var):\n return os.environ[self.config_env_var]\n return self.default_config_exe\n def get_config_output(self, config_exe, option):\n s,o = exec_command(config_exe+' '+self.append_config_exe+' '+option,use_tee=0)\n if not s:\n return o\n\n def calc_info(self):\n config_exe = find_executable(self.get_config_exe())\n if not os.path.isfile(config_exe):\n print 'File not found: %s. Cannot determine %s info.' \\\n % (config_exe, self.section)\n return\n info = {}\n macros = []\n libraries = []\n library_dirs = []\n include_dirs = []\n extra_link_args = []\n extra_compile_args = []\n version = self.get_config_output(config_exe,self.version_flag)\n if version:\n macros.append((self.__class__.__name__.split('.')[-1].upper(),\n '\"\\\\\"%s\\\\\"\"' % (version)))\n if self.version_macro_name:\n macros.append((self.version_macro_name+'_%s' % (version.replace('.','_')),None))\n if self.release_macro_name:\n release = self.get_config_output(config_exe,'--release')\n if release:\n macros.append((self.release_macro_name+'_%s' % (release.replace('.','_')),None))\n opts = self.get_config_output(config_exe,'--libs')\n if opts:\n for opt in opts.split():\n if opt[:2]=='-l':\n libraries.append(opt[2:])\n elif opt[:2]=='-L':\n library_dirs.append(opt[2:])\n else:\n extra_link_args.append(opt)\n opts = self.get_config_output(config_exe,self.cflags_flag)\n if opts:\n for opt in opts.split():\n if opt[:2]=='-I':\n include_dirs.append(opt[2:])\n elif opt[:2]=='-D':\n if '=' in opt:\n n,v = opt[2:].split('=')\n macros.append((n,v))\n else:\n macros.append((opt[2:],None))\n else:\n extra_compile_args.append(opt)\n if macros: dict_append(info, define_macros = macros)\n if libraries: dict_append(info, libraries = libraries)\n if library_dirs: dict_append(info, library_dirs = library_dirs)\n if include_dirs: dict_append(info, include_dirs = include_dirs)\n if extra_link_args: dict_append(info, extra_link_args = extra_link_args)\n if extra_compile_args: dict_append(info, extra_compile_args = extra_compile_args)\n if info:\n self.set_info(**info)\n return\n\nclass wx_info(_pkg_config_info):\n section = 'wx'\n config_env_var = 'WX_CONFIG'\n default_config_exe = 'wx-config'\n append_config_exe = ''\n version_macro_name = 'WX_VERSION'\n release_macro_name = 'WX_RELEASE'\n version_flag = '--version'\n cflags_flag = '--cxxflags'\n\nclass gdk_pixbuf_xlib_2_info(_pkg_config_info):\n section = 'gdk_pixbuf_xlib_2'\n append_config_exe = 'gdk-pixbuf-xlib-2.0'\n version_macro_name = 'GDK_PIXBUF_XLIB_VERSION'\n\nclass gdk_pixbuf_2_info(_pkg_config_info):\n section = 'gdk_pixbuf_2'\n append_config_exe = 'gdk-pixbuf-2.0'\n version_macro_name = 'GDK_PIXBUF_VERSION'\n\nclass gdk_x11_2_info(_pkg_config_info):\n section = 'gdk_x11_2'\n append_config_exe = 'gdk-x11-2.0'\n version_macro_name = 'GDK_X11_VERSION'\n\nclass gdk_2_info(_pkg_config_info):\n section = 'gdk_2'\n append_config_exe = 'gdk-2.0'\n version_macro_name = 'GDK_VERSION'\n\nclass gdk_info(_pkg_config_info):\n section = 'gdk'\n append_config_exe = 'gdk'\n version_macro_name = 'GDK_VERSION'\n\nclass gtkp_x11_2_info(_pkg_config_info):\n section = 'gtkp_x11_2'\n append_config_exe = 'gtk+-x11-2.0'\n version_macro_name = 'GTK_X11_VERSION'\n\n\nclass gtkp_2_info(_pkg_config_info):\n section = 'gtkp_2'\n append_config_exe = 'gtk+-2.0'\n version_macro_name = 'GTK_VERSION'\n\nclass xft_info(_pkg_config_info):\n section = 'xft'\n append_config_exe = 'xft'\n version_macro_name = 'XFT_VERSION'\n\nclass freetype2_info(_pkg_config_info):\n section = 'freetype2'\n append_config_exe = 'freetype2'\n version_macro_name = 'FREETYPE2_VERSION'\n\n## def vstr2hex(version):\n## bits = []\n## n = [24,16,8,4,0]\n## r = 0\n## for s in version.split('.'):\n## r |= int(s) << n[0]\n## del n[0]\n## return r\n\n#--------------------------------------------------------------------\n\ndef combine_paths(*args,**kws):\n \"\"\" Return a list of existing paths composed by all combinations of\n items from arguments.\n \"\"\"\n r = []\n for a in args:\n if not a: continue\n if is_string(a):\n a = [a]\n r.append(a)\n args = r\n if not args: return []\n if len(args)==1:\n result = reduce(lambda a,b:a+b,map(glob,args[0]),[])\n elif len (args)==2:\n result = []\n for a0 in args[0]:\n for a1 in args[1]:\n result.extend(glob(os.path.join(a0,a1)))\n else:\n result = combine_paths(*(combine_paths(args[0],args[1])+args[2:]))\n verbosity = kws.get('verbosity',1)\n if verbosity>1 and result:\n print '(','paths:',','.join(result),')'\n return result\n\nlanguage_map = {'c':0,'c++':1,'f77':2,'f90':3}\ninv_language_map = {0:'c',1:'c++',2:'f77',3:'f90'}\ndef dict_append(d,**kws):\n languages = []\n for k,v in kws.items():\n if k=='language':\n languages.append(v)\n continue\n if d.has_key(k):\n if k in ['library_dirs','include_dirs','define_macros']:\n [d[k].append(vv) for vv in v if vv not in d[k]]\n else:\n d[k].extend(v)\n else:\n d[k] = v\n if languages:\n l = inv_language_map[max([language_map.get(l,0) for l in languages])]\n d['language'] = l\n return\n\ndef show_all():\n import system_info\n import pprint\n match_info = re.compile(r'.*?_info').match\n show_only = []\n for n in sys.argv[1:]:\n if n[-5:] != '_info':\n n = n + '_info'\n show_only.append(n)\n show_all = not show_only\n for n in filter(match_info,dir(system_info)):\n if n in ['system_info','get_info']: continue\n if not show_all:\n if n not in show_only: continue\n del show_only[show_only.index(n)]\n c = getattr(system_info,n)()\n c.verbosity = 2\n r = c.get_info()\n if show_only:\n print 'Info classes not defined:',','.join(show_only)\nif __name__ == \"__main__\":\n show_all()\n", + "source_code_before": "#!/usr/bin/env python\n\"\"\"\nThis file defines a set of system_info classes for getting\ninformation about various resources (libraries, library directories,\ninclude directories, etc.) in the system. Currently, the following\nclasses are available:\n\n atlas_info\n atlas_threads_info\n atlas_blas_info\n atlas_blas_threads_info\n lapack_atlas_info\n blas_info\n lapack_info\n blas_opt_info # usage recommended\n lapack_opt_info # usage recommended\n fftw_info,dfftw_info,sfftw_info\n fftw_threads_info,dfftw_threads_info,sfftw_threads_info\n djbfft_info\n x11_info\n lapack_src_info\n blas_src_info\n numpy_info\n numarray_info\n numpy_info\n boost_python_info\n agg2_info\n wx_info\n gdk_pixbuf_xlib_2_info\n gdk_pixbuf_2_info\n gdk_x11_2_info\n gtkp_x11_2_info\n gtkp_2_info\n xft_info\n freetype2_info\n\nUsage:\n info_dict = get_info()\n where is a string 'atlas','x11','fftw','lapack','blas',\n 'lapack_src', 'blas_src', etc. For a complete list of allowed names,\n see the definition of get_info() function below.\n\n Returned info_dict is a dictionary which is compatible with\n distutils.setup keyword arguments. If info_dict == {}, then the\n asked resource is not available (system_info could not find it).\n\n Several *_info classes specify an environment variable to specify\n the locations of software. When setting the corresponding environment\n variable to 'None' then the software will be ignored, even when it\n is available in system.\n\nGlobal parameters:\n system_info.search_static_first - search static libraries (.a)\n in precedence to shared ones (.so, .sl) if enabled.\n system_info.verbosity - output the results to stdout if enabled.\n\nThe file 'site.cfg' in the same directory as this module is read\nfor configuration options. The format is that used by ConfigParser (i.e.,\nWindows .INI style). The section DEFAULT has options that are the default\nfor each section. The available sections are fftw, atlas, and x11. Appropiate\ndefaults are used if nothing is specified.\n\nThe order of finding the locations of resources is the following:\n 1. environment variable\n 2. section in site.cfg\n 3. DEFAULT section in site.cfg\nOnly the first complete match is returned.\n\nExample:\n----------\n[DEFAULT]\nlibrary_dirs = /usr/lib:/usr/local/lib:/opt/lib\ninclude_dirs = /usr/include:/usr/local/include:/opt/include\nsrc_dirs = /usr/local/src:/opt/src\n# search static libraries (.a) in preference to shared ones (.so)\nsearch_static_first = 0\n\n[fftw]\nfftw_libs = rfftw, fftw\nfftw_opt_libs = rfftw_threaded, fftw_threaded\n# if the above aren't found, look for {s,d}fftw_libs and {s,d}fftw_opt_libs\n\n[atlas]\nlibrary_dirs = /usr/lib/3dnow:/usr/lib/3dnow/atlas\n# for overriding the names of the atlas libraries\natlas_libs = lapack, f77blas, cblas, atlas\n\n[x11]\nlibrary_dirs = /usr/X11R6/lib\ninclude_dirs = /usr/X11R6/include\n----------\n\nAuthors:\n Pearu Peterson , February 2002\n David M. Cooke , April 2002\n\nCopyright 2002 Pearu Peterson all rights reserved,\nPearu Peterson \nPermission to use, modify, and distribute this software is given under the\nterms of the SciPy (BSD style) license. See LICENSE.txt that came with\nthis distribution for specifics.\n\nNO WARRANTY IS EXPRESSED OR IMPLIED. USE AT YOUR OWN RISK.\n\"\"\"\n\nimport sys,os,re\nimport warnings\nfrom distutils.errors import DistutilsError\nfrom glob import glob\nimport ConfigParser\nfrom exec_command import find_executable, exec_command, get_pythonexe\nfrom numpy.distutils.misc_util import is_sequence, is_string\nimport distutils.sysconfig\n\nfrom distutils.sysconfig import get_config_vars\n\nif sys.platform == 'win32':\n default_lib_dirs = ['C:\\\\',\n os.path.join(distutils.sysconfig.EXEC_PREFIX, 'libs')]\n default_include_dirs = []\n default_src_dirs = ['.']\n default_x11_lib_dirs = []\n default_x11_include_dirs = []\nelse:\n default_lib_dirs = ['/usr/local/lib', '/opt/lib', '/usr/lib',\n '/opt/local/lib', '/sw/lib']\n default_include_dirs = ['/usr/local/include',\n '/opt/include', '/usr/include',\n '/opt/local/include', '/sw/include']\n default_src_dirs = ['.','/usr/local/src', '/opt/src','/sw/src']\n default_x11_lib_dirs = ['/usr/X11R6/lib','/usr/X11/lib','/usr/lib']\n default_x11_include_dirs = ['/usr/X11R6/include','/usr/X11/include',\n '/usr/include']\n\nif os.path.join(sys.prefix, 'lib') not in default_lib_dirs:\n default_lib_dirs.insert(0,os.path.join(sys.prefix, 'lib'))\n default_include_dirs.append(os.path.join(sys.prefix, 'include'))\n default_src_dirs.append(os.path.join(sys.prefix, 'src'))\n\ndefault_lib_dirs = filter(os.path.isdir, default_lib_dirs)\ndefault_include_dirs = filter(os.path.isdir, default_include_dirs)\ndefault_src_dirs = filter(os.path.isdir, default_src_dirs)\n\nso_ext = get_config_vars('SO')[0] or ''\n\ndef get_info(name,notfound_action=0):\n \"\"\"\n notfound_action:\n 0 - do nothing\n 1 - display warning message\n 2 - raise error\n \"\"\"\n cl = {'atlas':atlas_info, # use lapack_opt or blas_opt instead\n 'atlas_threads':atlas_threads_info, # ditto\n 'atlas_blas':atlas_blas_info,\n 'atlas_blas_threads':atlas_blas_threads_info,\n 'lapack_atlas':lapack_atlas_info, # use lapack_opt instead\n 'lapack_atlas_threads':lapack_atlas_threads_info, # ditto\n 'mkl':mkl_info,\n 'lapack_mkl':lapack_mkl_info, # use lapack_opt instead\n 'blas_mkl':blas_mkl_info, # use blas_opt instead\n 'x11':x11_info,\n 'fft_opt':fft_opt_info,\n 'fftw':fftw_info,\n 'fftw2':fftw2_info,\n 'fftw3':fftw3_info,\n 'dfftw':dfftw_info,\n 'sfftw':sfftw_info,\n 'fftw_threads':fftw_threads_info,\n 'dfftw_threads':dfftw_threads_info,\n 'sfftw_threads':sfftw_threads_info,\n 'djbfft':djbfft_info,\n 'blas':blas_info, # use blas_opt instead\n 'lapack':lapack_info, # use lapack_opt instead\n 'lapack_src':lapack_src_info,\n 'blas_src':blas_src_info,\n 'numpy':numpy_info,\n 'f2py':f2py_info,\n 'Numeric':Numeric_info,\n 'numarray':numarray_info,\n 'lapack_opt':lapack_opt_info,\n 'blas_opt':blas_opt_info,\n 'boost_python':boost_python_info,\n 'agg2':agg2_info,\n 'wx':wx_info,\n 'gdk_pixbuf_xlib_2':gdk_pixbuf_xlib_2_info,\n 'gdk-pixbuf-xlib-2.0':gdk_pixbuf_xlib_2_info,\n 'gdk_pixbuf_2':gdk_pixbuf_2_info,\n 'gdk-pixbuf-2.0':gdk_pixbuf_2_info,\n 'gdk':gdk_info,\n 'gdk_2':gdk_2_info,\n 'gdk-2.0':gdk_2_info,\n 'gdk_x11_2':gdk_x11_2_info,\n 'gdk-x11-2.0':gdk_x11_2_info,\n 'gtkp_x11_2':gtkp_x11_2_info,\n 'gtk+-x11-2.0':gtkp_x11_2_info,\n 'gtkp_2':gtkp_2_info,\n 'gtk+-2.0':gtkp_2_info,\n 'xft':xft_info,\n 'freetype2':freetype2_info,\n }.get(name.lower(),system_info)\n return cl().get_info(notfound_action)\n\nclass NotFoundError(DistutilsError):\n \"\"\"Some third-party program or library is not found.\"\"\"\n\nclass AtlasNotFoundError(NotFoundError):\n \"\"\"\n Atlas (http://math-atlas.sourceforge.net/) libraries not found.\n Directories to search for the libraries can be specified in the\n numpy/distutils/site.cfg file (section [atlas]) or by setting\n the ATLAS environment variable.\"\"\"\n\nclass LapackNotFoundError(NotFoundError):\n \"\"\"\n Lapack (http://www.netlib.org/lapack/) libraries not found.\n Directories to search for the libraries can be specified in the\n numpy/distutils/site.cfg file (section [lapack]) or by setting\n the LAPACK environment variable.\"\"\"\n\nclass LapackSrcNotFoundError(LapackNotFoundError):\n \"\"\"\n Lapack (http://www.netlib.org/lapack/) sources not found.\n Directories to search for the sources can be specified in the\n numpy/distutils/site.cfg file (section [lapack_src]) or by setting\n the LAPACK_SRC environment variable.\"\"\"\n\nclass BlasNotFoundError(NotFoundError):\n \"\"\"\n Blas (http://www.netlib.org/blas/) libraries not found.\n Directories to search for the libraries can be specified in the\n numpy/distutils/site.cfg file (section [blas]) or by setting\n the BLAS environment variable.\"\"\"\n\nclass BlasSrcNotFoundError(BlasNotFoundError):\n \"\"\"\n Blas (http://www.netlib.org/blas/) sources not found.\n Directories to search for the sources can be specified in the\n numpy/distutils/site.cfg file (section [blas_src]) or by setting\n the BLAS_SRC environment variable.\"\"\"\n\nclass FFTWNotFoundError(NotFoundError):\n \"\"\"\n FFTW (http://www.fftw.org/) libraries not found.\n Directories to search for the libraries can be specified in the\n numpy/distutils/site.cfg file (section [fftw]) or by setting\n the FFTW environment variable.\"\"\"\n\nclass DJBFFTNotFoundError(NotFoundError):\n \"\"\"\n DJBFFT (http://cr.yp.to/djbfft.html) libraries not found.\n Directories to search for the libraries can be specified in the\n numpy/distutils/site.cfg file (section [djbfft]) or by setting\n the DJBFFT environment variable.\"\"\"\n\nclass NumericNotFoundError(NotFoundError):\n \"\"\"\n Numeric (http://www.numpy.org/) module not found.\n Get it from above location, install it, and retry setup.py.\"\"\"\n\nclass X11NotFoundError(NotFoundError):\n \"\"\"X11 libraries not found.\"\"\"\n\nclass system_info:\n\n \"\"\" get_info() is the only public method. Don't use others.\n \"\"\"\n section = 'DEFAULT'\n dir_env_var = None\n search_static_first = 0 # XXX: disabled by default, may disappear in\n # future unless it is proved to be useful.\n verbosity = 1\n saved_results = {}\n\n notfounderror = NotFoundError\n\n def __init__ (self,\n default_lib_dirs=default_lib_dirs,\n default_include_dirs=default_include_dirs,\n verbosity = 1,\n ):\n self.__class__.info = {}\n self.local_prefixes = []\n defaults = {}\n defaults['libraries'] = ''\n defaults['library_dirs'] = os.pathsep.join(default_lib_dirs)\n defaults['include_dirs'] = os.pathsep.join(default_include_dirs)\n defaults['src_dirs'] = os.pathsep.join(default_src_dirs)\n defaults['search_static_first'] = str(self.search_static_first)\n self.cp = ConfigParser.ConfigParser(defaults)\n try:\n f = __file__\n except NameError,msg:\n f = sys.argv[0]\n cf = os.path.join(os.path.split(os.path.abspath(f))[0],\n 'site.cfg')\n self.cp.read([cf])\n if not self.cp.has_section(self.section):\n self.cp.add_section(self.section)\n self.search_static_first = self.cp.getboolean(self.section,\n 'search_static_first')\n assert isinstance(self.search_static_first, int)\n\n def calc_libraries_info(self):\n libs = self.get_libraries()\n dirs = self.get_lib_dirs()\n info = {}\n for lib in libs:\n i = None\n for d in dirs:\n i = self.check_libs(d,[lib])\n if i is not None:\n break\n if i is not None:\n dict_append(info,**i)\n else:\n print 'Library %s was not found. Ignoring' % (lib)\n return info\n\n def set_info(self,**info):\n if info:\n lib_info = self.calc_libraries_info()\n dict_append(info,**lib_info)\n self.saved_results[self.__class__.__name__] = info\n\n def has_info(self):\n return self.saved_results.has_key(self.__class__.__name__)\n\n def get_info(self,notfound_action=0):\n \"\"\" Return a dictonary with items that are compatible\n with numpy.distutils.setup keyword arguments.\n \"\"\"\n flag = 0\n if not self.has_info():\n flag = 1\n if self.verbosity>0:\n print self.__class__.__name__ + ':'\n if hasattr(self, 'calc_info'):\n self.calc_info()\n if notfound_action:\n if not self.has_info():\n if notfound_action==1:\n warnings.warn(self.notfounderror.__doc__)\n elif notfound_action==2:\n raise self.notfounderror,self.notfounderror.__doc__\n else:\n raise ValueError(repr(notfound_action))\n\n if self.verbosity>0:\n if not self.has_info():\n print ' NOT AVAILABLE'\n self.set_info()\n else:\n print ' FOUND:'\n\n res = self.saved_results.get(self.__class__.__name__)\n if self.verbosity>0 and flag:\n for k,v in res.items():\n v = str(v)\n if k=='sources' and len(v)>200: v = v[:60]+' ...\\n... '+v[-60:]\n print ' %s = %s'%(k,v)\n print\n\n return res\n\n def get_paths(self, section, key):\n dirs = self.cp.get(section, key).split(os.pathsep)\n env_var = self.dir_env_var\n if env_var:\n if is_sequence(env_var):\n e0 = env_var[-1]\n for e in env_var:\n if os.environ.has_key(e):\n e0 = e\n break\n if not env_var[0]==e0:\n print 'Setting %s=%s' % (env_var[0],e0)\n env_var = e0\n if env_var and os.environ.has_key(env_var):\n d = os.environ[env_var]\n if d=='None':\n print 'Disabled',self.__class__.__name__,'(%s is None)' \\\n % (self.dir_env_var)\n return []\n if os.path.isfile(d):\n dirs = [os.path.dirname(d)] + dirs\n l = getattr(self,'_lib_names',[])\n if len(l)==1:\n b = os.path.basename(d)\n b = os.path.splitext(b)[0]\n if b[:3]=='lib':\n print 'Replacing _lib_names[0]==%r with %r' \\\n % (self._lib_names[0], b[3:])\n self._lib_names[0] = b[3:]\n else:\n ds = d.split(os.pathsep)\n ds2 = []\n for d in ds:\n if os.path.isdir(d):\n ds2.append(d)\n for dd in ['include','lib']:\n d1 = os.path.join(d,dd)\n if os.path.isdir(d1):\n ds2.append(d1)\n dirs = ds2 + dirs\n default_dirs = self.cp.get('DEFAULT', key).split(os.pathsep)\n dirs.extend(default_dirs)\n ret = []\n [ret.append(d) for d in dirs if os.path.isdir(d) and d not in ret]\n if self.verbosity>1:\n print '(',key,'=',':'.join(ret),')'\n return ret\n\n def get_lib_dirs(self, key='library_dirs'):\n return self.get_paths(self.section, key)\n\n def get_include_dirs(self, key='include_dirs'):\n return self.get_paths(self.section, key)\n\n def get_src_dirs(self, key='src_dirs'):\n return self.get_paths(self.section, key)\n\n def get_libs(self, key, default):\n try:\n libs = self.cp.get(self.section, key)\n except ConfigParser.NoOptionError:\n if not default:\n return []\n if is_string(default):\n return [default]\n return default\n return [b for b in [a.strip() for a in libs.split(',')] if b]\n\n def get_libraries(self, key='libraries'):\n return self.get_libs(key,'')\n\n def check_libs(self,lib_dir,libs,opt_libs =[]):\n \"\"\" If static or shared libraries are available then return\n their info dictionary. \"\"\"\n if self.search_static_first:\n exts = ['.a',so_ext]\n else:\n exts = [so_ext,'.a']\n if sys.platform=='cygwin':\n exts.append('.dll.a')\n for ext in exts:\n info = self._check_libs(lib_dir,libs,opt_libs,[ext])\n if info is not None: return info\n return\n\n def check_libs2(self,lib_dir,libs,opt_libs =[]):\n \"\"\" If static or shared libraries are available then return\n their info dictionary. \"\"\"\n if self.search_static_first:\n exts = ['.a',so_ext]\n else:\n exts = [so_ext,'.a']\n if sys.platform=='cygwin':\n exts.append('.dll.a')\n info = self._check_libs(lib_dir,libs,opt_libs,exts)\n if info is not None: return info\n return\n\n def _lib_list(self, lib_dir, libs, exts):\n assert is_string(lib_dir)\n liblist = []\n for l in libs:\n for ext in exts:\n p = self.combine_paths(lib_dir, 'lib'+l+ext)\n if p:\n assert len(p)==1\n liblist.append(p[0])\n break\n return liblist\n\n def _extract_lib_names(self,libs):\n return [os.path.splitext(os.path.basename(p))[0][3:] \\\n for p in libs]\n\n def _check_libs(self,lib_dir,libs, opt_libs, exts):\n found_libs = self._lib_list(lib_dir, libs, exts)\n if len(found_libs) == len(libs):\n found_libs = self._extract_lib_names(found_libs)\n info = {'libraries' : found_libs, 'library_dirs' : [lib_dir]}\n opt_found_libs = self._lib_list(lib_dir, opt_libs, exts)\n if len(opt_found_libs) == len(opt_libs):\n opt_found_libs = self._extract_lib_names(opt_found_libs)\n info['libraries'].extend(opt_found_libs)\n return info\n\n def combine_paths(self,*args):\n return combine_paths(*args,**{'verbosity':self.verbosity})\n\n\nclass fft_opt_info(system_info):\n\n def calc_info(self):\n info = {}\n fftw_info = get_info('fftw3') or get_info('fftw2') or get_info('dfftw')\n djbfft_info = get_info('djbfft')\n if fftw_info:\n dict_append(info,**fftw_info)\n if djbfft_info:\n dict_append(info,**djbfft_info)\n self.set_info(**info)\n return\n\n\nclass fftw_info(system_info):\n #variables to override\n section = 'fftw'\n dir_env_var = 'FFTW'\n notfounderror = FFTWNotFoundError\n ver_info = [ { 'name':'fftw3',\n 'libs':['fftw3'],\n 'includes':['fftw3.h'],\n 'macros':[('SCIPY_FFTW3_H',None)]},\n { 'name':'fftw2',\n 'libs':['rfftw', 'fftw'],\n 'includes':['fftw.h','rfftw.h'],\n 'macros':[('SCIPY_FFTW_H',None)]}]\n\n def __init__(self):\n system_info.__init__(self)\n\n def calc_ver_info(self,ver_param):\n \"\"\"Returns True on successful version detection, else False\"\"\"\n lib_dirs = self.get_lib_dirs()\n incl_dirs = self.get_include_dirs()\n incl_dir = None\n libs = self.get_libs(self.section+'_libs', ver_param['libs'])\n info = None\n for d in lib_dirs:\n r = self.check_libs(d,libs)\n if r is not None:\n info = r\n break\n if info is not None:\n flag = 0\n for d in incl_dirs:\n if len(self.combine_paths(d,ver_param['includes']))==len(ver_param['includes']):\n dict_append(info,include_dirs=[d])\n flag = 1\n incl_dirs = [d]\n incl_dir = d\n break\n if flag:\n dict_append(info,define_macros=ver_param['macros'])\n else:\n info = None\n if info is not None:\n self.set_info(**info)\n return True\n else:\n if self.verbosity>0:\n print ' %s not found' % (ver_param['name'])\n return False\n\n def calc_info(self):\n for i in self.ver_info:\n if self.calc_ver_info(i):\n break\n\nclass fftw2_info(fftw_info):\n #variables to override\n section = 'fftw'\n dir_env_var = 'FFTW'\n notfounderror = FFTWNotFoundError\n ver_info = [ { 'name':'fftw2',\n 'libs':['rfftw', 'fftw'],\n 'includes':['fftw.h','rfftw.h'],\n 'macros':[('SCIPY_FFTW_H',None)]}\n ]\n\nclass fftw3_info(fftw_info):\n #variables to override\n section = 'fftw3'\n dir_env_var = 'FFTW3'\n notfounderror = FFTWNotFoundError\n ver_info = [ { 'name':'fftw3',\n 'libs':['fftw3'],\n 'includes':['fftw3.h'],\n 'macros':[('SCIPY_FFTW3_H',None)]},\n ]\n\nclass dfftw_info(fftw_info):\n section = 'fftw'\n dir_env_var = 'FFTW'\n ver_info = [ { 'name':'dfftw',\n 'libs':['drfftw','dfftw'],\n 'includes':['dfftw.h','drfftw.h'],\n 'macros':[('SCIPY_DFFTW_H',None)]} ]\n\nclass sfftw_info(fftw_info):\n section = 'fftw'\n dir_env_var = 'FFTW'\n ver_info = [ { 'name':'sfftw',\n 'libs':['srfftw','sfftw'],\n 'includes':['sfftw.h','srfftw.h'],\n 'macros':[('SCIPY_SFFTW_H',None)]} ]\n\nclass fftw_threads_info(fftw_info):\n section = 'fftw'\n dir_env_var = 'FFTW'\n ver_info = [ { 'name':'fftw threads',\n 'libs':['rfftw_threads','fftw_threads'],\n 'includes':['fftw_threads.h','rfftw_threads.h'],\n 'macros':[('SCIPY_FFTW_THREADS_H',None)]} ]\n\nclass dfftw_threads_info(fftw_info):\n section = 'fftw'\n dir_env_var = 'FFTW'\n ver_info = [ { 'name':'dfftw threads',\n 'libs':['drfftw_threads','dfftw_threads'],\n 'includes':['dfftw_threads.h','drfftw_threads.h'],\n 'macros':[('SCIPY_DFFTW_THREADS_H',None)]} ]\n\nclass sfftw_threads_info(fftw_info):\n section = 'fftw'\n dir_env_var = 'FFTW'\n ver_info = [ { 'name':'sfftw threads',\n 'libs':['srfftw_threads','sfftw_threads'],\n 'includes':['sfftw_threads.h','srfftw_threads.h'],\n 'macros':[('SCIPY_SFFTW_THREADS_H',None)]} ]\n\nclass djbfft_info(system_info):\n section = 'djbfft'\n dir_env_var = 'DJBFFT'\n notfounderror = DJBFFTNotFoundError\n\n def get_paths(self, section, key):\n pre_dirs = system_info.get_paths(self, section, key)\n dirs = []\n for d in pre_dirs:\n dirs.extend(self.combine_paths(d,['djbfft'])+[d])\n return [ d for d in dirs if os.path.isdir(d) ]\n\n def calc_info(self):\n lib_dirs = self.get_lib_dirs()\n incl_dirs = self.get_include_dirs()\n info = None\n for d in lib_dirs:\n p = self.combine_paths (d,['djbfft.a'])\n if p:\n info = {'extra_objects':p}\n break\n p = self.combine_paths (d,['libdjbfft.a','libdjbfft'+so_ext])\n if p:\n info = {'libraries':['djbfft'],'library_dirs':[d]}\n break\n if info is None:\n return\n for d in incl_dirs:\n if len(self.combine_paths(d,['fftc8.h','fftfreq.h']))==2:\n dict_append(info,include_dirs=[d],\n define_macros=[('SCIPY_DJBFFT_H',None)])\n self.set_info(**info)\n return\n return\n\nclass mkl_info(system_info):\n section = 'mkl'\n dir_env_var = 'MKL'\n _lib_mkl = ['mkl','vml','guide']\n\n def get_mkl_rootdir(self):\n mklroot = os.environ.get('MKLROOT',None)\n if mklroot is not None:\n return mklroot\n paths = os.environ.get('LD_LIBRARY_PATH','').split(os.pathsep)\n ld_so_conf = '/etc/ld.so.conf'\n if os.path.isfile(ld_so_conf):\n for d in open(ld_so_conf,'r').readlines():\n d = d.strip()\n if d: paths.append(d)\n intel_mkl_dirs = []\n for path in paths:\n path_atoms = path.split(os.sep)\n for m in path_atoms:\n if m.startswith('mkl'):\n d = os.sep.join(path_atoms[:path_atoms.index(m)+2])\n intel_mkl_dirs.append(d)\n break\n for d in paths:\n dirs = glob(os.path.join(d,'mkl','*')) + glob(os.path.join(d,'mkl*'))\n for d in dirs:\n if os.path.isdir(os.path.join(d,'lib')):\n return d\n return None\n\n def __init__(self):\n mklroot = self.get_mkl_rootdir()\n if mklroot is None:\n system_info.__init__(self)\n else:\n from cpuinfo import cpu\n if cpu.is_Itanium():\n plt = '64'\n l = 'mkl_ipf'\n elif cpu.is_Xeon():\n plt = 'em64t'\n l = 'mkl_em64t'\n else:\n plt = '32'\n l = 'mkl_ia32'\n if l not in self._lib_mkl:\n self._lib_mkl.insert(0,l)\n system_info.__init__(self,\n default_lib_dirs=[os.path.join(mklroot,'lib',plt)],\n default_include_dirs=[os.path.join(mklroot,'include')])\n\n def calc_info(self):\n lib_dirs = self.get_lib_dirs()\n incl_dirs = self.get_include_dirs()\n mkl_libs = self.get_libs('mkl_libs',self._lib_mkl)\n mkl = None\n for d in lib_dirs:\n mkl = self.check_libs2(d,mkl_libs)\n if mkl is not None:\n break\n if mkl is None:\n return\n info = {}\n dict_append(info,**mkl)\n dict_append(info,libraries = ['pthread'], include_dirs = incl_dirs)\n self.set_info(**info)\n\nclass lapack_mkl_info(mkl_info):\n\n def calc_info(self):\n mkl = get_info('mkl')\n if not mkl:\n return\n lapack_libs = self.get_libs('lapack_libs',['mkl_lapack'])\n info = {'libraries': lapack_libs}\n dict_append(info,**mkl)\n self.set_info(**info)\n\nclass blas_mkl_info(mkl_info):\n pass\n\nclass atlas_info(system_info):\n section = 'atlas'\n dir_env_var = 'ATLAS'\n _lib_names = ['f77blas','cblas']\n if sys.platform[:7]=='freebsd':\n _lib_atlas = ['atlas_r']\n _lib_lapack = ['alapack_r']\n else:\n _lib_atlas = ['atlas']\n _lib_lapack = ['lapack']\n\n notfounderror = AtlasNotFoundError\n\n def get_paths(self, section, key):\n pre_dirs = system_info.get_paths(self, section, key)\n dirs = []\n for d in pre_dirs:\n dirs.extend(self.combine_paths(d,['atlas*','ATLAS*',\n 'sse','3dnow','sse2'])+[d])\n return [ d for d in dirs if os.path.isdir(d) ]\n\n def calc_info(self):\n lib_dirs = self.get_lib_dirs()\n info = {}\n atlas_libs = self.get_libs('atlas_libs',\n self._lib_names + self._lib_atlas)\n lapack_libs = self.get_libs('lapack_libs',self._lib_lapack)\n atlas = None\n lapack = None\n atlas_1 = None\n for d in lib_dirs:\n atlas = self.check_libs(d,atlas_libs,[])\n lapack_atlas = self.check_libs(d,['lapack_atlas'],[])\n if atlas is not None:\n lib_dirs2 = self.combine_paths(d,['atlas*','ATLAS*'])+[d]\n for d2 in lib_dirs2:\n lapack = self.check_libs(d2,lapack_libs,[])\n if lapack is not None:\n break\n else:\n lapack = None\n if lapack is not None:\n break\n if atlas:\n atlas_1 = atlas\n print self.__class__\n if atlas is None:\n atlas = atlas_1\n if atlas is None:\n return\n include_dirs = self.get_include_dirs()\n h = (self.combine_paths(lib_dirs+include_dirs,'cblas.h') or [None])[0]\n if h:\n h = os.path.dirname(h)\n dict_append(info,include_dirs=[h])\n info['language'] = 'c'\n if lapack is not None:\n dict_append(info,**lapack)\n dict_append(info,**atlas)\n elif 'lapack_atlas' in atlas['libraries']:\n dict_append(info,**atlas)\n dict_append(info,define_macros=[('ATLAS_WITH_LAPACK_ATLAS',None)])\n self.set_info(**info)\n return\n else:\n dict_append(info,**atlas)\n dict_append(info,define_macros=[('ATLAS_WITHOUT_LAPACK',None)])\n message = \"\"\"\n*********************************************************************\n Could not find lapack library within the ATLAS installation.\n*********************************************************************\n\"\"\"\n warnings.warn(message)\n self.set_info(**info)\n return\n\n # Check if lapack library is complete, only warn if it is not.\n lapack_dir = lapack['library_dirs'][0]\n lapack_name = lapack['libraries'][0]\n lapack_lib = None\n for e in ['.a',so_ext]:\n fn = os.path.join(lapack_dir,'lib'+lapack_name+e)\n if os.path.exists(fn):\n lapack_lib = fn\n break\n if lapack_lib is not None:\n sz = os.stat(lapack_lib)[6]\n if sz <= 4000*1024:\n message = \"\"\"\n*********************************************************************\n Lapack library (from ATLAS) is probably incomplete:\n size of %s is %sk (expected >4000k)\n\n Follow the instructions in the KNOWN PROBLEMS section of the file\n numpy/INSTALL.txt.\n*********************************************************************\n\"\"\" % (lapack_lib,sz/1024)\n warnings.warn(message)\n else:\n info['language'] = 'f77'\n\n self.set_info(**info)\n\nclass atlas_blas_info(atlas_info):\n _lib_names = ['f77blas','cblas']\n\n def calc_info(self):\n lib_dirs = self.get_lib_dirs()\n info = {}\n atlas_libs = self.get_libs('atlas_libs',\n self._lib_names + self._lib_atlas)\n atlas = None\n for d in lib_dirs:\n atlas = self.check_libs(d,atlas_libs,[])\n if atlas is not None:\n break\n if atlas is None:\n return\n include_dirs = self.get_include_dirs()\n h = (self.combine_paths(lib_dirs+include_dirs,'cblas.h') or [None])[0]\n if h:\n h = os.path.dirname(h)\n dict_append(info,include_dirs=[h])\n info['language'] = 'c'\n\n dict_append(info,**atlas)\n\n self.set_info(**info)\n return\n\n\nclass atlas_threads_info(atlas_info):\n dir_env_var = ['PTATLAS','ATLAS']\n _lib_names = ['ptf77blas','ptcblas']\n\nclass atlas_blas_threads_info(atlas_blas_info):\n dir_env_var = ['PTATLAS','ATLAS']\n _lib_names = ['ptf77blas','ptcblas']\n\nclass lapack_atlas_info(atlas_info):\n _lib_names = ['lapack_atlas'] + atlas_info._lib_names\n\nclass lapack_atlas_threads_info(atlas_threads_info):\n _lib_names = ['lapack_atlas'] + atlas_threads_info._lib_names\n\nclass lapack_info(system_info):\n section = 'lapack'\n dir_env_var = 'LAPACK'\n _lib_names = ['lapack']\n notfounderror = LapackNotFoundError\n\n def calc_info(self):\n lib_dirs = self.get_lib_dirs()\n\n lapack_libs = self.get_libs('lapack_libs', self._lib_names)\n for d in lib_dirs:\n lapack = self.check_libs(d,lapack_libs,[])\n if lapack is not None:\n info = lapack\n break\n else:\n return\n info['language'] = 'f77'\n self.set_info(**info)\n\nclass lapack_src_info(system_info):\n section = 'lapack_src'\n dir_env_var = 'LAPACK_SRC'\n notfounderror = LapackSrcNotFoundError\n\n def get_paths(self, section, key):\n pre_dirs = system_info.get_paths(self, section, key)\n dirs = []\n for d in pre_dirs:\n dirs.extend([d] + self.combine_paths(d,['LAPACK*/SRC','SRC']))\n return [ d for d in dirs if os.path.isdir(d) ]\n\n def calc_info(self):\n src_dirs = self.get_src_dirs()\n src_dir = ''\n for d in src_dirs:\n if os.path.isfile(os.path.join(d,'dgesv.f')):\n src_dir = d\n break\n if not src_dir:\n #XXX: Get sources from netlib. May be ask first.\n return\n # The following is extracted from LAPACK-3.0/SRC/Makefile\n allaux='''\n ilaenv ieeeck lsame lsamen xerbla\n ''' # *.f\n laux = '''\n bdsdc bdsqr disna labad lacpy ladiv lae2 laebz laed0 laed1\n laed2 laed3 laed4 laed5 laed6 laed7 laed8 laed9 laeda laev2\n lagtf lagts lamch lamrg lanst lapy2 lapy3 larnv larrb larre\n larrf lartg laruv las2 lascl lasd0 lasd1 lasd2 lasd3 lasd4\n lasd5 lasd6 lasd7 lasd8 lasd9 lasda lasdq lasdt laset lasq1\n lasq2 lasq3 lasq4 lasq5 lasq6 lasr lasrt lassq lasv2 pttrf\n stebz stedc steqr sterf\n ''' # [s|d]*.f\n lasrc = '''\n gbbrd gbcon gbequ gbrfs gbsv gbsvx gbtf2 gbtrf gbtrs gebak\n gebal gebd2 gebrd gecon geequ gees geesx geev geevx gegs gegv\n gehd2 gehrd gelq2 gelqf gels gelsd gelss gelsx gelsy geql2\n geqlf geqp3 geqpf geqr2 geqrf gerfs gerq2 gerqf gesc2 gesdd\n gesv gesvd gesvx getc2 getf2 getrf getri getrs ggbak ggbal\n gges ggesx ggev ggevx ggglm gghrd gglse ggqrf ggrqf ggsvd\n ggsvp gtcon gtrfs gtsv gtsvx gttrf gttrs gtts2 hgeqz hsein\n hseqr labrd lacon laein lags2 lagtm lahqr lahrd laic1 lals0\n lalsa lalsd langb lange langt lanhs lansb lansp lansy lantb\n lantp lantr lapll lapmt laqgb laqge laqp2 laqps laqsb laqsp\n laqsy lar1v lar2v larf larfb larfg larft larfx largv larrv\n lartv larz larzb larzt laswp lasyf latbs latdf latps latrd\n latrs latrz latzm lauu2 lauum pbcon pbequ pbrfs pbstf pbsv\n pbsvx pbtf2 pbtrf pbtrs pocon poequ porfs posv posvx potf2\n potrf potri potrs ppcon ppequ pprfs ppsv ppsvx pptrf pptri\n pptrs ptcon pteqr ptrfs ptsv ptsvx pttrs ptts2 spcon sprfs\n spsv spsvx sptrf sptri sptrs stegr stein sycon syrfs sysv\n sysvx sytf2 sytrf sytri sytrs tbcon tbrfs tbtrs tgevc tgex2\n tgexc tgsen tgsja tgsna tgsy2 tgsyl tpcon tprfs tptri tptrs\n trcon trevc trexc trrfs trsen trsna trsyl trti2 trtri trtrs\n tzrqf tzrzf\n ''' # [s|c|d|z]*.f\n sd_lasrc = '''\n laexc lag2 lagv2 laln2 lanv2 laqtr lasy2 opgtr opmtr org2l\n org2r orgbr orghr orgl2 orglq orgql orgqr orgr2 orgrq orgtr\n orm2l orm2r ormbr ormhr orml2 ormlq ormql ormqr ormr2 ormr3\n ormrq ormrz ormtr rscl sbev sbevd sbevx sbgst sbgv sbgvd sbgvx\n sbtrd spev spevd spevx spgst spgv spgvd spgvx sptrd stev stevd\n stevr stevx syev syevd syevr syevx sygs2 sygst sygv sygvd\n sygvx sytd2 sytrd\n ''' # [s|d]*.f\n cz_lasrc = '''\n bdsqr hbev hbevd hbevx hbgst hbgv hbgvd hbgvx hbtrd hecon heev\n heevd heevr heevx hegs2 hegst hegv hegvd hegvx herfs hesv\n hesvx hetd2 hetf2 hetrd hetrf hetri hetrs hpcon hpev hpevd\n hpevx hpgst hpgv hpgvd hpgvx hprfs hpsv hpsvx hptrd hptrf\n hptri hptrs lacgv lacp2 lacpy lacrm lacrt ladiv laed0 laed7\n laed8 laesy laev2 lahef lanhb lanhe lanhp lanht laqhb laqhe\n laqhp larcm larnv lartg lascl laset lasr lassq pttrf rot spmv\n spr stedc steqr symv syr ung2l ung2r ungbr unghr ungl2 unglq\n ungql ungqr ungr2 ungrq ungtr unm2l unm2r unmbr unmhr unml2\n unmlq unmql unmqr unmr2 unmr3 unmrq unmrz unmtr upgtr upmtr\n ''' # [c|z]*.f\n #######\n sclaux = laux + ' econd ' # s*.f\n dzlaux = laux + ' secnd ' # d*.f\n slasrc = lasrc + sd_lasrc # s*.f\n dlasrc = lasrc + sd_lasrc # d*.f\n clasrc = lasrc + cz_lasrc + ' srot srscl ' # c*.f\n zlasrc = lasrc + cz_lasrc + ' drot drscl ' # z*.f\n oclasrc = ' icmax1 scsum1 ' # *.f\n ozlasrc = ' izmax1 dzsum1 ' # *.f\n sources = ['s%s.f'%f for f in (sclaux+slasrc).split()] \\\n + ['d%s.f'%f for f in (dzlaux+dlasrc).split()] \\\n + ['c%s.f'%f for f in (clasrc).split()] \\\n + ['z%s.f'%f for f in (zlasrc).split()] \\\n + ['%s.f'%f for f in (allaux+oclasrc+ozlasrc).split()]\n sources = [os.path.join(src_dir,f) for f in sources]\n #XXX: should we check here actual existence of source files?\n info = {'sources':sources,'language':'f77'}\n self.set_info(**info)\n\natlas_version_c_text = r'''\n/* This file is generated from numpy_distutils/system_info.py */\n#ifdef __CPLUSPLUS__\nextern \"C\" {\n#endif\n#include \"Python.h\"\nstatic PyMethodDef module_methods[] = { {NULL,NULL} };\nDL_EXPORT(void) initatlas_version(void) {\n void ATL_buildinfo(void);\n ATL_buildinfo();\n Py_InitModule(\"atlas_version\", module_methods);\n}\n#ifdef __CPLUSCPLUS__\n}\n#endif\n'''\n\ndef _get_build_temp():\n from distutils.util import get_platform\n plat_specifier = \".%s-%s\" % (get_platform(), sys.version[0:3])\n return os.path.join('build','temp'+plat_specifier)\n\ndef get_atlas_version(**config):\n os.environ['NO_SCIPY_IMPORT']='get_atlas_version'\n from core import Extension, setup\n from misc_util import get_cmd\n import log\n magic = hex(hash(repr(config)))\n def atlas_version_c(extension, build_dir,magic=magic):\n source = os.path.join(build_dir,'atlas_version_%s.c' % (magic))\n if os.path.isfile(source):\n from distutils.dep_util import newer\n if newer(source,__file__):\n return source\n f = open(source,'w')\n f.write(atlas_version_c_text)\n f.close()\n return source\n ext = Extension('atlas_version',\n sources=[atlas_version_c],\n **config)\n build_dir = _get_build_temp()\n extra_args = ['--build-lib',build_dir]\n for a in sys.argv:\n if re.match('[-][-]compiler[=]',a):\n extra_args.append(a)\n import distutils.core\n old_dist = distutils.core._setup_distribution\n distutils.core._setup_distribution = None\n try:\n dist = setup(ext_modules=[ext],\n script_name = 'get_atlas_version',\n script_args = ['build_src','build_ext']+extra_args)\n except Exception,msg:\n print \"##### msg: %s\" % msg\n if not msg:\n msg = \"Unknown Exception\"\n log.warn(msg)\n return None\n distutils.core._setup_distribution = old_dist\n\n from distutils.sysconfig import get_config_var\n so_ext = get_config_var('SO')\n target = os.path.join(build_dir,'atlas_version'+so_ext)\n cmd = [get_pythonexe(),'-c',\n '\"import imp,os;os.environ[\\\\\"NO_SCIPY_IMPORT\\\\\"]='\\\n '\\\\\"system_info.get_atlas_version:load atlas_version\\\\\";'\\\n 'imp.load_dynamic(\\\\\"atlas_version\\\\\",\\\\\"%s\\\\\")\"'\\\n % (os.path.basename(target))]\n s,o = exec_command(cmd,execute_in=os.path.dirname(target),use_tee=0)\n atlas_version = None\n if not s:\n m = re.search(r'ATLAS version (?P\\d+[.]\\d+[.]\\d+)',o)\n if m:\n atlas_version = m.group('version')\n if atlas_version is None:\n if re.search(r'undefined symbol: ATL_buildinfo',o,re.M):\n atlas_version = '3.2.1_pre3.3.6'\n else:\n print 'Command:',' '.join(cmd)\n print 'Status:',s\n print 'Output:',o\n return atlas_version\n\n\nclass lapack_opt_info(system_info):\n\n def calc_info(self):\n\n if sys.platform=='darwin' and not os.environ.get('ATLAS',None):\n args = []\n link_args = []\n if os.path.exists('/System/Library/Frameworks/Accelerate.framework/'):\n args.extend(['-faltivec'])\n link_args.extend(['-Wl,-framework','-Wl,Accelerate'])\n elif os.path.exists('/System/Library/Frameworks/vecLib.framework/'):\n args.extend(['-faltivec'])\n link_args.extend(['-Wl,-framework','-Wl,vecLib'])\n if args:\n self.set_info(extra_compile_args=args,\n extra_link_args=link_args,\n define_macros=[('NO_ATLAS_INFO',3)])\n return\n\n lapack_mkl_info = get_info('lapack_mkl')\n if lapack_mkl_info:\n self.set_info(**lapack_mkl_info)\n return\n\n atlas_info = get_info('atlas_threads')\n if not atlas_info:\n atlas_info = get_info('atlas')\n #atlas_info = {} ## uncomment for testing\n atlas_version = None\n need_lapack = 0\n need_blas = 0\n info = {}\n if atlas_info:\n version_info = atlas_info.copy()\n atlas_version = get_atlas_version(**version_info)\n if not atlas_info.has_key('define_macros'):\n atlas_info['define_macros'] = []\n if atlas_version is None:\n atlas_info['define_macros'].append(('NO_ATLAS_INFO',2))\n else:\n atlas_info['define_macros'].append(('ATLAS_INFO',\n '\"\\\\\"%s\\\\\"\"' % atlas_version))\n\t\tif atlas_version=='3.2.1_pre3.3.6':\n\t\t atlas_info['define_macros'].append(('NO_ATLAS_INFO',4))\n l = atlas_info.get('define_macros',[])\n if ('ATLAS_WITH_LAPACK_ATLAS',None) in l \\\n or ('ATLAS_WITHOUT_LAPACK',None) in l:\n need_lapack = 1\n info = atlas_info\n else:\n warnings.warn(AtlasNotFoundError.__doc__)\n need_blas = 1\n need_lapack = 1\n dict_append(info,define_macros=[('NO_ATLAS_INFO',1)])\n\n if need_lapack:\n lapack_info = get_info('lapack')\n #lapack_info = {} ## uncomment for testing\n if lapack_info:\n dict_append(info,**lapack_info)\n else:\n warnings.warn(LapackNotFoundError.__doc__)\n lapack_src_info = get_info('lapack_src')\n if not lapack_src_info:\n warnings.warn(LapackSrcNotFoundError.__doc__)\n return\n dict_append(info,libraries=[('flapack_src',lapack_src_info)])\n\n if need_blas:\n blas_info = get_info('blas')\n #blas_info = {} ## uncomment for testing\n if blas_info:\n dict_append(info,**blas_info)\n else:\n warnings.warn(BlasNotFoundError.__doc__)\n blas_src_info = get_info('blas_src')\n if not blas_src_info:\n warnings.warn(BlasSrcNotFoundError.__doc__)\n return\n dict_append(info,libraries=[('fblas_src',blas_src_info)])\n\n self.set_info(**info)\n return\n\n\nclass blas_opt_info(system_info):\n\n def calc_info(self):\n\n if sys.platform=='darwin' and not os.environ.get('ATLAS',None):\n args = []\n link_args = []\n if os.path.exists('/System/Library/Frameworks/Accelerate.framework/'):\n args.extend(['-faltivec',\n '-I/System/Library/Frameworks/vecLib.framework/Headers',\n ])\n link_args.extend(['-Wl,-framework','-Wl,Accelerate'])\n elif os.path.exists('/System/Library/Frameworks/vecLib.framework/'):\n args.extend(['-faltivec',\n '-I/System/Library/Frameworks/vecLib.framework/Headers',\n ])\n link_args.extend(['-Wl,-framework','-Wl,vecLib'])\n if args:\n self.set_info(extra_compile_args=args,\n extra_link_args=link_args,\n define_macros=[('NO_ATLAS_INFO',3)])\n return\n\n blas_mkl_info = get_info('blas_mkl')\n if blas_mkl_info:\n self.set_info(**blas_mkl_info)\n return\n\n atlas_info = get_info('atlas_blas_threads')\n if not atlas_info:\n atlas_info = get_info('atlas_blas')\n atlas_version = None\n need_blas = 0\n info = {}\n if atlas_info:\n version_info = atlas_info.copy()\n atlas_version = get_atlas_version(**version_info)\n if not atlas_info.has_key('define_macros'):\n atlas_info['define_macros'] = []\n if atlas_version is None:\n atlas_info['define_macros'].append(('NO_ATLAS_INFO',2))\n else:\n atlas_info['define_macros'].append(('ATLAS_INFO',\n '\"\\\\\"%s\\\\\"\"' % atlas_version))\n info = atlas_info\n else:\n warnings.warn(AtlasNotFoundError.__doc__)\n need_blas = 1\n dict_append(info,define_macros=[('NO_ATLAS_INFO',1)])\n\n if need_blas:\n blas_info = get_info('blas')\n if blas_info:\n dict_append(info,**blas_info)\n else:\n warnings.warn(BlasNotFoundError.__doc__)\n blas_src_info = get_info('blas_src')\n if not blas_src_info:\n warnings.warn(BlasSrcNotFoundError.__doc__)\n return\n dict_append(info,libraries=[('fblas_src',blas_src_info)])\n\n self.set_info(**info)\n return\n\n\nclass blas_info(system_info):\n section = 'blas'\n dir_env_var = 'BLAS'\n _lib_names = ['blas']\n notfounderror = BlasNotFoundError\n\n def calc_info(self):\n lib_dirs = self.get_lib_dirs()\n\n blas_libs = self.get_libs('blas_libs', self._lib_names)\n for d in lib_dirs:\n blas = self.check_libs(d,blas_libs,[])\n if blas is not None:\n info = blas\n break\n else:\n return\n info['language'] = 'f77' # XXX: is it generally true?\n self.set_info(**info)\n\n\nclass blas_src_info(system_info):\n section = 'blas_src'\n dir_env_var = 'BLAS_SRC'\n notfounderror = BlasSrcNotFoundError\n\n def get_paths(self, section, key):\n pre_dirs = system_info.get_paths(self, section, key)\n dirs = []\n for d in pre_dirs:\n dirs.extend([d] + self.combine_paths(d,['blas']))\n return [ d for d in dirs if os.path.isdir(d) ]\n\n def calc_info(self):\n src_dirs = self.get_src_dirs()\n src_dir = ''\n for d in src_dirs:\n if os.path.isfile(os.path.join(d,'daxpy.f')):\n src_dir = d\n break\n if not src_dir:\n #XXX: Get sources from netlib. May be ask first.\n return\n blas1 = '''\n caxpy csscal dnrm2 dzasum saxpy srotg zdotc ccopy cswap drot\n dznrm2 scasum srotm zdotu cdotc dasum drotg icamax scnrm2\n srotmg zdrot cdotu daxpy drotm idamax scopy sscal zdscal crotg\n dcabs1 drotmg isamax sdot sswap zrotg cscal dcopy dscal izamax\n snrm2 zaxpy zscal csrot ddot dswap sasum srot zcopy zswap\n '''\n blas2 = '''\n cgbmv chpmv ctrsv dsymv dtrsv sspr2 strmv zhemv ztpmv cgemv\n chpr dgbmv dsyr lsame ssymv strsv zher ztpsv cgerc chpr2 dgemv\n dsyr2 sgbmv ssyr xerbla zher2 ztrmv cgeru ctbmv dger dtbmv\n sgemv ssyr2 zgbmv zhpmv ztrsv chbmv ctbsv dsbmv dtbsv sger\n stbmv zgemv zhpr chemv ctpmv dspmv dtpmv ssbmv stbsv zgerc\n zhpr2 cher ctpsv dspr dtpsv sspmv stpmv zgeru ztbmv cher2\n ctrmv dspr2 dtrmv sspr stpsv zhbmv ztbsv\n '''\n blas3 = '''\n cgemm csymm ctrsm dsyrk sgemm strmm zhemm zsyr2k chemm csyr2k\n dgemm dtrmm ssymm strsm zher2k zsyrk cher2k csyrk dsymm dtrsm\n ssyr2k zherk ztrmm cherk ctrmm dsyr2k ssyrk zgemm zsymm ztrsm\n '''\n sources = [os.path.join(src_dir,f+'.f') \\\n for f in (blas1+blas2+blas3).split()]\n #XXX: should we check here actual existence of source files?\n info = {'sources':sources,'language':'f77'}\n self.set_info(**info)\n\nclass x11_info(system_info):\n section = 'x11'\n notfounderror = X11NotFoundError\n\n def __init__(self):\n system_info.__init__(self,\n default_lib_dirs=default_x11_lib_dirs,\n default_include_dirs=default_x11_include_dirs)\n\n def calc_info(self):\n if sys.platform in ['win32']:\n return\n lib_dirs = self.get_lib_dirs()\n include_dirs = self.get_include_dirs()\n x11_libs = self.get_libs('x11_libs', ['X11'])\n for lib_dir in lib_dirs:\n info = self.check_libs(lib_dir, x11_libs, [])\n if info is not None:\n break\n else:\n return\n inc_dir = None\n for d in include_dirs:\n if self.combine_paths(d, 'X11/X.h'):\n inc_dir = d\n break\n if inc_dir is not None:\n dict_append(info, include_dirs=[inc_dir])\n self.set_info(**info)\n\nclass _numpy_info(system_info):\n section = 'Numeric'\n modulename = 'Numeric'\n notfounderror = NumericNotFoundError\n\n def __init__(self):\n from distutils.sysconfig import get_python_inc\n include_dirs = []\n try:\n module = __import__(self.modulename)\n prefix = []\n for name in module.__file__.split(os.sep):\n if name=='lib':\n break\n prefix.append(name)\n include_dirs.append(get_python_inc(prefix=os.sep.join(prefix)))\n except ImportError:\n pass\n py_incl_dir = get_python_inc()\n include_dirs.append(py_incl_dir)\n for d in default_include_dirs:\n d = os.path.join(d, os.path.basename(py_incl_dir))\n if d not in include_dirs:\n include_dirs.append(d)\n system_info.__init__(self,\n default_lib_dirs=[],\n default_include_dirs=include_dirs)\n\n def calc_info(self):\n try:\n module = __import__(self.modulename)\n except ImportError:\n return\n info = {}\n macros = []\n for v in ['__version__','version']:\n vrs = getattr(module,v,None)\n if vrs is None:\n continue\n macros = [(self.modulename.upper()+'_VERSION',\n '\"\\\\\"%s\\\\\"\"' % (vrs)),\n (self.modulename.upper(),None)]\n break\n## try:\n## macros.append(\n## (self.modulename.upper()+'_VERSION_HEX',\n## hex(vstr2hex(module.__version__))),\n## )\n## except Exception,msg:\n## print msg\n dict_append(info, define_macros = macros)\n include_dirs = self.get_include_dirs()\n inc_dir = None\n for d in include_dirs:\n if self.combine_paths(d,\n os.path.join(self.modulename,\n 'arrayobject.h')):\n inc_dir = d\n break\n if inc_dir is not None:\n dict_append(info, include_dirs=[inc_dir])\n if info:\n self.set_info(**info)\n return\n\nclass numarray_info(_numpy_info):\n section = 'numarray'\n modulename = 'numarray'\n\nclass Numeric_info(_numpy_info):\n section = 'Numeric'\n modulename = 'Numeric'\n\nclass numpy_info(_numpy_info):\n section = 'numpy'\n modulename = 'numpy'\n\nclass f2py_info(system_info):\n def calc_info(self):\n try:\n import numpy.f2py as f2py\n except ImportError:\n return\n f2py_dir = os.path.join(os.path.dirname(f2py.__file__),'src')\n self.set_info(sources = [os.path.join(f2py_dir,'fortranobject.c')],\n include_dirs = [f2py_dir])\n return\n\nclass boost_python_info(system_info):\n section = 'boost_python'\n dir_env_var = 'BOOST'\n\n def get_paths(self, section, key):\n pre_dirs = system_info.get_paths(self, section, key)\n dirs = []\n for d in pre_dirs:\n dirs.extend([d] + self.combine_paths(d,['boost*']))\n return [ d for d in dirs if os.path.isdir(d) ]\n\n def calc_info(self):\n from distutils.sysconfig import get_python_inc\n src_dirs = self.get_src_dirs()\n src_dir = ''\n for d in src_dirs:\n if os.path.isfile(os.path.join(d,'libs','python','src','module.cpp')):\n src_dir = d\n break\n if not src_dir:\n return\n py_incl_dir = get_python_inc()\n srcs_dir = os.path.join(src_dir,'libs','python','src')\n bpl_srcs = glob(os.path.join(srcs_dir,'*.cpp'))\n bpl_srcs += glob(os.path.join(srcs_dir,'*','*.cpp'))\n info = {'libraries':[('boost_python_src',{'include_dirs':[src_dir,py_incl_dir],\n 'sources':bpl_srcs})],\n 'include_dirs':[src_dir],\n }\n if info:\n self.set_info(**info)\n return\n\nclass agg2_info(system_info):\n section = 'agg2'\n dir_env_var = 'AGG2'\n\n def get_paths(self, section, key):\n pre_dirs = system_info.get_paths(self, section, key)\n dirs = []\n for d in pre_dirs:\n dirs.extend([d] + self.combine_paths(d,['agg2*']))\n return [ d for d in dirs if os.path.isdir(d) ]\n\n def calc_info(self):\n src_dirs = self.get_src_dirs()\n src_dir = ''\n for d in src_dirs:\n if os.path.isfile(os.path.join(d,'src','agg_affine_matrix.cpp')):\n src_dir = d\n break\n if not src_dir:\n return\n if sys.platform=='win32':\n agg2_srcs = glob(os.path.join(src_dir,'src','platform','win32','agg_win32_bmp.cpp'))\n else:\n agg2_srcs = glob(os.path.join(src_dir,'src','*.cpp'))\n agg2_srcs += [os.path.join(src_dir,'src','platform','X11','agg_platform_support.cpp')]\n\n info = {'libraries':[('agg2_src',{'sources':agg2_srcs,\n 'include_dirs':[os.path.join(src_dir,'include')],\n })],\n 'include_dirs':[os.path.join(src_dir,'include')],\n }\n if info:\n self.set_info(**info)\n return\n\nclass _pkg_config_info(system_info):\n section = None\n config_env_var = 'PKG_CONFIG'\n default_config_exe = 'pkg-config'\n append_config_exe = ''\n version_macro_name = None\n release_macro_name = None\n version_flag = '--modversion'\n cflags_flag = '--cflags'\n\n def get_config_exe(self):\n if os.environ.has_key(self.config_env_var):\n return os.environ[self.config_env_var]\n return self.default_config_exe\n def get_config_output(self, config_exe, option):\n s,o = exec_command(config_exe+' '+self.append_config_exe+' '+option,use_tee=0)\n if not s:\n return o\n\n def calc_info(self):\n config_exe = find_executable(self.get_config_exe())\n if not os.path.isfile(config_exe):\n print 'File not found: %s. Cannot determine %s info.' \\\n % (config_exe, self.section)\n return\n info = {}\n macros = []\n libraries = []\n library_dirs = []\n include_dirs = []\n extra_link_args = []\n extra_compile_args = []\n version = self.get_config_output(config_exe,self.version_flag)\n if version:\n macros.append((self.__class__.__name__.split('.')[-1].upper(),\n '\"\\\\\"%s\\\\\"\"' % (version)))\n if self.version_macro_name:\n macros.append((self.version_macro_name+'_%s' % (version.replace('.','_')),None))\n if self.release_macro_name:\n release = self.get_config_output(config_exe,'--release')\n if release:\n macros.append((self.release_macro_name+'_%s' % (release.replace('.','_')),None))\n opts = self.get_config_output(config_exe,'--libs')\n if opts:\n for opt in opts.split():\n if opt[:2]=='-l':\n libraries.append(opt[2:])\n elif opt[:2]=='-L':\n library_dirs.append(opt[2:])\n else:\n extra_link_args.append(opt)\n opts = self.get_config_output(config_exe,self.cflags_flag)\n if opts:\n for opt in opts.split():\n if opt[:2]=='-I':\n include_dirs.append(opt[2:])\n elif opt[:2]=='-D':\n if '=' in opt:\n n,v = opt[2:].split('=')\n macros.append((n,v))\n else:\n macros.append((opt[2:],None))\n else:\n extra_compile_args.append(opt)\n if macros: dict_append(info, define_macros = macros)\n if libraries: dict_append(info, libraries = libraries)\n if library_dirs: dict_append(info, library_dirs = library_dirs)\n if include_dirs: dict_append(info, include_dirs = include_dirs)\n if extra_link_args: dict_append(info, extra_link_args = extra_link_args)\n if extra_compile_args: dict_append(info, extra_compile_args = extra_compile_args)\n if info:\n self.set_info(**info)\n return\n\nclass wx_info(_pkg_config_info):\n section = 'wx'\n config_env_var = 'WX_CONFIG'\n default_config_exe = 'wx-config'\n append_config_exe = ''\n version_macro_name = 'WX_VERSION'\n release_macro_name = 'WX_RELEASE'\n version_flag = '--version'\n cflags_flag = '--cxxflags'\n\nclass gdk_pixbuf_xlib_2_info(_pkg_config_info):\n section = 'gdk_pixbuf_xlib_2'\n append_config_exe = 'gdk-pixbuf-xlib-2.0'\n version_macro_name = 'GDK_PIXBUF_XLIB_VERSION'\n\nclass gdk_pixbuf_2_info(_pkg_config_info):\n section = 'gdk_pixbuf_2'\n append_config_exe = 'gdk-pixbuf-2.0'\n version_macro_name = 'GDK_PIXBUF_VERSION'\n\nclass gdk_x11_2_info(_pkg_config_info):\n section = 'gdk_x11_2'\n append_config_exe = 'gdk-x11-2.0'\n version_macro_name = 'GDK_X11_VERSION'\n\nclass gdk_2_info(_pkg_config_info):\n section = 'gdk_2'\n append_config_exe = 'gdk-2.0'\n version_macro_name = 'GDK_VERSION'\n\nclass gdk_info(_pkg_config_info):\n section = 'gdk'\n append_config_exe = 'gdk'\n version_macro_name = 'GDK_VERSION'\n\nclass gtkp_x11_2_info(_pkg_config_info):\n section = 'gtkp_x11_2'\n append_config_exe = 'gtk+-x11-2.0'\n version_macro_name = 'GTK_X11_VERSION'\n\n\nclass gtkp_2_info(_pkg_config_info):\n section = 'gtkp_2'\n append_config_exe = 'gtk+-2.0'\n version_macro_name = 'GTK_VERSION'\n\nclass xft_info(_pkg_config_info):\n section = 'xft'\n append_config_exe = 'xft'\n version_macro_name = 'XFT_VERSION'\n\nclass freetype2_info(_pkg_config_info):\n section = 'freetype2'\n append_config_exe = 'freetype2'\n version_macro_name = 'FREETYPE2_VERSION'\n\n## def vstr2hex(version):\n## bits = []\n## n = [24,16,8,4,0]\n## r = 0\n## for s in version.split('.'):\n## r |= int(s) << n[0]\n## del n[0]\n## return r\n\n#--------------------------------------------------------------------\n\ndef combine_paths(*args,**kws):\n \"\"\" Return a list of existing paths composed by all combinations of\n items from arguments.\n \"\"\"\n r = []\n for a in args:\n if not a: continue\n if is_string(a):\n a = [a]\n r.append(a)\n args = r\n if not args: return []\n if len(args)==1:\n result = reduce(lambda a,b:a+b,map(glob,args[0]),[])\n elif len (args)==2:\n result = []\n for a0 in args[0]:\n for a1 in args[1]:\n result.extend(glob(os.path.join(a0,a1)))\n else:\n result = combine_paths(*(combine_paths(args[0],args[1])+args[2:]))\n verbosity = kws.get('verbosity',1)\n if verbosity>1 and result:\n print '(','paths:',','.join(result),')'\n return result\n\nlanguage_map = {'c':0,'c++':1,'f77':2,'f90':3}\ninv_language_map = {0:'c',1:'c++',2:'f77',3:'f90'}\ndef dict_append(d,**kws):\n languages = []\n for k,v in kws.items():\n if k=='language':\n languages.append(v)\n continue\n if d.has_key(k):\n if k in ['library_dirs','include_dirs','define_macros']:\n [d[k].append(vv) for vv in v if vv not in d[k]]\n else:\n d[k].extend(v)\n else:\n d[k] = v\n if languages:\n l = inv_language_map[max([language_map.get(l,0) for l in languages])]\n d['language'] = l\n return\n\ndef show_all():\n import system_info\n import pprint\n match_info = re.compile(r'.*?_info').match\n show_only = []\n for n in sys.argv[1:]:\n if n[-5:] != '_info':\n n = n + '_info'\n show_only.append(n)\n show_all = not show_only\n for n in filter(match_info,dir(system_info)):\n if n in ['system_info','get_info']: continue\n if not show_all:\n if n not in show_only: continue\n del show_only[show_only.index(n)]\n c = getattr(system_info,n)()\n c.verbosity = 2\n r = c.get_info()\n if show_only:\n print 'Info classes not defined:',','.join(show_only)\nif __name__ == \"__main__\":\n show_all()\n", + "methods": [ + { + "name": "get_info", + "long_name": "get_info( name , notfound_action = 0 )", + "filename": "system_info.py", + "nloc": 51, + "complexity": 1, + "token_count": 226, + "parameters": [ + "name", + "notfound_action" + ], + "start_line": 147, + "end_line": 203, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 57, + "top_nesting_level": 0 + }, + { + "name": "__init__", + "long_name": "__init__( self , default_lib_dirs = default_lib_dirs , default_include_dirs = default_include_dirs , verbosity = 1 , )", + "filename": "system_info.py", + "nloc": 26, + "complexity": 3, + "token_count": 207, + "parameters": [ + "self", + "default_lib_dirs", + "default_include_dirs", + "verbosity" + ], + "start_line": 278, + "end_line": 303, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 26, + "top_nesting_level": 1 + }, + { + "name": "calc_libraries_info", + "long_name": "calc_libraries_info( self )", + "filename": "system_info.py", + "nloc": 15, + "complexity": 5, + "token_count": 78, + "parameters": [ + "self" + ], + "start_line": 305, + "end_line": 319, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 15, + "top_nesting_level": 1 + }, + { + "name": "set_info", + "long_name": "set_info( self , ** info )", + "filename": "system_info.py", + "nloc": 5, + "complexity": 2, + "token_count": 37, + "parameters": [ + "self", + "info" + ], + "start_line": 321, + "end_line": 325, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 5, + "top_nesting_level": 1 + }, + { + "name": "has_info", + "long_name": "has_info( self )", + "filename": "system_info.py", + "nloc": 2, + "complexity": 1, + "token_count": 18, + "parameters": [ + "self" + ], + "start_line": 327, + "end_line": 328, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 1 + }, + { + "name": "get_info", + "long_name": "get_info( self , notfound_action = 0 )", + "filename": "system_info.py", + "nloc": 30, + "complexity": 15, + "token_count": 208, + "parameters": [ + "self", + "notfound_action" + ], + "start_line": 330, + "end_line": 365, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 36, + "top_nesting_level": 1 + }, + { + "name": "get_paths", + "long_name": "get_paths( self , section , key )", + "filename": "system_info.py", + "nloc": 47, + "complexity": 20, + "token_count": 399, + "parameters": [ + "self", + "section", + "key" + ], + "start_line": 367, + "end_line": 413, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 47, + "top_nesting_level": 1 + }, + { + "name": "get_lib_dirs", + "long_name": "get_lib_dirs( self , key = 'library_dirs' )", + "filename": "system_info.py", + "nloc": 2, + "complexity": 1, + "token_count": 20, + "parameters": [ + "self", + "key" + ], + "start_line": 415, + "end_line": 416, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 1 + }, + { + "name": "get_include_dirs", + "long_name": "get_include_dirs( self , key = 'include_dirs' )", + "filename": "system_info.py", + "nloc": 2, + "complexity": 1, + "token_count": 20, + "parameters": [ + "self", + "key" + ], + "start_line": 418, + "end_line": 419, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 1 + }, + { + "name": "get_src_dirs", + "long_name": "get_src_dirs( self , key = 'src_dirs' )", + "filename": "system_info.py", + "nloc": 2, + "complexity": 1, + "token_count": 20, + "parameters": [ + "self", + "key" + ], + "start_line": 421, + "end_line": 422, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 1 + }, + { + "name": "get_libs", + "long_name": "get_libs( self , key , default )", + "filename": "system_info.py", + "nloc": 10, + "complexity": 7, + "token_count": 74, + "parameters": [ + "self", + "key", + "default" + ], + "start_line": 424, + "end_line": 433, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 10, + "top_nesting_level": 1 + }, + { + "name": "get_libraries", + "long_name": "get_libraries( self , key = 'libraries' )", + "filename": "system_info.py", + "nloc": 2, + "complexity": 1, + "token_count": 18, + "parameters": [ + "self", + "key" + ], + "start_line": 435, + "end_line": 436, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 1 + }, + { + "name": "check_libs", + "long_name": "check_libs( self , lib_dir , libs , opt_libs = [ ] )", + "filename": "system_info.py", + "nloc": 11, + "complexity": 5, + "token_count": 79, + "parameters": [ + "self", + "lib_dir", + "libs", + "opt_libs" + ], + "start_line": 438, + "end_line": 450, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 13, + "top_nesting_level": 1 + }, + { + "name": "check_libs2", + "long_name": "check_libs2( self , lib_dir , libs , opt_libs = [ ] )", + "filename": "system_info.py", + "nloc": 10, + "complexity": 4, + "token_count": 72, + "parameters": [ + "self", + "lib_dir", + "libs", + "opt_libs" + ], + "start_line": 452, + "end_line": 463, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 12, + "top_nesting_level": 1 + }, + { + "name": "_lib_list", + "long_name": "_lib_list( self , lib_dir , libs , exts )", + "filename": "system_info.py", + "nloc": 11, + "complexity": 4, + "token_count": 66, + "parameters": [ + "self", + "lib_dir", + "libs", + "exts" + ], + "start_line": 465, + "end_line": 475, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 11, + "top_nesting_level": 1 + }, + { + "name": "_extract_lib_names", + "long_name": "_extract_lib_names( self , libs )", + "filename": "system_info.py", + "nloc": 3, + "complexity": 2, + "token_count": 37, + "parameters": [ + "self", + "libs" + ], + "start_line": 477, + "end_line": 479, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "_check_libs", + "long_name": "_check_libs( self , lib_dir , libs , opt_libs , exts )", + "filename": "system_info.py", + "nloc": 10, + "complexity": 3, + "token_count": 99, + "parameters": [ + "self", + "lib_dir", + "libs", + "opt_libs", + "exts" + ], + "start_line": 481, + "end_line": 490, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 10, + "top_nesting_level": 1 + }, + { + "name": "combine_paths", + "long_name": "combine_paths( self , * args )", + "filename": "system_info.py", + "nloc": 2, + "complexity": 1, + "token_count": 23, + "parameters": [ + "self", + "args" + ], + "start_line": 492, + "end_line": 493, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 1 + }, + { + "name": "calc_info", + "long_name": "calc_info( self )", + "filename": "system_info.py", + "nloc": 10, + "complexity": 5, + "token_count": 59, + "parameters": [ + "self" + ], + "start_line": 498, + "end_line": 507, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 10, + "top_nesting_level": 1 + }, + { + "name": "__init__", + "long_name": "__init__( self )", + "filename": "system_info.py", + "nloc": 2, + "complexity": 1, + "token_count": 11, + "parameters": [ + "self" + ], + "start_line": 524, + "end_line": 525, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 1 + }, + { + "name": "calc_ver_info", + "long_name": "calc_ver_info( self , ver_param )", + "filename": "system_info.py", + "nloc": 31, + "complexity": 9, + "token_count": 184, + "parameters": [ + "self", + "ver_param" + ], + "start_line": 527, + "end_line": 558, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 32, + "top_nesting_level": 1 + }, + { + "name": "calc_info", + "long_name": "calc_info( self )", + "filename": "system_info.py", + "nloc": 4, + "complexity": 3, + "token_count": 21, + "parameters": [ + "self" + ], + "start_line": 560, + "end_line": 563, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 1 + }, + { + "name": "get_paths", + "long_name": "get_paths( self , section , key )", + "filename": "system_info.py", + "nloc": 6, + "complexity": 4, + "token_count": 66, + "parameters": [ + "self", + "section", + "key" + ], + "start_line": 632, + "end_line": 637, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 6, + "top_nesting_level": 1 + }, + { + "name": "calc_info", + "long_name": "calc_info( self )", + "filename": "system_info.py", + "nloc": 22, + "complexity": 7, + "token_count": 144, + "parameters": [ + "self" + ], + "start_line": 639, + "end_line": 660, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 22, + "top_nesting_level": 1 + }, + { + "name": "get_mkl_rootdir", + "long_name": "get_mkl_rootdir( self )", + "filename": "system_info.py", + "nloc": 24, + "complexity": 11, + "token_count": 211, + "parameters": [ + "self" + ], + "start_line": 667, + "end_line": 690, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 24, + "top_nesting_level": 1 + }, + { + "name": "__init__", + "long_name": "__init__( self )", + "filename": "system_info.py", + "nloc": 20, + "complexity": 5, + "token_count": 119, + "parameters": [ + "self" + ], + "start_line": 692, + "end_line": 711, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 20, + "top_nesting_level": 1 + }, + { + "name": "calc_info", + "long_name": "calc_info( self )", + "filename": "system_info.py", + "nloc": 15, + "complexity": 4, + "token_count": 94, + "parameters": [ + "self" + ], + "start_line": 713, + "end_line": 727, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 15, + "top_nesting_level": 1 + }, + { + "name": "calc_info", + "long_name": "calc_info( self )", + "filename": "system_info.py", + "nloc": 8, + "complexity": 2, + "token_count": 49, + "parameters": [ + "self" + ], + "start_line": 731, + "end_line": 738, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 8, + "top_nesting_level": 1 + }, + { + "name": "get_paths", + "long_name": "get_paths( self , section , key )", + "filename": "system_info.py", + "nloc": 7, + "complexity": 4, + "token_count": 74, + "parameters": [ + "self", + "section", + "key" + ], + "start_line": 756, + "end_line": 762, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 7, + "top_nesting_level": 1 + }, + { + "name": "calc_info", + "long_name": "calc_info( self )", + "filename": "system_info.py", + "nloc": 78, + "complexity": 17, + "token_count": 441, + "parameters": [ + "self" + ], + "start_line": 764, + "end_line": 844, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 81, + "top_nesting_level": 1 + }, + { + "name": "calc_info", + "long_name": "calc_info( self )", + "filename": "system_info.py", + "nloc": 21, + "complexity": 6, + "token_count": 138, + "parameters": [ + "self" + ], + "start_line": 849, + "end_line": 871, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 23, + "top_nesting_level": 1 + }, + { + "name": "calc_info", + "long_name": "calc_info( self )", + "filename": "system_info.py", + "nloc": 12, + "complexity": 3, + "token_count": 68, + "parameters": [ + "self" + ], + "start_line": 894, + "end_line": 906, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 13, + "top_nesting_level": 1 + }, + { + "name": "get_paths", + "long_name": "get_paths( self , section , key )", + "filename": "system_info.py", + "nloc": 6, + "complexity": 4, + "token_count": 68, + "parameters": [ + "self", + "section", + "key" + ], + "start_line": 913, + "end_line": 918, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 6, + "top_nesting_level": 1 + }, + { + "name": "calc_info", + "long_name": "calc_info( self )", + "filename": "system_info.py", + "nloc": 81, + "complexity": 10, + "token_count": 232, + "parameters": [ + "self" + ], + "start_line": 920, + "end_line": 1004, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 85, + "top_nesting_level": 1 + }, + { + "name": "_get_build_temp", + "long_name": "_get_build_temp( )", + "filename": "system_info.py", + "nloc": 4, + "complexity": 1, + "token_count": 41, + "parameters": [], + "start_line": 1023, + "end_line": 1026, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 0 + }, + { + "name": "get_atlas_version.atlas_version_c", + "long_name": "get_atlas_version.atlas_version_c( extension , build_dir , magic = magic )", + "filename": "system_info.py", + "nloc": 10, + "complexity": 3, + "token_count": 74, + "parameters": [ + "extension", + "build_dir", + "magic" + ], + "start_line": 1034, + "end_line": 1043, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 10, + "top_nesting_level": 1 + }, + { + "name": "get_atlas_version", + "long_name": "get_atlas_version( ** config )", + "filename": "system_info.py", + "nloc": 51, + "complexity": 9, + "token_count": 314, + "parameters": [ + "config" + ], + "start_line": 1028, + "end_line": 1088, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 61, + "top_nesting_level": 0 + }, + { + "name": "calc_info", + "long_name": "calc_info( self )", + "filename": "system_info.py", + "nloc": 72, + "complexity": 20, + "token_count": 443, + "parameters": [ + "self" + ], + "start_line": 1093, + "end_line": 1173, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 81, + "top_nesting_level": 1 + }, + { + "name": "calc_info", + "long_name": "calc_info( self )", + "filename": "system_info.py", + "nloc": 57, + "complexity": 14, + "token_count": 331, + "parameters": [ + "self" + ], + "start_line": 1178, + "end_line": 1239, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 62, + "top_nesting_level": 1 + }, + { + "name": "calc_info", + "long_name": "calc_info( self )", + "filename": "system_info.py", + "nloc": 12, + "complexity": 3, + "token_count": 68, + "parameters": [ + "self" + ], + "start_line": 1248, + "end_line": 1260, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 13, + "top_nesting_level": 1 + }, + { + "name": "get_paths", + "long_name": "get_paths( self , section , key )", + "filename": "system_info.py", + "nloc": 6, + "complexity": 4, + "token_count": 66, + "parameters": [ + "self", + "section", + "key" + ], + "start_line": 1268, + "end_line": 1273, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 6, + "top_nesting_level": 1 + }, + { + "name": "calc_info", + "long_name": "calc_info( self )", + "filename": "system_info.py", + "nloc": 34, + "complexity": 5, + "token_count": 106, + "parameters": [ + "self" + ], + "start_line": 1275, + "end_line": 1310, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 36, + "top_nesting_level": 1 + }, + { + "name": "__init__", + "long_name": "__init__( self )", + "filename": "system_info.py", + "nloc": 4, + "complexity": 1, + "token_count": 19, + "parameters": [ + "self" + ], + "start_line": 1316, + "end_line": 1319, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 1 + }, + { + "name": "calc_info", + "long_name": "calc_info( self )", + "filename": "system_info.py", + "nloc": 20, + "complexity": 7, + "token_count": 114, + "parameters": [ + "self" + ], + "start_line": 1321, + "end_line": 1340, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 20, + "top_nesting_level": 1 + }, + { + "name": "__init__", + "long_name": "__init__( self )", + "filename": "system_info.py", + "nloc": 22, + "complexity": 6, + "token_count": 139, + "parameters": [ + "self" + ], + "start_line": 1347, + "end_line": 1368, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 22, + "top_nesting_level": 1 + }, + { + "name": "calc_info", + "long_name": "calc_info( self )", + "filename": "system_info.py", + "nloc": 29, + "complexity": 8, + "token_count": 161, + "parameters": [ + "self" + ], + "start_line": 1370, + "end_line": 1405, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 36, + "top_nesting_level": 1 + }, + { + "name": "calc_info", + "long_name": "calc_info( self )", + "filename": "system_info.py", + "nloc": 9, + "complexity": 2, + "token_count": 64, + "parameters": [ + "self" + ], + "start_line": 1420, + "end_line": 1428, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 9, + "top_nesting_level": 1 + }, + { + "name": "get_paths", + "long_name": "get_paths( self , section , key )", + "filename": "system_info.py", + "nloc": 6, + "complexity": 4, + "token_count": 66, + "parameters": [ + "self", + "section", + "key" + ], + "start_line": 1434, + "end_line": 1439, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 6, + "top_nesting_level": 1 + }, + { + "name": "calc_info", + "long_name": "calc_info( self )", + "filename": "system_info.py", + "nloc": 21, + "complexity": 5, + "token_count": 156, + "parameters": [ + "self" + ], + "start_line": 1441, + "end_line": 1461, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 21, + "top_nesting_level": 1 + }, + { + "name": "get_paths", + "long_name": "get_paths( self , section , key )", + "filename": "system_info.py", + "nloc": 6, + "complexity": 4, + "token_count": 66, + "parameters": [ + "self", + "section", + "key" + ], + "start_line": 1467, + "end_line": 1472, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 6, + "top_nesting_level": 1 + }, + { + "name": "calc_info", + "long_name": "calc_info( self )", + "filename": "system_info.py", + "nloc": 22, + "complexity": 6, + "token_count": 177, + "parameters": [ + "self" + ], + "start_line": 1474, + "end_line": 1496, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 23, + "top_nesting_level": 1 + }, + { + "name": "get_config_exe", + "long_name": "get_config_exe( self )", + "filename": "system_info.py", + "nloc": 4, + "complexity": 2, + "token_count": 30, + "parameters": [ + "self" + ], + "start_line": 1508, + "end_line": 1511, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 1 + }, + { + "name": "get_config_output", + "long_name": "get_config_output( self , config_exe , option )", + "filename": "system_info.py", + "nloc": 4, + "complexity": 2, + "token_count": 37, + "parameters": [ + "self", + "config_exe", + "option" + ], + "start_line": 1512, + "end_line": 1515, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 1 + }, + { + "name": "calc_info", + "long_name": "calc_info( self )", + "filename": "system_info.py", + "nloc": 54, + "complexity": 22, + "token_count": 435, + "parameters": [ + "self" + ], + "start_line": 1517, + "end_line": 1570, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 54, + "top_nesting_level": 1 + }, + { + "name": "combine_paths", + "long_name": "combine_paths( * args , ** kws )", + "filename": "system_info.py", + "nloc": 22, + "complexity": 11, + "token_count": 191, + "parameters": [ + "args", + "kws" + ], + "start_line": 1639, + "end_line": 1663, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 25, + "top_nesting_level": 0 + }, + { + "name": "dict_append", + "long_name": "dict_append( d , ** kws )", + "filename": "system_info.py", + "nloc": 17, + "complexity": 9, + "token_count": 128, + "parameters": [ + "d", + "kws" + ], + "start_line": 1667, + "end_line": 1683, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 17, + "top_nesting_level": 0 + }, + { + "name": "show_all", + "long_name": "show_all( )", + "filename": "system_info.py", + "nloc": 20, + "complexity": 8, + "token_count": 137, + "parameters": [], + "start_line": 1685, + "end_line": 1704, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 20, + "top_nesting_level": 0 + } + ], + "methods_before": [ + { + "name": "get_info", + "long_name": "get_info( name , notfound_action = 0 )", + "filename": "system_info.py", + "nloc": 51, + "complexity": 1, + "token_count": 226, + "parameters": [ + "name", + "notfound_action" + ], + "start_line": 146, + "end_line": 202, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 57, + "top_nesting_level": 0 + }, + { + "name": "__init__", + "long_name": "__init__( self , default_lib_dirs = default_lib_dirs , default_include_dirs = default_include_dirs , verbosity = 1 , )", + "filename": "system_info.py", + "nloc": 26, + "complexity": 3, + "token_count": 207, + "parameters": [ + "self", + "default_lib_dirs", + "default_include_dirs", + "verbosity" + ], + "start_line": 277, + "end_line": 302, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 26, + "top_nesting_level": 1 + }, + { + "name": "calc_libraries_info", + "long_name": "calc_libraries_info( self )", + "filename": "system_info.py", + "nloc": 15, + "complexity": 5, + "token_count": 78, + "parameters": [ + "self" + ], + "start_line": 304, + "end_line": 318, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 15, + "top_nesting_level": 1 + }, + { + "name": "set_info", + "long_name": "set_info( self , ** info )", + "filename": "system_info.py", + "nloc": 5, + "complexity": 2, + "token_count": 37, + "parameters": [ + "self", + "info" + ], + "start_line": 320, + "end_line": 324, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 5, + "top_nesting_level": 1 + }, + { + "name": "has_info", + "long_name": "has_info( self )", + "filename": "system_info.py", + "nloc": 2, + "complexity": 1, + "token_count": 18, + "parameters": [ + "self" + ], + "start_line": 326, + "end_line": 327, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 1 + }, + { + "name": "get_info", + "long_name": "get_info( self , notfound_action = 0 )", + "filename": "system_info.py", + "nloc": 30, + "complexity": 15, + "token_count": 208, + "parameters": [ + "self", + "notfound_action" + ], + "start_line": 329, + "end_line": 364, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 36, + "top_nesting_level": 1 + }, + { + "name": "get_paths", + "long_name": "get_paths( self , section , key )", + "filename": "system_info.py", + "nloc": 47, + "complexity": 20, + "token_count": 399, + "parameters": [ + "self", + "section", + "key" + ], + "start_line": 366, + "end_line": 412, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 47, + "top_nesting_level": 1 + }, + { + "name": "get_lib_dirs", + "long_name": "get_lib_dirs( self , key = 'library_dirs' )", + "filename": "system_info.py", + "nloc": 2, + "complexity": 1, + "token_count": 20, + "parameters": [ + "self", + "key" + ], + "start_line": 414, + "end_line": 415, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 1 + }, + { + "name": "get_include_dirs", + "long_name": "get_include_dirs( self , key = 'include_dirs' )", + "filename": "system_info.py", + "nloc": 2, + "complexity": 1, + "token_count": 20, + "parameters": [ + "self", + "key" + ], + "start_line": 417, + "end_line": 418, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 1 + }, + { + "name": "get_src_dirs", + "long_name": "get_src_dirs( self , key = 'src_dirs' )", + "filename": "system_info.py", + "nloc": 2, + "complexity": 1, + "token_count": 20, + "parameters": [ + "self", + "key" + ], + "start_line": 420, + "end_line": 421, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 1 + }, + { + "name": "get_libs", + "long_name": "get_libs( self , key , default )", + "filename": "system_info.py", + "nloc": 10, + "complexity": 7, + "token_count": 74, + "parameters": [ + "self", + "key", + "default" + ], + "start_line": 423, + "end_line": 432, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 10, + "top_nesting_level": 1 + }, + { + "name": "get_libraries", + "long_name": "get_libraries( self , key = 'libraries' )", + "filename": "system_info.py", + "nloc": 2, + "complexity": 1, + "token_count": 18, + "parameters": [ + "self", + "key" + ], + "start_line": 434, + "end_line": 435, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 1 + }, + { + "name": "check_libs", + "long_name": "check_libs( self , lib_dir , libs , opt_libs = [ ] )", + "filename": "system_info.py", + "nloc": 11, + "complexity": 5, + "token_count": 79, + "parameters": [ + "self", + "lib_dir", + "libs", + "opt_libs" + ], + "start_line": 437, + "end_line": 449, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 13, + "top_nesting_level": 1 + }, + { + "name": "check_libs2", + "long_name": "check_libs2( self , lib_dir , libs , opt_libs = [ ] )", + "filename": "system_info.py", + "nloc": 10, + "complexity": 4, + "token_count": 72, + "parameters": [ + "self", + "lib_dir", + "libs", + "opt_libs" + ], + "start_line": 451, + "end_line": 462, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 12, + "top_nesting_level": 1 + }, + { + "name": "_lib_list", + "long_name": "_lib_list( self , lib_dir , libs , exts )", + "filename": "system_info.py", + "nloc": 11, + "complexity": 4, + "token_count": 66, + "parameters": [ + "self", + "lib_dir", + "libs", + "exts" + ], + "start_line": 464, + "end_line": 474, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 11, + "top_nesting_level": 1 + }, + { + "name": "_extract_lib_names", + "long_name": "_extract_lib_names( self , libs )", + "filename": "system_info.py", + "nloc": 3, + "complexity": 2, + "token_count": 37, + "parameters": [ + "self", + "libs" + ], + "start_line": 476, + "end_line": 478, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "_check_libs", + "long_name": "_check_libs( self , lib_dir , libs , opt_libs , exts )", + "filename": "system_info.py", + "nloc": 10, + "complexity": 3, + "token_count": 99, + "parameters": [ + "self", + "lib_dir", + "libs", + "opt_libs", + "exts" + ], + "start_line": 480, + "end_line": 489, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 10, + "top_nesting_level": 1 + }, + { + "name": "combine_paths", + "long_name": "combine_paths( self , * args )", + "filename": "system_info.py", + "nloc": 2, + "complexity": 1, + "token_count": 23, + "parameters": [ + "self", + "args" + ], + "start_line": 491, + "end_line": 492, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 1 + }, + { + "name": "calc_info", + "long_name": "calc_info( self )", + "filename": "system_info.py", + "nloc": 10, + "complexity": 5, + "token_count": 59, + "parameters": [ + "self" + ], + "start_line": 497, + "end_line": 506, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 10, + "top_nesting_level": 1 + }, + { + "name": "__init__", + "long_name": "__init__( self )", + "filename": "system_info.py", + "nloc": 2, + "complexity": 1, + "token_count": 11, + "parameters": [ + "self" + ], + "start_line": 523, + "end_line": 524, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 1 + }, + { + "name": "calc_ver_info", + "long_name": "calc_ver_info( self , ver_param )", + "filename": "system_info.py", + "nloc": 31, + "complexity": 9, + "token_count": 184, + "parameters": [ + "self", + "ver_param" + ], + "start_line": 526, + "end_line": 557, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 32, + "top_nesting_level": 1 + }, + { + "name": "calc_info", + "long_name": "calc_info( self )", + "filename": "system_info.py", + "nloc": 4, + "complexity": 3, + "token_count": 21, + "parameters": [ + "self" + ], + "start_line": 559, + "end_line": 562, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 1 + }, + { + "name": "get_paths", + "long_name": "get_paths( self , section , key )", + "filename": "system_info.py", + "nloc": 6, + "complexity": 4, + "token_count": 66, + "parameters": [ + "self", + "section", + "key" + ], + "start_line": 631, + "end_line": 636, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 6, + "top_nesting_level": 1 + }, + { + "name": "calc_info", + "long_name": "calc_info( self )", + "filename": "system_info.py", + "nloc": 22, + "complexity": 7, + "token_count": 144, + "parameters": [ + "self" + ], + "start_line": 638, + "end_line": 659, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 22, + "top_nesting_level": 1 + }, + { + "name": "get_mkl_rootdir", + "long_name": "get_mkl_rootdir( self )", + "filename": "system_info.py", + "nloc": 24, + "complexity": 11, + "token_count": 211, + "parameters": [ + "self" + ], + "start_line": 666, + "end_line": 689, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 24, + "top_nesting_level": 1 + }, + { + "name": "__init__", + "long_name": "__init__( self )", + "filename": "system_info.py", + "nloc": 20, + "complexity": 5, + "token_count": 119, + "parameters": [ + "self" + ], + "start_line": 691, + "end_line": 710, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 20, + "top_nesting_level": 1 + }, + { + "name": "calc_info", + "long_name": "calc_info( self )", + "filename": "system_info.py", + "nloc": 15, + "complexity": 4, + "token_count": 94, + "parameters": [ + "self" + ], + "start_line": 712, + "end_line": 726, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 15, + "top_nesting_level": 1 + }, + { + "name": "calc_info", + "long_name": "calc_info( self )", + "filename": "system_info.py", + "nloc": 8, + "complexity": 2, + "token_count": 49, + "parameters": [ + "self" + ], + "start_line": 730, + "end_line": 737, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 8, + "top_nesting_level": 1 + }, + { + "name": "get_paths", + "long_name": "get_paths( self , section , key )", + "filename": "system_info.py", + "nloc": 7, + "complexity": 4, + "token_count": 74, + "parameters": [ + "self", + "section", + "key" + ], + "start_line": 755, + "end_line": 761, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 7, + "top_nesting_level": 1 + }, + { + "name": "calc_info", + "long_name": "calc_info( self )", + "filename": "system_info.py", + "nloc": 78, + "complexity": 17, + "token_count": 441, + "parameters": [ + "self" + ], + "start_line": 763, + "end_line": 843, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 81, + "top_nesting_level": 1 + }, + { + "name": "calc_info", + "long_name": "calc_info( self )", + "filename": "system_info.py", + "nloc": 21, + "complexity": 6, + "token_count": 138, + "parameters": [ + "self" + ], + "start_line": 848, + "end_line": 870, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 23, + "top_nesting_level": 1 + }, + { + "name": "calc_info", + "long_name": "calc_info( self )", + "filename": "system_info.py", + "nloc": 12, + "complexity": 3, + "token_count": 68, + "parameters": [ + "self" + ], + "start_line": 893, + "end_line": 905, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 13, + "top_nesting_level": 1 + }, + { + "name": "get_paths", + "long_name": "get_paths( self , section , key )", + "filename": "system_info.py", + "nloc": 6, + "complexity": 4, + "token_count": 68, + "parameters": [ + "self", + "section", + "key" + ], + "start_line": 912, + "end_line": 917, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 6, + "top_nesting_level": 1 + }, + { + "name": "calc_info", + "long_name": "calc_info( self )", + "filename": "system_info.py", + "nloc": 81, + "complexity": 10, + "token_count": 232, + "parameters": [ + "self" + ], + "start_line": 919, + "end_line": 1003, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 85, + "top_nesting_level": 1 + }, + { + "name": "_get_build_temp", + "long_name": "_get_build_temp( )", + "filename": "system_info.py", + "nloc": 4, + "complexity": 1, + "token_count": 41, + "parameters": [], + "start_line": 1022, + "end_line": 1025, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 0 + }, + { + "name": "get_atlas_version.atlas_version_c", + "long_name": "get_atlas_version.atlas_version_c( extension , build_dir , magic = magic )", + "filename": "system_info.py", + "nloc": 10, + "complexity": 3, + "token_count": 74, + "parameters": [ + "extension", + "build_dir", + "magic" + ], + "start_line": 1033, + "end_line": 1042, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 10, + "top_nesting_level": 1 + }, + { + "name": "get_atlas_version", + "long_name": "get_atlas_version( ** config )", + "filename": "system_info.py", + "nloc": 51, + "complexity": 9, + "token_count": 314, + "parameters": [ + "config" + ], + "start_line": 1027, + "end_line": 1087, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 61, + "top_nesting_level": 0 + }, + { + "name": "calc_info", + "long_name": "calc_info( self )", + "filename": "system_info.py", + "nloc": 72, + "complexity": 20, + "token_count": 443, + "parameters": [ + "self" + ], + "start_line": 1092, + "end_line": 1172, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 81, + "top_nesting_level": 1 + }, + { + "name": "calc_info", + "long_name": "calc_info( self )", + "filename": "system_info.py", + "nloc": 57, + "complexity": 14, + "token_count": 331, + "parameters": [ + "self" + ], + "start_line": 1177, + "end_line": 1238, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 62, + "top_nesting_level": 1 + }, + { + "name": "calc_info", + "long_name": "calc_info( self )", + "filename": "system_info.py", + "nloc": 12, + "complexity": 3, + "token_count": 68, + "parameters": [ + "self" + ], + "start_line": 1247, + "end_line": 1259, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 13, + "top_nesting_level": 1 + }, + { + "name": "get_paths", + "long_name": "get_paths( self , section , key )", + "filename": "system_info.py", + "nloc": 6, + "complexity": 4, + "token_count": 66, + "parameters": [ + "self", + "section", + "key" + ], + "start_line": 1267, + "end_line": 1272, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 6, + "top_nesting_level": 1 + }, + { + "name": "calc_info", + "long_name": "calc_info( self )", + "filename": "system_info.py", + "nloc": 34, + "complexity": 5, + "token_count": 106, + "parameters": [ + "self" + ], + "start_line": 1274, + "end_line": 1309, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 36, + "top_nesting_level": 1 + }, + { + "name": "__init__", + "long_name": "__init__( self )", + "filename": "system_info.py", + "nloc": 4, + "complexity": 1, + "token_count": 19, + "parameters": [ + "self" + ], + "start_line": 1315, + "end_line": 1318, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 1 + }, + { + "name": "calc_info", + "long_name": "calc_info( self )", + "filename": "system_info.py", + "nloc": 20, + "complexity": 7, + "token_count": 114, + "parameters": [ + "self" + ], + "start_line": 1320, + "end_line": 1339, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 20, + "top_nesting_level": 1 + }, + { + "name": "__init__", + "long_name": "__init__( self )", + "filename": "system_info.py", + "nloc": 22, + "complexity": 6, + "token_count": 139, + "parameters": [ + "self" + ], + "start_line": 1346, + "end_line": 1367, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 22, + "top_nesting_level": 1 + }, + { + "name": "calc_info", + "long_name": "calc_info( self )", + "filename": "system_info.py", + "nloc": 29, + "complexity": 8, + "token_count": 161, + "parameters": [ + "self" + ], + "start_line": 1369, + "end_line": 1404, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 36, + "top_nesting_level": 1 + }, + { + "name": "calc_info", + "long_name": "calc_info( self )", + "filename": "system_info.py", + "nloc": 9, + "complexity": 2, + "token_count": 64, + "parameters": [ + "self" + ], + "start_line": 1419, + "end_line": 1427, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 9, + "top_nesting_level": 1 + }, + { + "name": "get_paths", + "long_name": "get_paths( self , section , key )", + "filename": "system_info.py", + "nloc": 6, + "complexity": 4, + "token_count": 66, + "parameters": [ + "self", + "section", + "key" + ], + "start_line": 1433, + "end_line": 1438, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 6, + "top_nesting_level": 1 + }, + { + "name": "calc_info", + "long_name": "calc_info( self )", + "filename": "system_info.py", + "nloc": 21, + "complexity": 5, + "token_count": 156, + "parameters": [ + "self" + ], + "start_line": 1440, + "end_line": 1460, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 21, + "top_nesting_level": 1 + }, + { + "name": "get_paths", + "long_name": "get_paths( self , section , key )", + "filename": "system_info.py", + "nloc": 6, + "complexity": 4, + "token_count": 66, + "parameters": [ + "self", + "section", + "key" + ], + "start_line": 1466, + "end_line": 1471, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 6, + "top_nesting_level": 1 + }, + { + "name": "calc_info", + "long_name": "calc_info( self )", + "filename": "system_info.py", + "nloc": 22, + "complexity": 6, + "token_count": 177, + "parameters": [ + "self" + ], + "start_line": 1473, + "end_line": 1495, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 23, + "top_nesting_level": 1 + }, + { + "name": "get_config_exe", + "long_name": "get_config_exe( self )", + "filename": "system_info.py", + "nloc": 4, + "complexity": 2, + "token_count": 30, + "parameters": [ + "self" + ], + "start_line": 1507, + "end_line": 1510, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 1 + }, + { + "name": "get_config_output", + "long_name": "get_config_output( self , config_exe , option )", + "filename": "system_info.py", + "nloc": 4, + "complexity": 2, + "token_count": 37, + "parameters": [ + "self", + "config_exe", + "option" + ], + "start_line": 1511, + "end_line": 1514, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 1 + }, + { + "name": "calc_info", + "long_name": "calc_info( self )", + "filename": "system_info.py", + "nloc": 54, + "complexity": 22, + "token_count": 435, + "parameters": [ + "self" + ], + "start_line": 1516, + "end_line": 1569, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 54, + "top_nesting_level": 1 + }, + { + "name": "combine_paths", + "long_name": "combine_paths( * args , ** kws )", + "filename": "system_info.py", + "nloc": 22, + "complexity": 11, + "token_count": 191, + "parameters": [ + "args", + "kws" + ], + "start_line": 1638, + "end_line": 1662, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 25, + "top_nesting_level": 0 + }, + { + "name": "dict_append", + "long_name": "dict_append( d , ** kws )", + "filename": "system_info.py", + "nloc": 17, + "complexity": 9, + "token_count": 128, + "parameters": [ + "d", + "kws" + ], + "start_line": 1666, + "end_line": 1682, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 17, + "top_nesting_level": 0 + }, + { + "name": "show_all", + "long_name": "show_all( )", + "filename": "system_info.py", + "nloc": 20, + "complexity": 8, + "token_count": 137, + "parameters": [], + "start_line": 1684, + "end_line": 1703, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 20, + "top_nesting_level": 0 + } + ], + "changed_methods": [], + "nloc": 1507, + "complexity": 328, + "token_count": 8481, + "diff_parsed": { + "added": [ + " os.path.join(distutils.sysconfig.EXEC_PREFIX,", + " 'libs')]" + ], + "deleted": [ + " os.path.join(distutils.sysconfig.EXEC_PREFIX, 'libs')]" + ] + } + }, + { + "old_path": "numpy/random/setup.py", + "new_path": "numpy/random/setup.py", + "filename": "setup.py", + "extension": "py", + "change_type": "MODIFY", + "diff": "@@ -16,7 +16,6 @@ def generate_libraries(ext, build_dir):\n if config_cmd.try_run(tc):\n libs.append('Advapi32')\n ext.libraries.extend(libs)\n- print \"**** got \", libs\n return None\n \n libs = []\n", + "added_lines": 0, + "deleted_lines": 1, + "source_code": "\nfrom os.path import join, split\n\ndef configuration(parent_package='',top_path=None):\n from numpy.distutils.misc_util import Configuration, get_mathlibs\n config = Configuration('random',parent_package,top_path)\n\n def generate_libraries(ext, build_dir):\n config_cmd = config.get_config_cmd()\n if top_path is None:\n libs = get_mathlibs()\n else:\n path = join(split(build_dir)[0],'core')\n libs = get_mathlibs(path)\n tc = testcode_wincrypt()\n if config_cmd.try_run(tc):\n libs.append('Advapi32')\n ext.libraries.extend(libs)\n return None\n\n libs = []\n # Configure mtrand\n config.add_extension('mtrand',\n sources=[join('mtrand', x) for x in \n ['mtrand.c', 'randomkit.c', 'initarray.c',\n 'distributions.c']]+[generate_libraries],\n libraries=libs,\n depends = [join('mtrand','*.h'),\n join('mtrand','*.pyx'),\n join('mtrand','*.pxi'),\n ]\n )\n \n return config\n\ndef testcode_wincrypt():\n return \"\"\"\\\n/* check to see if _WIN32 is defined */\nint main(int argc, char *argv[])\n{\n#ifdef _WIN32\n return 0;\n#else\n#error No _WIN32\n#endif\n return -1;\n}\n\"\"\"\n\nif __name__ == '__main__':\n from numpy.distutils.core import setup\n setup(**configuration(top_path='').todict())\n\n", + "source_code_before": "\nfrom os.path import join, split\n\ndef configuration(parent_package='',top_path=None):\n from numpy.distutils.misc_util import Configuration, get_mathlibs\n config = Configuration('random',parent_package,top_path)\n\n def generate_libraries(ext, build_dir):\n config_cmd = config.get_config_cmd()\n if top_path is None:\n libs = get_mathlibs()\n else:\n path = join(split(build_dir)[0],'core')\n libs = get_mathlibs(path)\n tc = testcode_wincrypt()\n if config_cmd.try_run(tc):\n libs.append('Advapi32')\n ext.libraries.extend(libs)\n print \"**** got \", libs\n return None\n\n libs = []\n # Configure mtrand\n config.add_extension('mtrand',\n sources=[join('mtrand', x) for x in \n ['mtrand.c', 'randomkit.c', 'initarray.c',\n 'distributions.c']]+[generate_libraries],\n libraries=libs,\n depends = [join('mtrand','*.h'),\n join('mtrand','*.pyx'),\n join('mtrand','*.pxi'),\n ]\n )\n \n return config\n\ndef testcode_wincrypt():\n return \"\"\"\\\n/* check to see if _WIN32 is defined */\nint main(int argc, char *argv[])\n{\n#ifdef _WIN32\n return 0;\n#else\n#error No _WIN32\n#endif\n return -1;\n}\n\"\"\"\n\nif __name__ == '__main__':\n from numpy.distutils.core import setup\n setup(**configuration(top_path='').todict())\n\n", + "methods": [ + { + "name": "configuration.generate_libraries", + "long_name": "configuration.generate_libraries( ext , build_dir )", + "filename": "setup.py", + "nloc": 12, + "complexity": 3, + "token_count": 75, + "parameters": [ + "ext", + "build_dir" + ], + "start_line": 8, + "end_line": 19, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 12, + "top_nesting_level": 1 + }, + { + "name": "configuration", + "long_name": "configuration( parent_package = '' , top_path = None )", + "filename": "setup.py", + "nloc": 16, + "complexity": 2, + "token_count": 102, + "parameters": [ + "parent_package", + "top_path" + ], + "start_line": 4, + "end_line": 34, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 31, + "top_nesting_level": 0 + }, + { + "name": "testcode_wincrypt", + "long_name": "testcode_wincrypt( )", + "filename": "setup.py", + "nloc": 13, + "complexity": 1, + "token_count": 6, + "parameters": [], + "start_line": 36, + "end_line": 48, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 13, + "top_nesting_level": 0 + } + ], + "methods_before": [ + { + "name": "configuration.generate_libraries", + "long_name": "configuration.generate_libraries( ext , build_dir )", + "filename": "setup.py", + "nloc": 13, + "complexity": 3, + "token_count": 79, + "parameters": [ + "ext", + "build_dir" + ], + "start_line": 8, + "end_line": 20, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 13, + "top_nesting_level": 1 + }, + { + "name": "configuration", + "long_name": "configuration( parent_package = '' , top_path = None )", + "filename": "setup.py", + "nloc": 16, + "complexity": 2, + "token_count": 102, + "parameters": [ + "parent_package", + "top_path" + ], + "start_line": 4, + "end_line": 35, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 32, + "top_nesting_level": 0 + }, + { + "name": "testcode_wincrypt", + "long_name": "testcode_wincrypt( )", + "filename": "setup.py", + "nloc": 13, + "complexity": 1, + "token_count": 6, + "parameters": [], + "start_line": 37, + "end_line": 49, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 13, + "top_nesting_level": 0 + } + ], + "changed_methods": [ + { + "name": "configuration", + "long_name": "configuration( parent_package = '' , top_path = None )", + "filename": "setup.py", + "nloc": 16, + "complexity": 2, + "token_count": 102, + "parameters": [ + "parent_package", + "top_path" + ], + "start_line": 4, + "end_line": 35, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 32, + "top_nesting_level": 0 + }, + { + "name": "configuration.generate_libraries", + "long_name": "configuration.generate_libraries( ext , build_dir )", + "filename": "setup.py", + "nloc": 13, + "complexity": 3, + "token_count": 79, + "parameters": [ + "ext", + "build_dir" + ], + "start_line": 8, + "end_line": 20, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 13, + "top_nesting_level": 1 + } + ], + "nloc": 44, + "complexity": 6, + "token_count": 219, + "diff_parsed": { + "added": [], + "deleted": [ + " print \"**** got \", libs" + ] + } + } + ] + }, + { + "hash": "ad19f35e7920f83356e44960d21fb9f958f2565b", + "msg": "use array style in *_fill", + "author": { + "name": "sasha", + "email": "sasha@localhost" + }, + "committer": { + "name": "sasha", + "email": "sasha@localhost" + }, + "author_date": "2006-02-10T07:32:58+00:00", + "author_timezone": 0, + "committer_date": "2006-02-10T07:32:58+00:00", + "committer_timezone": 0, + "branches": [ + "main" + ], + "in_main_branch": true, + "merge": false, + "parents": [ + "d99b73b34ffc1778e9ff2423b56a8994d0e9be78" + ], + "project_name": "repo_copy", + "project_path": "/tmp/tmpdjwupkfu/repo_copy", + "deletions": 3, + "insertions": 2, + "lines": 5, + "files": 1, + "dmm_unit_size": null, + "dmm_unit_complexity": null, + "dmm_unit_interfacing": null, + "modified_files": [ + { + "old_path": "numpy/core/src/arraytypes.inc.src", + "new_path": "numpy/core/src/arraytypes.inc.src", + "filename": "arraytypes.inc.src", + "extension": "src", + "change_type": "MODIFY", + "diff": "@@ -1652,9 +1652,8 @@ static void\n \t@typ@ start = buffer[0];\n \t@typ@ delta = buffer[1];\n \tdelta -= start;\n-\tbuffer += 2;\n-\tfor (i=2; idescr->f->copyswap(&t1, ip, !PyArray_ISNOTSWAPPED(ap),\n\t\t\t\t ap->descr->elsize);\n return @func1@((@typ1@)t1);\n\t}\n}\n\nstatic int \n@TYP@_setitem(PyObject *op, char *ov, PyArrayObject *ap) {\n @typ@ temp; /* ensures alignment */\n\n if (PyArray_IsScalar(op, @kind@)) {\n temp = ((Py@kind@ScalarObject *)op)->obval;\n }\n else {\n temp = (@typ@)@func2@(op);\n }\n if (PyErr_Occurred()) return -1;\n if (ap == NULL || PyArray_ISBEHAVED(ap)) \n *((@typ@ *)ov)=temp;\n else {\n ap->descr->f->copyswap(ov, &temp, !PyArray_ISNOTSWAPPED(ap), \n\t\t\t\t ap->descr->elsize);\n }\n \n return 0;\n}\n\n/**end repeat**/\n\n\n/**begin repeat \n\n#TYP=CFLOAT,CDOUBLE#\n#typ=float, double#\n*/\n\nstatic PyObject * \n@TYP@_getitem(char *ip, PyArrayObject *ap) {\n @typ@ t1, t2;\n\n if ((ap==NULL) || PyArray_ISBEHAVED_RO(ap)) { \n return PyComplex_FromDoubles((double)((@typ@ *)ip)[0], \n (double)((@typ@ *)ip)[1]);\n }\n else {\n\t\tint size = sizeof(@typ@);\n\t\tBool swap = !PyArray_ISNOTSWAPPED(ap);\n copy_and_swap(&t1, ip, size, 1, 0, swap);\n copy_and_swap(&t2, ip+size, size, 1, 0, swap);\n return PyComplex_FromDoubles((double)t1, (double)t2);\n }\n}\n/**end repeat**/\n\n/**begin repeat \n\n#TYP=CFLOAT, CDOUBLE, CLONGDOUBLE#\n#typ=float, double, longdouble#\n#kind=CFloat, CDouble, CLongDouble#\n*/\nstatic int \n@TYP@_setitem(PyObject *op, char *ov, PyArrayObject *ap) \n{\n Py_complex oop;\n PyObject *op2;\n c@typ@ temp;\n\tint rsize;\n \n if (!(PyArray_IsScalar(op, @kind@))) {\n if (PyArray_Check(op) && (PyArray_NDIM(op)==0)) {\n op2 = ((PyArrayObject *)op)->descr->f->getitem \\\n (((PyArrayObject *)op)->data, \n (PyArrayObject *)op);\n\t\t}\n\t\telse { \n op2 = op; Py_INCREF(op);\n }\n if (op2 == Py_None) {\n oop.real = oop.imag = _getNAN();\n }\n else {\n oop = PyComplex_AsCComplex (op2);\n }\n Py_DECREF(op2);\n if (PyErr_Occurred()) return -1;\n temp.real = (@typ@) oop.real;\n temp.imag = (@typ@) oop.imag; \n }\n\telse {\n temp = ((Py@kind@ScalarObject *)op)->obval;\n }\n\t\n memcpy(ov, &temp, ap->descr->elsize);\n if (!PyArray_ISNOTSWAPPED(ap))\n byte_swap_vector(ov, 2, sizeof(@typ@));\n\t\n\trsize = sizeof(@typ@);\n\tcopy_and_swap(ov, &temp, rsize, 2, rsize, !PyArray_ISNOTSWAPPED(ap));\n return 0;\n}\n/**end repeat**/\n\nstatic PyObject * \nLONGDOUBLE_getitem(char *ip, PyArrayObject *ap) \n{\n return PyArray_Scalar(ip, ap->descr, NULL);\n}\n\nstatic int \nLONGDOUBLE_setitem(PyObject *op, char *ov, PyArrayObject *ap) {\n longdouble temp; /* ensures alignment */\n\n if (PyArray_IsScalar(op, LongDouble)) {\n temp = ((PyLongDoubleScalarObject *)op)->obval;\n }\n else {\n if (op == Py_None) temp = (longdouble)_getNAN();\n else temp = (longdouble)PyFloat_AsDouble(op);\n }\n if (PyErr_Occurred()) return -1;\n if (ap == NULL || PyArray_ISBEHAVED(ap)) \n *((longdouble *)ov)=temp;\n else {\n copy_and_swap(ov, &temp, ap->descr->elsize, 1, 0,\n !PyArray_ISNOTSWAPPED(ap));\n }\n \n return 0;\n}\n\nstatic PyObject * \nCLONGDOUBLE_getitem(char *ip, PyArrayObject *ap) \n{\n return PyArray_Scalar(ip, ap->descr, NULL);\n}\n\n\n/* UNICODE */\nstatic PyObject * \nUNICODE_getitem(char *ip, PyArrayObject *ap) \n{\n\tPyObject *obj;\n\tint mysize;\n\tPyArray_UCS4 *dptr;\n\n\tmysize = ap->descr->elsize >> 2;\n\tdptr = (PyArray_UCS4 *)ip + mysize-1;\n\twhile(mysize > 0 && *dptr-- == 0) mysize--;\n\tif (!PyArray_ISNOTSWAPPED(ap) && (obj != NULL)) {\n\t\tbyte_swap_vector(PyArray_BYTES(ap), mysize, 4);\n\t}\n#ifdef Py_UNICODE_WIDE\n\tobj = PyUnicode_FromUnicode((const PyArray_UCS4 *)ip, mysize);\n#else\n\t/* create new empty unicode object of length mysize*2 */\n\tobj = MyPyUnicode_New(mysize*2);\n\tif (obj == NULL) return obj;\n\tmysize = PyUCS2Buffer_FromUCS4(((PyUnicodeObject *)obj)->str, \n\t\t\t\t (PyArray_UCS4 *)ip, mysize);\n\t/* reset length of unicode object to ucs2size */\n\tif (MyPyUnicode_Resize((PyUnicodeObject *)obj, mysize) < 0) {\n\t\tPy_DECREF(obj);\n\t\treturn NULL;\n\t}\n#endif\n\n\treturn obj;\n}\n\nstatic int \nUNICODE_setitem(PyObject *op, char *ov, PyArrayObject *ap) \n{\n PyObject *temp;\n\tPy_UNICODE *ptr;\n\tint datalen;\n\n\tif ((temp=PyObject_Unicode(op)) == NULL) return -1;\n\tptr = PyUnicode_AS_UNICODE(temp);\n\tif ((ptr == NULL) || (PyErr_Occurred())) {\n\t\tPy_DECREF(temp);\n\t\treturn -1;\n\t}\n\tdatalen = PyUnicode_GET_DATA_SIZE(temp);\n\n#ifdef Py_UNICODE_WIDE\n\tmemcpy(ov, ptr, MIN(ap->descr->elsize, datalen));\n#else\n datalen = PyUCS2Buffer_AsUCS4(ptr, (PyArray_UCS4 *)ov, datalen >> 1,\n\t\t\t\t ap->descr->elsize >> 2);\n\tdatalen <<= 2;\n#endif\n\t/* Fill in the rest of the space with 0 */\n\tif (ap->descr->elsize > datalen) {\n\t\tmemset(ov + datalen, 0, (ap->descr->elsize - datalen));\n\t}\n\t\n\tif (!PyArray_ISNOTSWAPPED(ap)) \n\t\tbyte_swap_vector(ov, ap->descr->elsize >> 2, 4);\n\tPy_DECREF(temp);\n\treturn 0;\n}\n\n/* STRING -- can handle both NULL-terminated and not NULL-terminated cases */\nstatic PyObject * \nSTRING_getitem(char *ip, PyArrayObject *ap) \n{\n\tif (ip[ap->descr->elsize-1])\n\t\treturn PyString_FromStringAndSize(ip,ap->descr->elsize);\n\telse\n\t\treturn PyString_FromString(ip);\n}\n\nstatic int \nSTRING_setitem(PyObject *op, char *ov, PyArrayObject *ap) \n{\n\tchar *ptr;\n\tint len;\n\tPyObject *temp=PyObject_Str(op);\n\t\n\tif (temp == NULL) return -1;\n\t\n\tif (PyString_AsStringAndSize(temp, &ptr, &len) == -1) {\n\t\tPy_DECREF(temp);\n\t\treturn -1;\n\t}\n\tmemcpy(ov, ptr, MIN(ap->descr->elsize,len));\n\tif (ap->descr->elsize > len) {\n\t\tmemset(ov + len, 0, (ap->descr->elsize - len));\n\t}\n\tPy_DECREF(temp);\n\treturn 0;\n}\n\n/* OBJECT */\n\nstatic PyObject * \nOBJECT_getitem(char *ip, PyArrayObject *ap) \n{\n\tPy_INCREF(*(PyObject **)ip);\n\treturn *(PyObject **)ip;\n}\n\nstatic int \nOBJECT_setitem(PyObject *op, char *ov, PyArrayObject *ap) \n{\n\tPy_XDECREF(*(PyObject **)ov);\n\tPy_INCREF(op);\n\t*(PyObject **)ov = op;\n\treturn PyErr_Occurred() ? -1:0;\n}\n\n/* VOID */\n\nstatic PyObject *\nVOID_getitem(char *ip, PyArrayObject *ap)\n{\n PyObject *u=NULL;\n\tPyArray_Descr* descr;\n int itemsize;\n\n\tdescr = ap->descr;\n\tif (descr->fields && descr->fields != Py_None) {\n\t\tPyObject *key;\n\t\tPyObject *names;\n\t\tint i, n;\n\t\tPyObject *ret;\n\t\tPyObject *tup, *title;\n\t\tPyArray_Descr *new;\n\t\tint offset;\n\t\tint savedflags;\n\n\t\t/* get the names from the fields dictionary*/\n\t\tkey = PyInt_FromLong(-1);\n\t\tnames = PyDict_GetItem(descr->fields, key);\n\t\tPy_DECREF(key);\n\t\tif (!names) goto finish;\n\t\tn = PyList_GET_SIZE(names);\n\t\tret = PyTuple_New(n);\n\t\tsavedflags = ap->flags;\n\t\tfor (i=0; ifields, key);\n\t\t\tif (!PyArg_ParseTuple(tup, \"Oi|O\", &new, &offset, \n\t\t\t\t\t &title)) {\n\t\t\t\tPy_DECREF(ret); \n\t\t\t\tap->descr = descr;\n\t\t\t\treturn NULL;\n\t\t\t}\n\t\t\tap->descr = new;\n\t\t\t/* update alignment based on offset */\n\t\t\tif ((new->alignment > 1) &&\t\t\t\\\n\t\t\t ((((intp)(ip+offset)) % new->alignment) != 0))\n\t\t\t\tap->flags &= ~ALIGNED;\n\t\t\telse\n\t\t\t\tap->flags |= ALIGNED;\n\n\t\t\tPyTuple_SET_ITEM(ret, i,\t\t\t\\\n\t\t\t\t\t new->f->getitem(ip+offset, ap));\n\t\t\tap->flags = savedflags;\n\t\t}\n\t\tap->descr = descr;\n\t\treturn ret;\n\t}\n\n\tif (descr->subarray) {\n\t\t/* return an array of the basic type */\n\t\tPyArray_Dims shape={NULL,-1};\n\t\tPyObject *ret;\n\t\tif (!(PyArray_IntpConverter(descr->subarray->shape, \n\t\t\t\t\t &shape))) {\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\treturn NULL;\n\t\t}\n Py_INCREF(descr->subarray->base);\n\t\tret = PyArray_NewFromDescr(&PyArray_Type,\n\t\t\t\t\t descr->subarray->base,\n\t\t\t\t\t shape.len, shape.ptr,\n\t\t\t\t\t NULL, ip, ap->flags, NULL);\n\t\tPyDimMem_FREE(shape.ptr);\n\t\tif (!ret) return NULL;\n\t\tPyArray_BASE(ret) = (PyObject *)ap;\n\t\tPy_INCREF(ap);\n\t\tPyArray_UpdateFlags((PyArrayObject *)ret, UPDATE_ALL_FLAGS);\n\t\treturn ret;\n\t}\n\n finish:\n\titemsize=ap->descr->elsize;\n\tif (PyArray_ISWRITEABLE(ap))\n\t\tu = PyBuffer_FromReadWriteMemory(ip, itemsize);\n\telse\n\t\tu = PyBuffer_FromMemory(ip, itemsize);\n\tif (u==NULL) goto fail;\n\n\t/* default is to return buffer object pointing to current item */\n\t/* a view of it */\n\treturn u; \n\t\n fail:\n return NULL;\n}\n\n\n\nstatic int PyArray_CopyObject(PyArrayObject *, PyObject *);\n\nstatic int\nVOID_setitem(PyObject *op, char *ip, PyArrayObject *ap)\n{\n\tPyArray_Descr* descr;\n int itemsize=ap->descr->elsize;\n\tint res;\n\n\tdescr = ap->descr;\n\tif (descr->fields && (descr->fields != Py_None) && \\\n\t PyTuple_Check(op)) {\n\t\tPyObject *key;\n\t\tPyObject *names;\n\t\tint i, n;\n\t\tPyObject *tup, *title;\n\t\tPyArray_Descr *new;\n\t\tint offset;\n\t\tint savedflags;\n\t\tres = -1;\n\t\t/* get the names from the fields dictionary*/\n\t\tkey = PyInt_FromLong(-1);\n\t\tnames = PyDict_GetItem(descr->fields, key);\n\t\tPy_DECREF(key);\n\t\tif (!names) goto finish;\n\t\tn = PyList_GET_SIZE(names);\n\t\tif (PyTuple_GET_SIZE(op) != n) {\n\t\t\tPyErr_SetString(PyExc_ValueError, \n\t\t\t\t\t\"size of tuple must match\"\\\n\t\t\t\t\t\"number of fields.\");\n\t\t\treturn -1;\n\t\t}\n\t\tsavedflags = ap->flags;\n\t\tfor (i=0; ifields, key);\n\t\t\tif (!PyArg_ParseTuple(tup, \"Oi|O\", &new, &offset, \n\t\t\t\t\t &title)) {\n\t\t\t\tap->descr = descr;\n\t\t\t\treturn -1;\n\t\t\t}\n\t\t\tap->descr = new;\n\t\t\t/* remember to update alignment flags */\n\t\t\tif ((new->alignment > 1) &&\t\t\t\\\n\t\t\t ((((intp)(ip+offset)) % new->alignment) != 0))\n\t\t\t\tap->flags &= ~ALIGNED;\n\t\t\telse\n\t\t\t\tap->flags |= ALIGNED;\n\n\t\t\tres = new->f->setitem(PyTuple_GET_ITEM(op, i),\n\t\t\t\t\t ip+offset, ap);\n\t\t\tap->flags = savedflags;\n\t\t\tif (res < 0) break;\n\t\t}\n\t\tap->descr = descr;\n\t\treturn res;\n\t}\n\n\tif (descr->subarray) {\n\t\t/* copy into an array of the same basic type */\n\t\tPyArray_Dims shape={NULL,-1};\n\t\tPyObject *ret;\n\t\tif (!(PyArray_IntpConverter(descr->subarray->shape, \n\t\t\t\t\t &shape))) {\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\treturn -1;\n\t\t}\n Py_INCREF(descr->subarray->base);\n\t\tret = PyArray_NewFromDescr(&PyArray_Type,\n\t\t\t\t\t descr->subarray->base,\n\t\t\t\t\t shape.len, shape.ptr,\n\t\t\t\t\t NULL, ip, ap->flags, NULL);\n\t\tPyDimMem_FREE(shape.ptr);\n\t\tif (!ret) return -1;\n\t\tPyArray_BASE(ret) = (PyObject *)ap;\n\t\tPy_INCREF(ap);\n\t\tPyArray_UpdateFlags((PyArrayObject *)ret, UPDATE_ALL_FLAGS);\n\t\tres = PyArray_CopyObject((PyArrayObject *)ret, op);\n\t\tPy_DECREF(ret);\n\t\treturn res;\n\t}\n\n finish:\n\t/* Default is to use buffer interface to set item */\n\t{\n\t\tconst void *buffer;\n\t\tint buflen;\n\t\tres = PyObject_AsReadBuffer(op, &buffer, &buflen);\n\t\tif (res == -1) goto fail;\n\t\tmemcpy(ip, buffer, MIN(buflen, itemsize));\n }\n\treturn 0;\n\n fail:\n return -1; \n}\n\n\n/****************** XXX_to_YYY *******************************/ \n\n/* Assumes contiguous, and aligned, from and to */\n\n\n/**begin repeat\n#to=(BYTE,UBYTE,SHORT,USHORT,INT,UINT,LONG,ULONG,LONGLONG,ULONGLONG,FLOAT,DOUBLE,LONGDOUBLE)*16#\n#from=BYTE*13,UBYTE*13,SHORT*13,USHORT*13,INT*13,UINT*13,LONG*13,ULONG*13,LONGLONG*13,ULONGLONG*13,FLOAT*13,DOUBLE*13,LONGDOUBLE*13,CFLOAT*13,CDOUBLE*13,CLONGDOUBLE*13#\n#totyp=(byte, ubyte, short, ushort, int, uint, long, ulong, longlong, ulonglong, float, double, longdouble)*16#\n#fromtyp=byte*13, ubyte*13, short*13, ushort*13, int*13, uint*13, long*13, ulong*13, longlong*13, ulonglong*13, float*13, double*13, longdouble*13, float*13, double*13, longdouble*13#\n#incr= ip++*169,ip+=2*39#\n*/\nstatic void \n@from@_to_@to@(@fromtyp@ *ip, @totyp@ *op, intp n, PyArrayObject *aip, \n\t PyArrayObject *aop) {\n\tregister intp i; \n\tfor(i=0;idescr->elsize*3, 1#\n*/\nstatic void \n@from@_to_OBJECT(@fromtyp@ *ip, PyObject **op, intp n, PyArrayObject *aip,\n\t\t PyArrayObject *aop)\n{\n\tregister intp i; \n\tint skip=@skip@;\n\tfor(i=0;idescr->elsize*3#\n*/\nstatic void \nOBJECT_to_@to@(PyObject **ip, @totyp@ *op, intp n, PyArrayObject *aip,\n\t\t PyArrayObject *aop)\n{\n\tregister intp i; \n\tint skip=@skip@;\n\tfor(i=0;idescr->elsize*3)*3#\n#convert=1*17,0*3,1*17,0*3,0*20#\n#convstr=(Int*9,Long*2,Float*3,Complex*3,Tuple*3)*3#\n*/\nstatic void\n@from@_to_@to@(@fromtyp@ *ip, @totyp@ *op, intp n, PyArrayObject *aip, \n\t PyArrayObject *aop)\n{\n\tregister intp i;\n\tPyObject *temp=NULL;\n\tint skip=aip->descr->elsize;\n\tint oskip=@oskip@;\n\tfor(i=0; idescr->elsize;\n\tfor(i=0; i= 0x02040000) || defined(PyOS_ascii_strtod)\nstatic int\n@fname@_fromstr(char *str, @type@ *ip, char **endptr, void *ignore)\n{\n\tdouble result;\n\n\tresult = PyOS_ascii_strtod(str, endptr);\n\t*ip = (@type@) result;\n\treturn 0;\n}\n#else\n#define @fname@_fromstr NULL\n#endif\n/**end repeat**/\n\n\n\n/**begin repeat\n#fname=BOOL,CFLOAT,CDOUBLE,CLONGDOUBLE,OBJECT,STRING,UNICODE,VOID#\n*/\n#define @fname@_fromstr NULL\n/**end repeat**/\n\n\n/****************** copyswapn *************************************/\n\n/**begin repeat\n\n#fname=SHORT,USHORT,INT,UINT,LONG,ULONG,LONGLONG,ULONGLONG,FLOAT,DOUBLE,LONGDOUBLE#\n#fsize=SHORT,SHORT,INT,INT,LONG,LONG,LONGLONG,LONGLONG,FLOAT,DOUBLE,LONGDOUBLE#\n#type=short,ushort,int,uint,long,ulong,longlong,ulonglong,float,double,longdouble#\n*/\nstatic void\n@fname@_copyswapn (void *dst, void *src, intp n, int swap, int itemsize)\n{\n\tif (src != NULL) /* copy first if needed */\n\t\tmemcpy(dst, src, n*sizeof(@type@));\n\n\tif (swap) {\n\t\tregister char *a, *b, c;\n\t\tfor (a = (char *)dst; n>0; n--) {\n#if SIZEOF_@fsize@ == 2\n\t\t\tb = a + 1;\n\t\t\tc = *a; *a++ = *b; *b = c;\n\t\t\ta += 1;\n#elif SIZEOF_@fsize@ == 4\n\t\t\tb = a + 3;\n c = *a; *a++ = *b; *b-- = c;\n c = *a; *a++ = *b; *b = c;\n\t\t\ta += 2;\n#elif SIZEOF_@fsize@ == 8\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\t\t\ta += 4;\n#elif SIZEOF_@fsize@ == 10\n b = a + 9;\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 c = *a; *a++ = *b; *b = c;\n\t\t\ta += 5;\n#elif SIZEOF_@fsize@ == 12\n b = a + 11;\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 c = *a; *a++ = *b; *b-- = c;\n c = *a; *a++ = *b; *b = c;\n\t\t\ta += 6;\n#elif SIZEOF_@fsize@ == 16\n b = a + 15;\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 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\t\t\ta += 8;\n#else\n\t\t\tregister int i, nn;\n b = a + (SIZEOF_@fsize@-1);\n\t\t\tnn = SIZEOF_@fsize@ / 2;\n for (i=0; i0; nn--) {\n#if SIZEOF_@fsize@ == 4\n\t\t\tb = a + 3;\n c = *a; *a++ = *b; *b-- = c;\n c = *a; *a++ = *b; *b = c;\n\t\t\ta += 2;\n#elif SIZEOF_@fsize@ == 8\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\t\t\ta += 4;\n#elif SIZEOF_@fsize@ == 10\n b = a + 9;\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 c = *a; *a++ = *b; *b = c;\n\t\t\ta += 5;\n#elif SIZEOF_@fsize@ == 12\n b = a + 11;\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 c = *a; *a++ = *b; *b-- = c;\n c = *a; *a++ = *b; *b = c;\n\t\t\ta += 6;\n#elif SIZEOF_@fsize@ == 16\n b = a + 15;\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 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\t\t\ta += 8;\n#else\n\t\t\tregister int i, kn;\n\n b = a + (SIZEOF_@fsize@-1);\n\t\t\tkn = SIZEOF_@fsize@ / 2;\n for (i=0; i0; n--) {\n\t\t\tb = a + 3;\n\t\t\tc=*a; *a++ = *b; *b-- = c;\n\t\t\tc=*a; *a++ = *b; *b-- = c;\n\t\t\ta += 1;\n\t\t}\n\t}\n}\n\n\nstatic void\nOBJECT_copyswap (PyObject **dst, PyObject **src, int swap, int itemsize)\n{\n OBJECT_copyswapn(dst, src, 1, swap, itemsize);\n}\n\nstatic void\nSTRING_copyswap (char *dst, char *src, int swap, int itemsize)\n{\n\tif (src != NULL) \n\t\tmemcpy(dst, src, itemsize);\n\t\n}\n\n/* ignore swap */\nstatic void\nVOID_copyswap (char *dst, char *src, int swap, int itemsize)\n{\n\tif (src != NULL) \n\t\tmemcpy(dst, src, itemsize);\t\n\treturn;\n}\n\nstatic void\nUNICODE_copyswap (char *dst, char *src, int swap, int itemsize)\n{\n\n\tif (src != NULL) \n\t\tmemcpy(dst, src, itemsize);\n\t\n\tif (swap) {\n\t\tregister char *a, *b, c;\n a = (char *)dst;\n b = a + 3;\n\t\tc=*a; *a++ = *b; *b-- = c;\n\t\tc=*a; *a++ = *b; *b-- = c;\n\t}\n}\n\n\n/****************** nonzero **********************************/\n\n/**begin repeat\n#fname=BOOL,BYTE,UBYTE,SHORT,USHORT,INT,UINT,LONG,ULONG,LONGLONG,ULONGLONG,FLOAT,DOUBLE,LONGDOUBLE#\n#type=Bool, byte, ubyte, short, ushort, int, uint, long, ulong, longlong, ulonglong, float, double, longdouble#\n*/\nstatic Bool \n@fname@_nonzero (@type@ *ip, PyArrayObject *ap)\n{\n\t@type@ t1;\n\tif (ap==NULL || PyArray_ISBEHAVED_RO(ap))\n\t\treturn (Bool) (*ip != 0);\n\telse {\n\t\t/* don't worry about swap, since we are just testing\n\t\t whether or not equal to 0 */\n\t\tmemcpy(&t1, ip, sizeof(@type@));\n\t\treturn (Bool) (t1 != 0);\n\t}\n}\n/**end repeat**/\n\n/**begin repeat\n#fname=CFLOAT,CDOUBLE,CLONGDOUBLE#\n#type=cfloat, cdouble, clongdouble#\n*/\nstatic Bool \n@fname@_nonzero (@type@ *ip, PyArrayObject *ap)\n{\n\t@type@ t1;\n\tif (ap==NULL || PyArray_ISBEHAVED_RO(ap))\n\t\treturn (Bool) ((ip->real != 0) || (ip->imag != 0));\n\telse {\n\t\t/* don't worry about swap, since we are just testing\n\t\t whether or not equal to 0 */\n\t\tmemcpy(&t1, ip, sizeof(@type@));\n\t\treturn (Bool) ((t1.real != 0) || (t1.imag != 0));\n\t}\n}\n/**end repeat**/\n\n\n\n#define WHITESPACE \" \\t\\n\\r\\v\\f\"\n#define WHITELEN 6\n\nstatic Bool\nPy_STRING_ISSPACE(char ch) \n{\n\tchar white[] = WHITESPACE;\n\tint j;\n\tBool space=FALSE;\n\tfor (j=0; jdescr->elsize;\n\tint i;\n\tBool nonz = FALSE;\n\n\tfor (i=0; idescr->elsize >> 2;\n\tint i;\n\tBool nonz = FALSE;\n\tchar *buffer=NULL;\t\n\n\tif ((!PyArray_ISNOTSWAPPED(ap)) || \\\n\t (!PyArray_ISALIGNED(ap))) {\n\t\tbuffer = _pya_malloc(ap->descr->elsize);\n\t\tif (buffer == NULL) {\n\t\t\treturn nonz;\n\t\t}\n\t\tmemcpy(buffer, ip, ap->descr->elsize);\n\t\tif (!PyArray_ISNOTSWAPPED(ap)) {\n\t\t\tbyte_swap_vector(buffer, len, 4);\n\t\t}\n\t\tip = (PyArray_UCS4 *)buffer;\n\t}\n\n\tfor (i=0; idescr->elsize;\n\tBool nonz = FALSE;\n\t\n\tfor (i=0; idescr->elsize);\n}\n\n/* taken from Python */\nstatic int \nUNICODE_compare(register PyArray_UCS4 *ip1, register PyArray_UCS4 *ip2, \n\t\tPyArrayObject *ap)\n{\n register int itemsize=ap->descr->elsize;\n\tregister PyArray_UCS4 c1, c2;\n\n\tif (itemsize < 0) return 0;\n\t\n\twhile(itemsize-- > 0) {\n\t\tc1 = *ip1++;\n\t\tc2 = *ip2++;\n\t\t\n\t\tif (c1 != c2) \n\t\t\treturn (c1 < c2) ? -1 : 1;\n\t}\n\treturn 0;\n}\n\n/* possibly redefine compare in terms of fields and subarrays if any */\n\n/* as it is, it compares raw-bytes as it they were strings */\n#define VOID_compare STRING_compare\n\n/****************** argfunc **********************************/\n\n/**begin repeat\n\n#fname= BOOL,BYTE, UBYTE, SHORT, USHORT, INT, UINT, LONG, ULONG, LONGLONG, ULONGLONG, FLOAT, DOUBLE, LONGDOUBLE, CFLOAT, CDOUBLE, CLONGDOUBLE#\n#type= Bool, byte, ubyte, short, ushort, int, uint, long, ulong, longlong, ulonglong, float, double, longdouble, float, double, longdouble#\n#incr= ip++*14, ip+=2*3#\n*/\n\nstatic int\n@fname@_argmax(@type@ *ip, intp n, intp *max_ind, PyArrayObject *aip)\n{\n\tregister intp i;\n\t@type@ mp=*ip;\n\t*max_ind=0;\n\tfor (i=1; i mp) {\n\t\t\tmp = *ip;\n\t\t\t*max_ind = i;\n\t\t}\n\t}\n\treturn 0;\n}\n\n/**end repeat**/\n\nstatic int \nOBJECT_argmax(PyObject **ip, intp n, intp *max_ind, PyArrayObject *aip) \n{\n\tregister intp i; \n\tPyObject *mp=ip[0]; *max_ind=0;\n\tfor(i=1; i 0) { \n\t\t\tmp = *ip; \n\t\t\t*max_ind=i;\n\t\t} \n\t} \n\treturn 0;\n}\n\n/**begin repeat\n\n#fname= STRING, UNICODE#\n#type= char, PyArray_UCS4#\n\n*/\nstatic int \n@fname@_argmax(@type@ *ip, intp n, intp *max_ind, PyArrayObject *aip) \n{\n\tregister intp i; \n\tint elsize = aip->descr->elsize;\n\t@type@ *mp = (@type@ *)_pya_malloc(elsize);\n\t\n\tif (mp==NULL) return 0;\n\tmemcpy(mp, ip, elsize);\n\t*max_ind = 0;\n\tfor(i=1; i 0) { \n\t\t\tmemcpy(mp, ip, elsize);\n\t\t\t*max_ind=i;\n\t\t} \n\t} \n\t_pya_free(mp);\n\treturn 0;\n}\n\n/**end repeat**/\n\n#define VOID_argmax NULL\n\nstatic void\nBOOL_dot(char *ip1, intp is1, char *ip2, intp is2, char *op, intp n, \n void *ignore)\n{\n\tregister Bool tmp=FALSE;\n\tregister intp i;\n\tfor(i=0;ireal;\n\tstart.imag = buffer->imag;\n\tdelta.real = buffer[1].real;\n\tdelta.imag = buffer[1].imag;\n\tdelta.real -= start.real;\n\tdelta.imag -= start.imag;\n\tbuffer += 2;\n\tfor (i=2; ireal = start.real + i*delta.real;\n\t\tbuffer->imag = start.imag + i*delta.imag;\n\t}\n}\n/**end repeat**/\n\n\n#define _ALIGN(type) offsetof(struct {char c; type v;},v)\n\n/**begin repeat\n\n#from= VOID, STRING, UNICODE#\n#align= char, char, PyArray_UCS4#\n#NAME= Void, String, Unicode#\n#endian= |, |, =#\n*/\n\nstatic PyArray_ArrFuncs _Py@NAME@_ArrFuncs = {\n\t{\n\t\t(PyArray_VectorUnaryFunc*)@from@_to_BOOL, \n\t\t(PyArray_VectorUnaryFunc*)@from@_to_BYTE, \n\t\t(PyArray_VectorUnaryFunc*)@from@_to_UBYTE, \n\t\t(PyArray_VectorUnaryFunc*)@from@_to_SHORT, \n\t\t(PyArray_VectorUnaryFunc*)@from@_to_USHORT, \n\t\t(PyArray_VectorUnaryFunc*)@from@_to_INT, \n\t\t(PyArray_VectorUnaryFunc*)@from@_to_UINT, \n\t\t(PyArray_VectorUnaryFunc*)@from@_to_LONG,\n\t\t(PyArray_VectorUnaryFunc*)@from@_to_ULONG, \n\t\t(PyArray_VectorUnaryFunc*)@from@_to_LONGLONG, \n\t\t(PyArray_VectorUnaryFunc*)@from@_to_ULONGLONG, \n\t\t(PyArray_VectorUnaryFunc*)@from@_to_FLOAT, \n\t\t(PyArray_VectorUnaryFunc*)@from@_to_DOUBLE, \n\t\t(PyArray_VectorUnaryFunc*)@from@_to_LONGDOUBLE, \n\t\t(PyArray_VectorUnaryFunc*)@from@_to_CFLOAT, \n\t\t(PyArray_VectorUnaryFunc*)@from@_to_CDOUBLE, \n\t\t(PyArray_VectorUnaryFunc*)@from@_to_CLONGDOUBLE, \n\t\t(PyArray_VectorUnaryFunc*)@from@_to_OBJECT, \n\t\t(PyArray_VectorUnaryFunc*)@from@_to_STRING, \n\t\t(PyArray_VectorUnaryFunc*)@from@_to_UNICODE, \n\t\t(PyArray_VectorUnaryFunc*)@from@_to_VOID\n\t},\n\t(PyArray_GetItemFunc*)@from@_getitem, \n\t(PyArray_SetItemFunc*)@from@_setitem,\n\t(PyArray_CopySwapNFunc*)@from@_copyswapn,\n\t(PyArray_CopySwapFunc*)@from@_copyswap,\n\t(PyArray_CompareFunc*)@from@_compare, \n\t(PyArray_ArgFunc*)@from@_argmax,\n\t(PyArray_DotFunc*)NULL, \n\t(PyArray_ScanFunc*)@from@_scan,\n\t(PyArray_FromStrFunc*)@from@_fromstr,\n\t(PyArray_NonzeroFunc*)@from@_nonzero,\n\t(PyArray_FillFunc*)NULL,\n\t{\n\t\tNULL, NULL, NULL, NULL\n\t},\n\t{\n\t\tNULL, NULL, NULL, NULL\n\t}\n};\n\nstatic PyArray_Descr @from@_Descr = { \n\tPyObject_HEAD_INIT(&PyArrayDescr_Type)\n\t&Py@NAME@ArrType_Type,\n\tPyArray_@from@LTR,\n\tPyArray_@from@LTR,\n\t'@endian@', 0,\n\tPyArray_@from@, 0,\n\t_ALIGN(@align@),\n\tNULL,\n\tNULL,\n\t&_Py@NAME@_ArrFuncs,\n};\n\n/**end repeat**/\n\n\n/**begin repeat\n\n#from= BOOL,BYTE,UBYTE,SHORT,USHORT,INT,UINT,LONG,ULONG,LONGLONG,ULONGLONG,FLOAT,DOUBLE,LONGDOUBLE,CFLOAT,CDOUBLE,CLONGDOUBLE,OBJECT#\n#num= 1*14,2*3,1#\n#fromtyp= Bool, byte, ubyte, short, ushort, int, uint, long, ulong, longlong, ulonglong, float, double, longdouble, float, double, longdouble, PyObject *#\n#NAME= Bool, Byte, UByte, Short, UShort, Int, UInt, Long, ULong, LongLong, ULongLong, Float, Double, LongDouble, CFloat, CDouble, CLongDouble, Object#\n#kind= GENBOOL, SIGNED, UNSIGNED, SIGNED, UNSIGNED, SIGNED, UNSIGNED, SIGNED, UNSIGNED, SIGNED, UNSIGNED, FLOATING, FLOATING, FLOATING, COMPLEX, COMPLEX, COMPLEX, OBJECT#\n#endian= |*3, =*14, |#\n#isobject= 0*17,1#\n*/\n\nstatic PyArray_ArrFuncs _Py@NAME@_ArrFuncs = {\n\t{\n\t\t(PyArray_VectorUnaryFunc*)@from@_to_BOOL, \n\t\t(PyArray_VectorUnaryFunc*)@from@_to_BYTE,\n\t\t(PyArray_VectorUnaryFunc*)@from@_to_UBYTE, \n\t\t(PyArray_VectorUnaryFunc*)@from@_to_SHORT, \n\t\t(PyArray_VectorUnaryFunc*)@from@_to_USHORT, \n\t\t(PyArray_VectorUnaryFunc*)@from@_to_INT, \n\t\t(PyArray_VectorUnaryFunc*)@from@_to_UINT, \n\t\t(PyArray_VectorUnaryFunc*)@from@_to_LONG,\n\t\t(PyArray_VectorUnaryFunc*)@from@_to_ULONG, \n\t\t(PyArray_VectorUnaryFunc*)@from@_to_LONGLONG, \n\t\t(PyArray_VectorUnaryFunc*)@from@_to_ULONGLONG, \n\t\t(PyArray_VectorUnaryFunc*)@from@_to_FLOAT, \n\t\t(PyArray_VectorUnaryFunc*)@from@_to_DOUBLE, \n\t\t(PyArray_VectorUnaryFunc*)@from@_to_LONGDOUBLE, \n\t\t(PyArray_VectorUnaryFunc*)@from@_to_CFLOAT, \n\t\t(PyArray_VectorUnaryFunc*)@from@_to_CDOUBLE, \n\t\t(PyArray_VectorUnaryFunc*)@from@_to_CLONGDOUBLE, \n\t\t(PyArray_VectorUnaryFunc*)@from@_to_OBJECT, \n\t\t(PyArray_VectorUnaryFunc*)@from@_to_STRING, \n\t\t(PyArray_VectorUnaryFunc*)@from@_to_UNICODE, \n\t\t(PyArray_VectorUnaryFunc*)@from@_to_VOID\n\t},\n\t(PyArray_GetItemFunc*)@from@_getitem, \n\t(PyArray_SetItemFunc*)@from@_setitem,\n\t(PyArray_CopySwapNFunc*)@from@_copyswapn,\n\t(PyArray_CopySwapFunc*)@from@_copyswap,\n\t(PyArray_CompareFunc*)@from@_compare, \n\t(PyArray_ArgFunc*)@from@_argmax,\n\t(PyArray_DotFunc*)@from@_dot, \n\t(PyArray_ScanFunc*)@from@_scan,\n\t(PyArray_FromStrFunc*)@from@_fromstr,\n\t(PyArray_NonzeroFunc*)@from@_nonzero,\n\t(PyArray_FillFunc*)@from@_fill,\n\t{\n\t\tNULL, NULL, NULL, NULL\n\t},\n\t{\n\t\tNULL, NULL, NULL, NULL\n\t}\n};\n\nstatic PyArray_Descr @from@_Descr = { \n\tPyObject_HEAD_INIT(&PyArrayDescr_Type)\n\t&Py@NAME@ArrType_Type,\n\tPyArray_@kind@LTR,\n\tPyArray_@from@LTR,\n\t'@endian@', @isobject@,\n\tPyArray_@from@, \n\t@num@*sizeof(@fromtyp@), \n\t_ALIGN(@fromtyp@),\n\tNULL,\n\tNULL,\n\t&_Py@NAME@_ArrFuncs,\n};\n\n/**end repeat**/\n\n#define _MAX_LETTER 128\nstatic char _letter_to_num[_MAX_LETTER];\n\nstatic PyArray_Descr *_builtin_descrs[] = {\n\t&BOOL_Descr,\n\t&BYTE_Descr,\n\t&UBYTE_Descr,\n\t&SHORT_Descr, \n\t&USHORT_Descr, \n\t&INT_Descr, \n\t&UINT_Descr, \n\t&LONG_Descr, \n\t&ULONG_Descr,\n\t&LONGLONG_Descr,\n\t&ULONGLONG_Descr,\n\t&FLOAT_Descr, \n\t&DOUBLE_Descr,\n\t&LONGDOUBLE_Descr,\n\t&CFLOAT_Descr, \n\t&CDOUBLE_Descr, \n\t&CLONGDOUBLE_Descr,\n\t&OBJECT_Descr, \n\t&STRING_Descr, \n\t&UNICODE_Descr,\n\t&VOID_Descr,\n};\n\n/*OBJECT_API\n Get the PyArray_Descr structure for a type.\n*/\nstatic PyArray_Descr *\nPyArray_DescrFromType(int type)\n{\n\tPyArray_Descr *ret=NULL;\n\n\tif (type < PyArray_NTYPES) {\n\t\tret = _builtin_descrs[type];\n\t}\n\telse if (type == PyArray_NOTYPE) {\n\t\t/* This needs to not raise an error so\n\t\t that PyArray_DescrFromType(PyArray_NOTYPE)\n\t\t works for backwards-compatible C-API \n\t\t*/\t\t\n\t\treturn NULL;\n\t}\n\telse if PyTypeNum_ISUSERDEF(type) {\n\t\tret = userdescrs[type-PyArray_USERDEF];\n\t} \n\telse {\n\t\tint num=PyArray_NTYPES;\n\t\tif (type < _MAX_LETTER) \n\t\t\tnum = (int) _letter_to_num[type];\n\t\tif (num >= PyArray_NTYPES)\n\t\t\tret = NULL;\n\t\telse\n\t\t\tret = _builtin_descrs[num];\n\t}\n\tif (ret==NULL) {\n\t\tPyErr_SetString(PyExc_ValueError, \n\t\t\t\t\"Invalid data-type for array\"); \n\t}\n\telse Py_INCREF(ret);\n\treturn ret;\n}\n\n\nstatic int\nset_typeinfo(PyObject *dict)\n{\n\tPyObject *infodict, *s;\n\tint i;\n\n\tfor (i=0; i<_MAX_LETTER; i++) {\n\t\t_letter_to_num[i] = PyArray_NTYPES;\n\t}\n\n/**begin repeat\n#name=BOOL,BYTE,UBYTE,SHORT,USHORT,INT,UINT,INTP,UINTP,LONG,ULONG,LONGLONG,ULONGLONG,FLOAT,DOUBLE,LONGDOUBLE,CFLOAT,CDOUBLE,CLONGDOUBLE,OBJECT,STRING,UNICODE,VOID#\n*/\n\t_letter_to_num[PyArray_@name@LTR] = PyArray_@name@;\n/**end repeat**/\n\t_letter_to_num[PyArray_STRINGLTR2] = PyArray_STRING;\n\n/**begin repeat\n#name=BOOL,BYTE,UBYTE,SHORT,USHORT,INT,UINT,LONG,ULONG,LONGLONG,ULONGLONG,FLOAT,DOUBLE,LONGDOUBLE,CFLOAT,CDOUBLE,CLONGDOUBLE,OBJECT,STRING,UNICODE,VOID#\n*/\n\t@name@_Descr.fields = Py_None;\n/**end repeat**/\n\t\n\t/* Set a dictionary with type information */\n\tinfodict = PyDict_New();\n\tif (infodict == NULL) return -1;\n\n#define BITSOF_INTP CHAR_BIT*SIZEOF_PY_INTPTR_T\n#define BITSOF_BYTE CHAR_BIT\n\n/**begin repeat \n\n#name=BOOL,BYTE,UBYTE,SHORT,USHORT,INT,UINT,INTP,UINTP,LONG,ULONG,LONGLONG,ULONGLONG#\n#uname=BOOL,BYTE*2,SHORT*2,INT*2,INTP*2,LONG*2,LONGLONG*2#\n#Name=Bool,Byte,UByte,Short,UShort,Int,UInt,Intp,UIntp,Long,ULong,LongLong,ULongLong#\n#type=Bool,byte,ubyte,short,ushort,int,uint,intp,uintp,long,ulong,longlong,ulonglong#\n#max=1,MAX_BYTE,MAX_UBYTE,MAX_SHORT,MAX_USHORT,MAX_INT,PyLong_FromUnsignedLong(MAX_UINT),PyLong_FromLongLong((longlong) MAX_INTP),PyLong_FromUnsignedLongLong((ulonglong) MAX_UINTP),MAX_LONG,PyLong_FromUnsignedLong((unsigned long) MAX_ULONG),PyLong_FromLongLong((longlong) MAX_LONGLONG), PyLong_FromUnsignedLongLong((ulonglong) MAX_ULONGLONG)#\n#min=0,MIN_BYTE,0,MIN_SHORT,0,MIN_INT,0,PyLong_FromLongLong((longlong) MIN_INTP),0,MIN_LONG,0,PyLong_FromLongLong((longlong) MIN_LONGLONG),0#\n#cx=i*6,N,N,N,l,N,N,N#\n#cn=i*7,N,i,l,i,N,i#\n*/\n \tPyDict_SetItemString(infodict, \"@name@\", \n\t\t\t s=Py_BuildValue(\"ciii@cx@@cn@O\", \n\t\t\t\t\t PyArray_@name@LTR, \n\t\t\t\t\t PyArray_@name@,\n\t\t\t\t\t BITSOF_@uname@,\n\t\t\t\t\t _ALIGN(@type@),\n\t\t\t\t\t @max@, @min@,\n\t\t\t\t (PyObject *)&Py@Name@ArrType_Type));\n\tPy_DECREF(s); \n/**end repeat**/\n\n#define BITSOF_CFLOAT 2*BITSOF_FLOAT\n#define BITSOF_CDOUBLE 2*BITSOF_DOUBLE\n#define BITSOF_CLONGDOUBLE 2*BITSOF_LONGDOUBLE\n\n/**begin repeat\n\n#type=float,double,longdouble,cfloat,cdouble,clongdouble#\n#name=FLOAT, DOUBLE, LONGDOUBLE, CFLOAT, CDOUBLE, CLONGDOUBLE#\n#Name=Float,Double,LongDouble,CFloat,CDouble,CLongDouble#\n*/\n \tPyDict_SetItemString(infodict, \"@name@\", \n\t\t\t s=Py_BuildValue(\"ciiiO\", PyArray_@name@LTR, \n\t\t\t\t\t PyArray_@name@, BITSOF_@name@,\n\t\t\t\t\t _ALIGN(@type@),\n (PyObject *)\\\n &Py@Name@ArrType_Type));\n\tPy_DECREF(s);\n/**end repeat**/\n\t\n\tPyDict_SetItemString(infodict, \"OBJECT\", \n\t\t\t s=Py_BuildValue(\"ciiiO\", PyArray_OBJECTLTR, \n\t\t\t\t\t PyArray_OBJECT, \n\t\t\t\t\t sizeof(PyObject *)*CHAR_BIT,\n\t\t\t\t\t _ALIGN(PyObject *),\n (PyObject *)\\\n &PyObjectArrType_Type));\n\tPy_DECREF(s);\n\tPyDict_SetItemString(infodict, \"STRING\", \n\t\t\t s=Py_BuildValue(\"ciiiO\", PyArray_STRINGLTR, \n\t\t\t\t\t PyArray_STRING, 0,\n\t\t\t\t\t _ALIGN(char),\n (PyObject *)\\\n &PyStringArrType_Type));\n\tPy_DECREF(s);\n\tPyDict_SetItemString(infodict, \"UNICODE\", \n\t\t\t s=Py_BuildValue(\"ciiiO\", PyArray_UNICODELTR, \n\t\t\t\t\t PyArray_UNICODE, 0,\n\t\t\t\t\t _ALIGN(PyArray_UCS4),\n (PyObject *)\\\n &PyUnicodeArrType_Type));\t\n\tPy_DECREF(s);\n\tPyDict_SetItemString(infodict, \"VOID\", \n\t\t\t s=Py_BuildValue(\"ciiiO\", PyArray_VOIDLTR, \n\t\t\t\t\t PyArray_VOID, 0,\n\t\t\t\t\t _ALIGN(char),\n (PyObject *)\\\n &PyVoidArrType_Type));\t\n\tPy_DECREF(s);\n\n#define SETTYPE(name) \\\n Py_INCREF(&Py##name##ArrType_Type); \\\n PyDict_SetItemString(infodict, #name, \\\n (PyObject *)&Py##name##ArrType_Type);\n\n SETTYPE(Generic)\n SETTYPE(Number)\n SETTYPE(Integer)\n\tSETTYPE(Inexact)\n SETTYPE(SignedInteger)\n SETTYPE(UnsignedInteger)\n SETTYPE(Floating)\n SETTYPE(ComplexFloating)\n SETTYPE(Flexible)\n SETTYPE(Character)\n\n#undef SETTYPE \t\n\n\tPyDict_SetItemString(dict, \"typeinfo\", infodict);\n\tPy_DECREF(infodict);\n\treturn 0;\n}\n\n#undef _MAX_LETTER\n\n", + "source_code_before": "/* -*- c -*- */\n\n/**begin repeat\n#name=UnsignedLong,UnsignedLongLong,LongLong#\n#type=ulong,ulonglong,longlong#\n */\nstatic @type@\nMyPyLong_As@name@(PyObject *vv)\n{\n\t@type@ ret;\n\n\tif (!PyLong_Check(vv)) {\n\t\tPyObject *mylong;\n\t\tmylong = PyNumber_Long(vv);\n\t\tif (mylong == NULL) return (@type@) -1;\n\t\tvv = mylong;\n\t}\n\telse Py_INCREF(vv);\n\n\tret = PyLong_As@name@(vv);\n\tPy_DECREF(vv);\n\treturn ret;\n}\n/**end repeat**/\n\n\nstatic double \n_getNAN(void) {\n#ifdef NAN\n return NAN;\n#else\n static double nan=0;\n \n if (nan == 0) {\n\t\tdouble mul = 1e100;\n\t\tdouble tmp = 0.0;\n\t\tdouble pinf=0;\n pinf = mul;\n for (;;) {\n pinf *= mul;\n if (pinf == tmp) break;\n tmp = pinf;\n }\n nan = pinf / pinf;\n }\n return nan;\n#endif\n}\n\nstatic double\nMyPyFloat_AsDouble(PyObject *obj)\n{\n if (obj == Py_None) return _getNAN();\n return PyFloat_AsDouble(obj); \n}\n\n\n/****************** getitem and setitem **********************/\n\n/**begin repeat\n\n#TYP=BOOL,BYTE,UBYTE,SHORT,USHORT,INT,LONG,UINT,ULONG,LONGLONG,ULONGLONG,FLOAT,DOUBLE#\n#func1=PyBool_FromLong, PyInt_FromLong*6, PyLong_FromUnsignedLong*2, PyLong_FromLongLong, PyLong_FromUnsignedLongLong, PyFloat_FromDouble*2#\n#func2=PyObject_IsTrue, PyInt_AsLong*6, MyPyLong_AsUnsignedLong*2, MyPyLong_AsLongLong, MyPyLong_AsUnsignedLongLong, MyPyFloat_AsDouble*2#\n#typ=Bool, byte, ubyte, short, ushort, int, long, uint, ulong, longlong, ulonglong, float, double#\n#typ1=long*7, ulong*2, longlong, ulonglong, float, double#\n#kind=Bool, Byte, UByte, Short, UShort, Int, Long, UInt, ULong, LongLong, ULongLong, Float, Double#\n*/\n\nstatic PyObject * \n@TYP@_getitem(char *ip, PyArrayObject *ap) {\n @typ@ t1;\n\n\tif ((ap==NULL) || PyArray_ISBEHAVED_RO(ap)) {\n t1 = *((@typ@ *)ip);\n return @func1@((@typ1@)t1);\n\t}\n\telse {\n ap->descr->f->copyswap(&t1, ip, !PyArray_ISNOTSWAPPED(ap),\n\t\t\t\t ap->descr->elsize);\n return @func1@((@typ1@)t1);\n\t}\n}\n\nstatic int \n@TYP@_setitem(PyObject *op, char *ov, PyArrayObject *ap) {\n @typ@ temp; /* ensures alignment */\n\n if (PyArray_IsScalar(op, @kind@)) {\n temp = ((Py@kind@ScalarObject *)op)->obval;\n }\n else {\n temp = (@typ@)@func2@(op);\n }\n if (PyErr_Occurred()) return -1;\n if (ap == NULL || PyArray_ISBEHAVED(ap)) \n *((@typ@ *)ov)=temp;\n else {\n ap->descr->f->copyswap(ov, &temp, !PyArray_ISNOTSWAPPED(ap), \n\t\t\t\t ap->descr->elsize);\n }\n \n return 0;\n}\n\n/**end repeat**/\n\n\n/**begin repeat \n\n#TYP=CFLOAT,CDOUBLE#\n#typ=float, double#\n*/\n\nstatic PyObject * \n@TYP@_getitem(char *ip, PyArrayObject *ap) {\n @typ@ t1, t2;\n\n if ((ap==NULL) || PyArray_ISBEHAVED_RO(ap)) { \n return PyComplex_FromDoubles((double)((@typ@ *)ip)[0], \n (double)((@typ@ *)ip)[1]);\n }\n else {\n\t\tint size = sizeof(@typ@);\n\t\tBool swap = !PyArray_ISNOTSWAPPED(ap);\n copy_and_swap(&t1, ip, size, 1, 0, swap);\n copy_and_swap(&t2, ip+size, size, 1, 0, swap);\n return PyComplex_FromDoubles((double)t1, (double)t2);\n }\n}\n/**end repeat**/\n\n/**begin repeat \n\n#TYP=CFLOAT, CDOUBLE, CLONGDOUBLE#\n#typ=float, double, longdouble#\n#kind=CFloat, CDouble, CLongDouble#\n*/\nstatic int \n@TYP@_setitem(PyObject *op, char *ov, PyArrayObject *ap) \n{\n Py_complex oop;\n PyObject *op2;\n c@typ@ temp;\n\tint rsize;\n \n if (!(PyArray_IsScalar(op, @kind@))) {\n if (PyArray_Check(op) && (PyArray_NDIM(op)==0)) {\n op2 = ((PyArrayObject *)op)->descr->f->getitem \\\n (((PyArrayObject *)op)->data, \n (PyArrayObject *)op);\n\t\t}\n\t\telse { \n op2 = op; Py_INCREF(op);\n }\n if (op2 == Py_None) {\n oop.real = oop.imag = _getNAN();\n }\n else {\n oop = PyComplex_AsCComplex (op2);\n }\n Py_DECREF(op2);\n if (PyErr_Occurred()) return -1;\n temp.real = (@typ@) oop.real;\n temp.imag = (@typ@) oop.imag; \n }\n\telse {\n temp = ((Py@kind@ScalarObject *)op)->obval;\n }\n\t\n memcpy(ov, &temp, ap->descr->elsize);\n if (!PyArray_ISNOTSWAPPED(ap))\n byte_swap_vector(ov, 2, sizeof(@typ@));\n\t\n\trsize = sizeof(@typ@);\n\tcopy_and_swap(ov, &temp, rsize, 2, rsize, !PyArray_ISNOTSWAPPED(ap));\n return 0;\n}\n/**end repeat**/\n\nstatic PyObject * \nLONGDOUBLE_getitem(char *ip, PyArrayObject *ap) \n{\n return PyArray_Scalar(ip, ap->descr, NULL);\n}\n\nstatic int \nLONGDOUBLE_setitem(PyObject *op, char *ov, PyArrayObject *ap) {\n longdouble temp; /* ensures alignment */\n\n if (PyArray_IsScalar(op, LongDouble)) {\n temp = ((PyLongDoubleScalarObject *)op)->obval;\n }\n else {\n if (op == Py_None) temp = (longdouble)_getNAN();\n else temp = (longdouble)PyFloat_AsDouble(op);\n }\n if (PyErr_Occurred()) return -1;\n if (ap == NULL || PyArray_ISBEHAVED(ap)) \n *((longdouble *)ov)=temp;\n else {\n copy_and_swap(ov, &temp, ap->descr->elsize, 1, 0,\n !PyArray_ISNOTSWAPPED(ap));\n }\n \n return 0;\n}\n\nstatic PyObject * \nCLONGDOUBLE_getitem(char *ip, PyArrayObject *ap) \n{\n return PyArray_Scalar(ip, ap->descr, NULL);\n}\n\n\n/* UNICODE */\nstatic PyObject * \nUNICODE_getitem(char *ip, PyArrayObject *ap) \n{\n\tPyObject *obj;\n\tint mysize;\n\tPyArray_UCS4 *dptr;\n\n\tmysize = ap->descr->elsize >> 2;\n\tdptr = (PyArray_UCS4 *)ip + mysize-1;\n\twhile(mysize > 0 && *dptr-- == 0) mysize--;\n\tif (!PyArray_ISNOTSWAPPED(ap) && (obj != NULL)) {\n\t\tbyte_swap_vector(PyArray_BYTES(ap), mysize, 4);\n\t}\n#ifdef Py_UNICODE_WIDE\n\tobj = PyUnicode_FromUnicode((const PyArray_UCS4 *)ip, mysize);\n#else\n\t/* create new empty unicode object of length mysize*2 */\n\tobj = MyPyUnicode_New(mysize*2);\n\tif (obj == NULL) return obj;\n\tmysize = PyUCS2Buffer_FromUCS4(((PyUnicodeObject *)obj)->str, \n\t\t\t\t (PyArray_UCS4 *)ip, mysize);\n\t/* reset length of unicode object to ucs2size */\n\tif (MyPyUnicode_Resize((PyUnicodeObject *)obj, mysize) < 0) {\n\t\tPy_DECREF(obj);\n\t\treturn NULL;\n\t}\n#endif\n\n\treturn obj;\n}\n\nstatic int \nUNICODE_setitem(PyObject *op, char *ov, PyArrayObject *ap) \n{\n PyObject *temp;\n\tPy_UNICODE *ptr;\n\tint datalen;\n\n\tif ((temp=PyObject_Unicode(op)) == NULL) return -1;\n\tptr = PyUnicode_AS_UNICODE(temp);\n\tif ((ptr == NULL) || (PyErr_Occurred())) {\n\t\tPy_DECREF(temp);\n\t\treturn -1;\n\t}\n\tdatalen = PyUnicode_GET_DATA_SIZE(temp);\n\n#ifdef Py_UNICODE_WIDE\n\tmemcpy(ov, ptr, MIN(ap->descr->elsize, datalen));\n#else\n datalen = PyUCS2Buffer_AsUCS4(ptr, (PyArray_UCS4 *)ov, datalen >> 1,\n\t\t\t\t ap->descr->elsize >> 2);\n\tdatalen <<= 2;\n#endif\n\t/* Fill in the rest of the space with 0 */\n\tif (ap->descr->elsize > datalen) {\n\t\tmemset(ov + datalen, 0, (ap->descr->elsize - datalen));\n\t}\n\t\n\tif (!PyArray_ISNOTSWAPPED(ap)) \n\t\tbyte_swap_vector(ov, ap->descr->elsize >> 2, 4);\n\tPy_DECREF(temp);\n\treturn 0;\n}\n\n/* STRING -- can handle both NULL-terminated and not NULL-terminated cases */\nstatic PyObject * \nSTRING_getitem(char *ip, PyArrayObject *ap) \n{\n\tif (ip[ap->descr->elsize-1])\n\t\treturn PyString_FromStringAndSize(ip,ap->descr->elsize);\n\telse\n\t\treturn PyString_FromString(ip);\n}\n\nstatic int \nSTRING_setitem(PyObject *op, char *ov, PyArrayObject *ap) \n{\n\tchar *ptr;\n\tint len;\n\tPyObject *temp=PyObject_Str(op);\n\t\n\tif (temp == NULL) return -1;\n\t\n\tif (PyString_AsStringAndSize(temp, &ptr, &len) == -1) {\n\t\tPy_DECREF(temp);\n\t\treturn -1;\n\t}\n\tmemcpy(ov, ptr, MIN(ap->descr->elsize,len));\n\tif (ap->descr->elsize > len) {\n\t\tmemset(ov + len, 0, (ap->descr->elsize - len));\n\t}\n\tPy_DECREF(temp);\n\treturn 0;\n}\n\n/* OBJECT */\n\nstatic PyObject * \nOBJECT_getitem(char *ip, PyArrayObject *ap) \n{\n\tPy_INCREF(*(PyObject **)ip);\n\treturn *(PyObject **)ip;\n}\n\nstatic int \nOBJECT_setitem(PyObject *op, char *ov, PyArrayObject *ap) \n{\n\tPy_XDECREF(*(PyObject **)ov);\n\tPy_INCREF(op);\n\t*(PyObject **)ov = op;\n\treturn PyErr_Occurred() ? -1:0;\n}\n\n/* VOID */\n\nstatic PyObject *\nVOID_getitem(char *ip, PyArrayObject *ap)\n{\n PyObject *u=NULL;\n\tPyArray_Descr* descr;\n int itemsize;\n\n\tdescr = ap->descr;\n\tif (descr->fields && descr->fields != Py_None) {\n\t\tPyObject *key;\n\t\tPyObject *names;\n\t\tint i, n;\n\t\tPyObject *ret;\n\t\tPyObject *tup, *title;\n\t\tPyArray_Descr *new;\n\t\tint offset;\n\t\tint savedflags;\n\n\t\t/* get the names from the fields dictionary*/\n\t\tkey = PyInt_FromLong(-1);\n\t\tnames = PyDict_GetItem(descr->fields, key);\n\t\tPy_DECREF(key);\n\t\tif (!names) goto finish;\n\t\tn = PyList_GET_SIZE(names);\n\t\tret = PyTuple_New(n);\n\t\tsavedflags = ap->flags;\n\t\tfor (i=0; ifields, key);\n\t\t\tif (!PyArg_ParseTuple(tup, \"Oi|O\", &new, &offset, \n\t\t\t\t\t &title)) {\n\t\t\t\tPy_DECREF(ret); \n\t\t\t\tap->descr = descr;\n\t\t\t\treturn NULL;\n\t\t\t}\n\t\t\tap->descr = new;\n\t\t\t/* update alignment based on offset */\n\t\t\tif ((new->alignment > 1) &&\t\t\t\\\n\t\t\t ((((intp)(ip+offset)) % new->alignment) != 0))\n\t\t\t\tap->flags &= ~ALIGNED;\n\t\t\telse\n\t\t\t\tap->flags |= ALIGNED;\n\n\t\t\tPyTuple_SET_ITEM(ret, i,\t\t\t\\\n\t\t\t\t\t new->f->getitem(ip+offset, ap));\n\t\t\tap->flags = savedflags;\n\t\t}\n\t\tap->descr = descr;\n\t\treturn ret;\n\t}\n\n\tif (descr->subarray) {\n\t\t/* return an array of the basic type */\n\t\tPyArray_Dims shape={NULL,-1};\n\t\tPyObject *ret;\n\t\tif (!(PyArray_IntpConverter(descr->subarray->shape, \n\t\t\t\t\t &shape))) {\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\treturn NULL;\n\t\t}\n Py_INCREF(descr->subarray->base);\n\t\tret = PyArray_NewFromDescr(&PyArray_Type,\n\t\t\t\t\t descr->subarray->base,\n\t\t\t\t\t shape.len, shape.ptr,\n\t\t\t\t\t NULL, ip, ap->flags, NULL);\n\t\tPyDimMem_FREE(shape.ptr);\n\t\tif (!ret) return NULL;\n\t\tPyArray_BASE(ret) = (PyObject *)ap;\n\t\tPy_INCREF(ap);\n\t\tPyArray_UpdateFlags((PyArrayObject *)ret, UPDATE_ALL_FLAGS);\n\t\treturn ret;\n\t}\n\n finish:\n\titemsize=ap->descr->elsize;\n\tif (PyArray_ISWRITEABLE(ap))\n\t\tu = PyBuffer_FromReadWriteMemory(ip, itemsize);\n\telse\n\t\tu = PyBuffer_FromMemory(ip, itemsize);\n\tif (u==NULL) goto fail;\n\n\t/* default is to return buffer object pointing to current item */\n\t/* a view of it */\n\treturn u; \n\t\n fail:\n return NULL;\n}\n\n\n\nstatic int PyArray_CopyObject(PyArrayObject *, PyObject *);\n\nstatic int\nVOID_setitem(PyObject *op, char *ip, PyArrayObject *ap)\n{\n\tPyArray_Descr* descr;\n int itemsize=ap->descr->elsize;\n\tint res;\n\n\tdescr = ap->descr;\n\tif (descr->fields && (descr->fields != Py_None) && \\\n\t PyTuple_Check(op)) {\n\t\tPyObject *key;\n\t\tPyObject *names;\n\t\tint i, n;\n\t\tPyObject *tup, *title;\n\t\tPyArray_Descr *new;\n\t\tint offset;\n\t\tint savedflags;\n\t\tres = -1;\n\t\t/* get the names from the fields dictionary*/\n\t\tkey = PyInt_FromLong(-1);\n\t\tnames = PyDict_GetItem(descr->fields, key);\n\t\tPy_DECREF(key);\n\t\tif (!names) goto finish;\n\t\tn = PyList_GET_SIZE(names);\n\t\tif (PyTuple_GET_SIZE(op) != n) {\n\t\t\tPyErr_SetString(PyExc_ValueError, \n\t\t\t\t\t\"size of tuple must match\"\\\n\t\t\t\t\t\"number of fields.\");\n\t\t\treturn -1;\n\t\t}\n\t\tsavedflags = ap->flags;\n\t\tfor (i=0; ifields, key);\n\t\t\tif (!PyArg_ParseTuple(tup, \"Oi|O\", &new, &offset, \n\t\t\t\t\t &title)) {\n\t\t\t\tap->descr = descr;\n\t\t\t\treturn -1;\n\t\t\t}\n\t\t\tap->descr = new;\n\t\t\t/* remember to update alignment flags */\n\t\t\tif ((new->alignment > 1) &&\t\t\t\\\n\t\t\t ((((intp)(ip+offset)) % new->alignment) != 0))\n\t\t\t\tap->flags &= ~ALIGNED;\n\t\t\telse\n\t\t\t\tap->flags |= ALIGNED;\n\n\t\t\tres = new->f->setitem(PyTuple_GET_ITEM(op, i),\n\t\t\t\t\t ip+offset, ap);\n\t\t\tap->flags = savedflags;\n\t\t\tif (res < 0) break;\n\t\t}\n\t\tap->descr = descr;\n\t\treturn res;\n\t}\n\n\tif (descr->subarray) {\n\t\t/* copy into an array of the same basic type */\n\t\tPyArray_Dims shape={NULL,-1};\n\t\tPyObject *ret;\n\t\tif (!(PyArray_IntpConverter(descr->subarray->shape, \n\t\t\t\t\t &shape))) {\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\treturn -1;\n\t\t}\n Py_INCREF(descr->subarray->base);\n\t\tret = PyArray_NewFromDescr(&PyArray_Type,\n\t\t\t\t\t descr->subarray->base,\n\t\t\t\t\t shape.len, shape.ptr,\n\t\t\t\t\t NULL, ip, ap->flags, NULL);\n\t\tPyDimMem_FREE(shape.ptr);\n\t\tif (!ret) return -1;\n\t\tPyArray_BASE(ret) = (PyObject *)ap;\n\t\tPy_INCREF(ap);\n\t\tPyArray_UpdateFlags((PyArrayObject *)ret, UPDATE_ALL_FLAGS);\n\t\tres = PyArray_CopyObject((PyArrayObject *)ret, op);\n\t\tPy_DECREF(ret);\n\t\treturn res;\n\t}\n\n finish:\n\t/* Default is to use buffer interface to set item */\n\t{\n\t\tconst void *buffer;\n\t\tint buflen;\n\t\tres = PyObject_AsReadBuffer(op, &buffer, &buflen);\n\t\tif (res == -1) goto fail;\n\t\tmemcpy(ip, buffer, MIN(buflen, itemsize));\n }\n\treturn 0;\n\n fail:\n return -1; \n}\n\n\n/****************** XXX_to_YYY *******************************/ \n\n/* Assumes contiguous, and aligned, from and to */\n\n\n/**begin repeat\n#to=(BYTE,UBYTE,SHORT,USHORT,INT,UINT,LONG,ULONG,LONGLONG,ULONGLONG,FLOAT,DOUBLE,LONGDOUBLE)*16#\n#from=BYTE*13,UBYTE*13,SHORT*13,USHORT*13,INT*13,UINT*13,LONG*13,ULONG*13,LONGLONG*13,ULONGLONG*13,FLOAT*13,DOUBLE*13,LONGDOUBLE*13,CFLOAT*13,CDOUBLE*13,CLONGDOUBLE*13#\n#totyp=(byte, ubyte, short, ushort, int, uint, long, ulong, longlong, ulonglong, float, double, longdouble)*16#\n#fromtyp=byte*13, ubyte*13, short*13, ushort*13, int*13, uint*13, long*13, ulong*13, longlong*13, ulonglong*13, float*13, double*13, longdouble*13, float*13, double*13, longdouble*13#\n#incr= ip++*169,ip+=2*39#\n*/\nstatic void \n@from@_to_@to@(@fromtyp@ *ip, @totyp@ *op, intp n, PyArrayObject *aip, \n\t PyArrayObject *aop) {\n\tregister intp i; \n\tfor(i=0;idescr->elsize*3, 1#\n*/\nstatic void \n@from@_to_OBJECT(@fromtyp@ *ip, PyObject **op, intp n, PyArrayObject *aip,\n\t\t PyArrayObject *aop)\n{\n\tregister intp i; \n\tint skip=@skip@;\n\tfor(i=0;idescr->elsize*3#\n*/\nstatic void \nOBJECT_to_@to@(PyObject **ip, @totyp@ *op, intp n, PyArrayObject *aip,\n\t\t PyArrayObject *aop)\n{\n\tregister intp i; \n\tint skip=@skip@;\n\tfor(i=0;idescr->elsize*3)*3#\n#convert=1*17,0*3,1*17,0*3,0*20#\n#convstr=(Int*9,Long*2,Float*3,Complex*3,Tuple*3)*3#\n*/\nstatic void\n@from@_to_@to@(@fromtyp@ *ip, @totyp@ *op, intp n, PyArrayObject *aip, \n\t PyArrayObject *aop)\n{\n\tregister intp i;\n\tPyObject *temp=NULL;\n\tint skip=aip->descr->elsize;\n\tint oskip=@oskip@;\n\tfor(i=0; idescr->elsize;\n\tfor(i=0; i= 0x02040000) || defined(PyOS_ascii_strtod)\nstatic int\n@fname@_fromstr(char *str, @type@ *ip, char **endptr, void *ignore)\n{\n\tdouble result;\n\n\tresult = PyOS_ascii_strtod(str, endptr);\n\t*ip = (@type@) result;\n\treturn 0;\n}\n#else\n#define @fname@_fromstr NULL\n#endif\n/**end repeat**/\n\n\n\n/**begin repeat\n#fname=BOOL,CFLOAT,CDOUBLE,CLONGDOUBLE,OBJECT,STRING,UNICODE,VOID#\n*/\n#define @fname@_fromstr NULL\n/**end repeat**/\n\n\n/****************** copyswapn *************************************/\n\n/**begin repeat\n\n#fname=SHORT,USHORT,INT,UINT,LONG,ULONG,LONGLONG,ULONGLONG,FLOAT,DOUBLE,LONGDOUBLE#\n#fsize=SHORT,SHORT,INT,INT,LONG,LONG,LONGLONG,LONGLONG,FLOAT,DOUBLE,LONGDOUBLE#\n#type=short,ushort,int,uint,long,ulong,longlong,ulonglong,float,double,longdouble#\n*/\nstatic void\n@fname@_copyswapn (void *dst, void *src, intp n, int swap, int itemsize)\n{\n\tif (src != NULL) /* copy first if needed */\n\t\tmemcpy(dst, src, n*sizeof(@type@));\n\n\tif (swap) {\n\t\tregister char *a, *b, c;\n\t\tfor (a = (char *)dst; n>0; n--) {\n#if SIZEOF_@fsize@ == 2\n\t\t\tb = a + 1;\n\t\t\tc = *a; *a++ = *b; *b = c;\n\t\t\ta += 1;\n#elif SIZEOF_@fsize@ == 4\n\t\t\tb = a + 3;\n c = *a; *a++ = *b; *b-- = c;\n c = *a; *a++ = *b; *b = c;\n\t\t\ta += 2;\n#elif SIZEOF_@fsize@ == 8\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\t\t\ta += 4;\n#elif SIZEOF_@fsize@ == 10\n b = a + 9;\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 c = *a; *a++ = *b; *b = c;\n\t\t\ta += 5;\n#elif SIZEOF_@fsize@ == 12\n b = a + 11;\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 c = *a; *a++ = *b; *b-- = c;\n c = *a; *a++ = *b; *b = c;\n\t\t\ta += 6;\n#elif SIZEOF_@fsize@ == 16\n b = a + 15;\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 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\t\t\ta += 8;\n#else\n\t\t\tregister int i, nn;\n b = a + (SIZEOF_@fsize@-1);\n\t\t\tnn = SIZEOF_@fsize@ / 2;\n for (i=0; i0; nn--) {\n#if SIZEOF_@fsize@ == 4\n\t\t\tb = a + 3;\n c = *a; *a++ = *b; *b-- = c;\n c = *a; *a++ = *b; *b = c;\n\t\t\ta += 2;\n#elif SIZEOF_@fsize@ == 8\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\t\t\ta += 4;\n#elif SIZEOF_@fsize@ == 10\n b = a + 9;\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 c = *a; *a++ = *b; *b = c;\n\t\t\ta += 5;\n#elif SIZEOF_@fsize@ == 12\n b = a + 11;\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 c = *a; *a++ = *b; *b-- = c;\n c = *a; *a++ = *b; *b = c;\n\t\t\ta += 6;\n#elif SIZEOF_@fsize@ == 16\n b = a + 15;\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 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\t\t\ta += 8;\n#else\n\t\t\tregister int i, kn;\n\n b = a + (SIZEOF_@fsize@-1);\n\t\t\tkn = SIZEOF_@fsize@ / 2;\n for (i=0; i0; n--) {\n\t\t\tb = a + 3;\n\t\t\tc=*a; *a++ = *b; *b-- = c;\n\t\t\tc=*a; *a++ = *b; *b-- = c;\n\t\t\ta += 1;\n\t\t}\n\t}\n}\n\n\nstatic void\nOBJECT_copyswap (PyObject **dst, PyObject **src, int swap, int itemsize)\n{\n OBJECT_copyswapn(dst, src, 1, swap, itemsize);\n}\n\nstatic void\nSTRING_copyswap (char *dst, char *src, int swap, int itemsize)\n{\n\tif (src != NULL) \n\t\tmemcpy(dst, src, itemsize);\n\t\n}\n\n/* ignore swap */\nstatic void\nVOID_copyswap (char *dst, char *src, int swap, int itemsize)\n{\n\tif (src != NULL) \n\t\tmemcpy(dst, src, itemsize);\t\n\treturn;\n}\n\nstatic void\nUNICODE_copyswap (char *dst, char *src, int swap, int itemsize)\n{\n\n\tif (src != NULL) \n\t\tmemcpy(dst, src, itemsize);\n\t\n\tif (swap) {\n\t\tregister char *a, *b, c;\n a = (char *)dst;\n b = a + 3;\n\t\tc=*a; *a++ = *b; *b-- = c;\n\t\tc=*a; *a++ = *b; *b-- = c;\n\t}\n}\n\n\n/****************** nonzero **********************************/\n\n/**begin repeat\n#fname=BOOL,BYTE,UBYTE,SHORT,USHORT,INT,UINT,LONG,ULONG,LONGLONG,ULONGLONG,FLOAT,DOUBLE,LONGDOUBLE#\n#type=Bool, byte, ubyte, short, ushort, int, uint, long, ulong, longlong, ulonglong, float, double, longdouble#\n*/\nstatic Bool \n@fname@_nonzero (@type@ *ip, PyArrayObject *ap)\n{\n\t@type@ t1;\n\tif (ap==NULL || PyArray_ISBEHAVED_RO(ap))\n\t\treturn (Bool) (*ip != 0);\n\telse {\n\t\t/* don't worry about swap, since we are just testing\n\t\t whether or not equal to 0 */\n\t\tmemcpy(&t1, ip, sizeof(@type@));\n\t\treturn (Bool) (t1 != 0);\n\t}\n}\n/**end repeat**/\n\n/**begin repeat\n#fname=CFLOAT,CDOUBLE,CLONGDOUBLE#\n#type=cfloat, cdouble, clongdouble#\n*/\nstatic Bool \n@fname@_nonzero (@type@ *ip, PyArrayObject *ap)\n{\n\t@type@ t1;\n\tif (ap==NULL || PyArray_ISBEHAVED_RO(ap))\n\t\treturn (Bool) ((ip->real != 0) || (ip->imag != 0));\n\telse {\n\t\t/* don't worry about swap, since we are just testing\n\t\t whether or not equal to 0 */\n\t\tmemcpy(&t1, ip, sizeof(@type@));\n\t\treturn (Bool) ((t1.real != 0) || (t1.imag != 0));\n\t}\n}\n/**end repeat**/\n\n\n\n#define WHITESPACE \" \\t\\n\\r\\v\\f\"\n#define WHITELEN 6\n\nstatic Bool\nPy_STRING_ISSPACE(char ch) \n{\n\tchar white[] = WHITESPACE;\n\tint j;\n\tBool space=FALSE;\n\tfor (j=0; jdescr->elsize;\n\tint i;\n\tBool nonz = FALSE;\n\n\tfor (i=0; idescr->elsize >> 2;\n\tint i;\n\tBool nonz = FALSE;\n\tchar *buffer=NULL;\t\n\n\tif ((!PyArray_ISNOTSWAPPED(ap)) || \\\n\t (!PyArray_ISALIGNED(ap))) {\n\t\tbuffer = _pya_malloc(ap->descr->elsize);\n\t\tif (buffer == NULL) {\n\t\t\treturn nonz;\n\t\t}\n\t\tmemcpy(buffer, ip, ap->descr->elsize);\n\t\tif (!PyArray_ISNOTSWAPPED(ap)) {\n\t\t\tbyte_swap_vector(buffer, len, 4);\n\t\t}\n\t\tip = (PyArray_UCS4 *)buffer;\n\t}\n\n\tfor (i=0; idescr->elsize;\n\tBool nonz = FALSE;\n\t\n\tfor (i=0; idescr->elsize);\n}\n\n/* taken from Python */\nstatic int \nUNICODE_compare(register PyArray_UCS4 *ip1, register PyArray_UCS4 *ip2, \n\t\tPyArrayObject *ap)\n{\n register int itemsize=ap->descr->elsize;\n\tregister PyArray_UCS4 c1, c2;\n\n\tif (itemsize < 0) return 0;\n\t\n\twhile(itemsize-- > 0) {\n\t\tc1 = *ip1++;\n\t\tc2 = *ip2++;\n\t\t\n\t\tif (c1 != c2) \n\t\t\treturn (c1 < c2) ? -1 : 1;\n\t}\n\treturn 0;\n}\n\n/* possibly redefine compare in terms of fields and subarrays if any */\n\n/* as it is, it compares raw-bytes as it they were strings */\n#define VOID_compare STRING_compare\n\n/****************** argfunc **********************************/\n\n/**begin repeat\n\n#fname= BOOL,BYTE, UBYTE, SHORT, USHORT, INT, UINT, LONG, ULONG, LONGLONG, ULONGLONG, FLOAT, DOUBLE, LONGDOUBLE, CFLOAT, CDOUBLE, CLONGDOUBLE#\n#type= Bool, byte, ubyte, short, ushort, int, uint, long, ulong, longlong, ulonglong, float, double, longdouble, float, double, longdouble#\n#incr= ip++*14, ip+=2*3#\n*/\n\nstatic int\n@fname@_argmax(@type@ *ip, intp n, intp *max_ind, PyArrayObject *aip)\n{\n\tregister intp i;\n\t@type@ mp=*ip;\n\t*max_ind=0;\n\tfor (i=1; i mp) {\n\t\t\tmp = *ip;\n\t\t\t*max_ind = i;\n\t\t}\n\t}\n\treturn 0;\n}\n\n/**end repeat**/\n\nstatic int \nOBJECT_argmax(PyObject **ip, intp n, intp *max_ind, PyArrayObject *aip) \n{\n\tregister intp i; \n\tPyObject *mp=ip[0]; *max_ind=0;\n\tfor(i=1; i 0) { \n\t\t\tmp = *ip; \n\t\t\t*max_ind=i;\n\t\t} \n\t} \n\treturn 0;\n}\n\n/**begin repeat\n\n#fname= STRING, UNICODE#\n#type= char, PyArray_UCS4#\n\n*/\nstatic int \n@fname@_argmax(@type@ *ip, intp n, intp *max_ind, PyArrayObject *aip) \n{\n\tregister intp i; \n\tint elsize = aip->descr->elsize;\n\t@type@ *mp = (@type@ *)_pya_malloc(elsize);\n\t\n\tif (mp==NULL) return 0;\n\tmemcpy(mp, ip, elsize);\n\t*max_ind = 0;\n\tfor(i=1; i 0) { \n\t\t\tmemcpy(mp, ip, elsize);\n\t\t\t*max_ind=i;\n\t\t} \n\t} \n\t_pya_free(mp);\n\treturn 0;\n}\n\n/**end repeat**/\n\n#define VOID_argmax NULL\n\nstatic void\nBOOL_dot(char *ip1, intp is1, char *ip2, intp is2, char *op, intp n, \n void *ignore)\n{\n\tregister Bool tmp=FALSE;\n\tregister intp i;\n\tfor(i=0;ireal;\n\tstart.imag = buffer->imag;\n\tdelta.real = buffer[1].real;\n\tdelta.imag = buffer[1].imag;\n\tdelta.real -= start.real;\n\tdelta.imag -= start.imag;\n\tbuffer += 2;\n\tfor (i=2; ireal = start.real + i*delta.real;\n\t\tbuffer->imag = start.imag + i*delta.imag;\n\t}\n}\n/**end repeat**/\n\n\n#define _ALIGN(type) offsetof(struct {char c; type v;},v)\n\n/**begin repeat\n\n#from= VOID, STRING, UNICODE#\n#align= char, char, PyArray_UCS4#\n#NAME= Void, String, Unicode#\n#endian= |, |, =#\n*/\n\nstatic PyArray_ArrFuncs _Py@NAME@_ArrFuncs = {\n\t{\n\t\t(PyArray_VectorUnaryFunc*)@from@_to_BOOL, \n\t\t(PyArray_VectorUnaryFunc*)@from@_to_BYTE, \n\t\t(PyArray_VectorUnaryFunc*)@from@_to_UBYTE, \n\t\t(PyArray_VectorUnaryFunc*)@from@_to_SHORT, \n\t\t(PyArray_VectorUnaryFunc*)@from@_to_USHORT, \n\t\t(PyArray_VectorUnaryFunc*)@from@_to_INT, \n\t\t(PyArray_VectorUnaryFunc*)@from@_to_UINT, \n\t\t(PyArray_VectorUnaryFunc*)@from@_to_LONG,\n\t\t(PyArray_VectorUnaryFunc*)@from@_to_ULONG, \n\t\t(PyArray_VectorUnaryFunc*)@from@_to_LONGLONG, \n\t\t(PyArray_VectorUnaryFunc*)@from@_to_ULONGLONG, \n\t\t(PyArray_VectorUnaryFunc*)@from@_to_FLOAT, \n\t\t(PyArray_VectorUnaryFunc*)@from@_to_DOUBLE, \n\t\t(PyArray_VectorUnaryFunc*)@from@_to_LONGDOUBLE, \n\t\t(PyArray_VectorUnaryFunc*)@from@_to_CFLOAT, \n\t\t(PyArray_VectorUnaryFunc*)@from@_to_CDOUBLE, \n\t\t(PyArray_VectorUnaryFunc*)@from@_to_CLONGDOUBLE, \n\t\t(PyArray_VectorUnaryFunc*)@from@_to_OBJECT, \n\t\t(PyArray_VectorUnaryFunc*)@from@_to_STRING, \n\t\t(PyArray_VectorUnaryFunc*)@from@_to_UNICODE, \n\t\t(PyArray_VectorUnaryFunc*)@from@_to_VOID\n\t},\n\t(PyArray_GetItemFunc*)@from@_getitem, \n\t(PyArray_SetItemFunc*)@from@_setitem,\n\t(PyArray_CopySwapNFunc*)@from@_copyswapn,\n\t(PyArray_CopySwapFunc*)@from@_copyswap,\n\t(PyArray_CompareFunc*)@from@_compare, \n\t(PyArray_ArgFunc*)@from@_argmax,\n\t(PyArray_DotFunc*)NULL, \n\t(PyArray_ScanFunc*)@from@_scan,\n\t(PyArray_FromStrFunc*)@from@_fromstr,\n\t(PyArray_NonzeroFunc*)@from@_nonzero,\n\t(PyArray_FillFunc*)NULL,\n\t{\n\t\tNULL, NULL, NULL, NULL\n\t},\n\t{\n\t\tNULL, NULL, NULL, NULL\n\t}\n};\n\nstatic PyArray_Descr @from@_Descr = { \n\tPyObject_HEAD_INIT(&PyArrayDescr_Type)\n\t&Py@NAME@ArrType_Type,\n\tPyArray_@from@LTR,\n\tPyArray_@from@LTR,\n\t'@endian@', 0,\n\tPyArray_@from@, 0,\n\t_ALIGN(@align@),\n\tNULL,\n\tNULL,\n\t&_Py@NAME@_ArrFuncs,\n};\n\n/**end repeat**/\n\n\n/**begin repeat\n\n#from= BOOL,BYTE,UBYTE,SHORT,USHORT,INT,UINT,LONG,ULONG,LONGLONG,ULONGLONG,FLOAT,DOUBLE,LONGDOUBLE,CFLOAT,CDOUBLE,CLONGDOUBLE,OBJECT#\n#num= 1*14,2*3,1#\n#fromtyp= Bool, byte, ubyte, short, ushort, int, uint, long, ulong, longlong, ulonglong, float, double, longdouble, float, double, longdouble, PyObject *#\n#NAME= Bool, Byte, UByte, Short, UShort, Int, UInt, Long, ULong, LongLong, ULongLong, Float, Double, LongDouble, CFloat, CDouble, CLongDouble, Object#\n#kind= GENBOOL, SIGNED, UNSIGNED, SIGNED, UNSIGNED, SIGNED, UNSIGNED, SIGNED, UNSIGNED, SIGNED, UNSIGNED, FLOATING, FLOATING, FLOATING, COMPLEX, COMPLEX, COMPLEX, OBJECT#\n#endian= |*3, =*14, |#\n#isobject= 0*17,1#\n*/\n\nstatic PyArray_ArrFuncs _Py@NAME@_ArrFuncs = {\n\t{\n\t\t(PyArray_VectorUnaryFunc*)@from@_to_BOOL, \n\t\t(PyArray_VectorUnaryFunc*)@from@_to_BYTE,\n\t\t(PyArray_VectorUnaryFunc*)@from@_to_UBYTE, \n\t\t(PyArray_VectorUnaryFunc*)@from@_to_SHORT, \n\t\t(PyArray_VectorUnaryFunc*)@from@_to_USHORT, \n\t\t(PyArray_VectorUnaryFunc*)@from@_to_INT, \n\t\t(PyArray_VectorUnaryFunc*)@from@_to_UINT, \n\t\t(PyArray_VectorUnaryFunc*)@from@_to_LONG,\n\t\t(PyArray_VectorUnaryFunc*)@from@_to_ULONG, \n\t\t(PyArray_VectorUnaryFunc*)@from@_to_LONGLONG, \n\t\t(PyArray_VectorUnaryFunc*)@from@_to_ULONGLONG, \n\t\t(PyArray_VectorUnaryFunc*)@from@_to_FLOAT, \n\t\t(PyArray_VectorUnaryFunc*)@from@_to_DOUBLE, \n\t\t(PyArray_VectorUnaryFunc*)@from@_to_LONGDOUBLE, \n\t\t(PyArray_VectorUnaryFunc*)@from@_to_CFLOAT, \n\t\t(PyArray_VectorUnaryFunc*)@from@_to_CDOUBLE, \n\t\t(PyArray_VectorUnaryFunc*)@from@_to_CLONGDOUBLE, \n\t\t(PyArray_VectorUnaryFunc*)@from@_to_OBJECT, \n\t\t(PyArray_VectorUnaryFunc*)@from@_to_STRING, \n\t\t(PyArray_VectorUnaryFunc*)@from@_to_UNICODE, \n\t\t(PyArray_VectorUnaryFunc*)@from@_to_VOID\n\t},\n\t(PyArray_GetItemFunc*)@from@_getitem, \n\t(PyArray_SetItemFunc*)@from@_setitem,\n\t(PyArray_CopySwapNFunc*)@from@_copyswapn,\n\t(PyArray_CopySwapFunc*)@from@_copyswap,\n\t(PyArray_CompareFunc*)@from@_compare, \n\t(PyArray_ArgFunc*)@from@_argmax,\n\t(PyArray_DotFunc*)@from@_dot, \n\t(PyArray_ScanFunc*)@from@_scan,\n\t(PyArray_FromStrFunc*)@from@_fromstr,\n\t(PyArray_NonzeroFunc*)@from@_nonzero,\n\t(PyArray_FillFunc*)@from@_fill,\n\t{\n\t\tNULL, NULL, NULL, NULL\n\t},\n\t{\n\t\tNULL, NULL, NULL, NULL\n\t}\n};\n\nstatic PyArray_Descr @from@_Descr = { \n\tPyObject_HEAD_INIT(&PyArrayDescr_Type)\n\t&Py@NAME@ArrType_Type,\n\tPyArray_@kind@LTR,\n\tPyArray_@from@LTR,\n\t'@endian@', @isobject@,\n\tPyArray_@from@, \n\t@num@*sizeof(@fromtyp@), \n\t_ALIGN(@fromtyp@),\n\tNULL,\n\tNULL,\n\t&_Py@NAME@_ArrFuncs,\n};\n\n/**end repeat**/\n\n#define _MAX_LETTER 128\nstatic char _letter_to_num[_MAX_LETTER];\n\nstatic PyArray_Descr *_builtin_descrs[] = {\n\t&BOOL_Descr,\n\t&BYTE_Descr,\n\t&UBYTE_Descr,\n\t&SHORT_Descr, \n\t&USHORT_Descr, \n\t&INT_Descr, \n\t&UINT_Descr, \n\t&LONG_Descr, \n\t&ULONG_Descr,\n\t&LONGLONG_Descr,\n\t&ULONGLONG_Descr,\n\t&FLOAT_Descr, \n\t&DOUBLE_Descr,\n\t&LONGDOUBLE_Descr,\n\t&CFLOAT_Descr, \n\t&CDOUBLE_Descr, \n\t&CLONGDOUBLE_Descr,\n\t&OBJECT_Descr, \n\t&STRING_Descr, \n\t&UNICODE_Descr,\n\t&VOID_Descr,\n};\n\n/*OBJECT_API\n Get the PyArray_Descr structure for a type.\n*/\nstatic PyArray_Descr *\nPyArray_DescrFromType(int type)\n{\n\tPyArray_Descr *ret=NULL;\n\n\tif (type < PyArray_NTYPES) {\n\t\tret = _builtin_descrs[type];\n\t}\n\telse if (type == PyArray_NOTYPE) {\n\t\t/* This needs to not raise an error so\n\t\t that PyArray_DescrFromType(PyArray_NOTYPE)\n\t\t works for backwards-compatible C-API \n\t\t*/\t\t\n\t\treturn NULL;\n\t}\n\telse if PyTypeNum_ISUSERDEF(type) {\n\t\tret = userdescrs[type-PyArray_USERDEF];\n\t} \n\telse {\n\t\tint num=PyArray_NTYPES;\n\t\tif (type < _MAX_LETTER) \n\t\t\tnum = (int) _letter_to_num[type];\n\t\tif (num >= PyArray_NTYPES)\n\t\t\tret = NULL;\n\t\telse\n\t\t\tret = _builtin_descrs[num];\n\t}\n\tif (ret==NULL) {\n\t\tPyErr_SetString(PyExc_ValueError, \n\t\t\t\t\"Invalid data-type for array\"); \n\t}\n\telse Py_INCREF(ret);\n\treturn ret;\n}\n\n\nstatic int\nset_typeinfo(PyObject *dict)\n{\n\tPyObject *infodict, *s;\n\tint i;\n\n\tfor (i=0; i<_MAX_LETTER; i++) {\n\t\t_letter_to_num[i] = PyArray_NTYPES;\n\t}\n\n/**begin repeat\n#name=BOOL,BYTE,UBYTE,SHORT,USHORT,INT,UINT,INTP,UINTP,LONG,ULONG,LONGLONG,ULONGLONG,FLOAT,DOUBLE,LONGDOUBLE,CFLOAT,CDOUBLE,CLONGDOUBLE,OBJECT,STRING,UNICODE,VOID#\n*/\n\t_letter_to_num[PyArray_@name@LTR] = PyArray_@name@;\n/**end repeat**/\n\t_letter_to_num[PyArray_STRINGLTR2] = PyArray_STRING;\n\n/**begin repeat\n#name=BOOL,BYTE,UBYTE,SHORT,USHORT,INT,UINT,LONG,ULONG,LONGLONG,ULONGLONG,FLOAT,DOUBLE,LONGDOUBLE,CFLOAT,CDOUBLE,CLONGDOUBLE,OBJECT,STRING,UNICODE,VOID#\n*/\n\t@name@_Descr.fields = Py_None;\n/**end repeat**/\n\t\n\t/* Set a dictionary with type information */\n\tinfodict = PyDict_New();\n\tif (infodict == NULL) return -1;\n\n#define BITSOF_INTP CHAR_BIT*SIZEOF_PY_INTPTR_T\n#define BITSOF_BYTE CHAR_BIT\n\n/**begin repeat \n\n#name=BOOL,BYTE,UBYTE,SHORT,USHORT,INT,UINT,INTP,UINTP,LONG,ULONG,LONGLONG,ULONGLONG#\n#uname=BOOL,BYTE*2,SHORT*2,INT*2,INTP*2,LONG*2,LONGLONG*2#\n#Name=Bool,Byte,UByte,Short,UShort,Int,UInt,Intp,UIntp,Long,ULong,LongLong,ULongLong#\n#type=Bool,byte,ubyte,short,ushort,int,uint,intp,uintp,long,ulong,longlong,ulonglong#\n#max=1,MAX_BYTE,MAX_UBYTE,MAX_SHORT,MAX_USHORT,MAX_INT,PyLong_FromUnsignedLong(MAX_UINT),PyLong_FromLongLong((longlong) MAX_INTP),PyLong_FromUnsignedLongLong((ulonglong) MAX_UINTP),MAX_LONG,PyLong_FromUnsignedLong((unsigned long) MAX_ULONG),PyLong_FromLongLong((longlong) MAX_LONGLONG), PyLong_FromUnsignedLongLong((ulonglong) MAX_ULONGLONG)#\n#min=0,MIN_BYTE,0,MIN_SHORT,0,MIN_INT,0,PyLong_FromLongLong((longlong) MIN_INTP),0,MIN_LONG,0,PyLong_FromLongLong((longlong) MIN_LONGLONG),0#\n#cx=i*6,N,N,N,l,N,N,N#\n#cn=i*7,N,i,l,i,N,i#\n*/\n \tPyDict_SetItemString(infodict, \"@name@\", \n\t\t\t s=Py_BuildValue(\"ciii@cx@@cn@O\", \n\t\t\t\t\t PyArray_@name@LTR, \n\t\t\t\t\t PyArray_@name@,\n\t\t\t\t\t BITSOF_@uname@,\n\t\t\t\t\t _ALIGN(@type@),\n\t\t\t\t\t @max@, @min@,\n\t\t\t\t (PyObject *)&Py@Name@ArrType_Type));\n\tPy_DECREF(s); \n/**end repeat**/\n\n#define BITSOF_CFLOAT 2*BITSOF_FLOAT\n#define BITSOF_CDOUBLE 2*BITSOF_DOUBLE\n#define BITSOF_CLONGDOUBLE 2*BITSOF_LONGDOUBLE\n\n/**begin repeat\n\n#type=float,double,longdouble,cfloat,cdouble,clongdouble#\n#name=FLOAT, DOUBLE, LONGDOUBLE, CFLOAT, CDOUBLE, CLONGDOUBLE#\n#Name=Float,Double,LongDouble,CFloat,CDouble,CLongDouble#\n*/\n \tPyDict_SetItemString(infodict, \"@name@\", \n\t\t\t s=Py_BuildValue(\"ciiiO\", PyArray_@name@LTR, \n\t\t\t\t\t PyArray_@name@, BITSOF_@name@,\n\t\t\t\t\t _ALIGN(@type@),\n (PyObject *)\\\n &Py@Name@ArrType_Type));\n\tPy_DECREF(s);\n/**end repeat**/\n\t\n\tPyDict_SetItemString(infodict, \"OBJECT\", \n\t\t\t s=Py_BuildValue(\"ciiiO\", PyArray_OBJECTLTR, \n\t\t\t\t\t PyArray_OBJECT, \n\t\t\t\t\t sizeof(PyObject *)*CHAR_BIT,\n\t\t\t\t\t _ALIGN(PyObject *),\n (PyObject *)\\\n &PyObjectArrType_Type));\n\tPy_DECREF(s);\n\tPyDict_SetItemString(infodict, \"STRING\", \n\t\t\t s=Py_BuildValue(\"ciiiO\", PyArray_STRINGLTR, \n\t\t\t\t\t PyArray_STRING, 0,\n\t\t\t\t\t _ALIGN(char),\n (PyObject *)\\\n &PyStringArrType_Type));\n\tPy_DECREF(s);\n\tPyDict_SetItemString(infodict, \"UNICODE\", \n\t\t\t s=Py_BuildValue(\"ciiiO\", PyArray_UNICODELTR, \n\t\t\t\t\t PyArray_UNICODE, 0,\n\t\t\t\t\t _ALIGN(PyArray_UCS4),\n (PyObject *)\\\n &PyUnicodeArrType_Type));\t\n\tPy_DECREF(s);\n\tPyDict_SetItemString(infodict, \"VOID\", \n\t\t\t s=Py_BuildValue(\"ciiiO\", PyArray_VOIDLTR, \n\t\t\t\t\t PyArray_VOID, 0,\n\t\t\t\t\t _ALIGN(char),\n (PyObject *)\\\n &PyVoidArrType_Type));\t\n\tPy_DECREF(s);\n\n#define SETTYPE(name) \\\n Py_INCREF(&Py##name##ArrType_Type); \\\n PyDict_SetItemString(infodict, #name, \\\n (PyObject *)&Py##name##ArrType_Type);\n\n SETTYPE(Generic)\n SETTYPE(Number)\n SETTYPE(Integer)\n\tSETTYPE(Inexact)\n SETTYPE(SignedInteger)\n SETTYPE(UnsignedInteger)\n SETTYPE(Floating)\n SETTYPE(ComplexFloating)\n SETTYPE(Flexible)\n SETTYPE(Character)\n\n#undef SETTYPE \t\n\n\tPyDict_SetItemString(dict, \"typeinfo\", infodict);\n\tPy_DECREF(infodict);\n\treturn 0;\n}\n\n#undef _MAX_LETTER\n\n", + "methods": [], + "methods_before": [], + "changed_methods": [], + "nloc": null, + "complexity": null, + "token_count": null, + "diff_parsed": { + "added": [ + "\tfor (i=2; i 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 try:\n return a.shape\n except AttributeError:\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.type, _nx.inexact):\n return a\n if issubclass(a.dtype.type, _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', 'UnsignedInt32', 'UnsignedInteger',\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', 'Float16', 'Float8',\n 'Complex32', 'Complex64', 'Complex8', 'Complex16',\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.sctype2char\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\nFloat16='f'\nFloat8='f'\nUnsignedInteger='L'\nComplex8='F'\nComplex16='F'\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.dtype.char)\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 try:\n return a.shape\n except AttributeError:\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.type, _nx.inexact):\n return a\n if issubclass(a.dtype.type, _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": 147, + "end_line": 148, + "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": 163, + "end_line": 165, + "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": 167, + "end_line": 170, + "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": 172, + "end_line": 174, + "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": 176, + "end_line": 185, + "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": 187, + "end_line": 199, + "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": 201, + "end_line": 206, + "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": 208, + "end_line": 213, + "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": 215, + "end_line": 221, + "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": 223, + "end_line": 228, + "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": 230, + "end_line": 235, + "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": 237, + "end_line": 242, + "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": 244, + "end_line": 249, + "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": 251, + "end_line": 255, + "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": 137, + "parameters": [ + "a", + "new_shape" + ], + "start_line": 257, + "end_line": 286, + "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": 288, + "end_line": 290, + "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": 292, + "end_line": 296, + "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": 298, + "end_line": 302, + "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": 304, + "end_line": 308, + "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": 310, + "end_line": 314, + "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": 5, + "complexity": 2, + "token_count": 22, + "parameters": [ + "a" + ], + "start_line": 316, + "end_line": 323, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 8, + "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": 325, + "end_line": 329, + "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": 331, + "end_line": 336, + "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": 338, + "end_line": 361, + "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": 363, + "end_line": 365, + "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": 367, + "end_line": 369, + "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": 371, + "end_line": 373, + "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": 375, + "end_line": 378, + "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": 380, + "end_line": 383, + "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": 385, + "end_line": 387, + "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": 389, + "end_line": 391, + "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": 393, + "end_line": 396, + "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": 398, + "end_line": 401, + "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": 403, + "end_line": 406, + "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": 408, + "end_line": 411, + "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": 413, + "end_line": 416, + "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": 418, + "end_line": 421, + "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": 423, + "end_line": 427, + "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": 429, + "end_line": 436, + "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": 438, + "end_line": 449, + "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": 188, + "parameters": [ + "a", + "decimals" + ], + "start_line": 451, + "end_line": 476, + "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": 480, + "end_line": 481, + "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": 483, + "end_line": 484, + "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": 486, + "end_line": 487, + "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": 147, + "end_line": 148, + "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": 163, + "end_line": 165, + "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": 167, + "end_line": 170, + "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": 172, + "end_line": 174, + "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": 176, + "end_line": 185, + "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": 187, + "end_line": 199, + "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": 201, + "end_line": 206, + "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": 208, + "end_line": 213, + "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": 215, + "end_line": 221, + "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": 223, + "end_line": 228, + "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": 230, + "end_line": 235, + "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": 237, + "end_line": 242, + "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": 244, + "end_line": 249, + "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": 251, + "end_line": 255, + "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": 137, + "parameters": [ + "a", + "new_shape" + ], + "start_line": 257, + "end_line": 286, + "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": 288, + "end_line": 290, + "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": 292, + "end_line": 296, + "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": 298, + "end_line": 302, + "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": 304, + "end_line": 308, + "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": 310, + "end_line": 314, + "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": 5, + "complexity": 2, + "token_count": 22, + "parameters": [ + "a" + ], + "start_line": 316, + "end_line": 323, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 8, + "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": 325, + "end_line": 329, + "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": 331, + "end_line": 336, + "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": 338, + "end_line": 361, + "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": 363, + "end_line": 365, + "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": 367, + "end_line": 369, + "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": 371, + "end_line": 373, + "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": 375, + "end_line": 378, + "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": 380, + "end_line": 383, + "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": 385, + "end_line": 387, + "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": 389, + "end_line": 391, + "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": 393, + "end_line": 396, + "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": 398, + "end_line": 401, + "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": 403, + "end_line": 406, + "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": 408, + "end_line": 411, + "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": 413, + "end_line": 416, + "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": 418, + "end_line": 421, + "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": 423, + "end_line": 427, + "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": 429, + "end_line": 436, + "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": 438, + "end_line": 449, + "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": 188, + "parameters": [ + "a", + "decimals" + ], + "start_line": 451, + "end_line": 476, + "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": 480, + "end_line": 481, + "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": 483, + "end_line": 484, + "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": 486, + "end_line": 487, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 0 + } + ], + "changed_methods": [ + { + "name": "put", + "long_name": "put( a , ind , v )", + "filename": "oldnumeric.py", + "nloc": 2, + "complexity": 1, + "token_count": 19, + "parameters": [ + "a", + "ind", + "v" + ], + "start_line": 187, + "end_line": 199, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 13, + "top_nesting_level": 0 + } + ], + "nloc": 277, + "complexity": 61, + "token_count": 2037, + "diff_parsed": { + "added": [ + " v = array(values, copy=False).astype(a.dtype)", + " a must be a contiguous numpy array." + ], + "deleted": [ + " v = array(values, copy=False).astype(a, a.dtype)", + " a must be a contiguous Numeric array." + ] + } + }, + { + "old_path": null, + "new_path": "numpy/core/tests/test_oldnumeric.py", + "filename": "test_oldnumeric.py", + "extension": "py", + "change_type": "ADD", + "diff": "@@ -0,0 +1,15 @@\n+from numpy.testing import *\n+\n+from numpy import array\n+from numpy.core.oldnumeric import put\n+\n+class test_put(ScipyTestCase):\n+ def check_bug_r2089(self, level=1):\n+ a = array([0,0,0])\n+ put(a,[1],[1.2])\n+ assert_array_equal(a,[0,1,0])\n+ put(a,[1],array([2.2]))\n+ assert_array_equal(a,[0,2,0])\n+\n+if __name__ == \"__main__\":\n+ ScipyTest().run()\n", + "added_lines": 15, + "deleted_lines": 0, + "source_code": "from numpy.testing import *\n\nfrom numpy import array\nfrom numpy.core.oldnumeric import put\n\nclass test_put(ScipyTestCase):\n def check_bug_r2089(self, level=1):\n a = array([0,0,0])\n put(a,[1],[1.2])\n assert_array_equal(a,[0,1,0])\n put(a,[1],array([2.2]))\n assert_array_equal(a,[0,2,0])\n\nif __name__ == \"__main__\":\n ScipyTest().run()\n", + "source_code_before": null, + "methods": [ + { + "name": "check_bug_r2089", + "long_name": "check_bug_r2089( self , level = 1 )", + "filename": "test_oldnumeric.py", + "nloc": 6, + "complexity": 1, + "token_count": 76, + "parameters": [ + "self", + "level" + ], + "start_line": 7, + "end_line": 12, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 6, + "top_nesting_level": 1 + } + ], + "methods_before": [], + "changed_methods": [ + { + "name": "check_bug_r2089", + "long_name": "check_bug_r2089( self , level = 1 )", + "filename": "test_oldnumeric.py", + "nloc": 6, + "complexity": 1, + "token_count": 76, + "parameters": [ + "self", + "level" + ], + "start_line": 7, + "end_line": 12, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 6, + "top_nesting_level": 1 + } + ], + "nloc": 12, + "complexity": 1, + "token_count": 113, + "diff_parsed": { + "added": [ + "from numpy.testing import *", + "", + "from numpy import array", + "from numpy.core.oldnumeric import put", + "", + "class test_put(ScipyTestCase):", + " def check_bug_r2089(self, level=1):", + " a = array([0,0,0])", + " put(a,[1],[1.2])", + " assert_array_equal(a,[0,1,0])", + " put(a,[1],array([2.2]))", + " assert_array_equal(a,[0,2,0])", + "", + "if __name__ == \"__main__\":", + " ScipyTest().run()" + ], + "deleted": [] + } + } + ] + }, + { + "hash": "7e34c2e10baa325f2ca22a12e655b1729ae59785", + "msg": "Change PyArray_Put so that values0 is forcecast to the right type.", + "author": { + "name": "Travis Oliphant", + "email": "oliphant@enthought.com" + }, + "committer": { + "name": "Travis Oliphant", + "email": "oliphant@enthought.com" + }, + "author_date": "2006-02-11T01:33:27+00:00", + "author_timezone": 0, + "committer_date": "2006-02-11T01:33:27+00:00", + "committer_timezone": 0, + "branches": [ + "main" + ], + "in_main_branch": true, + "merge": false, + "parents": [ + "fc7ac38dec262117bbc30698e0696e9911369207" + ], + "project_name": "repo_copy", + "project_path": "/tmp/tmpdjwupkfu/repo_copy", + "deletions": 3, + "insertions": 4, + "lines": 7, + "files": 2, + "dmm_unit_size": 0.0, + "dmm_unit_complexity": 0.0, + "dmm_unit_interfacing": 0.0, + "modified_files": [ + { + "old_path": "numpy/core/src/arrayobject.c", + "new_path": "numpy/core/src/arrayobject.c", + "filename": "arrayobject.c", + "extension": "c", + "change_type": "MODIFY", + "diff": "@@ -5739,7 +5739,7 @@ PyArray_FromArray(PyArrayObject *arr, PyArray_Descr *newtype, int flags)\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\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", + "added_lines": 1, + "deleted_lines": 1, + "source_code": "/*\n Provide multidimensional arrays as a basic object type in python. \n\nBased on Original Numeric implementation\nCopyright (c) 1995, 1996, 1997 Jim Hugunin, hugunin@mit.edu\n\nwith contributions from many Numeric Python developers 1995-2004 \n\nHeavily modified in 2005 with inspiration from Numarray \n\nby\n\nTravis Oliphant\nAssistant Professor at\nBrigham Young University \n\nmaintainer email: oliphant.travis@ieee.org\n\nNumarray design (which provided guidance) by \nSpace Science Telescope Institute \n (J. Todd Miller, Perry Greenfield, Rick White)\n*/\n\n/*OBJECT_API\n Get Priority from object\n*/\nstatic double\nPyArray_GetPriority(PyObject *obj, double default_) \n{\n PyObject *ret;\n double priority=PyArray_PRIORITY;\n\n\tif (PyArray_CheckExact(obj))\n\t\treturn priority;\n 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\n\n#ifndef Py_UNICODE_WIDE\n#include \"ucsnarrow.c\"\n#endif\n\n\nstatic PyArray_Descr **userdescrs=NULL;\n#define error_converting(x) (((x) == -1) && PyErr_Occurred())\n\n/* Computer-generated arraytype and scalartype code */\n#include \"scalartypes.inc\"\n#include \"arraytypes.inc\"\n\n\n/* Helper functions */\n\n/*OBJECT_API*/\nstatic intp\nPyArray_PyIntAsIntp(PyObject *o)\n{\n\tlonglong long_value = -1;\n\tPyObject *obj;\n\tstatic char *msg = \"an integer is required\";\n\tPyObject *arr;\n\tPyArray_Descr *descr;\n\tintp ret;\n\n\tif (!o) {\n\t\tPyErr_SetString(PyExc_TypeError, msg);\n\t\treturn -1;\n\t}\n\n\tif (PyInt_Check(o)) {\n\t\tlong_value = (longlong) PyInt_AS_LONG(o);\n\t\tgoto finish;\n\t} else if (PyLong_Check(o)) {\n\t\tlong_value = (longlong) PyLong_AsLongLong(o);\n\t\tgoto finish;\n\t}\n\n#if SIZEOF_INTP == SIZEOF_LONG \n\tdescr = &LONG_Descr;\n#elif SIZEOF_INTP == SIZEOF_INT\n\tdescr = &INT_Descr;\n#else\n\tdescr = &LONGLONG_DESCR;\n#endif\n\tarr = NULL;\n\n\tif (PyArray_Check(o)) {\n\t\tif (PyArray_SIZE(o)!=1 || !PyArray_ISINTEGER(o)) {\n\t\t\tPyErr_SetString(PyExc_TypeError, msg);\n\t\t\treturn -1;\n\t\t}\n\t\tPy_INCREF(descr);\n\t\tarr = PyArray_CastToType((PyArrayObject *)o, descr, 0);\n\t}\n\telse if (PyArray_IsScalar(o, Integer)) {\n\t\tPy_INCREF(descr);\n\t\tarr = PyArray_FromScalar(o, descr);\n\t}\n\tif (arr != NULL) {\n\t\tret = *((intp *)PyArray_DATA(arr));\n\t\tPy_DECREF(arr);\n\t\treturn ret;\n\t}\t\t\n\tif (o->ob_type->tp_as_number != NULL &&\t\t\t\\\n\t o->ob_type->tp_as_number->nb_long != NULL) {\n\t\tobj = o->ob_type->tp_as_number->nb_long(o);\n\t\tif (obj != NULL) {\n\t\t\tlong_value = (longlong) PyLong_AsLongLong(obj);\n\t\t\tPy_DECREF(obj);\n\t\t}\n\t}\n\telse if (o->ob_type->tp_as_number != NULL &&\t\t\\\n\t\t o->ob_type->tp_as_number->nb_int != NULL) {\n\t\tobj = o->ob_type->tp_as_number->nb_int(o);\n\t\tif (obj != NULL) {\n\t\t\tlong_value = (longlong) PyLong_AsLongLong(obj);\n\t\t\tPy_DECREF(obj);\n\t\t}\n\t}\n\telse {\n\t\tPyErr_SetString(PyExc_NotImplementedError,\"\");\n\t}\n\t\n finish:\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_INTP)\n\tif ((long_value < MIN_INTP) || (long_value > MAX_INTP)) {\n\t\tPyErr_SetString(PyExc_ValueError,\n\t\t\t\t\"integer won't fit into a C intp\");\n\t\treturn -1;\n\t}\n#endif\n\treturn (intp) long_value;\n}\n\n\nstatic PyObject *array_int(PyArrayObject *v);\n\n/*OBJECT_API*/\nstatic int\nPyArray_PyIntAsInt(PyObject *o)\n{\n\tlong long_value = -1;\n\tPyObject *obj;\n\tstatic char *msg = \"an integer is required\";\n\tPyObject *arr;\n\tPyArray_Descr *descr;\n\tint ret;\n\n\t\n\tif (!o) {\n\t\tPyErr_SetString(PyExc_TypeError, msg);\n\t\treturn -1;\n\t}\n\n\tif (PyInt_Check(o)) {\n\t\tlong_value = (long) PyInt_AS_LONG(o);\n\t\tgoto finish;\n\t} else if (PyLong_Check(o)) {\n\t\tlong_value = (long) PyLong_AsLong(o);\n\t\tgoto finish;\n\t}\n\n\tdescr = &INT_Descr;\n\tarr=NULL;\n\tif (PyArray_Check(o)) {\n\t\tif (PyArray_SIZE(o)!=1 || !PyArray_ISINTEGER(o)) {\n\t\t\tPyErr_SetString(PyExc_TypeError, msg);\n\t\t\treturn -1;\n\t\t}\n\t\tPy_INCREF(descr);\n\t\tarr = PyArray_CastToType((PyArrayObject *)o, descr, 0);\n\t}\n\tif (PyArray_IsScalar(o, Integer)) {\n\t\tPy_INCREF(descr);\n\t\tarr = PyArray_FromScalar(o, descr);\n\t}\n\tif (arr != NULL) {\n\t\tret = *((int *)PyArray_DATA(arr));\n\t\tPy_DECREF(arr);\n\t\treturn ret;\n\t}\t\t\n\tif (o->ob_type->tp_as_number != NULL &&\t\t\\\n\t o->ob_type->tp_as_number->nb_int != NULL) {\n\t\tobj = o->ob_type->tp_as_number->nb_int(o);\n\t\tif (obj == NULL) return -1;\n\t\tlong_value = (long) PyLong_AsLong(obj);\n\t\tPy_DECREF(obj);\n\t}\n\telse if (o->ob_type->tp_as_number != NULL &&\t\t\t\\\n\t\t o->ob_type->tp_as_number->nb_long != NULL) {\n\t\tobj = o->ob_type->tp_as_number->nb_long(o);\n\t\tif (obj == NULL) return -1;\n\t\tlong_value = (long) PyLong_AsLong(obj);\n\t\tPy_DECREF(obj);\n\t}\t\t\n\telse {\n\t\tPyErr_SetString(PyExc_NotImplementedError,\"\");\n\t}\n\n finish:\n\tif error_converting(long_value) {\n\t\tPyErr_SetString(PyExc_TypeError, msg);\n\t\treturn -1;\n\t}\n\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\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 dest->descr, 0,\n dest->nd, FORTRAN_IF(dest), NULL);\n if (src == NULL) return -1;\n\n ret = PyArray_CopyInto(dest, src);\n Py_DECREF(src);\n return ret;\n}\n\n\n/* These are also old calls (should use PyArray_New) */\n\n/* They all zero-out the memory as previously done */\n\n/* steals reference to descr -- and enforces native byteorder on it.*/\n/*OBJECT_API\n Like FromDimsAndData but uses the Descr structure instead of typecode\n as input.\n*/\nstatic PyObject *\nPyArray_FromDimsAndDataAndDescr(int nd, int *d, \n PyArray_Descr *descr,\n char *data)\n{\n\tPyObject *ret;\n#if SIZEOF_INTP != SIZEOF_INT\n\tint i;\n\tintp newd[MAX_DIMS];\n#endif\n\n\tif (!PyArray_ISNBO(descr->byteorder))\n\t\tdescr->byteorder = '=';\n\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\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_BOOL)\n\t\tPyArrayScalar_RETURN_BOOL_FROM_LONG(*(Bool*)data);\n\telse if (type_num == PyArray_OBJECT) {\n\t\tPy_INCREF(*((PyObject **)data));\n\t\treturn *((PyObject **)data);\n\t}\n\titemsize = descr->elsize;\n type = descr->typeobj;\n copyswap = descr->f->copyswap;\n\tswap = !PyArray_ISNBO(descr->byteorder);\n\tif (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 >> 2;\n\n#ifndef Py_UNICODE_WIDE\n\t\t\tlength *= 2;\n#endif\n\t\t\t/* Need an extra slot and need to use \n\t\t\t Python memory manager */\n\t\t\tuni->str = NULL;\n\t\t\tdestptr = PyMem_NEW(Py_UNICODE, length+1);\n\t\t\tif (destptr == NULL) {\n Py_DECREF(obj);\n\t\t\t\treturn PyErr_NoMemory();\n\t\t\t}\n\t\t\tuni->str = (Py_UNICODE *)destptr;\n\t\t\tuni->str[0] = 0;\n\t\t\tuni->str[length] = 0;\n\t\t\tuni->length = length;\n\t\t\tuni->hash = -1;\n\t\t\tuni->defenc = NULL;\n#ifndef Py_UNICODE_WIDE\n /* Allocated enough for 2-characters per itemsize.\n\t\t\t Now convert from the data-buffer\n */\n\t\t\tif (!PyArray_ISNBO(descr->byteorder)) {\n\t\t\t\t/* byteswap the data */\n\t\t\t\tbyte_swap_vector(data, itemsize >> 2, 4);\n\t\t\t}\n\t\t\tlength = PyUCS2Buffer_FromUCS4(uni->str, (PyArray_UCS4 *)data,\n\t\t\t\t\t\t itemsize >> 2);\n\t\t\t/* Resize the unicode result */\n\t\t\tif (MyPyUnicode_Resize(uni, length) < 0) {\n\t\t\t\tPy_DECREF(obj);\n\t\t\t\treturn NULL;\n\t\t\t}\n\t\t\treturn obj;\n#endif\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_XDECREF(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, 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, NULL);\n\tif (arr == NULL) return -1;\n\n\tif ((mit->subspace != NULL) && (mit->consec)) {\n\t\tif (mit->iteraxes[0] > 0) { /* then we need to swap */\n\t\t\t_swap_axes(mit, (PyArrayObject **)&arr);\n\t\t}\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\n/* This checks the args for any fancy indexing objects */\n\n#define SOBJ_NOTFANCY 0 \n#define SOBJ_ISFANCY 1\n#define SOBJ_BADARRAY 2\n#define SOBJ_TOOMANY 3\n#define SOBJ_LISTTUP 4\n\nstatic int\nfancy_indexing_check(PyObject *args)\n{\n\tint i, n;\n\tPyObject *obj;\n\tint retval = SOBJ_NOTFANCY;\n\n\tif (PyTuple_Check(args)) {\n\t\tn = PyTuple_GET_SIZE(args);\n\t\tif (n >= MAX_DIMS) return SOBJ_TOOMANY;\n\t\tfor (i=0; i=MAX_DIMS) return SOBJ_ISFANCY;\n\t\tfor (i=0; i SOBJ_ISFANCY) return retval;\n\t\t}\n\t}\n\n\treturn retval;\n}\n\n/* Called when treating array object like a mapping -- called first from \n Python when using a[object] unless object is a standard slice object\n (not an extended one). \n\n*/\n\n/* There are two situations: \n\n 1 - the subscript is a standard view and a reference to the \n array can be returned\n\n 2 - the subscript uses Boolean masks or integer indexing and\n therefore a new array is created and returned. \n\n*/\n\n/* Always returns arrays */\n\nstatic PyObject *iter_subscript(PyArrayIterObject *, PyObject *); \n\n\nstatic PyObject *\narray_subscript(PyArrayObject *self, PyObject *op) \n{\n intp dimensions[MAX_DIMS], strides[MAX_DIMS];\n\tintp offset;\n int nd, oned, fancy;\n\tintp i;\n PyArrayObject *other;\n\tPyArrayMapIterObject *mit;\n\n\tif (PyString_Check(op) || PyUnicode_Check(op)) {\n\t\tif (self->descr->fields) {\n\t\t\tPyObject *obj;\n\t\t\tobj = PyDict_GetItem(self->descr->fields, op);\n\t\t\tif (obj != NULL) {\n\t\t\t\tPyArray_Descr *descr;\n\t\t\t\tint offset;\n\t\t\t\tPyObject *title;\n\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\tfancy = fancy_indexing_check(op);\n\n\tif (fancy != SOBJ_NOTFANCY) { \n\t\toned = ((self->nd == 1) && !(PyTuple_Check(op) &&\t\\\n\t\t\t\t\t PyTuple_GET_SIZE(op) > 1));\n\n\t\t/* wrap arguments into a mapiter object */\n\t\tmit = (PyArrayMapIterObject *)\\\n\t\t\tPyArray_MapIterNew(op, oned, fancy);\n\t\tif (mit == NULL) return NULL;\n\t\tif (oned) {\n\t\t\tPyArrayIterObject *it;\n\t\t\tPyObject *rval;\n\t\t\tit = (PyArrayIterObject *)PyArray_IterNew((PyObject *)self);\n\t\t\tif (it == NULL) {Py_DECREF(mit); return NULL;}\n\t\t\trval = iter_subscript(it, mit->indexobj);\n\t\t\tPy_DECREF(it);\n\t\t\tPy_DECREF(mit);\n\t\t\treturn rval;\n\t\t}\n PyArray_MapIterBind(mit, self);\n other = (PyArrayObject *)PyArray_GetMap(mit);\n Py_DECREF(mit);\n return (PyObject *)other;\n }\n\n\ti = PyArray_PyIntAsIntp(op);\n\tif (!error_converting(i)) {\n\t\tif (i < 0 && self->nd > 0) i = i+self->dimensions[0];\n\t\treturn array_big_item(self, i);\n\t}\n\tPyErr_Clear();\n\n\t/* Standard (view-based) Indexing */\n if ((nd = parse_index(self, op, dimensions, strides, &offset)) \n == -1) \n return NULL;\n\n\t/* This will only work if new array will be a view */\n\tPy_INCREF(self->descr);\n\tif ((other = (PyArrayObject *)\t\t\t\t\t\\\n\t PyArray_NewFromDescr(self->ob_type, self->descr,\n\t\t\t\t nd, dimensions,\n\t\t\t\t strides, self->data+offset, \n\t\t\t\t self->flags,\n\t\t\t\t (PyObject *)self)) == NULL) \n\t\treturn NULL;\n\n\n\tother->base = (PyObject *)self;\n\tPy_INCREF(self);\n\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, fancy;\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\tfancy = fancy_indexing_check(index);\n\n\tif (fancy != SOBJ_NOTFANCY) { \n\t\toned = ((self->nd == 1) && !(PyTuple_Check(index) && \\\n\t\t\t\t\t PyTuple_GET_SIZE(index) > 1));\n\n\t\tmit = (PyArrayMapIterObject *)\t\t\t\\\n\t\t\tPyArray_MapIterNew(index, oned, fancy);\n\t\tif (mit == NULL) return -1;\n\t\tif (oned) {\n\t\t\tPyArrayIterObject *it;\n\t\t\tint rval;\n\t\t\tit = (PyArrayIterObject *)PyArray_IterNew((PyObject *)self);\n\t\t\tif (it == NULL) {Py_DECREF(mit); return -1;}\n\t\t\trval = iter_ass_subscript(it, mit->indexobj, op);\n\t\t\tPy_DECREF(it);\n\t\t\tPy_DECREF(mit);\n\t\t\treturn rval;\n\t\t}\n PyArray_MapIterBind(mit, self);\n ret = PyArray_SetMap(mit, op);\n Py_DECREF(mit);\n return ret;\n }\n\t\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\t\t\tif (other == Py_None) {\n\t\t\t\tPy_INCREF(Py_False);\n\t\t\t\treturn Py_False;\n\t\t\t}\n /* Try to convert other to an array */\n\t\t\tif (!PyArray_Check(other)) {\n\t\t\t\tarray_other = PyArray_FromObject(other, \n\t\t\t\t\t\t\t\t self->descr->type_num, 0, 0);\n\t\t\t\t/* If not successful, then return the integer\n\t\t\t\t object 0. This fixes code that used to\n\t\t\t\t allow equality comparisons between arrays\n\t\t\t\t and other objects which would give a result\n\t\t\t\t of 0\n\t\t\t\t*/\n\t\t\t\tif ((array_other == NULL) ||\t\\\n\t\t\t\t (array_other == Py_None)) {\n\t\t\t\t\tPy_XDECREF(array_other);\n\t\t\t\t\tPyErr_Clear();\n\t\t\t\t\tPy_INCREF(Py_False);\n\t\t\t\t\treturn Py_False;\n\t\t\t\t}\n\t\t\t}\n\t\t\telse {\n\t\t\t\tPy_INCREF(other);\n\t\t\t\tarray_other = other;\n\t\t\t}\n result = PyArray_GenericBinaryFunction(self, \n\t\t\t\t\t\t\t array_other, \n\t\t\t\t\t\t\t n_ops.equal);\n /* If the comparison results in NULL, then the \n\t\t\t two array objects can not be compared together so \n\t\t\t return zero \n */\n Py_DECREF(array_other);\n if (result == NULL) {\n PyErr_Clear();\n Py_INCREF(Py_False);\n return Py_False;\n }\n return result;\n case Py_NE:\n\t\t\tif (other == Py_None) {\n\t\t\t\tPy_INCREF(Py_True);\n\t\t\t\treturn Py_True;\n\t\t\t}\n /* Try to convert other to an array */\n\t\t\tif (!PyArray_Check(other)) {\n\t\t\t\tarray_other = PyArray_FromObject(other, \n\t\t\t\t\t\t\t\t self->descr->type_num, 0, 0);\n\t\t\t\t/* If not successful, then objects cannot be \n\t\t\t\t compared and cannot be equal, therefore, \n\t\t\t\t return True;\n\t\t\t\t*/\n\t\t\t\tif ((array_other == NULL) ||\t\\\n\t\t\t\t (array_other == Py_None)) {\n\t\t\t\t\tPy_XDECREF(array_other);\n\t\t\t\t\tPyErr_Clear();\n\t\t\t\t\tPy_INCREF(Py_True);\n\t\t\t\t\treturn Py_True;\n\t\t\t\t}\n\t\t\t}\n\t\t\telse {\n\t\t\t\tPy_INCREF(other);\n\t\t\t\tarray_other = other;\n\t\t\t}\n\t\t\tresult = PyArray_GenericBinaryFunction(self, \n\t\t\t\t\t\t\t array_other, \n\t\t\t\t\t\t\t n_ops.not_equal);\n\t\t\tPy_DECREF(array_other);\n if (result == NULL) {\n PyErr_Clear();\n Py_INCREF(Py_True);\n return Py_True;\n }\n 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 = PyArray_NDIM(temp)-1;\n\t\treturn temp;\n\t}\n\telse {\n\t\tif (flags) {\n\t\t\ttemp = PyArray_CheckFromAny((PyObject *)arr, NULL, \n 0, 0, flags, NULL);\n\t\t\tif (temp == NULL) return NULL;\n\t\t}\n\t\telse {\n\t\t\tPy_INCREF(arr);\n\t\t\ttemp = (PyObject *)arr;\n\t\t}\n\t}\n\tif (*axis < 0) *axis += n;\n\tif ((*axis < 0) || (*axis >= n)) {\n\t\tPyErr_Format(PyExc_ValueError, \n\t\t\t \"axis(=%d) out of bounds\", *axis);\n\t\tPy_DECREF(temp);\n\t\treturn NULL;\n\t}\n\treturn temp;\n}\n\n#include \"arraymethods.c\"\n\n/* Lifted from numarray */\nstatic PyObject *\nPyArray_IntTupleFromIntp(int len, intp *vals)\n{\n\tint i;\n PyObject *intTuple = PyTuple_New(len);\n if (!intTuple) goto fail;\n for(i=0; i= SIZEOF_INTP\n\t\tif (!(op = PyNumber_Int(seq))) return -1;\n#else\n\t\tif (!(op = PyNumber_Long(seq))) return -1;\n#endif\n\t\tnd = 1;\n#if SIZEOF_LONG >= SIZEOF_INTP\n\t\tvals[0] = (intp ) PyInt_AsLong(op);\n#else\n\t\tvals[0] = (intp ) PyLong_AsLongLong(op);\n#endif\n\t\tPy_DECREF(op);\n\t} else {\n\t\tfor(i=0; i < MIN(nd,maxvals); i++) {\n\t\t\top = PySequence_GetItem(seq, i);\n\t\t\tif (op == NULL) return -1;\n#if SIZEOF_LONG >= SIZEOF_INTP\n\t\t\tvals[i]=(intp )PyInt_AsLong(op);\n#else\n\t\t\tvals[i]=(intp )PyLong_AsLongLong(op);\n#endif\n\t\t\tPy_DECREF(op);\n\t\t\tif(PyErr_Occurred()) return -1;\n\t\t}\n\t}\n\treturn nd;\n}\n\n\n/* Check whether the given array is stored contiguously (row-wise) in\n memory. */\nstatic int\n_IsContiguous(PyArrayObject *ap) \n{\n\tregister intp sd;\n\tregister intp dim;\n\tregister int i;\n \n\n\tif (ap->nd == 0) return 1;\n\tsd = ap->descr->elsize;\n\tif (ap->nd == 1) return (ap->dimensions[0] == 1 || \\\n\t\t\t\t sd == ap->strides[0]);\n\tfor (i = ap->nd-1; i >= 0; --i) {\n\t\tdim = ap->dimensions[i];\n\t\t/* contiguous by definition */\n\t\tif (dim == 0) return 1;\n\t\tif (ap->strides[i] != sd) return 0;\n\t\tsd *= dim;\n\t}\n\treturn 1;\n}\n\n\nstatic int \n_IsFortranContiguous(PyArrayObject *ap) \n{\n\tregister intp sd;\n\tregister intp dim;\n\tregister int i;\n\t\n\tif (ap->nd == 0) return 1;\n\tsd = ap->descr->elsize;\n\tif (ap->nd == 1) return (ap->dimensions[0] == 1 || \\\n\t\t\t\t sd == ap->strides[0]);\n\tfor (i=0; i< ap->nd; ++i) {\n\t\tdim = ap->dimensions[i];\n\t\t/* contiguous by definition */\n\t\tif (dim == 0) return 1; \n\t\tif (ap->strides[i] != sd) return 0;\n\t\tsd *= dim;\n\t}\n\treturn 1;\n}\n\nstatic int\n_IsAligned(PyArrayObject *ap) \n{\n\tint i, alignment, aligned=1;\n\tintp ptr;\n\tint type = ap->descr->type_num;\n\n\tif ((type == PyArray_STRING) || (type == PyArray_VOID))\n\t\treturn 1;\n\n\talignment = ap->descr->alignment;\n\tif (alignment == 1) return 1;\n\n\tptr = (intp) ap->data;\n aligned = (ptr % alignment) == 0;\n for (i=0; i nd; i++)\n aligned &= ((ap->strides[i] % alignment) == 0);\n return aligned != 0;\n}\n\nstatic Bool\n_IsWriteable(PyArrayObject *ap)\n{\n\tPyObject *base=ap->base;\n\tvoid *dummy;\n\tint n;\n\n\t/* If we own our own data, then no-problem */\n\tif ((base == NULL) || (ap->flags & OWN_DATA)) return TRUE;\n\n\t/* Get to the final base object \n\t If it is a writeable array, then return TRUE\n\t If we can find an array object \n\t or a writeable buffer object as the final base object\n\t or a string object (for pickling support memory savings).\n\t - this last could be removed if a proper pickleable \n\t buffer was added to Python.\n\t*/\n\n\twhile(PyArray_Check(base)) {\n\t\tif (PyArray_CHKFLAGS(base, OWN_DATA)) \n\t\t\treturn (Bool) (PyArray_ISWRITEABLE(base));\n\t\tbase = PyArray_BASE(base);\n\t}\n\n\t/* here so pickle support works seamlessly \n\t and unpickled array can be set and reset writeable \n\t -- could be abused -- */\n\tif PyString_Check(base) return TRUE;\n\n\tif (PyObject_AsWriteBuffer(base, &dummy, &n) < 0)\n\t\treturn FALSE;\n\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 For axes with a positive stride this function checks for a walk\n beyond the right end of the buffer, for axes with a negative stride,\n it checks for a walk beyond the left end of the buffer. Zero strides\n are disallowed.\n*/\n/*OBJECT_API*/\nstatic Bool\nPyArray_CheckStrides(int elsize, int nd, intp numbytes, intp offset,\n\t\t intp *dims, intp *newstrides)\n{\n\tint i;\n\t\n\tif (numbytes == 0) \n\t\tnumbytes = PyArray_MultiplyList(dims, nd) * elsize;\n\t\n\tfor (i=0; i 0) {\n\t\t\t/* The last stride does not need to be fully inside\n\t\t\t the buffer, only its first elsize bytes */\n\t\t\tif (offset + stride*(dims[i]-1)+elsize > numbytes) {\n\t\t\t\treturn FALSE;\n\t\t\t}\n\t\t}\n\t\telse if (stride < 0) {\n\t\t\tif (offset + stride*dims[i] < 0) {\n\t\t\t\treturn FALSE;\n\t\t\t}\n\t\t} else {\n\t\t\t/* XXX: Zero strides may be useful, but currently \n\t\t\t XXX: allowing them would lead to strange results,\n\t\t\t XXX: for example :\n\t\t\t XXX: >>> x = arange(5)\n\t\t\t XXX: >>> x.strides = 0\n\t\t\t XXX: >>> x += 1\n\t\t\t XXX: >>> x\n\t\t\t XXX: array([5, 5, 5, 5, 5]) */\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 /* which could also be sub-fields of a VOID array */\n\t\tif (descr->hasobject) {\n if (descr != &OBJECT_Descr) {\n PyErr_SetString(PyExc_TypeError,\n \"fields with object members \" \\\n \"not yet supported.\");\n goto fail;\n }\n\t\t\tmemset(data, 0, sd);\n\t\t}\n\t}\n\telse {\n self->flags &= ~OWN_DATA; /* If data is passed in, \n\t\t\t\t\t this object won't own it \n\t\t\t\t\t by default.\n\t\t\t\t\t Caller must arrange for \n\t\t\t\t\t this to be reset if truly\n\t\t\t\t\t desired */\n }\n self->data = data;\n\n /* call the __array_finalize__\n\t method if a subtype 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, NULL);\n\tif (newarr == NULL) return -1;\n\tfromptr = PyArray_DATA(newarr);\n\tsize=PyArray_SIZE(arr);\n\tswap=!PyArray_ISNOTSWAPPED(arr);\n\tcopyswap = arr->descr->f->copyswap;\n\tif (PyArray_ISONESEGMENT(arr)) {\n\t\tchar *toptr=PyArray_DATA(arr);\n\t\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\", /* XXX ? */\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 strides.ptr, NULL, fortran, NULL);\n if (ret == NULL) {descr=NULL;goto fail;}\n if (type_num == PyArray_OBJECT) { /* place Py_None */\n PyArray_FillObjectArray(ret, Py_None);\n }\n }\n else { /* buffer given -- use it */\n if (dims.len == 1 && dims.ptr[0] == -1) {\n dims.ptr[offset] = 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, offset,\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 offset + (char *)buffer.ptr, \n\t\t\t\t\t buffer.flags, NULL); \n if (ret == NULL) {descr=NULL; goto fail;}\n PyArray_UpdateFlags(ret, UPDATE_ALL_FLAGS);\n ret->base = buffer.base;\n Py_INCREF(buffer.base); \n }\n\n PyDimMem_FREE(dims.ptr);\n if (strides.ptr) PyDimMem_FREE(strides.ptr);\n return (PyObject *)ret;\n \n fail:\n\tPy_XDECREF(descr);\n if (dims.ptr) PyDimMem_FREE(dims.ptr);\n if (strides.ptr) PyDimMem_FREE(strides.ptr);\n return NULL;\n}\n\n\nstatic PyObject *\narray_iter(PyArrayObject *arr)\n{\n\tif (arr->nd == 0) {\n\t\tPyErr_SetString(PyExc_TypeError,\n\t\t\t\t\"iteration over a scalar (0-dim array)\");\n\t\treturn NULL;\n\t}\n\treturn PySeqIter_New((PyObject *)arr);\n}\n\n\n/******************* array attribute get and set routines ******************/\n\nstatic PyObject *\narray_ndim_get(PyArrayObject *self)\n{\n\treturn PyInt_FromLong(self->nd);\n}\n\nstatic PyObject *\narray_flags_get(PyArrayObject *self)\n{\n return 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->data - new->data,\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 *arraydescr_protocol_typestr_get(PyArray_Descr *);\n\nstatic PyObject *\narray_typestr_get(PyArrayObject *self)\n{\n\treturn arraydescr_protocol_typestr_get(self->descr);\n}\n\nstatic PyObject *\narray_descr_get(PyArrayObject *self) \n{\n\tPy_INCREF(self->descr);\n\treturn (PyObject *)self->descr;\n}\n\n\n/* If the type is changed. \n Also needing change: strides, itemsize\n\n Either itemsize is exactly the same\n or the array is single-segment (contiguous or fortran) with\n compatibile dimensions\n\n The shape and strides will be adjusted in that case as well.\n*/\n\nstatic int\narray_descr_set(PyArrayObject *self, PyObject *arg)\n{\n PyArray_Descr *newtype=NULL;\n intp newdim;\n int index;\n char *msg = \"new type not compatible with array.\";\n\n if (!(PyArray_DescrConverter(arg, &newtype)) ||\n newtype == NULL) {\n PyErr_SetString(PyExc_TypeError, \"invalid data-type for array\");\n\t\treturn -1;\n }\n\tif (newtype->type_num == PyArray_OBJECT || \\\n\t self->descr->type_num == PyArray_OBJECT) {\n\t\tPyErr_SetString(PyExc_TypeError, \\\n\t\t\t\t\"Cannot change descriptor for object\"\\\n\t\t\t\t\"array.\");\n\t\tPy_DECREF(newtype);\n\t\treturn -1;\n\t}\n\n\tif ((newtype->elsize != self->descr->elsize) &&\t\t\\\n\t (self->nd == 0 || !PyArray_ISONESEGMENT(self) || \\\n\t newtype->subarray)) goto fail;\n\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\t/* We would decref newtype here --- temp will \n\t\t steal a reference to it */\n\t\ttemp = (PyArrayObject *)\t\t\t\t\\\n\t\t\tPyArray_NewFromDescr(&PyArray_Type, newtype, self->nd,\n\t\t\t\t\t self->dimensions, self->strides,\n\t\t\t\t\t self->data, self->flags, NULL);\n\t\tPyDimMem_FREE(self->dimensions);\n\t\tself->dimensions = temp->dimensions;\n\t\tself->nd = temp->nd;\n\t\tself->strides = temp->strides;\n\t\tnewtype = temp->descr;\n\t\t/* Fool deallocator not to delete these*/\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, \"descr\");\n\tif (res) return res;\n\tPyErr_Clear();\n\n\t/* get default */\n\tdobj = PyTuple_New(2);\n\tif (dobj == NULL) return NULL;\n\tPyTuple_SET_ITEM(dobj, 0, PyString_FromString(\"\"));\n\tPyTuple_SET_ITEM(dobj, 1, array_typestr_get(self));\n\tres = PyList_New(1);\n\tif (res == NULL) {Py_DECREF(dobj); return NULL;}\n\tPyList_SET_ITEM(res, 0, dobj);\n\treturn res;\n}\n\nstatic PyObject *\narray_struct_get(PyArrayObject *self)\n{\n PyArrayInterface *inter;\n \n inter = (PyArrayInterface *)_pya_malloc(sizeof(PyArrayInterface));\n inter->version = 2;\n inter->nd = self->nd;\n inter->typekind = self->descr->kind;\n inter->itemsize = self->descr->elsize;\n inter->flags = self->flags;\n /* reset unused flags */\n\tinter->flags &= ~(UPDATEIFCOPY | OWNDATA); \n\tif (PyArray_ISNOTSWAPPED(self)) inter->flags |= NOTSWAPPED;\n inter->strides = self->strides;\n inter->shape = self->dimensions;\n inter->data = self->data;\n\tPy_INCREF(self);\n return PyCObject_FromVoidPtrAndDesc(inter, self, gentype_struct_free);\n}\n\nstatic PyObject *\narray_base_get(PyArrayObject *self)\n{\n\tif (self->base == NULL) {\n\t\tPy_INCREF(Py_None);\n\t\treturn Py_None;\n\t}\n\telse {\n\t\tPy_INCREF(self->base);\n\t\treturn self->base;\n\t}\n}\n\n\nstatic PyObject *\narray_real_get(PyArrayObject *self)\n{\n\tPyArrayObject *ret;\n\n\tif (PyArray_ISCOMPLEX(self)) {\n\t\tret = (PyArrayObject *)PyArray_New(self->ob_type,\n\t\t\t\t\t\t self->nd,\n\t\t\t\t\t\t self->dimensions,\n\t\t\t\t\t\t self->descr->type_num - \\\n\t\t\t\t\t\t PyArray_NUM_FLOATTYPE,\n\t\t\t\t\t\t self->strides,\n\t\t\t\t\t\t self->data,\n\t\t\t\t\t\t 0,\n\t\t\t\t\t\t self->flags, (PyObject *)self);\n\t\tif (ret == NULL) return NULL;\n\t\tret->flags &= ~CONTIGUOUS;\n\t\tret->flags &= ~FORTRAN;\n\t\tPy_INCREF(self);\n\t\tret->base = (PyObject *)self;\n\t\treturn (PyObject *)ret;\n\t}\n\telse {\n\t\tPy_INCREF(self);\n\t\treturn (PyObject *)self;\n\t}\n}\n\n\nstatic int\narray_real_set(PyArrayObject *self, PyObject *val)\n{\n\tPyArrayObject *ret;\n\tPyArrayObject *new;\n\tint rint;\n\n\tnew = (PyArrayObject *)PyArray_FromAny(val, NULL, 0, 0, 0, NULL);\n\tif (new == NULL) return -1;\n\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, NULL); \n\t\tif (new == NULL) return -1;\n\t\tret = (PyArrayObject *)PyArray_New(self->ob_type,\n\t\t\t\t\t\t self->nd,\n\t\t\t\t\t\t self->dimensions,\n\t\t\t\t\t\t self->descr->type_num - \\\n\t\t\t\t\t\t PyArray_NUM_FLOATTYPE,\n\t\t\t\t\t\t self->strides,\n \t\t\t\t\t\t self->data +\t\t\\\n\t\t\t\t\t\t (self->descr->elsize >> 1),\n\t\t\t\t\t\t 0,\n\t\t\t\t\t\t self->flags, (PyObject *)self);\n\t\tif (ret == NULL) {\n\t\t\tPy_DECREF(new); \n\t\t\treturn -1;\n\t\t}\n\t\tret->flags &= ~CONTIGUOUS;\n\t\tret->flags &= ~FORTRAN;\n\t\tPy_INCREF(self);\n\t\tret->base = (PyObject *)self;\n\t\trint = PyArray_CopyInto(ret, new);\n\t\tPy_DECREF(ret);\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), NULL);\n\tif (arr == NULL) return -1;\n\tarrit = (PyArrayIterObject *)PyArray_IterNew(arr);\n\tif (arrit == NULL) goto exit;\n\tselfit = (PyArrayIterObject *)PyArray_IterNew((PyObject *)self);\n\tif (selfit == NULL) goto exit;\n\n swap = PyArray_ISNOTSWAPPED(self) != PyArray_ISNOTSWAPPED(arr);\n copyswap = self->descr->f->copyswap;\n if (PyArray_ISOBJECT(self)) {\n while(selfit->index < selfit->size) {\n Py_XDECREF(*((PyObject **)selfit->dataptr));\n Py_INCREF(*((PyObject **)arrit->dataptr)); \n memmove(selfit->dataptr, arrit->dataptr, \n sizeof(PyObject *));\n PyArray_ITER_NEXT(selfit);\n PyArray_ITER_NEXT(arrit);\n if (arrit->index == arrit->size) \n PyArray_ITER_RESET(arrit);\n }\n retval = 0; \n goto exit;\n }\n\n\twhile(selfit->index < selfit->size) {\n\t\tmemmove(selfit->dataptr, arrit->dataptr, self->descr->elsize);\n copyswap(selfit->dataptr, NULL, swap, self->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\t{\"dtype\",\n\t (getter)array_descr_get,\n\t (setter)array_descr_set,\n\t \"get(set) data-type-descriptor for array\"},\n {\"real\", \n\t (getter)array_real_get, \n\t (setter)array_real_set, \n\t \"real part of array\"},\n {\"imag\", \n\t (getter)array_imag_get, \n\t (setter)array_imag_set, \n\t \"imaginary part of array\"},\n\t{\"flat\", \n\t (getter)array_flat_get, \n\t (setter)array_flat_set, \n\t \"a 1-d view of a contiguous array\"}, \n\t{\"__array_data__\", \n\t (getter)array_dataptr_get,\n\t NULL,\n\t \"Array protocol: data\"},\n\t{\"__array_typestr__\",\n\t (getter)array_typestr_get,\n\t NULL,\n\t \"Array protocol: typestr\"},\n\t{\"__array_descr__\",\n\t (getter)array_protocol_descr_get,\n\t NULL,\n\t \"Array protocol: descr\"},\n\t{\"__array_shape__\", \n\t (getter)array_shape_get,\n\t NULL,\n\t \"Array protocol: shape\"},\n\t{\"__array_strides__\",\n\t (getter)array_protocol_strides_get,\n\t NULL,\n\t \"Array protocol: strides\"},\n {\"__array_struct__\",\n (getter)array_struct_get,\n NULL,\n \"Array protocol: struct\"},\n\t{\"__array_priority__\",\n\t (getter)array_priority_get,\n\t NULL,\n\t \"Array priority\"},\n \t{NULL, NULL, NULL, NULL}, /* Sentinel */\n};\n\n/****************** end of attribute get and set routines *******************/\n\n\nstatic PyObject *\narray_alloc(PyTypeObject *type, int nitems)\n{\n PyObject *obj;\n /* nitems will always be 0 */ \n obj = (PyObject *)_pya_malloc(sizeof(PyArrayObject));\n PyObject_Init(obj, type);\n return obj;\n}\n\n\nstatic char Arraytype__doc__[] = \n \"A array object represents a multidimensional, homogeneous array\\n\"\n\t\" of fixed-size items. An associated data-type-descriptor object\\n\"\n\t\" details the data-type in an array (including byteorder and any\\n\"\n\t\" fields). An array can be constructed using the numpy.array\\n\"\n\t\" command. Arrays are sequence, mapping and numeric objects.\\n\"\n\t\" More information is available in the numpy module and by looking\\n\"\n\t\" at the methods and attributes of an array.\\n\\n\"\n\t\" ndarray.__new__(subtype, shape=, dtype=int_, buffer=None, \\n\"\n\t\" offset=0, strides=None, fortran=False)\\n\\n\"\n\t\" There are two modes of creating an array using __new__:\\n\"\n\t\" 1) If buffer is None, then only shape, dtype, and fortran \\n\"\n\t\" are used\\n\"\n\t\" 2) If buffer is an object exporting the buffer interface, then\\n\"\n\t\" all keywords are interpreted.\\n\"\n\t\" The dtype parameter can be any object that can be interpreted \\n\"\n\t\" as a numpy.dtype object.\\n\\n\"\n\t\" No __init__ method is needed because the array is fully \\n\"\n\t\" initialized after the __new__ method.\";\n\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, 4*n);\n\t\telse\n\t\t\t*itemsize = MAX(*itemsize, n);\n\t\treturn 0;\n\t}\n\tfor (i=0; i n_lower) n_lower = d[1];\n }\n d[1] = n_lower;\n\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, 4*minsize);\n\t\t}\n\t\telse {\n\t\t\ttestsize = MAX(chksize, minsize);\n\t\t}\n\t\tif (testsize != outtype->elsize) {\n\t\t\tPyArray_DESCR_REPLACE(outtype);\n\t\t\touttype->elsize = testsize;\n\t\t\tPy_XDECREF(outtype->fields);\n\t\t\touttype->fields = NULL;\n\t\t}\n\t}\n\treturn outtype;\n}\n\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#ifndef Py_UNICODE_WIDE\n\t\tchktype->elsize <<= 1;\n#endif\t\t\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\t} else if (PyLong_Check(op)) {\n\t\t/* if integer can fit into a longlong then return that\n\t\t*/\n\t\tif ((PyLong_AsLongLong(op) == -1) && PyErr_Occurred()) {\n\t\t\tPyErr_Clear();\n\t\t\tgoto deflt;\n\t\t}\n\t\tchktype = PyArray_DescrFromType(PyArray_LONGLONG);\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 *= 4;\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\tif (ret->nd > 0) {\n\t\tPyErr_SetString(PyExc_ValueError,\n\t\t\t\t\"shape-mismatch on array construction\");\n\t\tPy_DECREF(ret);\n\t\treturn NULL;\n\t}\n\n ret->descr->f->setitem(op, ret->data, ret);\n\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 */\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\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\t\tgoto fail;\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\t\tgoto fail;\n }\n\t\n\tif(discover_dimensions(s,nd,d, !stop_at_string) == -1) goto fail;\n\n\tif (itemsize == 0 && PyTypeNum_ISEXTENDED(type)) {\n\t\tif (discover_itemsize(s, nd, &itemsize) == -1) goto fail;\n\t\tif (type == PyArray_UNICODE) itemsize*=4;\n\t}\n\n\tif (itemsize != typecode->elsize) {\n\t\tPyArray_DESCR_REPLACE(typecode);\n\t\ttypecode->elsize = itemsize;\n\t}\n\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) return NULL;\n if(Assign_Array(r,s) == -1) {\n\t\tPy_DECREF(r);\n\t\treturn NULL;\n\t}\n return (PyObject*)r;\n\n fail:\n\tPy_DECREF(typecode);\n\treturn NULL;\n}\n\n\n/*OBJECT_API\n Is the typenum valid?\n*/\nstatic int \nPyArray_ValidType(int type) \n{\n\tPyArray_Descr *descr;\n\tint res=TRUE;\n\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 << 2;\n\t\tif (mpd->type_num == PyArray_UNICODE &&\n\t\t at->type_num == PyArray_STRING) \n\t\t\tat->elsize = mpd->elsize >> 2;\n\t\tif (at->type_num == PyArray_VOID)\n\t\t\tat->elsize = mpd->elsize;\n\t}\n\n\tout = PyArray_NewFromDescr(mp->ob_type, at,\n\t\t\t\t mp->nd, \n\t\t\t\t mp->dimensions, \n\t\t\t\t NULL, NULL, \n\t\t\t\t fortran,\n\t\t\t\t (PyObject *)mp);\n\n\tif (out == NULL) return NULL;\n\tret = PyArray_CastTo((PyArrayObject *)out, mp);\n\tif (ret != -1) return out;\n\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 */\n/*OBJECT_API*/\nstatic PyObject *\nPyArray_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 break;\n\tcase PyArray_STRINGLTR:\n\t\ttype_num = PyArray_STRING;\n\t\tbreak;\n\tcase PyArray_UNICODELTR:\n\t\ttype_num = PyArray_UNICODE;\n\t\tsize <<= 2;\n\t\tbreak;\n\tcase 'V':\n\t\ttype_num = PyArray_VOID;\n\t\tbreak;\n\tdefault:\n\t\t_MY_FAIL\n\t}\n\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/* OBJECT_API */\nstatic PyObject *\nPyArray_FromStructInterface(PyObject *input)\n{\n\tPyArray_Descr *thetype;\n\tchar buf[40];\n\tPyArrayInterface *inter;\n\tPyObject *attr, *r;\n\tchar endian = PyArray_NATBYTE;\n \n attr = PyObject_GetAttrString(input, \"__array_struct__\");\n if (attr == NULL) {\n\t\tPyErr_Clear();\n\t\treturn Py_NotImplemented;\n\t}\n if (!PyCObject_Check(attr) || \\\n ((inter=((PyArrayInterface *)\\\n\t\t PyCObject_AsVoidPtr(attr)))->version != 2)) {\n PyErr_SetString(PyExc_ValueError, \"invalid __array_struct__\");\n\t\tPy_DECREF(attr);\n return NULL;\n }\n\tif ((inter->flags & NOTSWAPPED) != NOTSWAPPED) {\n\t\tendian = PyArray_OPPBYTE;\n\t\tinter->flags &= ~NOTSWAPPED;\n\t}\n\n snprintf(buf, 40, \"%c%c%d\", endian, inter->typekind, inter->itemsize);\n if (!(thetype=_array_typedescr_fromstr(buf))) {\n\t\tPy_DECREF(attr);\n return NULL;\n }\n\n r = PyArray_NewFromDescr(&PyArray_Type, thetype,\n\t\t\t\t inter->nd, inter->shape,\n\t\t\t\t inter->strides, inter->data,\n\t\t\t\t inter->flags, NULL);\n\tPy_INCREF(input);\n\tPyArray_BASE(r) = input;\n Py_DECREF(attr);\n PyArray_UpdateFlags((PyArrayObject *)r, UPDATE_ALL_FLAGS);\n return r;\n}\n\n/*OBJECT_API*/\nstatic PyObject *\nPyArray_FromInterface(PyObject *input)\n{\n\tPyObject *attr=NULL, *item=NULL;\n PyObject *tstr=NULL, *shape=NULL; \n PyArrayObject *ret;\n\tPyArray_Descr *type=NULL;\n\tchar *data;\n\tint buffer_len;\n\tint res, i, n;\n\tintp dims[MAX_DIMS], strides[MAX_DIMS];\n\tint dataflags = BEHAVED_FLAGS;\n\n\t/* Get the memory from __array_data__ and __array_offset__ */\n\t/* Get the shape */\n\t/* Get the typestring -- ignore array_descr */\n\t/* Get the strides */\n\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\treturn NULL;\n\t\t}\n\t\tif (n != PyTuple_GET_SIZE(attr)) {\n\t\t\tPyErr_SetString(PyExc_ValueError, \n\t\t\t\t\t\"mismatch in length of \"\\\n\t\t\t\t\t\"__array_strides__ and \"\\\n\t\t\t\t\t\"__array_shape__\");\n\t\t\tPy_DECREF(attr);\n\t\t\tPy_DECREF(ret);\n\t\t\treturn NULL;\n\t\t}\n\t\tfor (i=0; istrides, strides, n*sizeof(intp));\n\t}\n\telse PyErr_Clear();\n\tPyArray_UpdateFlags(ret, UPDATE_ALL_FLAGS);\n\treturn (PyObject *)ret;\n\n fail:\n\tPy_XDECREF(attr);\n\tPy_XDECREF(shape);\n\tPy_XDECREF(tstr);\n\treturn NULL;\n}\n\n/* OBJECT_API*/\nstatic PyObject *\nPyArray_FromArrayAttr(PyObject *op, PyArray_Descr *typecode, PyObject *context) \n{\n PyObject *new;\n PyObject *array_meth;\n\n array_meth = PyObject_GetAttrString(op, \"__array__\");\n if (array_meth == NULL) {PyErr_Clear(); return Py_NotImplemented;}\n if (context == NULL) {\n if (typecode == NULL) new = PyObject_CallFunction(array_meth, NULL);\n else new = PyObject_CallFunction(array_meth, \"O\", typecode);\n }\n else {\n if (typecode == NULL) {\n new = PyObject_CallFunction(array_meth, \"OO\", Py_None, context);\n if (new == NULL && PyErr_ExceptionMatches(PyExc_TypeError)) {\n PyErr_Clear();\n new = PyObject_CallFunction(array_meth, \"\");\n }\n }\n else {\n new = PyObject_CallFunction(array_meth, \"OO\", typecode, context);\n if (new == NULL && PyErr_ExceptionMatches(PyExc_TypeError)) {\n PyErr_Clear();\n new = PyObject_CallFunction(array_meth, \"O\", typecode);\n }\n }\n }\n Py_DECREF(array_meth);\n if (new == NULL) return NULL;\n if (!PyArray_Check(new)) {\n PyErr_SetString(PyExc_ValueError, \n \"object __array__ method not \" \\\n \"producing an array\");\n Py_DECREF(new);\n return NULL;\n }\n return new;\n} \n\n/* Does not check for ENSURECOPY and NOTSWAPPED in flags */\n/* Steals a reference to newtype --- which can be NULL */\n/*OBJECT_API*/\nstatic PyObject *\nPyArray_FromAny(PyObject *op, PyArray_Descr *newtype, int min_depth, \n int max_depth, int flags, PyObject *context) \n{\n /* This is the main code to make a NumPy array from a Python\n Object. It is called from lot's of different places which\n is why there are so many checks. The comments try to\n explain some of the checks. */\n\n PyObject *r=NULL;\n int seq = FALSE;\n \n\t/* Is input object already an array? */\n\t/* This is where the flags are used */\n if (PyArray_Check(op)) \n\t\tr = PyArray_FromArray((PyArrayObject *)op, newtype, flags);\n\telse if (PyArray_IsScalar(op, Generic)) {\n\t\tr = PyArray_FromScalar(op, newtype);\n\t}\n else if (((r = PyArray_FromStructInterface(op))!=Py_NotImplemented)|| \\\n ((r = PyArray_FromInterface(op)) != Py_NotImplemented) || \\\n ((r = PyArray_FromArrayAttr(op, newtype, context)) \\\n != Py_NotImplemented)) {\n PyObject *new;\n if (r == NULL) return NULL;\n if (newtype != NULL || flags != 0) {\n new = PyArray_FromArray((PyArrayObject *)r, newtype, flags);\n Py_DECREF(r);\n r = new;\n }\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\n\t\t\tPy_INCREF(newtype);\n\t\t\tr = Array_FromSequence(op, newtype, flags & FORTRAN,\n\t\t\t\t\t min_depth, max_depth);\n\t\t\tif (PyErr_Occurred() && r == NULL) {\n /* It wasn't really a sequence after all.\n * Try interpreting it as a scalar */\n\t\t\t\tPyErr_Clear();\n\t\t\t}\n else {\n\t\t\t\tseq = TRUE;\n\t\t\t\tPy_DECREF(newtype);\n\t\t\t}\n }\n if (!seq)\n\t\t\tr = Array_FromScalar(op, newtype);\n\t}\n\n /* If we didn't succeed return NULL */\n if (r == NULL) return NULL;\n\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: PyArray_FromAny \"\\\n\t\t\t\t\"not producing an array\");\n\t\tPy_DECREF(r);\n return NULL;\n }\n\n if (min_depth != 0 && ((PyArrayObject *)r)->nd < min_depth) {\n PyErr_SetString(PyExc_ValueError, \n \"object of too small depth for desired array\");\n Py_DECREF(r);\n return NULL;\n }\n if (max_depth != 0 && ((PyArrayObject *)r)->nd > max_depth) {\n PyErr_SetString(PyExc_ValueError, \n \"object too deep for desired array\");\n Py_DECREF(r);\n return NULL;\n }\n return r;\n}\n\n/* new reference -- accepts NULL for mintype*/\n/*OBJECT_API*/\nstatic PyArray_Descr *\nPyArray_DescrFromObject(PyObject *op, PyArray_Descr *mintype)\n{\n\treturn _array_find_type(op, mintype, MAX_DIMS);\n}\n\n/*OBJECT_API\n Return the typecode of the array a Python object would be converted\n to\n*/\nstatic int \nPyArray_ObjectType(PyObject *op, int minimum_type) \n{\n\tPyArray_Descr *intype;\n\tPyArray_Descr *outtype;\n\tint ret;\n\n\tintype = PyArray_DescrFromType(minimum_type);\n\tif (intype == NULL) PyErr_Clear();\n\touttype = _array_find_type(op, intype, MAX_DIMS);\n\tret = outtype->type_num;\n\tPy_DECREF(outtype);\n\tPy_DECREF(intype);\n\treturn ret;\n}\n\n\n/* flags is any of \n CONTIGUOUS, \n FORTRAN,\n ALIGNED, \n WRITEABLE, \n NOTSWAPPED,\n ENSURECOPY, \n UPDATEIFCOPY,\n FORCECAST,\n ENSUREARRAY\n\n or'd (|) together\n\n Any of these flags present means that the returned array should \n guarantee that aspect of the array. Otherwise the returned array\n won't guarantee it -- it will depend on the object as to whether or \n not it has such features. \n\n Note that ENSURECOPY is enough\n to guarantee CONTIGUOUS, ALIGNED and WRITEABLE\n and therefore it is redundant to include those as well. \n\n BEHAVED_FLAGS == ALIGNED | WRITEABLE\n CARRAY_FLAGS = CONTIGUOUS | BEHAVED_FLAGS\n FARRAY_FLAGS = FORTRAN | BEHAVED_FLAGS\n \n FORTRAN can be set in the FLAGS to request a FORTRAN array. \n Fortran arrays are always behaved (aligned, \n notswapped, and writeable) and not (C) CONTIGUOUS (if > 1d). \n\n UPDATEIFCOPY flag sets this flag in the returned array if a copy is\n made and the base argument points to the (possibly) misbehaved array.\n When the new array is deallocated, the original array held in base\n is updated with the contents of the new array. \n\n FORCECAST will cause a cast to occur regardless of whether or not\n it is safe. \n*/\n\n\n/* steals a reference to descr -- accepts NULL */\n/*OBJECT_API*/\nstatic PyObject *\nPyArray_CheckFromAny(PyObject *op, PyArray_Descr *descr, int min_depth, \n int max_depth, int requires, PyObject *context) \n{\n\tif (requires & NOTSWAPPED) {\n\t\tif (!descr && PyArray_Check(op) && \\\n\t\t !PyArray_ISNBO(PyArray_DESCR(op)->byteorder)) {\n\t\t\tdescr = PyArray_DescrNew(PyArray_DESCR(op));\n\t\t}\n\t\telse if ((descr && !PyArray_ISNBO(descr->byteorder))) {\n\t\t\tPyArray_DESCR_REPLACE(descr);\n\t\t}\n\t\tdescr->byteorder = PyArray_NATIVE;\n\t}\n\n\treturn PyArray_FromAny(op, descr, min_depth, max_depth,\n requires, context);\n}\n\n/* This is a quick wrapper around PyArray_FromAny(op, NULL, 0, 0, \n ENSUREARRAY) */\n/* that special cases Arrays and PyArray_Scalars up front */\n/* It *steals a reference* to the object */\n/* It also guarantees that the result is PyArray_Type 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_FromAny(op, NULL, 0, 0, ENSUREARRAY, NULL);\n Py_DECREF(op);\n return new;\n}\n\n/*OBJECT_API\n Check the type coercion rules.\n*/\nstatic int \nPyArray_CanCastSafely(int fromtype, int totype) \n{\n\tPyArray_Descr *from, *to;\n\tregister int felsize, telsize;\n\n if (fromtype == totype) return 1;\n if (fromtype == PyArray_BOOL) return 1;\n\tif (totype == PyArray_BOOL) return 0;\n if (totype == PyArray_OBJECT || totype == PyArray_VOID) return 1;\n\tif (fromtype == PyArray_OBJECT || fromtype == PyArray_VOID) return 0;\n\n\tfrom = PyArray_DescrFromType(fromtype);\n\tto = PyArray_DescrFromType(totype);\n\ttelsize = to->elsize;\n\tfelsize = from->elsize;\n\tPy_DECREF(from);\n\tPy_DECREF(to);\n\n switch(fromtype) {\n case PyArray_BYTE:\n\tcase PyArray_SHORT:\n case PyArray_INT:\n case PyArray_LONG:\n\tcase PyArray_LONGLONG:\n\t\tif (PyTypeNum_ISINTEGER(totype)) {\n\t\t\tif (PyTypeNum_ISUNSIGNED(totype)) {\n\t\t\t\treturn (telsize > felsize);\n\t\t\t}\n\t\t\telse {\n\t\t\t\treturn (telsize >= felsize);\n\t\t\t}\n\t\t}\n\t\telse if (PyTypeNum_ISFLOAT(totype)) {\n if (felsize < 8)\n return (telsize > felsize);\n else\n return (telsize >= felsize);\n\t\t}\n\t\telse if (PyTypeNum_ISCOMPLEX(totype)) {\n if (felsize < 8)\n return ((telsize >> 1) > felsize);\n else\n return ((telsize >> 1) >= felsize);\n\t\t}\n\t\telse return totype > fromtype;\n case PyArray_UBYTE:\n case PyArray_USHORT:\n case PyArray_UINT:\n\tcase PyArray_ULONG:\n\tcase PyArray_ULONGLONG:\n\t\tif (PyTypeNum_ISINTEGER(totype)) {\n\t\t\tif (PyTypeNum_ISSIGNED(totype)) {\n\t\t\t\treturn (telsize > felsize);\n\t\t\t}\n\t\t\telse {\n\t\t\t\treturn (telsize >= felsize);\n\t\t\t}\n\t\t}\n\t\telse if (PyTypeNum_ISFLOAT(totype)) {\n if (felsize < 8)\n return (telsize > felsize);\n else\n return (telsize >= felsize);\n\t\t}\n\t\telse if (PyTypeNum_ISCOMPLEX(totype)) {\n if (felsize < 8)\n return ((telsize >> 1) > felsize);\n else\n return ((telsize >> 1) >= felsize);\n\t\t}\n\t\telse return totype > fromtype;\n case PyArray_FLOAT:\n case PyArray_DOUBLE:\n\tcase PyArray_LONGDOUBLE:\n\t\tif (PyTypeNum_ISCOMPLEX(totype)) \n\t\t\treturn ((telsize >> 1) >= felsize);\n\t\telse\n\t\t\treturn (totype > fromtype);\n case PyArray_CFLOAT:\n case PyArray_CDOUBLE:\n\tcase PyArray_CLONGDOUBLE:\n\t\treturn (totype > fromtype);\n\tcase PyArray_STRING:\n\tcase PyArray_UNICODE:\n\t\treturn (totype > fromtype);\n default:\n return 0;\n }\n}\n\n/* leaves reference count alone --- cannot be NULL*/\n/*OBJECT_API*/\nstatic Bool\nPyArray_CanCastTo(PyArray_Descr *from, PyArray_Descr *to)\n{\n\tint fromtype=from->type_num;\n\tint totype=to->type_num;\n\tBool ret;\n\n\tret = (Bool) PyArray_CanCastSafely(fromtype, totype);\n\tif (ret) { /* Check String and Unicode more closely */\n\t\tif (fromtype == PyArray_STRING) {\n\t\t\tif (totype == PyArray_STRING) {\n\t\t\t\tret = (from->elsize <= to->elsize);\n\t\t\t}\n\t\t\telse if (totype == PyArray_UNICODE) {\n\t\t\t\tret = (from->elsize << 2 \\\n\t\t\t\t <= to->elsize);\n\t\t\t}\n\t\t}\n\t\telse if (fromtype == PyArray_UNICODE) {\n\t\t\tif (totype == PyArray_UNICODE) {\n\t\t\t\tret = (from->elsize <= to->elsize);\n\t\t\t}\n\t\t}\n\t\t/* TODO: If totype is STRING or unicode \n\t\t see if the length is long enough to hold the\n\t\t stringified value of the object.\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, NULL);\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 FORCECAST | ALIGNED, NULL);\n\t\t\tif (new==NULL) goto fail;\n Py_DECREF(obj);\n\t\t\tobj = new;\n\t\t\tr = iter_subscript_int(self, (PyArrayObject *)obj);\n\t\t}\n\t\telse {\n\t\t\tgoto fail;\n\t\t}\n\t\tPy_DECREF(obj);\n\t\treturn r;\n\t}\n\telse Py_DECREF(indtype);\n\n\n fail:\n\tif (!PyErr_Occurred())\n\t\tPyErr_SetString(PyExc_IndexError, \"unsupported iterator index\");\n\tPy_XDECREF(indtype);\n\tPy_XDECREF(obj);\n\treturn NULL;\n\n}\n\n\nstatic int\niter_ass_sub_Bool(PyArrayIterObject *self, PyArrayObject *ind,\n\t\t PyArrayIterObject *val, int swap)\n{\n\tint index, strides, itemsize;\n\tchar *dptr;\n PyArray_CopySwapFunc *copyswap;\n\n\tif (ind->nd != 1) {\n\t\tPyErr_SetString(PyExc_ValueError, \n\t\t\t\t\"boolean index array should have 1 dimension\");\n\t\treturn -1;\n\t}\n\titemsize = self->ao->descr->elsize;\n\tindex = ind->dimensions[0];\n\tstrides = ind->strides[0];\n\tdptr = ind->data;\n\tPyArray_ITER_RESET(self);\n\t/* Loop over Boolean array */\n copyswap = self->ao->descr->f->copyswap;\n\twhile(index--) {\n\t\tif (*((Bool *)dptr) != 0) {\n copyswap(self->dataptr, val->dataptr, swap,\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, NULL);\n\tif (arrval==NULL) return -1;\n\tval_it = (PyArrayIterObject *)PyArray_IterNew(arrval);\n\tif (val_it==NULL) goto finish;\n\n\t/* Check for Boolean -- this is first becasue\n\t Bool is a subclass of Int */\n\n copyswap = PyArray_DESCR(arrval)->f->copyswap;\n\tswap = (PyArray_ISNOTSWAPPED(self->ao)!=PyArray_ISNOTSWAPPED(arrval));\n\tif (PyBool_Check(ind)) {\n\t\tif (PyObject_IsTrue(ind)) {\n copyswap(self->dataptr, PyArray_DATA(arrval), \n swap, 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, NULL);\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_CheckFromAny(obj, indtype, 0, 0, \n FORCECAST | BEHAVED_NS_FLAGS, NULL);\n\t\t\tPy_DECREF(obj);\n\t\t\tobj = new;\n\t\t\tif (new==NULL) goto finish;\n\t\t\tif (iter_ass_sub_int(self, (PyArrayObject *)obj,\n\t\t\t\t\t val_it, swap) < 0)\n\t\t\t\tgoto finish;\n\t\t\tretval=0;\n\t\t}\n\t}\n\n finish:\n\tif (!PyErr_Occurred() && retval < 0)\n\t\tPyErr_SetString(PyExc_IndexError, \n\t\t\t\t\"unsupported iterator index\");\n\tPy_XDECREF(indtype);\n\tPy_XDECREF(obj);\n\tPy_XDECREF(val_it);\n\tPy_XDECREF(arrval);\n\treturn retval;\n\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 {\"index\", T_INT, offsetof(PyArrayIterObject, index), RO, NULL},\n\t{NULL},\n};\n\nstatic PyObject *\niter_coords_get(PyArrayIterObject *self)\n{\n int nd;\n nd = self->ao->nd;\n if (self->contiguous) { /* coordinates not kept track of --- need to generate\n from index */\n intp val;\n int i;\n val = self->index;\n for (i=0;icoordinates[i] = val / self->factors[i];\n val = val % self->factors[i];\n }\n }\n return PyArray_IntTupleFromIntp(nd, self->coordinates);\n}\n\nstatic PyGetSetDef iter_getsets[] = {\n\t{\"coords\", \n\t (getter)iter_coords_get,\n\t NULL,\n\t \"An N-d tuple of current coordinates.\"},\n\t{NULL, NULL, NULL, NULL},\n};\n\nstatic PyTypeObject PyArrayIter_Type = {\n PyObject_HEAD_INIT(NULL)\n 0,\t\t\t\t\t /* ob_size */\n \"numpy.flatiter\",\t\t /* tp_name */\n sizeof(PyArrayIterObject), /* tp_basicsize */\n 0,\t\t\t\t\t /* tp_itemsize */\n /* methods */\n (destructor)arrayiter_dealloc,\t\t/* tp_dealloc */\n 0,\t\t\t\t\t/* tp_print */\n 0,\t\t\t\t\t/* tp_getattr */\n 0,\t\t\t\t\t/* tp_setattr */\n 0,\t\t\t\t\t/* tp_compare */\n 0,\t\t\t\t\t/* tp_repr */\n 0,\t\t\t\t\t/* tp_as_number */\n 0, \t\t\t /* tp_as_sequence */\n &iter_as_mapping, \t /* tp_as_mapping */\n 0,\t\t\t\t\t/* tp_hash */\n 0,\t\t\t\t\t/* tp_call */\n 0,\t\t\t\t\t/* tp_str */\n 0,\t \t/* tp_getattro */\n 0,\t\t\t\t\t/* tp_setattro */\n 0,\t\t\t\t\t/* tp_as_buffer */\n Py_TPFLAGS_DEFAULT, /* tp_flags */\n 0,\t\t\t\t\t/* tp_doc */\n 0, \t /* tp_traverse */\n 0,\t\t\t\t\t/* tp_clear */\n 0,\t\t\t\t\t/* tp_richcompare */\n 0,\t\t\t\t\t/* tp_weaklistoffset */\n 0, \t /* tp_iter */\n (iternextfunc)arrayiter_next,\t\t/* tp_iternext */\n iter_methods,\t\t\t\t/* tp_methods */\n iter_members,\t \t /* tp_members */\n iter_getsets, /* tp_getset */\n\n};\n\n/** END of Array Iterator **/\n\n\n\n/*********************** Subscript Array Iterator *************************\n * *\n * This object handles subscript behavior for array objects. *\n * It is an iterator object with a next method *\n * It abstracts the n-dimensional mapping behavior to make the looping *\n * code more understandable (maybe) *\n * and so that indexing can be set up ahead of time *\n */ \n\n/* convert an indexing object to an INTP indexing array iterator\n if possible -- otherwise, it is a Slice or Ellipsis object\n and has to be interpreted on bind to a particular \n array so leave it NULL for now.\n */\nstatic int\n_convert_obj(PyObject *obj, PyArrayIterObject **iter)\n{\n\tPyArray_Descr *indtype;\n\tPyObject *arr;\n\n\tif (PySlice_Check(obj) || (obj == Py_Ellipsis))\n\t\t*iter = NULL;\n\telse {\n\t\tindtype = PyArray_DescrFromType(PyArray_INTP);\n\t\tarr = PyArray_FromAny(obj, indtype, 0, 0, FORCECAST, NULL);\n\t\tif (arr == NULL) return -1;\n\t\t*iter = (PyArrayIterObject *)PyArray_IterNew(arr);\n\t\tPy_DECREF(arr);\n\t\tif (*iter == NULL) return -1;\n\t}\n\treturn 0;\n}\n\n/* Adjust dimensionality and strides for index object iterators \n --- i.e. broadcast\n */\n/*OBJECT_API*/\nstatic int\nPyArray_Broadcast(PyArrayMultiIterObject *mit)\n{\n\tint i, nd, k, j;\n\tintp tmp;\n\tPyArrayIterObject *it;\n\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\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, NULL);\n\tif (ba == NULL) return -1;\n\tnd = ba->nd;\n\tfor (j=0; jdata;\n\tcount = 0;\n\n\t/* pre-determine how many nonzero entries there are */\n\tfor (i=0; iao->data;\n\t\tcoords[j] = 0;\n\t\tdims_m1[j] = ba->dimensions[j]-1;\n\t}\n\n\tptr = (Bool *)ba->data;\n\n\tif (count == 0) goto finish;\n\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->index = 0;\n \tmit->ait = NULL;\n \tmit->subspace = NULL;\n\tmit->numiter = 0;\n\tmit->consec = 1;\n\tPy_INCREF(indexobj);\n\tmit->indexobj = indexobj;\n\n\tif (fancy == SOBJ_LISTTUP) {\n\t\tPyObject *newobj;\n\t\tnewobj = PySequence_Tuple(indexobj);\n\t\tif (newobj == NULL) goto fail;\n\t\tPy_DECREF(indexobj);\n\t\tindexobj = newobj;\n\t\tmit->indexobj = indexobj;\n\t}\n\n#undef SOBJ_NOTFANCY \n#undef SOBJ_ISFANCY \n#undef SOBJ_BADARRAY \n#undef SOBJ_TOOMANY \n#undef SOBJ_LISTTUP \n \n\tif (oned) return (PyObject *)mit;\n\n\t/* Must have some kind of fancy indexing if we are here */\n\t/* indexobj is either a list, an arrayobject, or a tuple \n\t (with at least 1 list or arrayobject or Bool object), */\n\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, NULL);\n\t\tif (arr == NULL) goto fail;\n\t\tmit->iters[0] = (PyArrayIterObject *)PyArray_IterNew(arr);\n\t\tif (mit->iters[0] == NULL) {Py_DECREF(arr); goto fail;}\n\t\tmit->nd = PyArray_NDIM(arr);\n\t\tmemcpy(mit->dimensions,PyArray_DIMS(arr),mit->nd*sizeof(intp));\n\t\tmit->size = PyArray_SIZE(arr);\n\t\tPy_DECREF(arr);\n\t\tPy_DECREF(mit->indexobj);\n\t\tmit->indexobj = Py_BuildValue(\"(N)\", PyInt_FromLong(0));\n\t}\n\telse { /* must be a tuple */\n\t\tPyObject *obj;\n\t\tPyArrayIterObject *iter;\n\t\tPyObject *new;\n\t\t/* Make a copy of the tuple -- we will be replacing \n\t\t index objects with 0's */\n\t\tn = PyTuple_GET_SIZE(indexobj);\n\t\tnew = PyTuple_New(n);\n\t\tif (new == NULL) goto fail;\n\t\tstarted = 0;\n\t\tnonindex = 0;\n\t\tfor (i=0; iconsec = 0;\n\t\t\t\tmit->iters[(mit->numiter)++] = iter;\n\t\t\t\tPyTuple_SET_ITEM(new,i,\n\t\t\t\t\t\t PyInt_FromLong(0));\n\t\t\t}\n\t\t\telse {\n\t\t\t\tif (started) nonindex = 1;\n\t\t\t\tPy_INCREF(obj);\n\t\t\t\tPyTuple_SET_ITEM(new,i,obj);\n\t\t\t}\n\t\t}\n\t\tPy_DECREF(mit->indexobj);\n\t\tmit->indexobj = new;\n\t\t/* Store the number of iterators actually converted */\n\t\t/* These will be mapped to actual axes at bind time */\n\t\tif (PyArray_Broadcast((PyArrayMultiIterObject *)mit) < 0)\n\t\t\tgoto fail;\n\t}\n\n return (PyObject *)mit;\n \n fail:\n Py_DECREF(mit);\n\treturn NULL;\n}\n\n\nstatic void\narraymapiter_dealloc(PyArrayMapIterObject *mit)\n{\n\tint i;\n\tPy_XDECREF(mit->indexobj);\n Py_XDECREF(mit->ait);\n\tPy_XDECREF(mit->subspace);\n\tfor (i=0; inumiter; i++)\n\t\tPy_XDECREF(mit->iters[i]);\n _pya_free(mit);\n}\n\n/* The mapiter object must be created new each time. It does not work\n to bind to a new array, and continue.\n\n This was the orginal intention, but currently that does not work. \n Do not expose the MapIter_Type to Python.\n\n It's not very useful anyway, since mapiter(indexobj); mapiter.bind(a); \n mapiter is equivalent to a[indexobj].flat but the latter gets to use \n slice syntax.\n*/\n\nstatic PyTypeObject PyArrayMapIter_Type = {\n PyObject_HEAD_INIT(NULL)\n 0,\t\t\t\t\t /* ob_size */\n \"numpy.mapiter\",\t\t \t/* tp_name */\n sizeof(PyArrayIterObject), /* tp_basicsize */\n 0,\t\t\t\t\t /* tp_itemsize */\n /* methods */\n (destructor)arraymapiter_dealloc,\t/* tp_dealloc */\n 0,\t\t\t\t\t/* tp_print */\n 0,\t\t\t\t\t/* tp_getattr */\n 0,\t\t\t\t\t/* tp_setattr */\n 0,\t\t\t\t\t/* tp_compare */\n 0,\t\t\t\t\t/* tp_repr */\n 0,\t\t\t\t\t/* tp_as_number */\n 0,\t\t\t\t\t/* tp_as_sequence */\n 0,\t\t\t\t\t/* tp_as_mapping */\n 0,\t\t\t\t\t/* tp_hash */\n 0,\t\t\t\t\t/* tp_call */\n 0,\t\t\t\t\t/* tp_str */\n 0, \t\t/* tp_getattro */\n 0,\t\t\t\t\t/* tp_setattro */\n 0,\t\t\t\t\t/* tp_as_buffer */\n Py_TPFLAGS_DEFAULT, /* tp_flags */\n 0,\t\t\t\t\t/* tp_doc */\n (traverseproc)0, \t /* tp_traverse */\n 0,\t\t\t\t\t/* tp_clear */\n 0,\t\t\t\t\t/* tp_richcompare */\n 0,\t\t\t\t\t/* tp_weaklistoffset */\n 0,\t\t \t /* tp_iter */\n (iternextfunc)0, \t /* tp_iternext */\n 0, \t /* tp_methods */\n 0,\t\t\t\t\t /* tp_members */\n 0,\t\t\t /* tp_getset */\n 0,\t\t\t\t\t /* tp_base */\n 0,\t\t\t\t\t /* tp_dict */\n 0,\t\t\t\t\t /* tp_descr_get */\n 0,\t\t\t\t\t /* tp_descr_set */\n 0,\t\t\t\t\t /* tp_dictoffset */\n (initproc)0,\t \t /* tp_init */\n 0, \t /* tp_alloc */\n 0,\t /* tp_new */\n 0,\t /* tp_free */\n 0,\t\t\t\t\t /* tp_is_gc */\n 0,\t\t\t\t\t /* tp_bases */\n 0,\t\t\t\t\t /* tp_mro */\n 0,\t\t\t\t\t /* tp_cache */\n 0,\t\t\t\t\t /* tp_subclasses */\n 0\t\t\t\t\t /* tp_weaklist */\n\n};\n\n/** END of Subscript Iterator **/\n\n\n/*OBJECT_API\n Get MultiIterator,\n*/\nstatic PyObject *\nPyArray_MultiIterNew(int n, ...)\n{\n va_list va;\n\tPyArrayMultiIterObject *multi;\n\tPyObject *current;\n\tPyObject *arr;\n\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 dtype objects can be set. \n*/\nstatic PyMemberDef arraydescr_members[] = {\n\t{\"type\", T_OBJECT, offsetof(PyArray_Descr, typeobj), RO, NULL},\n\t{\"kind\", T_CHAR, offsetof(PyArray_Descr, kind), RO, NULL},\n\t{\"char\", T_CHAR, offsetof(PyArray_Descr, type), RO, NULL},\n\t{\"num\", T_INT, offsetof(PyArray_Descr, type_num), RO, NULL},\n\t{\"byteorder\", T_CHAR, offsetof(PyArray_Descr, byteorder), RO, NULL},\n\t{\"itemsize\", T_INT, offsetof(PyArray_Descr, elsize), RO, NULL},\n\t{\"alignment\", T_INT, offsetof(PyArray_Descr, alignment), RO, NULL},\n {\"hasobject\", T_UBYTE, offsetof(PyArray_Descr, hasobject), RO, NULL},\n\t{NULL}, \n};\n\nstatic PyObject *\narraydescr_subdescr_get(PyArray_Descr *self)\n{\n\tif (self->subarray == NULL) {\n\t\tPy_INCREF(Py_None);\n\t\treturn Py_None;\n\t}\n\treturn Py_BuildValue(\"OO\", (PyObject *)self->subarray->base, \n\t\t\t self->subarray->shape);\n}\n\nstatic PyObject *\narraydescr_protocol_typestr_get(PyArray_Descr *self)\n{\n char basic_=self->kind;\n char endian = self->byteorder;\n\tint size=self->elsize;\n\n if (endian == '=') {\n endian = '<';\n if (!PyArray_IsNativeByteOrder(endian)) endian = '>';\n }\n \n\tif (self->type_num == PyArray_UNICODE) {\n\t\tsize >>= 2;\n\t}\n return PyString_FromFormat(\"%c%c%d\", endian, basic_, size);\n}\n\nstatic PyObject *\narraydescr_typename_get(PyArray_Descr *self)\n{\n int len;\n PyTypeObject *typeobj = self->typeobj;\n\tPyObject *res;\n\tstatic int suffix_len=0;\n\n\tif (PyTypeNum_ISUSERDEF(self->type_num)) {\n\t\tres = PyString_FromString(typeobj->tp_name);\n\t}\n\telse {\n\t\tif (suffix_len == 0) \n\t\t\tsuffix_len = strlen(\"scalar\");\n\t\tlen = strlen(typeobj->tp_name) - suffix_len;\n\t\tres = PyString_FromStringAndSize(typeobj->tp_name, len);\n\t}\n\tif (PyTypeNum_ISEXTENDED(self->type_num) && self->elsize != 0) {\n\t\tPyObject *p;\n\t\tp = PyString_FromFormat(\"%d\", self->elsize * 8);\n\t\tPyString_ConcatAndDel(&res, p);\n\t}\n\treturn res;\t\t\t\t\t\t \n}\n\nstatic PyObject *\narraydescr_base_get(PyArray_Descr *self)\n{\n\tif (self->subarray == NULL) {\n\t\tPy_INCREF(self);\n return (PyObject *)self;\n\t}\n Py_INCREF(self->subarray->base);\n return (PyObject *)(self->subarray->base);\n}\n\nstatic PyObject *\narraydescr_shape_get(PyArray_Descr *self)\n{\n\tif (self->subarray == NULL) {\n return Py_BuildValue(\"(N)\", PyInt_FromLong(1));\n\t}\n Py_INCREF(self->subarray->shape);\n return (PyObject *)(self->subarray->shape);\n}\n\nstatic PyObject *\narraydescr_protocol_descr_get(PyArray_Descr *self)\n{\n\tPyObject *dobj, *res;\n\n\tif (self->fields == NULL || self->fields == Py_None) {\n\t\t/* get default */\n\t\tdobj = PyTuple_New(2);\n\t\tif (dobj == NULL) return NULL;\n\t\tPyTuple_SET_ITEM(dobj, 0, PyString_FromString(\"\"));\n\t\tPyTuple_SET_ITEM(dobj, 1, \\\n\t\t\t\t arraydescr_protocol_typestr_get(self));\n\t\tres = PyList_New(1);\n\t\tif (res == NULL) {Py_DECREF(dobj); return NULL;}\n\t\tPyList_SET_ITEM(res, 0, dobj);\n\t\treturn res;\n\t}\n\n return PyObject_CallMethod(_numpy_internal, \"_array_descr\", \n\t\t\t\t \"O\", self);\n}\n\n/* returns 1 for a builtin type\n and 2 for a user-defined data-type descriptor\n return 0 if neither (i.e. it's a copy of one)\n*/\nstatic PyObject *\narraydescr_isbuiltin_get(PyArray_Descr *self) \n{\n\tlong val;\n\tval = 0;\n\tif (self->fields == Py_None) val = 1;\n\tif (PyTypeNum_ISUSERDEF(self->type_num)) val = 2;\n\treturn PyInt_FromLong(val);\n}\n\nstatic PyObject *\narraydescr_isnative_get(PyArray_Descr *self)\n{\n\tPyObject *ret;\n\n\tret = (PyArray_ISNBO(self->byteorder) ? Py_True : Py_False);\n\tPy_INCREF(ret);\n\treturn ret;\n}\n\nstatic PyObject *\narraydescr_fields_get(PyArray_Descr *self)\n{\n\tif (self->fields == NULL || self->fields == Py_None) {\n\t\tPy_INCREF(Py_None);\n\t\treturn Py_None;\n\t}\n\treturn PyDictProxy_New(self->fields);\n}\n\nstatic PyGetSetDef arraydescr_getsets[] = {\n\t{\"subdtype\", \n\t (getter)arraydescr_subdescr_get,\n\t NULL,\n\t \"A tuple of (descr, shape) or None.\"},\n\t{\"descr\",\n\t (getter)arraydescr_protocol_descr_get,\n\t NULL,\n\t \"The array_protocol type descriptor.\"},\n\t{\"str\",\n\t (getter)arraydescr_protocol_typestr_get,\n\t NULL,\n\t \"The array_protocol typestring.\"},\n {\"name\",\n (getter)arraydescr_typename_get,\n NULL,\n \"The name of the true data-type\"},\n\t{\"base\",\n\t (getter)arraydescr_base_get,\n\t NULL,\n\t \"The base data-type or self if no subdtype\"},\n {\"shape\",\n (getter)arraydescr_shape_get,\n NULL,\n \"The shape of the subdtype or (1,)\"},\n \t{\"isbuiltin\",\n\t (getter)arraydescr_isbuiltin_get,\n\t NULL,\n\t \"Is this a buillt-in data-type descriptor?\"},\n\t{\"isnative\",\n\t (getter)arraydescr_isnative_get,\n\t NULL,\n\t \"Is the byte-order of this descriptor native?\"},\n\t{\"fields\",\n\t (getter)arraydescr_fields_get,\n\t NULL,\n\t NULL},\n\t{NULL, NULL, NULL, NULL},\n};\n\nstatic PyArray_Descr *_convert_from_list(PyObject *obj, int align, int try_descr);\nstatic PyArray_Descr *_convert_from_dict(PyObject *obj, int align);\nstatic PyArray_Descr *_convert_from_commastring(PyObject *obj, int align);\nstatic PyArray_Descr *_convert_from_array_descr(PyObject *obj);\n\nstatic PyObject *\narraydescr_new(PyTypeObject *subtype, PyObject *args, PyObject *kwds)\n{\n\tPyObject *odescr;\n\tPyArray_Descr *descr, *conv;\n\tint align=0;\n\tBool copy=FALSE;\n\tstatic char *kwlist[] = {\"dtype\", \"align\", \"copy\", NULL};\n\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, \"dtype\");\n\tPy_DECREF(mod);\n\tif (obj == NULL) {Py_DECREF(ret); return NULL;}\n\tPyTuple_SET_ITEM(ret, 0, obj);\n\tif (PyTypeNum_ISUSERDEF(self->type_num) ||\t\t\\\n\t ((self->type_num == PyArray_VOID &&\t\t\t\\\n\t self->typeobj != &PyVoidArrType_Type))) {\n\t\tobj = (PyObject *)self->typeobj;\n\t\tPy_INCREF(obj);\n\t}\n\telse {\n\t\telsize = self->elsize;\n\t\tif (self->type_num == PyArray_UNICODE) {\n\t\t\telsize >>= 2;\n\t\t}\n\t\tobj = PyString_FromFormat(\"%c%d\",self->kind, elsize);\n\t}\n\tPyTuple_SET_ITEM(ret, 1, Py_BuildValue(\"(Nii)\", obj, 0, 1));\n\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 dtype object\\n\"\n\t\" with altered byteorders. If is not given all byteorders\\n\"\n\t\" are swapped. Otherwise endian can be '>', '<', or '=' to force\\n\"\n\t\" a byteorder. Descriptors in all fields are also updated in the\\n\"\n\t\" new dtype object.\";\n\nstatic PyObject *\narraydescr_newbyteorder(PyArray_Descr *self, PyObject *args) \n{\n\tchar endian=PyArray_SWAP;\n\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);\n\t\tif (self->type_num != PyArray_VOID) {\n\t\t\tPyObject *p;\n\t\t\tPyObject *t=PyString_FromString(\"'\");\n\t\t\tp = arraydescr_protocol_typestr_get(self);\n\t\t\tPyString_Concat(&p, t);\n\t\t\tPyString_ConcatAndDel(&t, p);\n\t\t\tp = PyString_FromString(\"(\");\n\t\t\tPyString_ConcatAndDel(&p, t);\n\t\t\tPyString_ConcatAndDel(&p, PyString_FromString(\", \"));\n\t\t\tPyString_ConcatAndDel(&p, sub);\n\t\t\tPyString_ConcatAndDel(&p, PyString_FromString(\")\"));\n\t\t\tsub = p;\n\t\t}\n\t}\n\telse if (self->subarray) {\n\t\tPyObject *p;\n\t\tPyObject *t = PyString_FromString(\"(\");\n\t\tp = arraydescr_str(self->subarray->base);\n\t\tPyString_ConcatAndDel(&t, p);\n\t\tPyString_ConcatAndDel(&t, PyString_FromString(\",\"));\n\t\tPyString_ConcatAndDel(&t, PyObject_Str(self->subarray->shape));\n\t\tPyString_ConcatAndDel(&t, PyString_FromString(\")\"));\n\t\tsub = t;\n\t}\n\telse {\n\t\tPyObject *t=PyString_FromString(\"'\");\n\t\tsub = arraydescr_protocol_typestr_get(self);\n\t\tPyString_Concat(&sub, t);\n\t\tPyString_ConcatAndDel(&t, sub);\n\t\tsub = t;\n\t}\n\treturn sub;\n}\n\nstatic PyObject *\narraydescr_repr(PyArray_Descr *self)\n{\n\tPyObject *sub, *s;\n\ts = PyString_FromString(\"dtype(\");\n sub = arraydescr_str(self);\n\tPyString_ConcatAndDel(&s, sub);\n\tsub = PyString_FromString(\")\");\n\tPyString_ConcatAndDel(&s, sub);\n\treturn s;\n}\n\nstatic int\narraydescr_compare(PyArray_Descr *self, PyObject *other)\n{\n \tif (!PyArray_DescrCheck(other)) {\n\t\tPyErr_SetString(PyExc_TypeError,\n\t\t\t\t\"not a dtype object.\");\n\t\treturn -1;\n\t}\n\tif (PyArray_EquivTypes(self, (PyArray_Descr *)other)) return 0;\n\tif (PyArray_CanCastTo(self, (PyArray_Descr *)other)) return -1;\n\treturn 1;\n}\n\n/*************************************************************************\n **************** Implement Mapping Protocol ***************************\n *************************************************************************/\n\nstatic int \ndescr_length(PyArray_Descr *self) \n{\n\n\tif (self->fields && self->fields != Py_None)\n\t\t/* Remove the last entry (root) */\n\t\treturn PyDict_Size(self->fields) - 1;\n\telse return 0;\n}\n\nstatic PyObject *\ndescr_subscript(PyArray_Descr *self, PyObject *op) \n{\n\n\tif (self->fields) {\n\t\tif (PyString_Check(op) || PyUnicode_Check(op)) {\n\t\t\tPyObject *obj;\n\t\t\tobj = PyDict_GetItem(self->fields, op);\n\t\t\tif (obj != NULL) {\n\t\t\t\tPyObject *descr;\n\t\t\t\tdescr = PyTuple_GET_ITEM(obj, 0);\n\t\t\t\tPy_INCREF(descr);\n\t\t\t\treturn descr;\n\t\t\t}\n\t\t\telse {\n\t\t\t\tPyErr_Format(PyExc_KeyError, \n\t\t\t\t\t \"field named \\'%s\\' not found.\",\n\t\t\t\t\t PyString_AsString(op));\n\t\t\t}\n\t\t}\n\t\telse {\n\t\t PyErr_SetString(PyExc_ValueError, \n\t\t\t\t \"only strings or unicode values allowed \" \\\n\t\t\t\t \"for getting fields.\");\n\t\t}\n\t}\n\telse {\n\t\tPyErr_Format(PyExc_KeyError, \n\t\t\t \"there are no fields in dtype %s.\",\n\t\t\t PyString_AsString(arraydescr_str(self)));\n\t}\n\n\treturn NULL;\n}\n\nstatic PyMappingMethods descr_as_mapping = {\n (inquiry)descr_length,\t\t /*mp_length*/\n (binaryfunc)descr_subscript,\t /*mp_subscript*/\n (objobjargproc)NULL,\t /*mp_ass_subscript*/\n};\n\n/****************** End of Mapping Protocol ******************************/\n\n\nstatic PyTypeObject PyArrayDescr_Type = {\n PyObject_HEAD_INIT(NULL)\n 0,\t\t\t\t\t /* ob_size */\n \"numpy.dtype\",\t\t \t /* tp_name */\n sizeof(PyArray_Descr), /* tp_basicsize */\n 0,\t\t\t\t\t /* tp_itemsize */\n /* methods */\n (destructor)arraydescr_dealloc,\t\t/* tp_dealloc */\n 0,\t\t\t\t\t/* tp_print */\n 0,\t\t\t\t\t/* tp_getattr */\n 0,\t\t\t\t\t/* tp_setattr */\n\t(cmpfunc)arraydescr_compare,\t\t/* tp_compare */\n (reprfunc)arraydescr_repr,\t /* tp_repr */\n 0,\t\t\t\t\t/* tp_as_number */\n 0, \t\t\t /* tp_as_sequence */\n &descr_as_mapping, \t /* tp_as_mapping */\n 0,\t\t\t\t\t/* tp_hash */\n 0,\t\t\t\t\t/* tp_call */\n (reprfunc)arraydescr_str, /* tp_str */\n 0,\t \t/* tp_getattro */\n 0,\t\t\t\t\t/* tp_setattro */\n 0,\t\t\t\t\t/* tp_as_buffer */\n Py_TPFLAGS_DEFAULT, /* tp_flags */\n 0,\t\t\t\t\t/* tp_doc */\n 0, \t /* tp_traverse */\n 0,\t\t\t\t\t/* tp_clear */\n 0,\t\t\t\t\t/* tp_richcompare */\n 0,\t\t\t\t\t/* tp_weaklistoffset */\n 0, \t /* tp_iter */\n 0,\t \t/* tp_iternext */\n arraydescr_methods,\t \t /* tp_methods */\n arraydescr_members,\t /* tp_members */\n arraydescr_getsets, /* tp_getset */\n 0,\t\t\t\t\t /* tp_base */\n 0,\t\t\t\t\t /* tp_dict */\n 0,\t\t\t\t\t /* tp_descr_get */\n 0,\t\t\t\t\t /* tp_descr_set */\n 0,\t\t\t\t\t /* tp_dictoffset */\n 0, \t \t /* tp_init */\n 0, \t /* tp_alloc */\n arraydescr_new,\t /* tp_new */\n 0,\t /* tp_free */\n 0,\t\t\t\t\t /* tp_is_gc */\n 0,\t\t\t\t\t /* tp_bases */\n 0,\t\t\t\t\t /* tp_mro */\n 0,\t\t\t\t\t /* tp_cache */\n 0,\t\t\t\t\t /* tp_subclasses */\n 0\t\t\t\t\t /* tp_weaklist */\n};\n", + "source_code_before": "/*\n Provide multidimensional arrays as a basic object type in python. \n\nBased on Original Numeric implementation\nCopyright (c) 1995, 1996, 1997 Jim Hugunin, hugunin@mit.edu\n\nwith contributions from many Numeric Python developers 1995-2004 \n\nHeavily modified in 2005 with inspiration from Numarray \n\nby\n\nTravis Oliphant\nAssistant Professor at\nBrigham Young University \n\nmaintainer email: oliphant.travis@ieee.org\n\nNumarray design (which provided guidance) by \nSpace Science Telescope Institute \n (J. Todd Miller, Perry Greenfield, Rick White)\n*/\n\n/*OBJECT_API\n Get Priority from object\n*/\nstatic double\nPyArray_GetPriority(PyObject *obj, double default_) \n{\n PyObject *ret;\n double priority=PyArray_PRIORITY;\n\n\tif (PyArray_CheckExact(obj))\n\t\treturn priority;\n 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\n\n#ifndef Py_UNICODE_WIDE\n#include \"ucsnarrow.c\"\n#endif\n\n\nstatic PyArray_Descr **userdescrs=NULL;\n#define error_converting(x) (((x) == -1) && PyErr_Occurred())\n\n/* Computer-generated arraytype and scalartype code */\n#include \"scalartypes.inc\"\n#include \"arraytypes.inc\"\n\n\n/* Helper functions */\n\n/*OBJECT_API*/\nstatic intp\nPyArray_PyIntAsIntp(PyObject *o)\n{\n\tlonglong long_value = -1;\n\tPyObject *obj;\n\tstatic char *msg = \"an integer is required\";\n\tPyObject *arr;\n\tPyArray_Descr *descr;\n\tintp ret;\n\n\tif (!o) {\n\t\tPyErr_SetString(PyExc_TypeError, msg);\n\t\treturn -1;\n\t}\n\n\tif (PyInt_Check(o)) {\n\t\tlong_value = (longlong) PyInt_AS_LONG(o);\n\t\tgoto finish;\n\t} else if (PyLong_Check(o)) {\n\t\tlong_value = (longlong) PyLong_AsLongLong(o);\n\t\tgoto finish;\n\t}\n\n#if SIZEOF_INTP == SIZEOF_LONG \n\tdescr = &LONG_Descr;\n#elif SIZEOF_INTP == SIZEOF_INT\n\tdescr = &INT_Descr;\n#else\n\tdescr = &LONGLONG_DESCR;\n#endif\n\tarr = NULL;\n\n\tif (PyArray_Check(o)) {\n\t\tif (PyArray_SIZE(o)!=1 || !PyArray_ISINTEGER(o)) {\n\t\t\tPyErr_SetString(PyExc_TypeError, msg);\n\t\t\treturn -1;\n\t\t}\n\t\tPy_INCREF(descr);\n\t\tarr = PyArray_CastToType((PyArrayObject *)o, descr, 0);\n\t}\n\telse if (PyArray_IsScalar(o, Integer)) {\n\t\tPy_INCREF(descr);\n\t\tarr = PyArray_FromScalar(o, descr);\n\t}\n\tif (arr != NULL) {\n\t\tret = *((intp *)PyArray_DATA(arr));\n\t\tPy_DECREF(arr);\n\t\treturn ret;\n\t}\t\t\n\tif (o->ob_type->tp_as_number != NULL &&\t\t\t\\\n\t o->ob_type->tp_as_number->nb_long != NULL) {\n\t\tobj = o->ob_type->tp_as_number->nb_long(o);\n\t\tif (obj != NULL) {\n\t\t\tlong_value = (longlong) PyLong_AsLongLong(obj);\n\t\t\tPy_DECREF(obj);\n\t\t}\n\t}\n\telse if (o->ob_type->tp_as_number != NULL &&\t\t\\\n\t\t o->ob_type->tp_as_number->nb_int != NULL) {\n\t\tobj = o->ob_type->tp_as_number->nb_int(o);\n\t\tif (obj != NULL) {\n\t\t\tlong_value = (longlong) PyLong_AsLongLong(obj);\n\t\t\tPy_DECREF(obj);\n\t\t}\n\t}\n\telse {\n\t\tPyErr_SetString(PyExc_NotImplementedError,\"\");\n\t}\n\t\n finish:\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_INTP)\n\tif ((long_value < MIN_INTP) || (long_value > MAX_INTP)) {\n\t\tPyErr_SetString(PyExc_ValueError,\n\t\t\t\t\"integer won't fit into a C intp\");\n\t\treturn -1;\n\t}\n#endif\n\treturn (intp) long_value;\n}\n\n\nstatic PyObject *array_int(PyArrayObject *v);\n\n/*OBJECT_API*/\nstatic int\nPyArray_PyIntAsInt(PyObject *o)\n{\n\tlong long_value = -1;\n\tPyObject *obj;\n\tstatic char *msg = \"an integer is required\";\n\tPyObject *arr;\n\tPyArray_Descr *descr;\n\tint ret;\n\n\t\n\tif (!o) {\n\t\tPyErr_SetString(PyExc_TypeError, msg);\n\t\treturn -1;\n\t}\n\n\tif (PyInt_Check(o)) {\n\t\tlong_value = (long) PyInt_AS_LONG(o);\n\t\tgoto finish;\n\t} else if (PyLong_Check(o)) {\n\t\tlong_value = (long) PyLong_AsLong(o);\n\t\tgoto finish;\n\t}\n\n\tdescr = &INT_Descr;\n\tarr=NULL;\n\tif (PyArray_Check(o)) {\n\t\tif (PyArray_SIZE(o)!=1 || !PyArray_ISINTEGER(o)) {\n\t\t\tPyErr_SetString(PyExc_TypeError, msg);\n\t\t\treturn -1;\n\t\t}\n\t\tPy_INCREF(descr);\n\t\tarr = PyArray_CastToType((PyArrayObject *)o, descr, 0);\n\t}\n\tif (PyArray_IsScalar(o, Integer)) {\n\t\tPy_INCREF(descr);\n\t\tarr = PyArray_FromScalar(o, descr);\n\t}\n\tif (arr != NULL) {\n\t\tret = *((int *)PyArray_DATA(arr));\n\t\tPy_DECREF(arr);\n\t\treturn ret;\n\t}\t\t\n\tif (o->ob_type->tp_as_number != NULL &&\t\t\\\n\t o->ob_type->tp_as_number->nb_int != NULL) {\n\t\tobj = o->ob_type->tp_as_number->nb_int(o);\n\t\tif (obj == NULL) return -1;\n\t\tlong_value = (long) PyLong_AsLong(obj);\n\t\tPy_DECREF(obj);\n\t}\n\telse if (o->ob_type->tp_as_number != NULL &&\t\t\t\\\n\t\t o->ob_type->tp_as_number->nb_long != NULL) {\n\t\tobj = o->ob_type->tp_as_number->nb_long(o);\n\t\tif (obj == NULL) return -1;\n\t\tlong_value = (long) PyLong_AsLong(obj);\n\t\tPy_DECREF(obj);\n\t}\t\t\n\telse {\n\t\tPyErr_SetString(PyExc_NotImplementedError,\"\");\n\t}\n\n finish:\n\tif error_converting(long_value) {\n\t\tPyErr_SetString(PyExc_TypeError, msg);\n\t\treturn -1;\n\t}\n\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\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 dest->descr, 0,\n dest->nd, FORTRAN_IF(dest), NULL);\n if (src == NULL) return -1;\n\n ret = PyArray_CopyInto(dest, src);\n Py_DECREF(src);\n return ret;\n}\n\n\n/* These are also old calls (should use PyArray_New) */\n\n/* They all zero-out the memory as previously done */\n\n/* steals reference to descr -- and enforces native byteorder on it.*/\n/*OBJECT_API\n Like FromDimsAndData but uses the Descr structure instead of typecode\n as input.\n*/\nstatic PyObject *\nPyArray_FromDimsAndDataAndDescr(int nd, int *d, \n PyArray_Descr *descr,\n char *data)\n{\n\tPyObject *ret;\n#if SIZEOF_INTP != SIZEOF_INT\n\tint i;\n\tintp newd[MAX_DIMS];\n#endif\n\n\tif (!PyArray_ISNBO(descr->byteorder))\n\t\tdescr->byteorder = '=';\n\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\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_BOOL)\n\t\tPyArrayScalar_RETURN_BOOL_FROM_LONG(*(Bool*)data);\n\telse if (type_num == PyArray_OBJECT) {\n\t\tPy_INCREF(*((PyObject **)data));\n\t\treturn *((PyObject **)data);\n\t}\n\titemsize = descr->elsize;\n type = descr->typeobj;\n copyswap = descr->f->copyswap;\n\tswap = !PyArray_ISNBO(descr->byteorder);\n\tif (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 >> 2;\n\n#ifndef Py_UNICODE_WIDE\n\t\t\tlength *= 2;\n#endif\n\t\t\t/* Need an extra slot and need to use \n\t\t\t Python memory manager */\n\t\t\tuni->str = NULL;\n\t\t\tdestptr = PyMem_NEW(Py_UNICODE, length+1);\n\t\t\tif (destptr == NULL) {\n Py_DECREF(obj);\n\t\t\t\treturn PyErr_NoMemory();\n\t\t\t}\n\t\t\tuni->str = (Py_UNICODE *)destptr;\n\t\t\tuni->str[0] = 0;\n\t\t\tuni->str[length] = 0;\n\t\t\tuni->length = length;\n\t\t\tuni->hash = -1;\n\t\t\tuni->defenc = NULL;\n#ifndef Py_UNICODE_WIDE\n /* Allocated enough for 2-characters per itemsize.\n\t\t\t Now convert from the data-buffer\n */\n\t\t\tif (!PyArray_ISNBO(descr->byteorder)) {\n\t\t\t\t/* byteswap the data */\n\t\t\t\tbyte_swap_vector(data, itemsize >> 2, 4);\n\t\t\t}\n\t\t\tlength = PyUCS2Buffer_FromUCS4(uni->str, (PyArray_UCS4 *)data,\n\t\t\t\t\t\t itemsize >> 2);\n\t\t\t/* Resize the unicode result */\n\t\t\tif (MyPyUnicode_Resize(uni, length) < 0) {\n\t\t\t\tPy_DECREF(obj);\n\t\t\t\treturn NULL;\n\t\t\t}\n\t\t\treturn obj;\n#endif\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_XDECREF(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, 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, NULL);\n\tif (arr == NULL) return -1;\n\n\tif ((mit->subspace != NULL) && (mit->consec)) {\n\t\tif (mit->iteraxes[0] > 0) { /* then we need to swap */\n\t\t\t_swap_axes(mit, (PyArrayObject **)&arr);\n\t\t}\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\n/* This checks the args for any fancy indexing objects */\n\n#define SOBJ_NOTFANCY 0 \n#define SOBJ_ISFANCY 1\n#define SOBJ_BADARRAY 2\n#define SOBJ_TOOMANY 3\n#define SOBJ_LISTTUP 4\n\nstatic int\nfancy_indexing_check(PyObject *args)\n{\n\tint i, n;\n\tPyObject *obj;\n\tint retval = SOBJ_NOTFANCY;\n\n\tif (PyTuple_Check(args)) {\n\t\tn = PyTuple_GET_SIZE(args);\n\t\tif (n >= MAX_DIMS) return SOBJ_TOOMANY;\n\t\tfor (i=0; i=MAX_DIMS) return SOBJ_ISFANCY;\n\t\tfor (i=0; i SOBJ_ISFANCY) return retval;\n\t\t}\n\t}\n\n\treturn retval;\n}\n\n/* Called when treating array object like a mapping -- called first from \n Python when using a[object] unless object is a standard slice object\n (not an extended one). \n\n*/\n\n/* There are two situations: \n\n 1 - the subscript is a standard view and a reference to the \n array can be returned\n\n 2 - the subscript uses Boolean masks or integer indexing and\n therefore a new array is created and returned. \n\n*/\n\n/* Always returns arrays */\n\nstatic PyObject *iter_subscript(PyArrayIterObject *, PyObject *); \n\n\nstatic PyObject *\narray_subscript(PyArrayObject *self, PyObject *op) \n{\n intp dimensions[MAX_DIMS], strides[MAX_DIMS];\n\tintp offset;\n int nd, oned, fancy;\n\tintp i;\n PyArrayObject *other;\n\tPyArrayMapIterObject *mit;\n\n\tif (PyString_Check(op) || PyUnicode_Check(op)) {\n\t\tif (self->descr->fields) {\n\t\t\tPyObject *obj;\n\t\t\tobj = PyDict_GetItem(self->descr->fields, op);\n\t\t\tif (obj != NULL) {\n\t\t\t\tPyArray_Descr *descr;\n\t\t\t\tint offset;\n\t\t\t\tPyObject *title;\n\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\tfancy = fancy_indexing_check(op);\n\n\tif (fancy != SOBJ_NOTFANCY) { \n\t\toned = ((self->nd == 1) && !(PyTuple_Check(op) &&\t\\\n\t\t\t\t\t PyTuple_GET_SIZE(op) > 1));\n\n\t\t/* wrap arguments into a mapiter object */\n\t\tmit = (PyArrayMapIterObject *)\\\n\t\t\tPyArray_MapIterNew(op, oned, fancy);\n\t\tif (mit == NULL) return NULL;\n\t\tif (oned) {\n\t\t\tPyArrayIterObject *it;\n\t\t\tPyObject *rval;\n\t\t\tit = (PyArrayIterObject *)PyArray_IterNew((PyObject *)self);\n\t\t\tif (it == NULL) {Py_DECREF(mit); return NULL;}\n\t\t\trval = iter_subscript(it, mit->indexobj);\n\t\t\tPy_DECREF(it);\n\t\t\tPy_DECREF(mit);\n\t\t\treturn rval;\n\t\t}\n PyArray_MapIterBind(mit, self);\n other = (PyArrayObject *)PyArray_GetMap(mit);\n Py_DECREF(mit);\n return (PyObject *)other;\n }\n\n\ti = PyArray_PyIntAsIntp(op);\n\tif (!error_converting(i)) {\n\t\tif (i < 0 && self->nd > 0) i = i+self->dimensions[0];\n\t\treturn array_big_item(self, i);\n\t}\n\tPyErr_Clear();\n\n\t/* Standard (view-based) Indexing */\n if ((nd = parse_index(self, op, dimensions, strides, &offset)) \n == -1) \n return NULL;\n\n\t/* This will only work if new array will be a view */\n\tPy_INCREF(self->descr);\n\tif ((other = (PyArrayObject *)\t\t\t\t\t\\\n\t PyArray_NewFromDescr(self->ob_type, self->descr,\n\t\t\t\t nd, dimensions,\n\t\t\t\t strides, self->data+offset, \n\t\t\t\t self->flags,\n\t\t\t\t (PyObject *)self)) == NULL) \n\t\treturn NULL;\n\n\n\tother->base = (PyObject *)self;\n\tPy_INCREF(self);\n\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, fancy;\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\tfancy = fancy_indexing_check(index);\n\n\tif (fancy != SOBJ_NOTFANCY) { \n\t\toned = ((self->nd == 1) && !(PyTuple_Check(index) && \\\n\t\t\t\t\t PyTuple_GET_SIZE(index) > 1));\n\n\t\tmit = (PyArrayMapIterObject *)\t\t\t\\\n\t\t\tPyArray_MapIterNew(index, oned, fancy);\n\t\tif (mit == NULL) return -1;\n\t\tif (oned) {\n\t\t\tPyArrayIterObject *it;\n\t\t\tint rval;\n\t\t\tit = (PyArrayIterObject *)PyArray_IterNew((PyObject *)self);\n\t\t\tif (it == NULL) {Py_DECREF(mit); return -1;}\n\t\t\trval = iter_ass_subscript(it, mit->indexobj, op);\n\t\t\tPy_DECREF(it);\n\t\t\tPy_DECREF(mit);\n\t\t\treturn rval;\n\t\t}\n PyArray_MapIterBind(mit, self);\n ret = PyArray_SetMap(mit, op);\n Py_DECREF(mit);\n return ret;\n }\n\t\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\t\t\tif (other == Py_None) {\n\t\t\t\tPy_INCREF(Py_False);\n\t\t\t\treturn Py_False;\n\t\t\t}\n /* Try to convert other to an array */\n\t\t\tif (!PyArray_Check(other)) {\n\t\t\t\tarray_other = PyArray_FromObject(other, \n\t\t\t\t\t\t\t\t self->descr->type_num, 0, 0);\n\t\t\t\t/* If not successful, then return the integer\n\t\t\t\t object 0. This fixes code that used to\n\t\t\t\t allow equality comparisons between arrays\n\t\t\t\t and other objects which would give a result\n\t\t\t\t of 0\n\t\t\t\t*/\n\t\t\t\tif ((array_other == NULL) ||\t\\\n\t\t\t\t (array_other == Py_None)) {\n\t\t\t\t\tPy_XDECREF(array_other);\n\t\t\t\t\tPyErr_Clear();\n\t\t\t\t\tPy_INCREF(Py_False);\n\t\t\t\t\treturn Py_False;\n\t\t\t\t}\n\t\t\t}\n\t\t\telse {\n\t\t\t\tPy_INCREF(other);\n\t\t\t\tarray_other = other;\n\t\t\t}\n result = PyArray_GenericBinaryFunction(self, \n\t\t\t\t\t\t\t array_other, \n\t\t\t\t\t\t\t n_ops.equal);\n /* If the comparison results in NULL, then the \n\t\t\t two array objects can not be compared together so \n\t\t\t return zero \n */\n Py_DECREF(array_other);\n if (result == NULL) {\n PyErr_Clear();\n Py_INCREF(Py_False);\n return Py_False;\n }\n return result;\n case Py_NE:\n\t\t\tif (other == Py_None) {\n\t\t\t\tPy_INCREF(Py_True);\n\t\t\t\treturn Py_True;\n\t\t\t}\n /* Try to convert other to an array */\n\t\t\tif (!PyArray_Check(other)) {\n\t\t\t\tarray_other = PyArray_FromObject(other, \n\t\t\t\t\t\t\t\t self->descr->type_num, 0, 0);\n\t\t\t\t/* If not successful, then objects cannot be \n\t\t\t\t compared and cannot be equal, therefore, \n\t\t\t\t return True;\n\t\t\t\t*/\n\t\t\t\tif ((array_other == NULL) ||\t\\\n\t\t\t\t (array_other == Py_None)) {\n\t\t\t\t\tPy_XDECREF(array_other);\n\t\t\t\t\tPyErr_Clear();\n\t\t\t\t\tPy_INCREF(Py_True);\n\t\t\t\t\treturn Py_True;\n\t\t\t\t}\n\t\t\t}\n\t\t\telse {\n\t\t\t\tPy_INCREF(other);\n\t\t\t\tarray_other = other;\n\t\t\t}\n\t\t\tresult = PyArray_GenericBinaryFunction(self, \n\t\t\t\t\t\t\t array_other, \n\t\t\t\t\t\t\t n_ops.not_equal);\n\t\t\tPy_DECREF(array_other);\n if (result == NULL) {\n PyErr_Clear();\n Py_INCREF(Py_True);\n return Py_True;\n }\n 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 = PyArray_NDIM(temp)-1;\n\t\treturn temp;\n\t}\n\telse {\n\t\tif (flags) {\n\t\t\ttemp = PyArray_CheckFromAny((PyObject *)arr, NULL, \n 0, 0, flags, NULL);\n\t\t\tif (temp == NULL) return NULL;\n\t\t}\n\t\telse {\n\t\t\tPy_INCREF(arr);\n\t\t\ttemp = (PyObject *)arr;\n\t\t}\n\t}\n\tif (*axis < 0) *axis += n;\n\tif ((*axis < 0) || (*axis >= n)) {\n\t\tPyErr_Format(PyExc_ValueError, \n\t\t\t \"axis(=%d) out of bounds\", *axis);\n\t\tPy_DECREF(temp);\n\t\treturn NULL;\n\t}\n\treturn temp;\n}\n\n#include \"arraymethods.c\"\n\n/* Lifted from numarray */\nstatic PyObject *\nPyArray_IntTupleFromIntp(int len, intp *vals)\n{\n\tint i;\n PyObject *intTuple = PyTuple_New(len);\n if (!intTuple) goto fail;\n for(i=0; i= SIZEOF_INTP\n\t\tif (!(op = PyNumber_Int(seq))) return -1;\n#else\n\t\tif (!(op = PyNumber_Long(seq))) return -1;\n#endif\n\t\tnd = 1;\n#if SIZEOF_LONG >= SIZEOF_INTP\n\t\tvals[0] = (intp ) PyInt_AsLong(op);\n#else\n\t\tvals[0] = (intp ) PyLong_AsLongLong(op);\n#endif\n\t\tPy_DECREF(op);\n\t} else {\n\t\tfor(i=0; i < MIN(nd,maxvals); i++) {\n\t\t\top = PySequence_GetItem(seq, i);\n\t\t\tif (op == NULL) return -1;\n#if SIZEOF_LONG >= SIZEOF_INTP\n\t\t\tvals[i]=(intp )PyInt_AsLong(op);\n#else\n\t\t\tvals[i]=(intp )PyLong_AsLongLong(op);\n#endif\n\t\t\tPy_DECREF(op);\n\t\t\tif(PyErr_Occurred()) return -1;\n\t\t}\n\t}\n\treturn nd;\n}\n\n\n/* Check whether the given array is stored contiguously (row-wise) in\n memory. */\nstatic int\n_IsContiguous(PyArrayObject *ap) \n{\n\tregister intp sd;\n\tregister intp dim;\n\tregister int i;\n \n\n\tif (ap->nd == 0) return 1;\n\tsd = ap->descr->elsize;\n\tif (ap->nd == 1) return (ap->dimensions[0] == 1 || \\\n\t\t\t\t sd == ap->strides[0]);\n\tfor (i = ap->nd-1; i >= 0; --i) {\n\t\tdim = ap->dimensions[i];\n\t\t/* contiguous by definition */\n\t\tif (dim == 0) return 1;\n\t\tif (ap->strides[i] != sd) return 0;\n\t\tsd *= dim;\n\t}\n\treturn 1;\n}\n\n\nstatic int \n_IsFortranContiguous(PyArrayObject *ap) \n{\n\tregister intp sd;\n\tregister intp dim;\n\tregister int i;\n\t\n\tif (ap->nd == 0) return 1;\n\tsd = ap->descr->elsize;\n\tif (ap->nd == 1) return (ap->dimensions[0] == 1 || \\\n\t\t\t\t sd == ap->strides[0]);\n\tfor (i=0; i< ap->nd; ++i) {\n\t\tdim = ap->dimensions[i];\n\t\t/* contiguous by definition */\n\t\tif (dim == 0) return 1; \n\t\tif (ap->strides[i] != sd) return 0;\n\t\tsd *= dim;\n\t}\n\treturn 1;\n}\n\nstatic int\n_IsAligned(PyArrayObject *ap) \n{\n\tint i, alignment, aligned=1;\n\tintp ptr;\n\tint type = ap->descr->type_num;\n\n\tif ((type == PyArray_STRING) || (type == PyArray_VOID))\n\t\treturn 1;\n\n\talignment = ap->descr->alignment;\n\tif (alignment == 1) return 1;\n\n\tptr = (intp) ap->data;\n aligned = (ptr % alignment) == 0;\n for (i=0; i nd; i++)\n aligned &= ((ap->strides[i] % alignment) == 0);\n return aligned != 0;\n}\n\nstatic Bool\n_IsWriteable(PyArrayObject *ap)\n{\n\tPyObject *base=ap->base;\n\tvoid *dummy;\n\tint n;\n\n\t/* If we own our own data, then no-problem */\n\tif ((base == NULL) || (ap->flags & OWN_DATA)) return TRUE;\n\n\t/* Get to the final base object \n\t If it is a writeable array, then return TRUE\n\t If we can find an array object \n\t or a writeable buffer object as the final base object\n\t or a string object (for pickling support memory savings).\n\t - this last could be removed if a proper pickleable \n\t buffer was added to Python.\n\t*/\n\n\twhile(PyArray_Check(base)) {\n\t\tif (PyArray_CHKFLAGS(base, OWN_DATA)) \n\t\t\treturn (Bool) (PyArray_ISWRITEABLE(base));\n\t\tbase = PyArray_BASE(base);\n\t}\n\n\t/* here so pickle support works seamlessly \n\t and unpickled array can be set and reset writeable \n\t -- could be abused -- */\n\tif PyString_Check(base) return TRUE;\n\n\tif (PyObject_AsWriteBuffer(base, &dummy, &n) < 0)\n\t\treturn FALSE;\n\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 For axes with a positive stride this function checks for a walk\n beyond the right end of the buffer, for axes with a negative stride,\n it checks for a walk beyond the left end of the buffer. Zero strides\n are disallowed.\n*/\n/*OBJECT_API*/\nstatic Bool\nPyArray_CheckStrides(int elsize, int nd, intp numbytes, intp offset,\n\t\t intp *dims, intp *newstrides)\n{\n\tint i;\n\t\n\tif (numbytes == 0) \n\t\tnumbytes = PyArray_MultiplyList(dims, nd) * elsize;\n\t\n\tfor (i=0; i 0) {\n\t\t\t/* The last stride does not need to be fully inside\n\t\t\t the buffer, only its first elsize bytes */\n\t\t\tif (offset + stride*(dims[i]-1)+elsize > numbytes) {\n\t\t\t\treturn FALSE;\n\t\t\t}\n\t\t}\n\t\telse if (stride < 0) {\n\t\t\tif (offset + stride*dims[i] < 0) {\n\t\t\t\treturn FALSE;\n\t\t\t}\n\t\t} else {\n\t\t\t/* XXX: Zero strides may be useful, but currently \n\t\t\t XXX: allowing them would lead to strange results,\n\t\t\t XXX: for example :\n\t\t\t XXX: >>> x = arange(5)\n\t\t\t XXX: >>> x.strides = 0\n\t\t\t XXX: >>> x += 1\n\t\t\t XXX: >>> x\n\t\t\t XXX: array([5, 5, 5, 5, 5]) */\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 /* which could also be sub-fields of a VOID array */\n\t\tif (descr->hasobject) {\n if (descr != &OBJECT_Descr) {\n PyErr_SetString(PyExc_TypeError,\n \"fields with object members \" \\\n \"not yet supported.\");\n goto fail;\n }\n\t\t\tmemset(data, 0, sd);\n\t\t}\n\t}\n\telse {\n self->flags &= ~OWN_DATA; /* If data is passed in, \n\t\t\t\t\t this object won't own it \n\t\t\t\t\t by default.\n\t\t\t\t\t Caller must arrange for \n\t\t\t\t\t this to be reset if truly\n\t\t\t\t\t desired */\n }\n self->data = data;\n\n /* call the __array_finalize__\n\t method if a subtype 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, NULL);\n\tif (newarr == NULL) return -1;\n\tfromptr = PyArray_DATA(newarr);\n\tsize=PyArray_SIZE(arr);\n\tswap=!PyArray_ISNOTSWAPPED(arr);\n\tcopyswap = arr->descr->f->copyswap;\n\tif (PyArray_ISONESEGMENT(arr)) {\n\t\tchar *toptr=PyArray_DATA(arr);\n\t\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\", /* XXX ? */\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 strides.ptr, NULL, fortran, NULL);\n if (ret == NULL) {descr=NULL;goto fail;}\n if (type_num == PyArray_OBJECT) { /* place Py_None */\n PyArray_FillObjectArray(ret, Py_None);\n }\n }\n else { /* buffer given -- use it */\n if (dims.len == 1 && dims.ptr[0] == -1) {\n dims.ptr[offset] = 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, offset,\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 offset + (char *)buffer.ptr, \n\t\t\t\t\t buffer.flags, NULL); \n if (ret == NULL) {descr=NULL; goto fail;}\n PyArray_UpdateFlags(ret, UPDATE_ALL_FLAGS);\n ret->base = buffer.base;\n Py_INCREF(buffer.base); \n }\n\n PyDimMem_FREE(dims.ptr);\n if (strides.ptr) PyDimMem_FREE(strides.ptr);\n return (PyObject *)ret;\n \n fail:\n\tPy_XDECREF(descr);\n if (dims.ptr) PyDimMem_FREE(dims.ptr);\n if (strides.ptr) PyDimMem_FREE(strides.ptr);\n return NULL;\n}\n\n\nstatic PyObject *\narray_iter(PyArrayObject *arr)\n{\n\tif (arr->nd == 0) {\n\t\tPyErr_SetString(PyExc_TypeError,\n\t\t\t\t\"iteration over a scalar (0-dim array)\");\n\t\treturn NULL;\n\t}\n\treturn PySeqIter_New((PyObject *)arr);\n}\n\n\n/******************* array attribute get and set routines ******************/\n\nstatic PyObject *\narray_ndim_get(PyArrayObject *self)\n{\n\treturn PyInt_FromLong(self->nd);\n}\n\nstatic PyObject *\narray_flags_get(PyArrayObject *self)\n{\n return 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->data - new->data,\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 *arraydescr_protocol_typestr_get(PyArray_Descr *);\n\nstatic PyObject *\narray_typestr_get(PyArrayObject *self)\n{\n\treturn arraydescr_protocol_typestr_get(self->descr);\n}\n\nstatic PyObject *\narray_descr_get(PyArrayObject *self) \n{\n\tPy_INCREF(self->descr);\n\treturn (PyObject *)self->descr;\n}\n\n\n/* If the type is changed. \n Also needing change: strides, itemsize\n\n Either itemsize is exactly the same\n or the array is single-segment (contiguous or fortran) with\n compatibile dimensions\n\n The shape and strides will be adjusted in that case as well.\n*/\n\nstatic int\narray_descr_set(PyArrayObject *self, PyObject *arg)\n{\n PyArray_Descr *newtype=NULL;\n intp newdim;\n int index;\n char *msg = \"new type not compatible with array.\";\n\n if (!(PyArray_DescrConverter(arg, &newtype)) ||\n newtype == NULL) {\n PyErr_SetString(PyExc_TypeError, \"invalid data-type for array\");\n\t\treturn -1;\n }\n\tif (newtype->type_num == PyArray_OBJECT || \\\n\t self->descr->type_num == PyArray_OBJECT) {\n\t\tPyErr_SetString(PyExc_TypeError, \\\n\t\t\t\t\"Cannot change descriptor for object\"\\\n\t\t\t\t\"array.\");\n\t\tPy_DECREF(newtype);\n\t\treturn -1;\n\t}\n\n\tif ((newtype->elsize != self->descr->elsize) &&\t\t\\\n\t (self->nd == 0 || !PyArray_ISONESEGMENT(self) || \\\n\t newtype->subarray)) goto fail;\n\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\t/* We would decref newtype here --- temp will \n\t\t steal a reference to it */\n\t\ttemp = (PyArrayObject *)\t\t\t\t\\\n\t\t\tPyArray_NewFromDescr(&PyArray_Type, newtype, self->nd,\n\t\t\t\t\t self->dimensions, self->strides,\n\t\t\t\t\t self->data, self->flags, NULL);\n\t\tPyDimMem_FREE(self->dimensions);\n\t\tself->dimensions = temp->dimensions;\n\t\tself->nd = temp->nd;\n\t\tself->strides = temp->strides;\n\t\tnewtype = temp->descr;\n\t\t/* Fool deallocator not to delete these*/\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, \"descr\");\n\tif (res) return res;\n\tPyErr_Clear();\n\n\t/* get default */\n\tdobj = PyTuple_New(2);\n\tif (dobj == NULL) return NULL;\n\tPyTuple_SET_ITEM(dobj, 0, PyString_FromString(\"\"));\n\tPyTuple_SET_ITEM(dobj, 1, array_typestr_get(self));\n\tres = PyList_New(1);\n\tif (res == NULL) {Py_DECREF(dobj); return NULL;}\n\tPyList_SET_ITEM(res, 0, dobj);\n\treturn res;\n}\n\nstatic PyObject *\narray_struct_get(PyArrayObject *self)\n{\n PyArrayInterface *inter;\n \n inter = (PyArrayInterface *)_pya_malloc(sizeof(PyArrayInterface));\n inter->version = 2;\n inter->nd = self->nd;\n inter->typekind = self->descr->kind;\n inter->itemsize = self->descr->elsize;\n inter->flags = self->flags;\n /* reset unused flags */\n\tinter->flags &= ~(UPDATEIFCOPY | OWNDATA); \n\tif (PyArray_ISNOTSWAPPED(self)) inter->flags |= NOTSWAPPED;\n inter->strides = self->strides;\n inter->shape = self->dimensions;\n inter->data = self->data;\n\tPy_INCREF(self);\n return PyCObject_FromVoidPtrAndDesc(inter, self, gentype_struct_free);\n}\n\nstatic PyObject *\narray_base_get(PyArrayObject *self)\n{\n\tif (self->base == NULL) {\n\t\tPy_INCREF(Py_None);\n\t\treturn Py_None;\n\t}\n\telse {\n\t\tPy_INCREF(self->base);\n\t\treturn self->base;\n\t}\n}\n\n\nstatic PyObject *\narray_real_get(PyArrayObject *self)\n{\n\tPyArrayObject *ret;\n\n\tif (PyArray_ISCOMPLEX(self)) {\n\t\tret = (PyArrayObject *)PyArray_New(self->ob_type,\n\t\t\t\t\t\t self->nd,\n\t\t\t\t\t\t self->dimensions,\n\t\t\t\t\t\t self->descr->type_num - \\\n\t\t\t\t\t\t PyArray_NUM_FLOATTYPE,\n\t\t\t\t\t\t self->strides,\n\t\t\t\t\t\t self->data,\n\t\t\t\t\t\t 0,\n\t\t\t\t\t\t self->flags, (PyObject *)self);\n\t\tif (ret == NULL) return NULL;\n\t\tret->flags &= ~CONTIGUOUS;\n\t\tret->flags &= ~FORTRAN;\n\t\tPy_INCREF(self);\n\t\tret->base = (PyObject *)self;\n\t\treturn (PyObject *)ret;\n\t}\n\telse {\n\t\tPy_INCREF(self);\n\t\treturn (PyObject *)self;\n\t}\n}\n\n\nstatic int\narray_real_set(PyArrayObject *self, PyObject *val)\n{\n\tPyArrayObject *ret;\n\tPyArrayObject *new;\n\tint rint;\n\n\tnew = (PyArrayObject *)PyArray_FromAny(val, NULL, 0, 0, 0, NULL);\n\tif (new == NULL) return -1;\n\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, NULL); \n\t\tif (new == NULL) return -1;\n\t\tret = (PyArrayObject *)PyArray_New(self->ob_type,\n\t\t\t\t\t\t self->nd,\n\t\t\t\t\t\t self->dimensions,\n\t\t\t\t\t\t self->descr->type_num - \\\n\t\t\t\t\t\t PyArray_NUM_FLOATTYPE,\n\t\t\t\t\t\t self->strides,\n \t\t\t\t\t\t self->data +\t\t\\\n\t\t\t\t\t\t (self->descr->elsize >> 1),\n\t\t\t\t\t\t 0,\n\t\t\t\t\t\t self->flags, (PyObject *)self);\n\t\tif (ret == NULL) {\n\t\t\tPy_DECREF(new); \n\t\t\treturn -1;\n\t\t}\n\t\tret->flags &= ~CONTIGUOUS;\n\t\tret->flags &= ~FORTRAN;\n\t\tPy_INCREF(self);\n\t\tret->base = (PyObject *)self;\n\t\trint = PyArray_CopyInto(ret, new);\n\t\tPy_DECREF(ret);\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), NULL);\n\tif (arr == NULL) return -1;\n\tarrit = (PyArrayIterObject *)PyArray_IterNew(arr);\n\tif (arrit == NULL) goto exit;\n\tselfit = (PyArrayIterObject *)PyArray_IterNew((PyObject *)self);\n\tif (selfit == NULL) goto exit;\n\n swap = PyArray_ISNOTSWAPPED(self) != PyArray_ISNOTSWAPPED(arr);\n copyswap = self->descr->f->copyswap;\n if (PyArray_ISOBJECT(self)) {\n while(selfit->index < selfit->size) {\n Py_XDECREF(*((PyObject **)selfit->dataptr));\n Py_INCREF(*((PyObject **)arrit->dataptr)); \n memmove(selfit->dataptr, arrit->dataptr, \n sizeof(PyObject *));\n PyArray_ITER_NEXT(selfit);\n PyArray_ITER_NEXT(arrit);\n if (arrit->index == arrit->size) \n PyArray_ITER_RESET(arrit);\n }\n retval = 0; \n goto exit;\n }\n\n\twhile(selfit->index < selfit->size) {\n\t\tmemmove(selfit->dataptr, arrit->dataptr, self->descr->elsize);\n copyswap(selfit->dataptr, NULL, swap, self->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\t{\"dtype\",\n\t (getter)array_descr_get,\n\t (setter)array_descr_set,\n\t \"get(set) data-type-descriptor for array\"},\n {\"real\", \n\t (getter)array_real_get, \n\t (setter)array_real_set, \n\t \"real part of array\"},\n {\"imag\", \n\t (getter)array_imag_get, \n\t (setter)array_imag_set, \n\t \"imaginary part of array\"},\n\t{\"flat\", \n\t (getter)array_flat_get, \n\t (setter)array_flat_set, \n\t \"a 1-d view of a contiguous array\"}, \n\t{\"__array_data__\", \n\t (getter)array_dataptr_get,\n\t NULL,\n\t \"Array protocol: data\"},\n\t{\"__array_typestr__\",\n\t (getter)array_typestr_get,\n\t NULL,\n\t \"Array protocol: typestr\"},\n\t{\"__array_descr__\",\n\t (getter)array_protocol_descr_get,\n\t NULL,\n\t \"Array protocol: descr\"},\n\t{\"__array_shape__\", \n\t (getter)array_shape_get,\n\t NULL,\n\t \"Array protocol: shape\"},\n\t{\"__array_strides__\",\n\t (getter)array_protocol_strides_get,\n\t NULL,\n\t \"Array protocol: strides\"},\n {\"__array_struct__\",\n (getter)array_struct_get,\n NULL,\n \"Array protocol: struct\"},\n\t{\"__array_priority__\",\n\t (getter)array_priority_get,\n\t NULL,\n\t \"Array priority\"},\n \t{NULL, NULL, NULL, NULL}, /* Sentinel */\n};\n\n/****************** end of attribute get and set routines *******************/\n\n\nstatic PyObject *\narray_alloc(PyTypeObject *type, int nitems)\n{\n PyObject *obj;\n /* nitems will always be 0 */ \n obj = (PyObject *)_pya_malloc(sizeof(PyArrayObject));\n PyObject_Init(obj, type);\n return obj;\n}\n\n\nstatic char Arraytype__doc__[] = \n \"A array object represents a multidimensional, homogeneous array\\n\"\n\t\" of fixed-size items. An associated data-type-descriptor object\\n\"\n\t\" details the data-type in an array (including byteorder and any\\n\"\n\t\" fields). An array can be constructed using the numpy.array\\n\"\n\t\" command. Arrays are sequence, mapping and numeric objects.\\n\"\n\t\" More information is available in the numpy module and by looking\\n\"\n\t\" at the methods and attributes of an array.\\n\\n\"\n\t\" ndarray.__new__(subtype, shape=, dtype=int_, buffer=None, \\n\"\n\t\" offset=0, strides=None, fortran=False)\\n\\n\"\n\t\" There are two modes of creating an array using __new__:\\n\"\n\t\" 1) If buffer is None, then only shape, dtype, and fortran \\n\"\n\t\" are used\\n\"\n\t\" 2) If buffer is an object exporting the buffer interface, then\\n\"\n\t\" all keywords are interpreted.\\n\"\n\t\" The dtype parameter can be any object that can be interpreted \\n\"\n\t\" as a numpy.dtype object.\\n\\n\"\n\t\" No __init__ method is needed because the array is fully \\n\"\n\t\" initialized after the __new__ method.\";\n\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, 4*n);\n\t\telse\n\t\t\t*itemsize = MAX(*itemsize, n);\n\t\treturn 0;\n\t}\n\tfor (i=0; i n_lower) n_lower = d[1];\n }\n d[1] = n_lower;\n\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, 4*minsize);\n\t\t}\n\t\telse {\n\t\t\ttestsize = MAX(chksize, minsize);\n\t\t}\n\t\tif (testsize != outtype->elsize) {\n\t\t\tPyArray_DESCR_REPLACE(outtype);\n\t\t\touttype->elsize = testsize;\n\t\t\tPy_XDECREF(outtype->fields);\n\t\t\touttype->fields = NULL;\n\t\t}\n\t}\n\treturn outtype;\n}\n\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#ifndef Py_UNICODE_WIDE\n\t\tchktype->elsize <<= 1;\n#endif\t\t\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\t} else if (PyLong_Check(op)) {\n\t\t/* if integer can fit into a longlong then return that\n\t\t*/\n\t\tif ((PyLong_AsLongLong(op) == -1) && PyErr_Occurred()) {\n\t\t\tPyErr_Clear();\n\t\t\tgoto deflt;\n\t\t}\n\t\tchktype = PyArray_DescrFromType(PyArray_LONGLONG);\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 *= 4;\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\tif (ret->nd > 0) {\n\t\tPyErr_SetString(PyExc_ValueError,\n\t\t\t\t\"shape-mismatch on array construction\");\n\t\tPy_DECREF(ret);\n\t\treturn NULL;\n\t}\n\n ret->descr->f->setitem(op, ret->data, ret);\n\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 */\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\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\t\tgoto fail;\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\t\tgoto fail;\n }\n\t\n\tif(discover_dimensions(s,nd,d, !stop_at_string) == -1) goto fail;\n\n\tif (itemsize == 0 && PyTypeNum_ISEXTENDED(type)) {\n\t\tif (discover_itemsize(s, nd, &itemsize) == -1) goto fail;\n\t\tif (type == PyArray_UNICODE) itemsize*=4;\n\t}\n\n\tif (itemsize != typecode->elsize) {\n\t\tPyArray_DESCR_REPLACE(typecode);\n\t\ttypecode->elsize = itemsize;\n\t}\n\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) return NULL;\n if(Assign_Array(r,s) == -1) {\n\t\tPy_DECREF(r);\n\t\treturn NULL;\n\t}\n return (PyObject*)r;\n\n fail:\n\tPy_DECREF(typecode);\n\treturn NULL;\n}\n\n\n/*OBJECT_API\n Is the typenum valid?\n*/\nstatic int \nPyArray_ValidType(int type) \n{\n\tPyArray_Descr *descr;\n\tint res=TRUE;\n\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 << 2;\n\t\tif (mpd->type_num == PyArray_UNICODE &&\n\t\t at->type_num == PyArray_STRING) \n\t\t\tat->elsize = mpd->elsize >> 2;\n\t\tif (at->type_num == PyArray_VOID)\n\t\t\tat->elsize = mpd->elsize;\n\t}\n\n\tout = PyArray_NewFromDescr(mp->ob_type, at,\n\t\t\t\t mp->nd, \n\t\t\t\t mp->dimensions, \n\t\t\t\t NULL, NULL, \n\t\t\t\t fortran,\n\t\t\t\t (PyObject *)mp);\n\n\tif (out == NULL) return NULL;\n\tret = PyArray_CastTo((PyArrayObject *)out, mp);\n\tif (ret != -1) return out;\n\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 */\n/*OBJECT_API*/\nstatic PyObject *\nPyArray_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 break;\n\tcase PyArray_STRINGLTR:\n\t\ttype_num = PyArray_STRING;\n\t\tbreak;\n\tcase PyArray_UNICODELTR:\n\t\ttype_num = PyArray_UNICODE;\n\t\tsize <<= 2;\n\t\tbreak;\n\tcase 'V':\n\t\ttype_num = PyArray_VOID;\n\t\tbreak;\n\tdefault:\n\t\t_MY_FAIL\n\t}\n\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/* OBJECT_API */\nstatic PyObject *\nPyArray_FromStructInterface(PyObject *input)\n{\n\tPyArray_Descr *thetype;\n\tchar buf[40];\n\tPyArrayInterface *inter;\n\tPyObject *attr, *r;\n\tchar endian = PyArray_NATBYTE;\n \n attr = PyObject_GetAttrString(input, \"__array_struct__\");\n if (attr == NULL) {\n\t\tPyErr_Clear();\n\t\treturn Py_NotImplemented;\n\t}\n if (!PyCObject_Check(attr) || \\\n ((inter=((PyArrayInterface *)\\\n\t\t PyCObject_AsVoidPtr(attr)))->version != 2)) {\n PyErr_SetString(PyExc_ValueError, \"invalid __array_struct__\");\n\t\tPy_DECREF(attr);\n return NULL;\n }\n\tif ((inter->flags & NOTSWAPPED) != NOTSWAPPED) {\n\t\tendian = PyArray_OPPBYTE;\n\t\tinter->flags &= ~NOTSWAPPED;\n\t}\n\n snprintf(buf, 40, \"%c%c%d\", endian, inter->typekind, inter->itemsize);\n if (!(thetype=_array_typedescr_fromstr(buf))) {\n\t\tPy_DECREF(attr);\n return NULL;\n }\n\n r = PyArray_NewFromDescr(&PyArray_Type, thetype,\n\t\t\t\t inter->nd, inter->shape,\n\t\t\t\t inter->strides, inter->data,\n\t\t\t\t inter->flags, NULL);\n\tPy_INCREF(input);\n\tPyArray_BASE(r) = input;\n Py_DECREF(attr);\n PyArray_UpdateFlags((PyArrayObject *)r, UPDATE_ALL_FLAGS);\n return r;\n}\n\n/*OBJECT_API*/\nstatic PyObject *\nPyArray_FromInterface(PyObject *input)\n{\n\tPyObject *attr=NULL, *item=NULL;\n PyObject *tstr=NULL, *shape=NULL; \n PyArrayObject *ret;\n\tPyArray_Descr *type=NULL;\n\tchar *data;\n\tint buffer_len;\n\tint res, i, n;\n\tintp dims[MAX_DIMS], strides[MAX_DIMS];\n\tint dataflags = BEHAVED_FLAGS;\n\n\t/* Get the memory from __array_data__ and __array_offset__ */\n\t/* Get the shape */\n\t/* Get the typestring -- ignore array_descr */\n\t/* Get the strides */\n\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\treturn NULL;\n\t\t}\n\t\tif (n != PyTuple_GET_SIZE(attr)) {\n\t\t\tPyErr_SetString(PyExc_ValueError, \n\t\t\t\t\t\"mismatch in length of \"\\\n\t\t\t\t\t\"__array_strides__ and \"\\\n\t\t\t\t\t\"__array_shape__\");\n\t\t\tPy_DECREF(attr);\n\t\t\tPy_DECREF(ret);\n\t\t\treturn NULL;\n\t\t}\n\t\tfor (i=0; istrides, strides, n*sizeof(intp));\n\t}\n\telse PyErr_Clear();\n\tPyArray_UpdateFlags(ret, UPDATE_ALL_FLAGS);\n\treturn (PyObject *)ret;\n\n fail:\n\tPy_XDECREF(attr);\n\tPy_XDECREF(shape);\n\tPy_XDECREF(tstr);\n\treturn NULL;\n}\n\n/* OBJECT_API*/\nstatic PyObject *\nPyArray_FromArrayAttr(PyObject *op, PyArray_Descr *typecode, PyObject *context) \n{\n PyObject *new;\n PyObject *array_meth;\n\n array_meth = PyObject_GetAttrString(op, \"__array__\");\n if (array_meth == NULL) {PyErr_Clear(); return Py_NotImplemented;}\n if (context == NULL) {\n if (typecode == NULL) new = PyObject_CallFunction(array_meth, NULL);\n else new = PyObject_CallFunction(array_meth, \"O\", typecode);\n }\n else {\n if (typecode == NULL) {\n new = PyObject_CallFunction(array_meth, \"OO\", Py_None, context);\n if (new == NULL && PyErr_ExceptionMatches(PyExc_TypeError)) {\n PyErr_Clear();\n new = PyObject_CallFunction(array_meth, \"\");\n }\n }\n else {\n new = PyObject_CallFunction(array_meth, \"OO\", typecode, context);\n if (new == NULL && PyErr_ExceptionMatches(PyExc_TypeError)) {\n PyErr_Clear();\n new = PyObject_CallFunction(array_meth, \"O\", typecode);\n }\n }\n }\n Py_DECREF(array_meth);\n if (new == NULL) return NULL;\n if (!PyArray_Check(new)) {\n PyErr_SetString(PyExc_ValueError, \n \"object __array__ method not \" \\\n \"producing an array\");\n Py_DECREF(new);\n return NULL;\n }\n return new;\n} \n\n/* Does not check for ENSURECOPY and NOTSWAPPED in flags */\n/* Steals a reference to newtype --- which can be NULL */\n/*OBJECT_API*/\nstatic PyObject *\nPyArray_FromAny(PyObject *op, PyArray_Descr *newtype, int min_depth, \n int max_depth, int flags, PyObject *context) \n{\n /* This is the main code to make a NumPy array from a Python\n Object. It is called from lot's of different places which\n is why there are so many checks. The comments try to\n explain some of the checks. */\n\n PyObject *r=NULL;\n int seq = FALSE;\n \n\t/* Is input object already an array? */\n\t/* This is where the flags are used */\n if (PyArray_Check(op)) \n\t\tr = PyArray_FromArray((PyArrayObject *)op, newtype, flags);\n\telse if (PyArray_IsScalar(op, Generic)) {\n\t\tr = PyArray_FromScalar(op, newtype);\n\t}\n else if (((r = PyArray_FromStructInterface(op))!=Py_NotImplemented)|| \\\n ((r = PyArray_FromInterface(op)) != Py_NotImplemented) || \\\n ((r = PyArray_FromArrayAttr(op, newtype, context)) \\\n != Py_NotImplemented)) {\n PyObject *new;\n if (r == NULL) return NULL;\n if (newtype != NULL || flags != 0) {\n new = PyArray_FromArray((PyArrayObject *)r, newtype, flags);\n Py_DECREF(r);\n r = new;\n }\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\n\t\t\tPy_INCREF(newtype);\n\t\t\tr = Array_FromSequence(op, newtype, flags & FORTRAN,\n\t\t\t\t\t min_depth, max_depth);\n\t\t\tif (PyErr_Occurred() && r == NULL) {\n /* It wasn't really a sequence after all.\n * Try interpreting it as a scalar */\n\t\t\t\tPyErr_Clear();\n\t\t\t}\n else {\n\t\t\t\tseq = TRUE;\n\t\t\t\tPy_DECREF(newtype);\n\t\t\t}\n }\n if (!seq)\n\t\t\tr = Array_FromScalar(op, newtype);\n\t}\n\n /* If we didn't succeed return NULL */\n if (r == NULL) return NULL;\n\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: PyArray_FromAny \"\\\n\t\t\t\t\"not producing an array\");\n\t\tPy_DECREF(r);\n return NULL;\n }\n\n if (min_depth != 0 && ((PyArrayObject *)r)->nd < min_depth) {\n PyErr_SetString(PyExc_ValueError, \n \"object of too small depth for desired array\");\n Py_DECREF(r);\n return NULL;\n }\n if (max_depth != 0 && ((PyArrayObject *)r)->nd > max_depth) {\n PyErr_SetString(PyExc_ValueError, \n \"object too deep for desired array\");\n Py_DECREF(r);\n return NULL;\n }\n return r;\n}\n\n/* new reference -- accepts NULL for mintype*/\n/*OBJECT_API*/\nstatic PyArray_Descr *\nPyArray_DescrFromObject(PyObject *op, PyArray_Descr *mintype)\n{\n\treturn _array_find_type(op, mintype, MAX_DIMS);\n}\n\n/*OBJECT_API\n Return the typecode of the array a Python object would be converted\n to\n*/\nstatic int \nPyArray_ObjectType(PyObject *op, int minimum_type) \n{\n\tPyArray_Descr *intype;\n\tPyArray_Descr *outtype;\n\tint ret;\n\n\tintype = PyArray_DescrFromType(minimum_type);\n\tif (intype == NULL) PyErr_Clear();\n\touttype = _array_find_type(op, intype, MAX_DIMS);\n\tret = outtype->type_num;\n\tPy_DECREF(outtype);\n\tPy_DECREF(intype);\n\treturn ret;\n}\n\n\n/* flags is any of \n CONTIGUOUS, \n FORTRAN,\n ALIGNED, \n WRITEABLE, \n NOTSWAPPED,\n ENSURECOPY, \n UPDATEIFCOPY,\n FORCECAST,\n ENSUREARRAY\n\n or'd (|) together\n\n Any of these flags present means that the returned array should \n guarantee that aspect of the array. Otherwise the returned array\n won't guarantee it -- it will depend on the object as to whether or \n not it has such features. \n\n Note that ENSURECOPY is enough\n to guarantee CONTIGUOUS, ALIGNED and WRITEABLE\n and therefore it is redundant to include those as well. \n\n BEHAVED_FLAGS == ALIGNED | WRITEABLE\n CARRAY_FLAGS = CONTIGUOUS | BEHAVED_FLAGS\n FARRAY_FLAGS = FORTRAN | BEHAVED_FLAGS\n \n FORTRAN can be set in the FLAGS to request a FORTRAN array. \n Fortran arrays are always behaved (aligned, \n notswapped, and writeable) and not (C) CONTIGUOUS (if > 1d). \n\n UPDATEIFCOPY flag sets this flag in the returned array if a copy is\n made and the base argument points to the (possibly) misbehaved array.\n When the new array is deallocated, the original array held in base\n is updated with the contents of the new array. \n\n FORCECAST will cause a cast to occur regardless of whether or not\n it is safe. \n*/\n\n\n/* steals a reference to descr -- accepts NULL */\n/*OBJECT_API*/\nstatic PyObject *\nPyArray_CheckFromAny(PyObject *op, PyArray_Descr *descr, int min_depth, \n int max_depth, int requires, PyObject *context) \n{\n\tif (requires & NOTSWAPPED) {\n\t\tif (!descr && PyArray_Check(op) && \\\n\t\t !PyArray_ISNBO(PyArray_DESCR(op)->byteorder)) {\n\t\t\tdescr = PyArray_DescrNew(PyArray_DESCR(op));\n\t\t}\n\t\telse if ((descr && !PyArray_ISNBO(descr->byteorder))) {\n\t\t\tPyArray_DESCR_REPLACE(descr);\n\t\t}\n\t\tdescr->byteorder = PyArray_NATIVE;\n\t}\n\n\treturn PyArray_FromAny(op, descr, min_depth, max_depth,\n requires, context);\n}\n\n/* This is a quick wrapper around PyArray_FromAny(op, NULL, 0, 0, \n ENSUREARRAY) */\n/* that special cases Arrays and PyArray_Scalars up front */\n/* It *steals a reference* to the object */\n/* It also guarantees that the result is PyArray_Type 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_FromAny(op, NULL, 0, 0, ENSUREARRAY, NULL);\n Py_DECREF(op);\n return new;\n}\n\n/*OBJECT_API\n Check the type coercion rules.\n*/\nstatic int \nPyArray_CanCastSafely(int fromtype, int totype) \n{\n\tPyArray_Descr *from, *to;\n\tregister int felsize, telsize;\n\n if (fromtype == totype) return 1;\n if (fromtype == PyArray_BOOL) return 1;\n\tif (totype == PyArray_BOOL) return 0;\n if (totype == PyArray_OBJECT || totype == PyArray_VOID) return 1;\n\tif (fromtype == PyArray_OBJECT || fromtype == PyArray_VOID) return 0;\n\n\tfrom = PyArray_DescrFromType(fromtype);\n\tto = PyArray_DescrFromType(totype);\n\ttelsize = to->elsize;\n\tfelsize = from->elsize;\n\tPy_DECREF(from);\n\tPy_DECREF(to);\n\n switch(fromtype) {\n case PyArray_BYTE:\n\tcase PyArray_SHORT:\n case PyArray_INT:\n case PyArray_LONG:\n\tcase PyArray_LONGLONG:\n\t\tif (PyTypeNum_ISINTEGER(totype)) {\n\t\t\tif (PyTypeNum_ISUNSIGNED(totype)) {\n\t\t\t\treturn (telsize > felsize);\n\t\t\t}\n\t\t\telse {\n\t\t\t\treturn (telsize >= felsize);\n\t\t\t}\n\t\t}\n\t\telse if (PyTypeNum_ISFLOAT(totype)) {\n if (felsize < 8)\n return (telsize > felsize);\n else\n return (telsize >= felsize);\n\t\t}\n\t\telse if (PyTypeNum_ISCOMPLEX(totype)) {\n if (felsize < 8)\n return ((telsize >> 1) > felsize);\n else\n return ((telsize >> 1) >= felsize);\n\t\t}\n\t\telse return totype > fromtype;\n case PyArray_UBYTE:\n case PyArray_USHORT:\n case PyArray_UINT:\n\tcase PyArray_ULONG:\n\tcase PyArray_ULONGLONG:\n\t\tif (PyTypeNum_ISINTEGER(totype)) {\n\t\t\tif (PyTypeNum_ISSIGNED(totype)) {\n\t\t\t\treturn (telsize > felsize);\n\t\t\t}\n\t\t\telse {\n\t\t\t\treturn (telsize >= felsize);\n\t\t\t}\n\t\t}\n\t\telse if (PyTypeNum_ISFLOAT(totype)) {\n if (felsize < 8)\n return (telsize > felsize);\n else\n return (telsize >= felsize);\n\t\t}\n\t\telse if (PyTypeNum_ISCOMPLEX(totype)) {\n if (felsize < 8)\n return ((telsize >> 1) > felsize);\n else\n return ((telsize >> 1) >= felsize);\n\t\t}\n\t\telse return totype > fromtype;\n case PyArray_FLOAT:\n case PyArray_DOUBLE:\n\tcase PyArray_LONGDOUBLE:\n\t\tif (PyTypeNum_ISCOMPLEX(totype)) \n\t\t\treturn ((telsize >> 1) >= felsize);\n\t\telse\n\t\t\treturn (totype > fromtype);\n case PyArray_CFLOAT:\n case PyArray_CDOUBLE:\n\tcase PyArray_CLONGDOUBLE:\n\t\treturn (totype > fromtype);\n\tcase PyArray_STRING:\n\tcase PyArray_UNICODE:\n\t\treturn (totype > fromtype);\n default:\n return 0;\n }\n}\n\n/* leaves reference count alone --- cannot be NULL*/\n/*OBJECT_API*/\nstatic Bool\nPyArray_CanCastTo(PyArray_Descr *from, PyArray_Descr *to)\n{\n\tint fromtype=from->type_num;\n\tint totype=to->type_num;\n\tBool ret;\n\n\tret = (Bool) PyArray_CanCastSafely(fromtype, totype);\n\tif (ret) { /* Check String and Unicode more closely */\n\t\tif (fromtype == PyArray_STRING) {\n\t\t\tif (totype == PyArray_STRING) {\n\t\t\t\tret = (from->elsize <= to->elsize);\n\t\t\t}\n\t\t\telse if (totype == PyArray_UNICODE) {\n\t\t\t\tret = (from->elsize << 2 \\\n\t\t\t\t <= to->elsize);\n\t\t\t}\n\t\t}\n\t\telse if (fromtype == PyArray_UNICODE) {\n\t\t\tif (totype == PyArray_UNICODE) {\n\t\t\t\tret = (from->elsize <= to->elsize);\n\t\t\t}\n\t\t}\n\t\t/* TODO: If totype is STRING or unicode \n\t\t see if the length is long enough to hold the\n\t\t stringified value of the object.\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, NULL);\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 FORCECAST | ALIGNED, NULL);\n\t\t\tif (new==NULL) goto fail;\n Py_DECREF(obj);\n\t\t\tobj = new;\n\t\t\tr = iter_subscript_int(self, (PyArrayObject *)obj);\n\t\t}\n\t\telse {\n\t\t\tgoto fail;\n\t\t}\n\t\tPy_DECREF(obj);\n\t\treturn r;\n\t}\n\telse Py_DECREF(indtype);\n\n\n fail:\n\tif (!PyErr_Occurred())\n\t\tPyErr_SetString(PyExc_IndexError, \"unsupported iterator index\");\n\tPy_XDECREF(indtype);\n\tPy_XDECREF(obj);\n\treturn NULL;\n\n}\n\n\nstatic int\niter_ass_sub_Bool(PyArrayIterObject *self, PyArrayObject *ind,\n\t\t PyArrayIterObject *val, int swap)\n{\n\tint index, strides, itemsize;\n\tchar *dptr;\n PyArray_CopySwapFunc *copyswap;\n\n\tif (ind->nd != 1) {\n\t\tPyErr_SetString(PyExc_ValueError, \n\t\t\t\t\"boolean index array should have 1 dimension\");\n\t\treturn -1;\n\t}\n\titemsize = self->ao->descr->elsize;\n\tindex = ind->dimensions[0];\n\tstrides = ind->strides[0];\n\tdptr = ind->data;\n\tPyArray_ITER_RESET(self);\n\t/* Loop over Boolean array */\n copyswap = self->ao->descr->f->copyswap;\n\twhile(index--) {\n\t\tif (*((Bool *)dptr) != 0) {\n copyswap(self->dataptr, val->dataptr, swap,\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, NULL);\n\tif (arrval==NULL) return -1;\n\tval_it = (PyArrayIterObject *)PyArray_IterNew(arrval);\n\tif (val_it==NULL) goto finish;\n\n\t/* Check for Boolean -- this is first becasue\n\t Bool is a subclass of Int */\n\n copyswap = PyArray_DESCR(arrval)->f->copyswap;\n\tswap = (PyArray_ISNOTSWAPPED(self->ao)!=PyArray_ISNOTSWAPPED(arrval));\n\tif (PyBool_Check(ind)) {\n\t\tif (PyObject_IsTrue(ind)) {\n copyswap(self->dataptr, PyArray_DATA(arrval), \n swap, 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, NULL);\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_CheckFromAny(obj, indtype, 0, 0, \n FORCECAST | BEHAVED_NS_FLAGS, NULL);\n\t\t\tPy_DECREF(obj);\n\t\t\tobj = new;\n\t\t\tif (new==NULL) goto finish;\n\t\t\tif (iter_ass_sub_int(self, (PyArrayObject *)obj,\n\t\t\t\t\t val_it, swap) < 0)\n\t\t\t\tgoto finish;\n\t\t\tretval=0;\n\t\t}\n\t}\n\n finish:\n\tif (!PyErr_Occurred() && retval < 0)\n\t\tPyErr_SetString(PyExc_IndexError, \n\t\t\t\t\"unsupported iterator index\");\n\tPy_XDECREF(indtype);\n\tPy_XDECREF(obj);\n\tPy_XDECREF(val_it);\n\tPy_XDECREF(arrval);\n\treturn retval;\n\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 {\"index\", T_INT, offsetof(PyArrayIterObject, index), RO, NULL},\n\t{NULL},\n};\n\nstatic PyObject *\niter_coords_get(PyArrayIterObject *self)\n{\n int nd;\n nd = self->ao->nd;\n if (self->contiguous) { /* coordinates not kept track of --- need to generate\n from index */\n intp val;\n int i;\n val = self->index;\n for (i=0;icoordinates[i] = val / self->factors[i];\n val = val % self->factors[i];\n }\n }\n return PyArray_IntTupleFromIntp(nd, self->coordinates);\n}\n\nstatic PyGetSetDef iter_getsets[] = {\n\t{\"coords\", \n\t (getter)iter_coords_get,\n\t NULL,\n\t \"An N-d tuple of current coordinates.\"},\n\t{NULL, NULL, NULL, NULL},\n};\n\nstatic PyTypeObject PyArrayIter_Type = {\n PyObject_HEAD_INIT(NULL)\n 0,\t\t\t\t\t /* ob_size */\n \"numpy.flatiter\",\t\t /* tp_name */\n sizeof(PyArrayIterObject), /* tp_basicsize */\n 0,\t\t\t\t\t /* tp_itemsize */\n /* methods */\n (destructor)arrayiter_dealloc,\t\t/* tp_dealloc */\n 0,\t\t\t\t\t/* tp_print */\n 0,\t\t\t\t\t/* tp_getattr */\n 0,\t\t\t\t\t/* tp_setattr */\n 0,\t\t\t\t\t/* tp_compare */\n 0,\t\t\t\t\t/* tp_repr */\n 0,\t\t\t\t\t/* tp_as_number */\n 0, \t\t\t /* tp_as_sequence */\n &iter_as_mapping, \t /* tp_as_mapping */\n 0,\t\t\t\t\t/* tp_hash */\n 0,\t\t\t\t\t/* tp_call */\n 0,\t\t\t\t\t/* tp_str */\n 0,\t \t/* tp_getattro */\n 0,\t\t\t\t\t/* tp_setattro */\n 0,\t\t\t\t\t/* tp_as_buffer */\n Py_TPFLAGS_DEFAULT, /* tp_flags */\n 0,\t\t\t\t\t/* tp_doc */\n 0, \t /* tp_traverse */\n 0,\t\t\t\t\t/* tp_clear */\n 0,\t\t\t\t\t/* tp_richcompare */\n 0,\t\t\t\t\t/* tp_weaklistoffset */\n 0, \t /* tp_iter */\n (iternextfunc)arrayiter_next,\t\t/* tp_iternext */\n iter_methods,\t\t\t\t/* tp_methods */\n iter_members,\t \t /* tp_members */\n iter_getsets, /* tp_getset */\n\n};\n\n/** END of Array Iterator **/\n\n\n\n/*********************** Subscript Array Iterator *************************\n * *\n * This object handles subscript behavior for array objects. *\n * It is an iterator object with a next method *\n * It abstracts the n-dimensional mapping behavior to make the looping *\n * code more understandable (maybe) *\n * and so that indexing can be set up ahead of time *\n */ \n\n/* convert an indexing object to an INTP indexing array iterator\n if possible -- otherwise, it is a Slice or Ellipsis object\n and has to be interpreted on bind to a particular \n array so leave it NULL for now.\n */\nstatic int\n_convert_obj(PyObject *obj, PyArrayIterObject **iter)\n{\n\tPyArray_Descr *indtype;\n\tPyObject *arr;\n\n\tif (PySlice_Check(obj) || (obj == Py_Ellipsis))\n\t\t*iter = NULL;\n\telse {\n\t\tindtype = PyArray_DescrFromType(PyArray_INTP);\n\t\tarr = PyArray_FromAny(obj, indtype, 0, 0, FORCECAST, NULL);\n\t\tif (arr == NULL) return -1;\n\t\t*iter = (PyArrayIterObject *)PyArray_IterNew(arr);\n\t\tPy_DECREF(arr);\n\t\tif (*iter == NULL) return -1;\n\t}\n\treturn 0;\n}\n\n/* Adjust dimensionality and strides for index object iterators \n --- i.e. broadcast\n */\n/*OBJECT_API*/\nstatic int\nPyArray_Broadcast(PyArrayMultiIterObject *mit)\n{\n\tint i, nd, k, j;\n\tintp tmp;\n\tPyArrayIterObject *it;\n\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\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, NULL);\n\tif (ba == NULL) return -1;\n\tnd = ba->nd;\n\tfor (j=0; jdata;\n\tcount = 0;\n\n\t/* pre-determine how many nonzero entries there are */\n\tfor (i=0; iao->data;\n\t\tcoords[j] = 0;\n\t\tdims_m1[j] = ba->dimensions[j]-1;\n\t}\n\n\tptr = (Bool *)ba->data;\n\n\tif (count == 0) goto finish;\n\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->index = 0;\n \tmit->ait = NULL;\n \tmit->subspace = NULL;\n\tmit->numiter = 0;\n\tmit->consec = 1;\n\tPy_INCREF(indexobj);\n\tmit->indexobj = indexobj;\n\n\tif (fancy == SOBJ_LISTTUP) {\n\t\tPyObject *newobj;\n\t\tnewobj = PySequence_Tuple(indexobj);\n\t\tif (newobj == NULL) goto fail;\n\t\tPy_DECREF(indexobj);\n\t\tindexobj = newobj;\n\t\tmit->indexobj = indexobj;\n\t}\n\n#undef SOBJ_NOTFANCY \n#undef SOBJ_ISFANCY \n#undef SOBJ_BADARRAY \n#undef SOBJ_TOOMANY \n#undef SOBJ_LISTTUP \n \n\tif (oned) return (PyObject *)mit;\n\n\t/* Must have some kind of fancy indexing if we are here */\n\t/* indexobj is either a list, an arrayobject, or a tuple \n\t (with at least 1 list or arrayobject or Bool object), */\n\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, NULL);\n\t\tif (arr == NULL) goto fail;\n\t\tmit->iters[0] = (PyArrayIterObject *)PyArray_IterNew(arr);\n\t\tif (mit->iters[0] == NULL) {Py_DECREF(arr); goto fail;}\n\t\tmit->nd = PyArray_NDIM(arr);\n\t\tmemcpy(mit->dimensions,PyArray_DIMS(arr),mit->nd*sizeof(intp));\n\t\tmit->size = PyArray_SIZE(arr);\n\t\tPy_DECREF(arr);\n\t\tPy_DECREF(mit->indexobj);\n\t\tmit->indexobj = Py_BuildValue(\"(N)\", PyInt_FromLong(0));\n\t}\n\telse { /* must be a tuple */\n\t\tPyObject *obj;\n\t\tPyArrayIterObject *iter;\n\t\tPyObject *new;\n\t\t/* Make a copy of the tuple -- we will be replacing \n\t\t index objects with 0's */\n\t\tn = PyTuple_GET_SIZE(indexobj);\n\t\tnew = PyTuple_New(n);\n\t\tif (new == NULL) goto fail;\n\t\tstarted = 0;\n\t\tnonindex = 0;\n\t\tfor (i=0; iconsec = 0;\n\t\t\t\tmit->iters[(mit->numiter)++] = iter;\n\t\t\t\tPyTuple_SET_ITEM(new,i,\n\t\t\t\t\t\t PyInt_FromLong(0));\n\t\t\t}\n\t\t\telse {\n\t\t\t\tif (started) nonindex = 1;\n\t\t\t\tPy_INCREF(obj);\n\t\t\t\tPyTuple_SET_ITEM(new,i,obj);\n\t\t\t}\n\t\t}\n\t\tPy_DECREF(mit->indexobj);\n\t\tmit->indexobj = new;\n\t\t/* Store the number of iterators actually converted */\n\t\t/* These will be mapped to actual axes at bind time */\n\t\tif (PyArray_Broadcast((PyArrayMultiIterObject *)mit) < 0)\n\t\t\tgoto fail;\n\t}\n\n return (PyObject *)mit;\n \n fail:\n Py_DECREF(mit);\n\treturn NULL;\n}\n\n\nstatic void\narraymapiter_dealloc(PyArrayMapIterObject *mit)\n{\n\tint i;\n\tPy_XDECREF(mit->indexobj);\n Py_XDECREF(mit->ait);\n\tPy_XDECREF(mit->subspace);\n\tfor (i=0; inumiter; i++)\n\t\tPy_XDECREF(mit->iters[i]);\n _pya_free(mit);\n}\n\n/* The mapiter object must be created new each time. It does not work\n to bind to a new array, and continue.\n\n This was the orginal intention, but currently that does not work. \n Do not expose the MapIter_Type to Python.\n\n It's not very useful anyway, since mapiter(indexobj); mapiter.bind(a); \n mapiter is equivalent to a[indexobj].flat but the latter gets to use \n slice syntax.\n*/\n\nstatic PyTypeObject PyArrayMapIter_Type = {\n PyObject_HEAD_INIT(NULL)\n 0,\t\t\t\t\t /* ob_size */\n \"numpy.mapiter\",\t\t \t/* tp_name */\n sizeof(PyArrayIterObject), /* tp_basicsize */\n 0,\t\t\t\t\t /* tp_itemsize */\n /* methods */\n (destructor)arraymapiter_dealloc,\t/* tp_dealloc */\n 0,\t\t\t\t\t/* tp_print */\n 0,\t\t\t\t\t/* tp_getattr */\n 0,\t\t\t\t\t/* tp_setattr */\n 0,\t\t\t\t\t/* tp_compare */\n 0,\t\t\t\t\t/* tp_repr */\n 0,\t\t\t\t\t/* tp_as_number */\n 0,\t\t\t\t\t/* tp_as_sequence */\n 0,\t\t\t\t\t/* tp_as_mapping */\n 0,\t\t\t\t\t/* tp_hash */\n 0,\t\t\t\t\t/* tp_call */\n 0,\t\t\t\t\t/* tp_str */\n 0, \t\t/* tp_getattro */\n 0,\t\t\t\t\t/* tp_setattro */\n 0,\t\t\t\t\t/* tp_as_buffer */\n Py_TPFLAGS_DEFAULT, /* tp_flags */\n 0,\t\t\t\t\t/* tp_doc */\n (traverseproc)0, \t /* tp_traverse */\n 0,\t\t\t\t\t/* tp_clear */\n 0,\t\t\t\t\t/* tp_richcompare */\n 0,\t\t\t\t\t/* tp_weaklistoffset */\n 0,\t\t \t /* tp_iter */\n (iternextfunc)0, \t /* tp_iternext */\n 0, \t /* tp_methods */\n 0,\t\t\t\t\t /* tp_members */\n 0,\t\t\t /* tp_getset */\n 0,\t\t\t\t\t /* tp_base */\n 0,\t\t\t\t\t /* tp_dict */\n 0,\t\t\t\t\t /* tp_descr_get */\n 0,\t\t\t\t\t /* tp_descr_set */\n 0,\t\t\t\t\t /* tp_dictoffset */\n (initproc)0,\t \t /* tp_init */\n 0, \t /* tp_alloc */\n 0,\t /* tp_new */\n 0,\t /* tp_free */\n 0,\t\t\t\t\t /* tp_is_gc */\n 0,\t\t\t\t\t /* tp_bases */\n 0,\t\t\t\t\t /* tp_mro */\n 0,\t\t\t\t\t /* tp_cache */\n 0,\t\t\t\t\t /* tp_subclasses */\n 0\t\t\t\t\t /* tp_weaklist */\n\n};\n\n/** END of Subscript Iterator **/\n\n\n/*OBJECT_API\n Get MultiIterator,\n*/\nstatic PyObject *\nPyArray_MultiIterNew(int n, ...)\n{\n va_list va;\n\tPyArrayMultiIterObject *multi;\n\tPyObject *current;\n\tPyObject *arr;\n\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 dtype objects can be set. \n*/\nstatic PyMemberDef arraydescr_members[] = {\n\t{\"type\", T_OBJECT, offsetof(PyArray_Descr, typeobj), RO, NULL},\n\t{\"kind\", T_CHAR, offsetof(PyArray_Descr, kind), RO, NULL},\n\t{\"char\", T_CHAR, offsetof(PyArray_Descr, type), RO, NULL},\n\t{\"num\", T_INT, offsetof(PyArray_Descr, type_num), RO, NULL},\n\t{\"byteorder\", T_CHAR, offsetof(PyArray_Descr, byteorder), RO, NULL},\n\t{\"itemsize\", T_INT, offsetof(PyArray_Descr, elsize), RO, NULL},\n\t{\"alignment\", T_INT, offsetof(PyArray_Descr, alignment), RO, NULL},\n {\"hasobject\", T_UBYTE, offsetof(PyArray_Descr, hasobject), RO, NULL},\n\t{NULL}, \n};\n\nstatic PyObject *\narraydescr_subdescr_get(PyArray_Descr *self)\n{\n\tif (self->subarray == NULL) {\n\t\tPy_INCREF(Py_None);\n\t\treturn Py_None;\n\t}\n\treturn Py_BuildValue(\"OO\", (PyObject *)self->subarray->base, \n\t\t\t self->subarray->shape);\n}\n\nstatic PyObject *\narraydescr_protocol_typestr_get(PyArray_Descr *self)\n{\n char basic_=self->kind;\n char endian = self->byteorder;\n\tint size=self->elsize;\n\n if (endian == '=') {\n endian = '<';\n if (!PyArray_IsNativeByteOrder(endian)) endian = '>';\n }\n \n\tif (self->type_num == PyArray_UNICODE) {\n\t\tsize >>= 2;\n\t}\n return PyString_FromFormat(\"%c%c%d\", endian, basic_, size);\n}\n\nstatic PyObject *\narraydescr_typename_get(PyArray_Descr *self)\n{\n int len;\n PyTypeObject *typeobj = self->typeobj;\n\tPyObject *res;\n\tstatic int suffix_len=0;\n\n\tif (PyTypeNum_ISUSERDEF(self->type_num)) {\n\t\tres = PyString_FromString(typeobj->tp_name);\n\t}\n\telse {\n\t\tif (suffix_len == 0) \n\t\t\tsuffix_len = strlen(\"scalar\");\n\t\tlen = strlen(typeobj->tp_name) - suffix_len;\n\t\tres = PyString_FromStringAndSize(typeobj->tp_name, len);\n\t}\n\tif (PyTypeNum_ISEXTENDED(self->type_num) && self->elsize != 0) {\n\t\tPyObject *p;\n\t\tp = PyString_FromFormat(\"%d\", self->elsize * 8);\n\t\tPyString_ConcatAndDel(&res, p);\n\t}\n\treturn res;\t\t\t\t\t\t \n}\n\nstatic PyObject *\narraydescr_base_get(PyArray_Descr *self)\n{\n\tif (self->subarray == NULL) {\n\t\tPy_INCREF(self);\n return (PyObject *)self;\n\t}\n Py_INCREF(self->subarray->base);\n return (PyObject *)(self->subarray->base);\n}\n\nstatic PyObject *\narraydescr_shape_get(PyArray_Descr *self)\n{\n\tif (self->subarray == NULL) {\n return Py_BuildValue(\"(N)\", PyInt_FromLong(1));\n\t}\n Py_INCREF(self->subarray->shape);\n return (PyObject *)(self->subarray->shape);\n}\n\nstatic PyObject *\narraydescr_protocol_descr_get(PyArray_Descr *self)\n{\n\tPyObject *dobj, *res;\n\n\tif (self->fields == NULL || self->fields == Py_None) {\n\t\t/* get default */\n\t\tdobj = PyTuple_New(2);\n\t\tif (dobj == NULL) return NULL;\n\t\tPyTuple_SET_ITEM(dobj, 0, PyString_FromString(\"\"));\n\t\tPyTuple_SET_ITEM(dobj, 1, \\\n\t\t\t\t arraydescr_protocol_typestr_get(self));\n\t\tres = PyList_New(1);\n\t\tif (res == NULL) {Py_DECREF(dobj); return NULL;}\n\t\tPyList_SET_ITEM(res, 0, dobj);\n\t\treturn res;\n\t}\n\n return PyObject_CallMethod(_numpy_internal, \"_array_descr\", \n\t\t\t\t \"O\", self);\n}\n\n/* returns 1 for a builtin type\n and 2 for a user-defined data-type descriptor\n return 0 if neither (i.e. it's a copy of one)\n*/\nstatic PyObject *\narraydescr_isbuiltin_get(PyArray_Descr *self) \n{\n\tlong val;\n\tval = 0;\n\tif (self->fields == Py_None) val = 1;\n\tif (PyTypeNum_ISUSERDEF(self->type_num)) val = 2;\n\treturn PyInt_FromLong(val);\n}\n\nstatic PyObject *\narraydescr_isnative_get(PyArray_Descr *self)\n{\n\tPyObject *ret;\n\n\tret = (PyArray_ISNBO(self->byteorder) ? Py_True : Py_False);\n\tPy_INCREF(ret);\n\treturn ret;\n}\n\nstatic PyObject *\narraydescr_fields_get(PyArray_Descr *self)\n{\n\tif (self->fields == NULL || self->fields == Py_None) {\n\t\tPy_INCREF(Py_None);\n\t\treturn Py_None;\n\t}\n\treturn PyDictProxy_New(self->fields);\n}\n\nstatic PyGetSetDef arraydescr_getsets[] = {\n\t{\"subdtype\", \n\t (getter)arraydescr_subdescr_get,\n\t NULL,\n\t \"A tuple of (descr, shape) or None.\"},\n\t{\"descr\",\n\t (getter)arraydescr_protocol_descr_get,\n\t NULL,\n\t \"The array_protocol type descriptor.\"},\n\t{\"str\",\n\t (getter)arraydescr_protocol_typestr_get,\n\t NULL,\n\t \"The array_protocol typestring.\"},\n {\"name\",\n (getter)arraydescr_typename_get,\n NULL,\n \"The name of the true data-type\"},\n\t{\"base\",\n\t (getter)arraydescr_base_get,\n\t NULL,\n\t \"The base data-type or self if no subdtype\"},\n {\"shape\",\n (getter)arraydescr_shape_get,\n NULL,\n \"The shape of the subdtype or (1,)\"},\n \t{\"isbuiltin\",\n\t (getter)arraydescr_isbuiltin_get,\n\t NULL,\n\t \"Is this a buillt-in data-type descriptor?\"},\n\t{\"isnative\",\n\t (getter)arraydescr_isnative_get,\n\t NULL,\n\t \"Is the byte-order of this descriptor native?\"},\n\t{\"fields\",\n\t (getter)arraydescr_fields_get,\n\t NULL,\n\t NULL},\n\t{NULL, NULL, NULL, NULL},\n};\n\nstatic PyArray_Descr *_convert_from_list(PyObject *obj, int align, int try_descr);\nstatic PyArray_Descr *_convert_from_dict(PyObject *obj, int align);\nstatic PyArray_Descr *_convert_from_commastring(PyObject *obj, int align);\nstatic PyArray_Descr *_convert_from_array_descr(PyObject *obj);\n\nstatic PyObject *\narraydescr_new(PyTypeObject *subtype, PyObject *args, PyObject *kwds)\n{\n\tPyObject *odescr;\n\tPyArray_Descr *descr, *conv;\n\tint align=0;\n\tBool copy=FALSE;\n\tstatic char *kwlist[] = {\"dtype\", \"align\", \"copy\", NULL};\n\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, \"dtype\");\n\tPy_DECREF(mod);\n\tif (obj == NULL) {Py_DECREF(ret); return NULL;}\n\tPyTuple_SET_ITEM(ret, 0, obj);\n\tif (PyTypeNum_ISUSERDEF(self->type_num) ||\t\t\\\n\t ((self->type_num == PyArray_VOID &&\t\t\t\\\n\t self->typeobj != &PyVoidArrType_Type))) {\n\t\tobj = (PyObject *)self->typeobj;\n\t\tPy_INCREF(obj);\n\t}\n\telse {\n\t\telsize = self->elsize;\n\t\tif (self->type_num == PyArray_UNICODE) {\n\t\t\telsize >>= 2;\n\t\t}\n\t\tobj = PyString_FromFormat(\"%c%d\",self->kind, elsize);\n\t}\n\tPyTuple_SET_ITEM(ret, 1, Py_BuildValue(\"(Nii)\", obj, 0, 1));\n\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 dtype object\\n\"\n\t\" with altered byteorders. If is not given all byteorders\\n\"\n\t\" are swapped. Otherwise endian can be '>', '<', or '=' to force\\n\"\n\t\" a byteorder. Descriptors in all fields are also updated in the\\n\"\n\t\" new dtype object.\";\n\nstatic PyObject *\narraydescr_newbyteorder(PyArray_Descr *self, PyObject *args) \n{\n\tchar endian=PyArray_SWAP;\n\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);\n\t\tif (self->type_num != PyArray_VOID) {\n\t\t\tPyObject *p;\n\t\t\tPyObject *t=PyString_FromString(\"'\");\n\t\t\tp = arraydescr_protocol_typestr_get(self);\n\t\t\tPyString_Concat(&p, t);\n\t\t\tPyString_ConcatAndDel(&t, p);\n\t\t\tp = PyString_FromString(\"(\");\n\t\t\tPyString_ConcatAndDel(&p, t);\n\t\t\tPyString_ConcatAndDel(&p, PyString_FromString(\", \"));\n\t\t\tPyString_ConcatAndDel(&p, sub);\n\t\t\tPyString_ConcatAndDel(&p, PyString_FromString(\")\"));\n\t\t\tsub = p;\n\t\t}\n\t}\n\telse if (self->subarray) {\n\t\tPyObject *p;\n\t\tPyObject *t = PyString_FromString(\"(\");\n\t\tp = arraydescr_str(self->subarray->base);\n\t\tPyString_ConcatAndDel(&t, p);\n\t\tPyString_ConcatAndDel(&t, PyString_FromString(\",\"));\n\t\tPyString_ConcatAndDel(&t, PyObject_Str(self->subarray->shape));\n\t\tPyString_ConcatAndDel(&t, PyString_FromString(\")\"));\n\t\tsub = t;\n\t}\n\telse {\n\t\tPyObject *t=PyString_FromString(\"'\");\n\t\tsub = arraydescr_protocol_typestr_get(self);\n\t\tPyString_Concat(&sub, t);\n\t\tPyString_ConcatAndDel(&t, sub);\n\t\tsub = t;\n\t}\n\treturn sub;\n}\n\nstatic PyObject *\narraydescr_repr(PyArray_Descr *self)\n{\n\tPyObject *sub, *s;\n\ts = PyString_FromString(\"dtype(\");\n sub = arraydescr_str(self);\n\tPyString_ConcatAndDel(&s, sub);\n\tsub = PyString_FromString(\")\");\n\tPyString_ConcatAndDel(&s, sub);\n\treturn s;\n}\n\nstatic int\narraydescr_compare(PyArray_Descr *self, PyObject *other)\n{\n \tif (!PyArray_DescrCheck(other)) {\n\t\tPyErr_SetString(PyExc_TypeError,\n\t\t\t\t\"not a dtype object.\");\n\t\treturn -1;\n\t}\n\tif (PyArray_EquivTypes(self, (PyArray_Descr *)other)) return 0;\n\tif (PyArray_CanCastTo(self, (PyArray_Descr *)other)) return -1;\n\treturn 1;\n}\n\n/*************************************************************************\n **************** Implement Mapping Protocol ***************************\n *************************************************************************/\n\nstatic int \ndescr_length(PyArray_Descr *self) \n{\n\n\tif (self->fields && self->fields != Py_None)\n\t\t/* Remove the last entry (root) */\n\t\treturn PyDict_Size(self->fields) - 1;\n\telse return 0;\n}\n\nstatic PyObject *\ndescr_subscript(PyArray_Descr *self, PyObject *op) \n{\n\n\tif (self->fields) {\n\t\tif (PyString_Check(op) || PyUnicode_Check(op)) {\n\t\t\tPyObject *obj;\n\t\t\tobj = PyDict_GetItem(self->fields, op);\n\t\t\tif (obj != NULL) {\n\t\t\t\tPyObject *descr;\n\t\t\t\tdescr = PyTuple_GET_ITEM(obj, 0);\n\t\t\t\tPy_INCREF(descr);\n\t\t\t\treturn descr;\n\t\t\t}\n\t\t\telse {\n\t\t\t\tPyErr_Format(PyExc_KeyError, \n\t\t\t\t\t \"field named \\'%s\\' not found.\",\n\t\t\t\t\t PyString_AsString(op));\n\t\t\t}\n\t\t}\n\t\telse {\n\t\t PyErr_SetString(PyExc_ValueError, \n\t\t\t\t \"only strings or unicode values allowed \" \\\n\t\t\t\t \"for getting fields.\");\n\t\t}\n\t}\n\telse {\n\t\tPyErr_Format(PyExc_KeyError, \n\t\t\t \"there are no fields in dtype %s.\",\n\t\t\t PyString_AsString(arraydescr_str(self)));\n\t}\n\n\treturn NULL;\n}\n\nstatic PyMappingMethods descr_as_mapping = {\n (inquiry)descr_length,\t\t /*mp_length*/\n (binaryfunc)descr_subscript,\t /*mp_subscript*/\n (objobjargproc)NULL,\t /*mp_ass_subscript*/\n};\n\n/****************** End of Mapping Protocol ******************************/\n\n\nstatic PyTypeObject PyArrayDescr_Type = {\n PyObject_HEAD_INIT(NULL)\n 0,\t\t\t\t\t /* ob_size */\n \"numpy.dtype\",\t\t \t /* tp_name */\n sizeof(PyArray_Descr), /* tp_basicsize */\n 0,\t\t\t\t\t /* tp_itemsize */\n /* methods */\n (destructor)arraydescr_dealloc,\t\t/* tp_dealloc */\n 0,\t\t\t\t\t/* tp_print */\n 0,\t\t\t\t\t/* tp_getattr */\n 0,\t\t\t\t\t/* tp_setattr */\n\t(cmpfunc)arraydescr_compare,\t\t/* tp_compare */\n (reprfunc)arraydescr_repr,\t /* tp_repr */\n 0,\t\t\t\t\t/* tp_as_number */\n 0, \t\t\t /* tp_as_sequence */\n &descr_as_mapping, \t /* tp_as_mapping */\n 0,\t\t\t\t\t/* tp_hash */\n 0,\t\t\t\t\t/* tp_call */\n (reprfunc)arraydescr_str, /* tp_str */\n 0,\t \t/* tp_getattro */\n 0,\t\t\t\t\t/* tp_setattro */\n 0,\t\t\t\t\t/* tp_as_buffer */\n Py_TPFLAGS_DEFAULT, /* tp_flags */\n 0,\t\t\t\t\t/* tp_doc */\n 0, \t /* tp_traverse */\n 0,\t\t\t\t\t/* tp_clear */\n 0,\t\t\t\t\t/* tp_richcompare */\n 0,\t\t\t\t\t/* tp_weaklistoffset */\n 0, \t /* tp_iter */\n 0,\t \t/* tp_iternext */\n arraydescr_methods,\t \t /* tp_methods */\n arraydescr_members,\t /* tp_members */\n arraydescr_getsets, /* tp_getset */\n 0,\t\t\t\t\t /* tp_base */\n 0,\t\t\t\t\t /* tp_dict */\n 0,\t\t\t\t\t /* tp_descr_get */\n 0,\t\t\t\t\t /* tp_descr_set */\n 0,\t\t\t\t\t /* tp_dictoffset */\n 0, \t \t /* tp_init */\n 0, \t /* tp_alloc */\n arraydescr_new,\t /* tp_new */\n 0,\t /* tp_free */\n 0,\t\t\t\t\t /* tp_is_gc */\n 0,\t\t\t\t\t /* tp_bases */\n 0,\t\t\t\t\t /* tp_mro */\n 0,\t\t\t\t\t /* tp_cache */\n 0,\t\t\t\t\t /* tp_subclasses */\n 0\t\t\t\t\t /* tp_weaklist */\n};\n", + "methods": [ + { + "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": 28, + "end_line": 46, + "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": 67, + "end_line": 95, + "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": 101, + "end_line": 130, + "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": 136, + "end_line": 186, + "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": 209, + "end_line": 240, + "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": 243, + "end_line": 277, + "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": 293, + "end_line": 315, + "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": 321, + "end_line": 342, + "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": 346, + "end_line": 384, + "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": 389, + "end_line": 409, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 21, + "top_nesting_level": 0 + }, + { + "name": "PyArray_PyIntAsIntp", + "long_name": "PyArray_PyIntAsIntp( PyObject * o)", + "filename": "arrayobject.c", + "nloc": 71, + "complexity": 21, + "token_count": 413, + "parameters": [ + "o" + ], + "start_line": 429, + "end_line": 511, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 83, + "top_nesting_level": 0 + }, + { + "name": "PyArray_PyIntAsInt", + "long_name": "PyArray_PyIntAsInt( PyObject * o)", + "filename": "arrayobject.c", + "nloc": 67, + "complexity": 19, + "token_count": 406, + "parameters": [ + "o" + ], + "start_line": 518, + "end_line": 592, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 75, + "top_nesting_level": 0 + }, + { + "name": "index2ptr", + "long_name": "index2ptr( PyArrayObject * mp , intp i)", + "filename": "arrayobject.c", + "nloc": 15, + "complexity": 7, + "token_count": 98, + "parameters": [ + "mp", + "i" + ], + "start_line": 595, + "end_line": 610, + "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": 616, + "end_line": 624, + "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": 640, + "end_line": 720, + "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": 81, + "parameters": [ + "dest", + "src_object" + ], + "start_line": 724, + "end_line": 738, + "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": 751, + "end_line": 777, + "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": 783, + "end_line": 797, + "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": 806, + "end_line": 826, + "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": 92, + "complexity": 14, + "token_count": 554, + "parameters": [ + "data", + "descr", + "base" + ], + "start_line": 835, + "end_line": 940, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 106, + "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": 956, + "end_line": 959, + "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": 969, + "end_line": 991, + "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": 1005, + "end_line": 1045, + "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": 1060, + "end_line": 1101, + "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": 1108, + "end_line": 1199, + "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": 1205, + "end_line": 1234, + "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": 1237, + "end_line": 1273, + "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": 1282, + "end_line": 1319, + "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": 1326, + "end_line": 1334, + "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": 1337, + "end_line": 1362, + "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": 1365, + "end_line": 1368, + "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": 1372, + "end_line": 1407, + "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": 1413, + "end_line": 1416, + "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": 1422, + "end_line": 1430, + "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": 1436, + "end_line": 1486, + "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": 1493, + "end_line": 1538, + "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": 1542, + "end_line": 1636, + "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": 1639, + "end_line": 1676, + "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": 1688, + "end_line": 1741, + "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": 382, + "parameters": [ + "mit", + "op" + ], + "start_line": 1744, + "end_line": 1804, + "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": 1807, + "end_line": 1834, + "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": 1837, + "end_line": 1856, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 20, + "top_nesting_level": 0 + }, + { + "name": "fancy_indexing_check", + "long_name": "fancy_indexing_check( PyObject * args)", + "filename": "arrayobject.c", + "nloc": 56, + "complexity": 22, + "token_count": 295, + "parameters": [ + "args" + ], + "start_line": 1868, + "end_line": 1930, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 63, + "top_nesting_level": 0 + }, + { + "name": "array_subscript", + "long_name": "array_subscript( PyArrayObject * self , PyObject * op)", + "filename": "arrayobject.c", + "nloc": 103, + "complexity": 28, + "token_count": 666, + "parameters": [ + "self", + "op" + ], + "start_line": 1954, + "end_line": 2072, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 119, + "top_nesting_level": 0 + }, + { + "name": "array_ass_sub", + "long_name": "array_ass_sub( PyArrayObject * self , PyObject * index , PyObject * op)", + "filename": "arrayobject.c", + "nloc": 93, + "complexity": 28, + "token_count": 588, + "parameters": [ + "self", + "index", + "op" + ], + "start_line": 2087, + "end_line": 2192, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 106, + "top_nesting_level": 0 + }, + { + "name": "array_subscript_nice", + "long_name": "array_subscript_nice( PyArrayObject * self , PyObject * op)", + "filename": "arrayobject.c", + "nloc": 4, + "complexity": 1, + "token_count": 27, + "parameters": [ + "self", + "op" + ], + "start_line": 2201, + "end_line": 2204, + "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": 2223, + "end_line": 2235, + "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": 2238, + "end_line": 2253, + "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": 2257, + "end_line": 2266, + "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": 2269, + "end_line": 2280, + "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": 2351, + "end_line": 2384, + "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": 2394, + "end_line": 2433, + "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": 2436, + "end_line": 2459, + "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": 2463, + "end_line": 2486, + "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": 2490, + "end_line": 2497, + "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": 2500, + "end_line": 2507, + "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": 2510, + "end_line": 2518, + "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": 2521, + "end_line": 2524, + "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": 2527, + "end_line": 2530, + "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": 2533, + "end_line": 2536, + "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": 2539, + "end_line": 2542, + "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": 2545, + "end_line": 2548, + "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": 2551, + "end_line": 2554, + "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": 2557, + "end_line": 2560, + "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": 2563, + "end_line": 2566, + "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": 2569, + "end_line": 2572, + "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": 2575, + "end_line": 2578, + "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": 2581, + "end_line": 2584, + "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": 2587, + "end_line": 2590, + "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": 2593, + "end_line": 2596, + "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": 2599, + "end_line": 2602, + "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": 2605, + "end_line": 2608, + "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": 2611, + "end_line": 2614, + "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": 2617, + "end_line": 2620, + "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": 2623, + "end_line": 2626, + "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": 2629, + "end_line": 2632, + "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": 2635, + "end_line": 2638, + "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": 2641, + "end_line": 2644, + "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": 2647, + "end_line": 2650, + "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": 2653, + "end_line": 2656, + "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": 2659, + "end_line": 2662, + "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": 2665, + "end_line": 2668, + "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": 2671, + "end_line": 2674, + "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": 2677, + "end_line": 2680, + "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": 2683, + "end_line": 2687, + "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": 2690, + "end_line": 2694, + "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": 2698, + "end_line": 2716, + "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": 2719, + "end_line": 2736, + "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": 2741, + "end_line": 2756, + "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": 2760, + "end_line": 2786, + "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": 2789, + "end_line": 2814, + "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": 2817, + "end_line": 2839, + "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": 2842, + "end_line": 2864, + "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": 2867, + "end_line": 2889, + "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": 2892, + "end_line": 2896, + "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": 2957, + "end_line": 2997, + "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": 3001, + "end_line": 3022, + "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": 3025, + "end_line": 3037, + "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": 3058, + "end_line": 3105, + "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": 3108, + "end_line": 3144, + "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": 3153, + "end_line": 3170, + "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": 3173, + "end_line": 3185, + "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": 3188, + "end_line": 3200, + "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": 81, + "complexity": 17, + "token_count": 357, + "parameters": [ + "self", + "other", + "cmp_op" + ], + "start_line": 3203, + "end_line": 3300, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 98, + "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": 171, + "parameters": [ + "arr", + "axis", + "flags" + ], + "start_line": 3303, + "end_line": 3332, + "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": 3338, + "end_line": 3358, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 21, + "top_nesting_level": 0 + }, + { + "name": "PyArray_IntpFromSequence", + "long_name": "PyArray_IntpFromSequence( PyObject * seq , intp * vals , int maxvals)", + "filename": "arrayobject.c", + "nloc": 24, + "complexity": 11, + "token_count": 203, + "parameters": [ + "seq", + "vals", + "maxvals" + ], + "start_line": 3366, + "end_line": 3401, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 36, + "top_nesting_level": 0 + }, + { + "name": "_IsContiguous", + "long_name": "_IsContiguous( PyArrayObject * ap)", + "filename": "arrayobject.c", + "nloc": 17, + "complexity": 7, + "token_count": 128, + "parameters": [ + "ap" + ], + "start_line": 3407, + "end_line": 3426, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 20, + "top_nesting_level": 0 + }, + { + "name": "_IsFortranContiguous", + "long_name": "_IsFortranContiguous( PyArrayObject * ap)", + "filename": "arrayobject.c", + "nloc": 17, + "complexity": 7, + "token_count": 126, + "parameters": [ + "ap" + ], + "start_line": 3430, + "end_line": 3448, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 19, + "top_nesting_level": 0 + }, + { + "name": "_IsAligned", + "long_name": "_IsAligned( PyArrayObject * ap)", + "filename": "arrayobject.c", + "nloc": 15, + "complexity": 5, + "token_count": 119, + "parameters": [ + "ap" + ], + "start_line": 3451, + "end_line": 3468, + "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": 3471, + "end_line": 3504, + "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": 3511, + "end_line": 3538, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 28, + "top_nesting_level": 0 + }, + { + "name": "PyArray_CheckStrides", + "long_name": "PyArray_CheckStrides( int elsize , int nd , intp numbytes , intp offset , intp * dims , intp * newstrides)", + "filename": "arrayobject.c", + "nloc": 23, + "complexity": 7, + "token_count": 135, + "parameters": [ + "elsize", + "nd", + "numbytes", + "offset", + "dims", + "newstrides" + ], + "start_line": 3552, + "end_line": 3587, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 36, + "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": 3607, + "end_line": 3631, + "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": 3637, + "end_line": 3659, + "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": 3663, + "end_line": 3705, + "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": 136, + "complexity": 27, + "token_count": 781, + "parameters": [ + "subtype", + "descr", + "nd", + "dims", + "strides", + "data", + "flags", + "obj" + ], + "start_line": 3713, + "end_line": 3878, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 166, + "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": 3887, + "end_line": 3985, + "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": 3991, + "end_line": 4008, + "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": 231, + "parameters": [ + "arr", + "obj" + ], + "start_line": 4012, + "end_line": 4054, + "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": 19, + "token_count": 577, + "parameters": [ + "subtype", + "args", + "kwds" + ], + "start_line": 4057, + "end_line": 4174, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 118, + "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": 4178, + "end_line": 4186, + "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": 4192, + "end_line": 4195, + "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": 4198, + "end_line": 4202, + "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": 4205, + "end_line": 4208, + "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": 4212, + "end_line": 4241, + "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": 4245, + "end_line": 4248, + "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": 37, + "complexity": 7, + "token_count": 239, + "parameters": [ + "self", + "obj" + ], + "start_line": 4251, + "end_line": 4290, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 40, + "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": 4294, + "end_line": 4301, + "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": 4304, + "end_line": 4312, + "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": 4316, + "end_line": 4322, + "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": 4325, + "end_line": 4339, + "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": 4342, + "end_line": 4386, + "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": 4390, + "end_line": 4393, + "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": 4396, + "end_line": 4407, + "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": 4410, + "end_line": 4421, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 12, + "top_nesting_level": 0 + }, + { + "name": "array_typestr_get", + "long_name": "array_typestr_get( PyArrayObject * self)", + "filename": "arrayobject.c", + "nloc": 4, + "complexity": 1, + "token_count": 16, + "parameters": [ + "self" + ], + "start_line": 4427, + "end_line": 4430, + "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": 4433, + "end_line": 4437, + "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": 62, + "complexity": 15, + "token_count": 438, + "parameters": [ + "self", + "arg" + ], + "start_line": 4451, + "end_line": 4537, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 87, + "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": 4540, + "end_line": 4558, + "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": 4561, + "end_line": 4579, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 19, + "top_nesting_level": 0 + }, + { + "name": "array_base_get", + "long_name": "array_base_get( PyArrayObject * self)", + "filename": "arrayobject.c", + "nloc": 11, + "complexity": 2, + "token_count": 41, + "parameters": [ + "self" + ], + "start_line": 4582, + "end_line": 4592, + "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": 4596, + "end_line": 4621, + "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": 191, + "parameters": [ + "self", + "val" + ], + "start_line": 4625, + "end_line": 4658, + "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": 4661, + "end_line": 4694, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 34, + "top_nesting_level": 0 + }, + { + "name": "array_imag_set", + "long_name": "array_imag_set( PyArrayObject * self , PyObject * val)", + "filename": "arrayobject.c", + "nloc": 37, + "complexity": 4, + "token_count": 207, + "parameters": [ + "self", + "val" + ], + "start_line": 4697, + "end_line": 4734, + "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": 4737, + "end_line": 4740, + "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": 348, + "parameters": [ + "self", + "val" + ], + "start_line": 4743, + "end_line": 4793, + "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": 4883, + "end_line": 4890, + "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": 4992, + "end_line": 5025, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 34, + "top_nesting_level": 0 + }, + { + "name": "discover_itemsize", + "long_name": "discover_itemsize( PyObject * s , int nd , int * itemsize)", + "filename": "arrayobject.c", + "nloc": 21, + "complexity": 9, + "token_count": 158, + "parameters": [ + "s", + "nd", + "itemsize" + ], + "start_line": 5028, + "end_line": 5050, + "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": 5057, + "end_line": 5083, + "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": 5089, + "end_line": 5121, + "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": 128, + "complexity": 34, + "token_count": 742, + "parameters": [ + "op", + "minitype", + "max" + ], + "start_line": 5133, + "end_line": 5281, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 149, + "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": 5284, + "end_line": 5307, + "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": 29, + "complexity": 7, + "token_count": 168, + "parameters": [ + "op", + "typecode" + ], + "start_line": 5312, + "end_line": 5346, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 35, + "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": 54, + "complexity": 21, + "token_count": 352, + "parameters": [ + "s", + "typecode", + "fortran", + "min_depth", + "max_depth" + ], + "start_line": 5351, + "end_line": 5414, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 64, + "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": 5421, + "end_line": 5430, + "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": 5436, + "end_line": 5529, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 94, + "top_nesting_level": 0 + }, + { + "name": "PyArray_CastToType", + "long_name": "PyArray_CastToType( PyArrayObject * mp , PyArray_Descr * at , int fortran)", + "filename": "arrayobject.c", + "nloc": 40, + "complexity": 16, + "token_count": 276, + "parameters": [ + "mp", + "at", + "fortran" + ], + "start_line": 5539, + "end_line": 5585, + "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": 5595, + "end_line": 5648, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 54, + "top_nesting_level": 0 + }, + { + "name": "PyArray_FromArray", + "long_name": "PyArray_FromArray( PyArrayObject * arr , PyArray_Descr * newtype , int flags)", + "filename": "arrayobject.c", + "nloc": 114, + "complexity": 33, + "token_count": 678, + "parameters": [ + "arr", + "newtype", + "flags" + ], + "start_line": 5653, + "end_line": 5782, + "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": 501, + "parameters": [ + "str" + ], + "start_line": 5786, + "end_line": 5894, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 109, + "top_nesting_level": 0 + }, + { + "name": "PyArray_FromStructInterface", + "long_name": "PyArray_FromStructInterface( PyObject * input)", + "filename": "arrayobject.c", + "nloc": 38, + "complexity": 6, + "token_count": 234, + "parameters": [ + "input" + ], + "start_line": 5898, + "end_line": 5938, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 41, + "top_nesting_level": 0 + }, + { + "name": "PyArray_FromInterface", + "long_name": "PyArray_FromInterface( PyObject * input)", + "filename": "arrayobject.c", + "nloc": 129, + "complexity": 28, + "token_count": 793, + "parameters": [ + "input" + ], + "start_line": 5942, + "end_line": 6080, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 139, + "top_nesting_level": 0 + }, + { + "name": "PyArray_FromArrayAttr", + "long_name": "PyArray_FromArrayAttr( PyObject * op , PyArray_Descr * typecode , PyObject * context)", + "filename": "arrayobject.c", + "nloc": 37, + "complexity": 11, + "token_count": 221, + "parameters": [ + "op", + "typecode", + "context" + ], + "start_line": 6084, + "end_line": 6121, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 38, + "top_nesting_level": 0 + }, + { + "name": "PyArray_FromAny", + "long_name": "PyArray_FromAny( PyObject * op , PyArray_Descr * newtype , int min_depth , int max_depth , int flags , PyObject * context)", + "filename": "arrayobject.c", + "nloc": 63, + "complexity": 20, + "token_count": 383, + "parameters": [ + "op", + "newtype", + "min_depth", + "max_depth", + "flags", + "context" + ], + "start_line": 6127, + "end_line": 6207, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 81, + "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": 6212, + "end_line": 6215, + "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": 6222, + "end_line": 6235, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 14, + "top_nesting_level": 0 + }, + { + "name": "PyArray_CheckFromAny", + "long_name": "PyArray_CheckFromAny( PyObject * op , PyArray_Descr * descr , int min_depth , int max_depth , int requires , PyObject * context)", + "filename": "arrayobject.c", + "nloc": 16, + "complexity": 7, + "token_count": 111, + "parameters": [ + "op", + "descr", + "min_depth", + "max_depth", + "requires", + "context" + ], + "start_line": 6281, + "end_line": 6297, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 17, + "top_nesting_level": 0 + }, + { + "name": "PyArray_EnsureArray", + "long_name": "PyArray_EnsureArray( PyObject * op)", + "filename": "arrayobject.c", + "nloc": 14, + "complexity": 5, + "token_count": 89, + "parameters": [ + "op" + ], + "start_line": 6310, + "end_line": 6326, + "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": 6332, + "end_line": 6420, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 89, + "top_nesting_level": 0 + }, + { + "name": "PyArray_CanCastTo", + "long_name": "PyArray_CanCastTo( PyArray_Descr * from , PyArray_Descr * to)", + "filename": "arrayobject.c", + "nloc": 24, + "complexity": 7, + "token_count": 132, + "parameters": [ + "from", + "to" + ], + "start_line": 6425, + "end_line": 6453, + "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": 6466, + "end_line": 6504, + "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": 6512, + "end_line": 6529, + "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": 6534, + "end_line": 6544, + "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": 6547, + "end_line": 6551, + "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": 6554, + "end_line": 6557, + "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": 6561, + "end_line": 6611, + "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": 6614, + "end_line": 6668, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 55, + "top_nesting_level": 0 + }, + { + "name": "iter_subscript", + "long_name": "iter_subscript( PyArrayIterObject * self , PyObject * ind)", + "filename": "arrayobject.c", + "nloc": 113, + "complexity": 23, + "token_count": 668, + "parameters": [ + "self", + "ind" + ], + "start_line": 6672, + "end_line": 6805, + "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": 6809, + "end_line": 6841, + "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": 6844, + "end_line": 6886, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 43, + "top_nesting_level": 0 + }, + { + "name": "iter_ass_subscript", + "long_name": "iter_ass_subscript( PyArrayIterObject * self , PyObject * ind , PyObject * val)", + "filename": "arrayobject.c", + "nloc": 115, + "complexity": 27, + "token_count": 698, + "parameters": [ + "self", + "ind", + "val" + ], + "start_line": 6889, + "end_line": 7023, + "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": 7036, + "end_line": 7081, + "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": 7086, + "end_line": 7090, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 5, + "top_nesting_level": 0 + }, + { + "name": "iter_coords_get", + "long_name": "iter_coords_get( PyArrayIterObject * self)", + "filename": "arrayobject.c", + "nloc": 15, + "complexity": 3, + "token_count": 91, + "parameters": [ + "self" + ], + "start_line": 7106, + "end_line": 7121, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 16, + "top_nesting_level": 0 + }, + { + "name": "_convert_obj", + "long_name": "_convert_obj( PyObject * obj , PyArrayIterObject ** iter)", + "filename": "arrayobject.c", + "nloc": 16, + "complexity": 5, + "token_count": 106, + "parameters": [ + "obj", + "iter" + ], + "start_line": 7186, + "end_line": 7202, + "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": 7209, + "end_line": 7278, + "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": 7282, + "end_line": 7319, + "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": 7325, + "end_line": 7369, + "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": 98, + "complexity": 21, + "token_count": 662, + "parameters": [ + "mit", + "arr" + ], + "start_line": 7387, + "end_line": 7515, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 129, + "top_nesting_level": 0 + }, + { + "name": "_nonzero_indices", + "long_name": "_nonzero_indices( PyObject * myBool , PyArrayIterObject ** iters)", + "filename": "arrayobject.c", + "nloc": 60, + "complexity": 15, + "token_count": 462, + "parameters": [ + "myBool", + "iters" + ], + "start_line": 7521, + "end_line": 7593, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 73, + "top_nesting_level": 0 + }, + { + "name": "PyArray_MapIterNew", + "long_name": "PyArray_MapIterNew( PyObject * indexobj , int oned , int fancy)", + "filename": "arrayobject.c", + "nloc": 104, + "complexity": 24, + "token_count": 726, + "parameters": [ + "indexobj", + "oned", + "fancy" + ], + "start_line": 7596, + "end_line": 7722, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 127, + "top_nesting_level": 0 + }, + { + "name": "arraymapiter_dealloc", + "long_name": "arraymapiter_dealloc( PyArrayMapIterObject * mit)", + "filename": "arrayobject.c", + "nloc": 10, + "complexity": 2, + "token_count": 62, + "parameters": [ + "mit" + ], + "start_line": 7726, + "end_line": 7735, + "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": 7806, + "end_line": 7855, + "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": 267, + "parameters": [ + "subtype", + "args", + "kwds" + ], + "start_line": 7858, + "end_line": 7903, + "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": 7906, + "end_line": 7925, + "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": 7928, + "end_line": 7935, + "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": 7938, + "end_line": 7948, + "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": 7951, + "end_line": 7961, + "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": 7964, + "end_line": 7967, + "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": 7970, + "end_line": 7982, + "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": 8012, + "end_line": 8019, + "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": 8078, + "end_line": 8087, + "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": 8105, + "end_line": 8127, + "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": 8133, + "end_line": 8143, + "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": 8162, + "end_line": 8170, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 9, + "top_nesting_level": 0 + }, + { + "name": "arraydescr_protocol_typestr_get", + "long_name": "arraydescr_protocol_typestr_get( PyArray_Descr * self)", + "filename": "arrayobject.c", + "nloc": 14, + "complexity": 4, + "token_count": 79, + "parameters": [ + "self" + ], + "start_line": 8173, + "end_line": 8188, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 16, + "top_nesting_level": 0 + }, + { + "name": "arraydescr_typename_get", + "long_name": "arraydescr_typename_get( PyArray_Descr * self)", + "filename": "arrayobject.c", + "nloc": 22, + "complexity": 5, + "token_count": 132, + "parameters": [ + "self" + ], + "start_line": 8191, + "end_line": 8213, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 23, + "top_nesting_level": 0 + }, + { + "name": "arraydescr_base_get", + "long_name": "arraydescr_base_get( PyArray_Descr * self)", + "filename": "arrayobject.c", + "nloc": 9, + "complexity": 2, + "token_count": 52, + "parameters": [ + "self" + ], + "start_line": 8216, + "end_line": 8224, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 9, + "top_nesting_level": 0 + }, + { + "name": "arraydescr_shape_get", + "long_name": "arraydescr_shape_get( PyArray_Descr * self)", + "filename": "arrayobject.c", + "nloc": 8, + "complexity": 2, + "token_count": 51, + "parameters": [ + "self" + ], + "start_line": 8227, + "end_line": 8234, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 8, + "top_nesting_level": 0 + }, + { + "name": "arraydescr_protocol_descr_get", + "long_name": "arraydescr_protocol_descr_get( PyArray_Descr * self)", + "filename": "arrayobject.c", + "nloc": 17, + "complexity": 5, + "token_count": 119, + "parameters": [ + "self" + ], + "start_line": 8237, + "end_line": 8256, + "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": 8263, + "end_line": 8270, + "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": 8273, + "end_line": 8280, + "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": 8283, + "end_line": 8290, + "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": 8338, + "end_line": 8390, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 53, + "top_nesting_level": 0 + }, + { + "name": "arraydescr_reduce", + "long_name": "arraydescr_reduce( PyArray_Descr * self , PyObject * args)", + "filename": "arrayobject.c", + "nloc": 54, + "complexity": 13, + "token_count": 395, + "parameters": [ + "self", + "args" + ], + "start_line": 8396, + "end_line": 8457, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 62, + "top_nesting_level": 0 + }, + { + "name": "arraydescr_setstate", + "long_name": "arraydescr_setstate( PyArray_Descr * self , PyObject * args)", + "filename": "arrayobject.c", + "nloc": 35, + "complexity": 8, + "token_count": 260, + "parameters": [ + "self", + "args" + ], + "start_line": 8465, + "end_line": 8507, + "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": 8527, + "end_line": 8593, + "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": 8604, + "end_line": 8612, + "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": 8627, + "end_line": 8672, + "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": 8675, + "end_line": 8684, + "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": 8687, + "end_line": 8697, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 11, + "top_nesting_level": 0 + }, + { + "name": "descr_length", + "long_name": "descr_length( PyArray_Descr * self)", + "filename": "arrayobject.c", + "nloc": 6, + "complexity": 3, + "token_count": 34, + "parameters": [ + "self" + ], + "start_line": 8704, + "end_line": 8711, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 8, + "top_nesting_level": 0 + }, + { + "name": "descr_subscript", + "long_name": "descr_subscript( PyArray_Descr * self , PyObject * op)", + "filename": "arrayobject.c", + "nloc": 31, + "complexity": 5, + "token_count": 126, + "parameters": [ + "self", + "op" + ], + "start_line": 8714, + "end_line": 8746, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 33, + "top_nesting_level": 0 + } + ], + "methods_before": [ + { + "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": 28, + "end_line": 46, + "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": 67, + "end_line": 95, + "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": 101, + "end_line": 130, + "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": 136, + "end_line": 186, + "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": 209, + "end_line": 240, + "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": 243, + "end_line": 277, + "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": 293, + "end_line": 315, + "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": 321, + "end_line": 342, + "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": 346, + "end_line": 384, + "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": 389, + "end_line": 409, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 21, + "top_nesting_level": 0 + }, + { + "name": "PyArray_PyIntAsIntp", + "long_name": "PyArray_PyIntAsIntp( PyObject * o)", + "filename": "arrayobject.c", + "nloc": 71, + "complexity": 21, + "token_count": 413, + "parameters": [ + "o" + ], + "start_line": 429, + "end_line": 511, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 83, + "top_nesting_level": 0 + }, + { + "name": "PyArray_PyIntAsInt", + "long_name": "PyArray_PyIntAsInt( PyObject * o)", + "filename": "arrayobject.c", + "nloc": 67, + "complexity": 19, + "token_count": 406, + "parameters": [ + "o" + ], + "start_line": 518, + "end_line": 592, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 75, + "top_nesting_level": 0 + }, + { + "name": "index2ptr", + "long_name": "index2ptr( PyArrayObject * mp , intp i)", + "filename": "arrayobject.c", + "nloc": 15, + "complexity": 7, + "token_count": 98, + "parameters": [ + "mp", + "i" + ], + "start_line": 595, + "end_line": 610, + "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": 616, + "end_line": 624, + "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": 640, + "end_line": 720, + "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": 81, + "parameters": [ + "dest", + "src_object" + ], + "start_line": 724, + "end_line": 738, + "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": 751, + "end_line": 777, + "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": 783, + "end_line": 797, + "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": 806, + "end_line": 826, + "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": 92, + "complexity": 14, + "token_count": 554, + "parameters": [ + "data", + "descr", + "base" + ], + "start_line": 835, + "end_line": 940, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 106, + "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": 956, + "end_line": 959, + "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": 969, + "end_line": 991, + "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": 1005, + "end_line": 1045, + "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": 1060, + "end_line": 1101, + "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": 1108, + "end_line": 1199, + "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": 1205, + "end_line": 1234, + "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": 1237, + "end_line": 1273, + "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": 1282, + "end_line": 1319, + "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": 1326, + "end_line": 1334, + "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": 1337, + "end_line": 1362, + "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": 1365, + "end_line": 1368, + "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": 1372, + "end_line": 1407, + "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": 1413, + "end_line": 1416, + "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": 1422, + "end_line": 1430, + "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": 1436, + "end_line": 1486, + "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": 1493, + "end_line": 1538, + "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": 1542, + "end_line": 1636, + "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": 1639, + "end_line": 1676, + "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": 1688, + "end_line": 1741, + "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": 382, + "parameters": [ + "mit", + "op" + ], + "start_line": 1744, + "end_line": 1804, + "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": 1807, + "end_line": 1834, + "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": 1837, + "end_line": 1856, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 20, + "top_nesting_level": 0 + }, + { + "name": "fancy_indexing_check", + "long_name": "fancy_indexing_check( PyObject * args)", + "filename": "arrayobject.c", + "nloc": 56, + "complexity": 22, + "token_count": 295, + "parameters": [ + "args" + ], + "start_line": 1868, + "end_line": 1930, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 63, + "top_nesting_level": 0 + }, + { + "name": "array_subscript", + "long_name": "array_subscript( PyArrayObject * self , PyObject * op)", + "filename": "arrayobject.c", + "nloc": 103, + "complexity": 28, + "token_count": 666, + "parameters": [ + "self", + "op" + ], + "start_line": 1954, + "end_line": 2072, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 119, + "top_nesting_level": 0 + }, + { + "name": "array_ass_sub", + "long_name": "array_ass_sub( PyArrayObject * self , PyObject * index , PyObject * op)", + "filename": "arrayobject.c", + "nloc": 93, + "complexity": 28, + "token_count": 588, + "parameters": [ + "self", + "index", + "op" + ], + "start_line": 2087, + "end_line": 2192, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 106, + "top_nesting_level": 0 + }, + { + "name": "array_subscript_nice", + "long_name": "array_subscript_nice( PyArrayObject * self , PyObject * op)", + "filename": "arrayobject.c", + "nloc": 4, + "complexity": 1, + "token_count": 27, + "parameters": [ + "self", + "op" + ], + "start_line": 2201, + "end_line": 2204, + "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": 2223, + "end_line": 2235, + "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": 2238, + "end_line": 2253, + "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": 2257, + "end_line": 2266, + "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": 2269, + "end_line": 2280, + "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": 2351, + "end_line": 2384, + "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": 2394, + "end_line": 2433, + "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": 2436, + "end_line": 2459, + "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": 2463, + "end_line": 2486, + "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": 2490, + "end_line": 2497, + "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": 2500, + "end_line": 2507, + "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": 2510, + "end_line": 2518, + "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": 2521, + "end_line": 2524, + "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": 2527, + "end_line": 2530, + "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": 2533, + "end_line": 2536, + "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": 2539, + "end_line": 2542, + "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": 2545, + "end_line": 2548, + "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": 2551, + "end_line": 2554, + "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": 2557, + "end_line": 2560, + "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": 2563, + "end_line": 2566, + "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": 2569, + "end_line": 2572, + "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": 2575, + "end_line": 2578, + "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": 2581, + "end_line": 2584, + "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": 2587, + "end_line": 2590, + "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": 2593, + "end_line": 2596, + "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": 2599, + "end_line": 2602, + "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": 2605, + "end_line": 2608, + "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": 2611, + "end_line": 2614, + "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": 2617, + "end_line": 2620, + "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": 2623, + "end_line": 2626, + "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": 2629, + "end_line": 2632, + "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": 2635, + "end_line": 2638, + "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": 2641, + "end_line": 2644, + "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": 2647, + "end_line": 2650, + "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": 2653, + "end_line": 2656, + "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": 2659, + "end_line": 2662, + "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": 2665, + "end_line": 2668, + "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": 2671, + "end_line": 2674, + "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": 2677, + "end_line": 2680, + "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": 2683, + "end_line": 2687, + "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": 2690, + "end_line": 2694, + "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": 2698, + "end_line": 2716, + "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": 2719, + "end_line": 2736, + "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": 2741, + "end_line": 2756, + "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": 2760, + "end_line": 2786, + "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": 2789, + "end_line": 2814, + "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": 2817, + "end_line": 2839, + "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": 2842, + "end_line": 2864, + "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": 2867, + "end_line": 2889, + "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": 2892, + "end_line": 2896, + "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": 2957, + "end_line": 2997, + "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": 3001, + "end_line": 3022, + "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": 3025, + "end_line": 3037, + "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": 3058, + "end_line": 3105, + "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": 3108, + "end_line": 3144, + "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": 3153, + "end_line": 3170, + "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": 3173, + "end_line": 3185, + "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": 3188, + "end_line": 3200, + "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": 81, + "complexity": 17, + "token_count": 357, + "parameters": [ + "self", + "other", + "cmp_op" + ], + "start_line": 3203, + "end_line": 3300, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 98, + "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": 171, + "parameters": [ + "arr", + "axis", + "flags" + ], + "start_line": 3303, + "end_line": 3332, + "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": 3338, + "end_line": 3358, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 21, + "top_nesting_level": 0 + }, + { + "name": "PyArray_IntpFromSequence", + "long_name": "PyArray_IntpFromSequence( PyObject * seq , intp * vals , int maxvals)", + "filename": "arrayobject.c", + "nloc": 24, + "complexity": 11, + "token_count": 203, + "parameters": [ + "seq", + "vals", + "maxvals" + ], + "start_line": 3366, + "end_line": 3401, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 36, + "top_nesting_level": 0 + }, + { + "name": "_IsContiguous", + "long_name": "_IsContiguous( PyArrayObject * ap)", + "filename": "arrayobject.c", + "nloc": 17, + "complexity": 7, + "token_count": 128, + "parameters": [ + "ap" + ], + "start_line": 3407, + "end_line": 3426, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 20, + "top_nesting_level": 0 + }, + { + "name": "_IsFortranContiguous", + "long_name": "_IsFortranContiguous( PyArrayObject * ap)", + "filename": "arrayobject.c", + "nloc": 17, + "complexity": 7, + "token_count": 126, + "parameters": [ + "ap" + ], + "start_line": 3430, + "end_line": 3448, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 19, + "top_nesting_level": 0 + }, + { + "name": "_IsAligned", + "long_name": "_IsAligned( PyArrayObject * ap)", + "filename": "arrayobject.c", + "nloc": 15, + "complexity": 5, + "token_count": 119, + "parameters": [ + "ap" + ], + "start_line": 3451, + "end_line": 3468, + "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": 3471, + "end_line": 3504, + "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": 3511, + "end_line": 3538, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 28, + "top_nesting_level": 0 + }, + { + "name": "PyArray_CheckStrides", + "long_name": "PyArray_CheckStrides( int elsize , int nd , intp numbytes , intp offset , intp * dims , intp * newstrides)", + "filename": "arrayobject.c", + "nloc": 23, + "complexity": 7, + "token_count": 135, + "parameters": [ + "elsize", + "nd", + "numbytes", + "offset", + "dims", + "newstrides" + ], + "start_line": 3552, + "end_line": 3587, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 36, + "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": 3607, + "end_line": 3631, + "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": 3637, + "end_line": 3659, + "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": 3663, + "end_line": 3705, + "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": 136, + "complexity": 27, + "token_count": 781, + "parameters": [ + "subtype", + "descr", + "nd", + "dims", + "strides", + "data", + "flags", + "obj" + ], + "start_line": 3713, + "end_line": 3878, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 166, + "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": 3887, + "end_line": 3985, + "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": 3991, + "end_line": 4008, + "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": 231, + "parameters": [ + "arr", + "obj" + ], + "start_line": 4012, + "end_line": 4054, + "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": 19, + "token_count": 577, + "parameters": [ + "subtype", + "args", + "kwds" + ], + "start_line": 4057, + "end_line": 4174, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 118, + "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": 4178, + "end_line": 4186, + "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": 4192, + "end_line": 4195, + "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": 4198, + "end_line": 4202, + "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": 4205, + "end_line": 4208, + "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": 4212, + "end_line": 4241, + "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": 4245, + "end_line": 4248, + "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": 37, + "complexity": 7, + "token_count": 239, + "parameters": [ + "self", + "obj" + ], + "start_line": 4251, + "end_line": 4290, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 40, + "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": 4294, + "end_line": 4301, + "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": 4304, + "end_line": 4312, + "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": 4316, + "end_line": 4322, + "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": 4325, + "end_line": 4339, + "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": 4342, + "end_line": 4386, + "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": 4390, + "end_line": 4393, + "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": 4396, + "end_line": 4407, + "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": 4410, + "end_line": 4421, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 12, + "top_nesting_level": 0 + }, + { + "name": "array_typestr_get", + "long_name": "array_typestr_get( PyArrayObject * self)", + "filename": "arrayobject.c", + "nloc": 4, + "complexity": 1, + "token_count": 16, + "parameters": [ + "self" + ], + "start_line": 4427, + "end_line": 4430, + "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": 4433, + "end_line": 4437, + "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": 62, + "complexity": 15, + "token_count": 438, + "parameters": [ + "self", + "arg" + ], + "start_line": 4451, + "end_line": 4537, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 87, + "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": 4540, + "end_line": 4558, + "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": 4561, + "end_line": 4579, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 19, + "top_nesting_level": 0 + }, + { + "name": "array_base_get", + "long_name": "array_base_get( PyArrayObject * self)", + "filename": "arrayobject.c", + "nloc": 11, + "complexity": 2, + "token_count": 41, + "parameters": [ + "self" + ], + "start_line": 4582, + "end_line": 4592, + "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": 4596, + "end_line": 4621, + "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": 191, + "parameters": [ + "self", + "val" + ], + "start_line": 4625, + "end_line": 4658, + "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": 4661, + "end_line": 4694, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 34, + "top_nesting_level": 0 + }, + { + "name": "array_imag_set", + "long_name": "array_imag_set( PyArrayObject * self , PyObject * val)", + "filename": "arrayobject.c", + "nloc": 37, + "complexity": 4, + "token_count": 207, + "parameters": [ + "self", + "val" + ], + "start_line": 4697, + "end_line": 4734, + "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": 4737, + "end_line": 4740, + "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": 348, + "parameters": [ + "self", + "val" + ], + "start_line": 4743, + "end_line": 4793, + "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": 4883, + "end_line": 4890, + "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": 4992, + "end_line": 5025, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 34, + "top_nesting_level": 0 + }, + { + "name": "discover_itemsize", + "long_name": "discover_itemsize( PyObject * s , int nd , int * itemsize)", + "filename": "arrayobject.c", + "nloc": 21, + "complexity": 9, + "token_count": 158, + "parameters": [ + "s", + "nd", + "itemsize" + ], + "start_line": 5028, + "end_line": 5050, + "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": 5057, + "end_line": 5083, + "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": 5089, + "end_line": 5121, + "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": 128, + "complexity": 34, + "token_count": 742, + "parameters": [ + "op", + "minitype", + "max" + ], + "start_line": 5133, + "end_line": 5281, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 149, + "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": 5284, + "end_line": 5307, + "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": 29, + "complexity": 7, + "token_count": 168, + "parameters": [ + "op", + "typecode" + ], + "start_line": 5312, + "end_line": 5346, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 35, + "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": 54, + "complexity": 21, + "token_count": 352, + "parameters": [ + "s", + "typecode", + "fortran", + "min_depth", + "max_depth" + ], + "start_line": 5351, + "end_line": 5414, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 64, + "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": 5421, + "end_line": 5430, + "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": 5436, + "end_line": 5529, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 94, + "top_nesting_level": 0 + }, + { + "name": "PyArray_CastToType", + "long_name": "PyArray_CastToType( PyArrayObject * mp , PyArray_Descr * at , int fortran)", + "filename": "arrayobject.c", + "nloc": 40, + "complexity": 16, + "token_count": 276, + "parameters": [ + "mp", + "at", + "fortran" + ], + "start_line": 5539, + "end_line": 5585, + "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": 5595, + "end_line": 5648, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 54, + "top_nesting_level": 0 + }, + { + "name": "PyArray_FromArray", + "long_name": "PyArray_FromArray( PyArrayObject * arr , PyArray_Descr * newtype , int flags)", + "filename": "arrayobject.c", + "nloc": 114, + "complexity": 33, + "token_count": 676, + "parameters": [ + "arr", + "newtype", + "flags" + ], + "start_line": 5653, + "end_line": 5782, + "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": 501, + "parameters": [ + "str" + ], + "start_line": 5786, + "end_line": 5894, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 109, + "top_nesting_level": 0 + }, + { + "name": "PyArray_FromStructInterface", + "long_name": "PyArray_FromStructInterface( PyObject * input)", + "filename": "arrayobject.c", + "nloc": 38, + "complexity": 6, + "token_count": 234, + "parameters": [ + "input" + ], + "start_line": 5898, + "end_line": 5938, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 41, + "top_nesting_level": 0 + }, + { + "name": "PyArray_FromInterface", + "long_name": "PyArray_FromInterface( PyObject * input)", + "filename": "arrayobject.c", + "nloc": 129, + "complexity": 28, + "token_count": 793, + "parameters": [ + "input" + ], + "start_line": 5942, + "end_line": 6080, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 139, + "top_nesting_level": 0 + }, + { + "name": "PyArray_FromArrayAttr", + "long_name": "PyArray_FromArrayAttr( PyObject * op , PyArray_Descr * typecode , PyObject * context)", + "filename": "arrayobject.c", + "nloc": 37, + "complexity": 11, + "token_count": 221, + "parameters": [ + "op", + "typecode", + "context" + ], + "start_line": 6084, + "end_line": 6121, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 38, + "top_nesting_level": 0 + }, + { + "name": "PyArray_FromAny", + "long_name": "PyArray_FromAny( PyObject * op , PyArray_Descr * newtype , int min_depth , int max_depth , int flags , PyObject * context)", + "filename": "arrayobject.c", + "nloc": 63, + "complexity": 20, + "token_count": 383, + "parameters": [ + "op", + "newtype", + "min_depth", + "max_depth", + "flags", + "context" + ], + "start_line": 6127, + "end_line": 6207, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 81, + "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": 6212, + "end_line": 6215, + "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": 6222, + "end_line": 6235, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 14, + "top_nesting_level": 0 + }, + { + "name": "PyArray_CheckFromAny", + "long_name": "PyArray_CheckFromAny( PyObject * op , PyArray_Descr * descr , int min_depth , int max_depth , int requires , PyObject * context)", + "filename": "arrayobject.c", + "nloc": 16, + "complexity": 7, + "token_count": 111, + "parameters": [ + "op", + "descr", + "min_depth", + "max_depth", + "requires", + "context" + ], + "start_line": 6281, + "end_line": 6297, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 17, + "top_nesting_level": 0 + }, + { + "name": "PyArray_EnsureArray", + "long_name": "PyArray_EnsureArray( PyObject * op)", + "filename": "arrayobject.c", + "nloc": 14, + "complexity": 5, + "token_count": 89, + "parameters": [ + "op" + ], + "start_line": 6310, + "end_line": 6326, + "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": 6332, + "end_line": 6420, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 89, + "top_nesting_level": 0 + }, + { + "name": "PyArray_CanCastTo", + "long_name": "PyArray_CanCastTo( PyArray_Descr * from , PyArray_Descr * to)", + "filename": "arrayobject.c", + "nloc": 24, + "complexity": 7, + "token_count": 132, + "parameters": [ + "from", + "to" + ], + "start_line": 6425, + "end_line": 6453, + "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": 6466, + "end_line": 6504, + "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": 6512, + "end_line": 6529, + "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": 6534, + "end_line": 6544, + "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": 6547, + "end_line": 6551, + "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": 6554, + "end_line": 6557, + "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": 6561, + "end_line": 6611, + "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": 6614, + "end_line": 6668, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 55, + "top_nesting_level": 0 + }, + { + "name": "iter_subscript", + "long_name": "iter_subscript( PyArrayIterObject * self , PyObject * ind)", + "filename": "arrayobject.c", + "nloc": 113, + "complexity": 23, + "token_count": 668, + "parameters": [ + "self", + "ind" + ], + "start_line": 6672, + "end_line": 6805, + "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": 6809, + "end_line": 6841, + "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": 6844, + "end_line": 6886, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 43, + "top_nesting_level": 0 + }, + { + "name": "iter_ass_subscript", + "long_name": "iter_ass_subscript( PyArrayIterObject * self , PyObject * ind , PyObject * val)", + "filename": "arrayobject.c", + "nloc": 115, + "complexity": 27, + "token_count": 698, + "parameters": [ + "self", + "ind", + "val" + ], + "start_line": 6889, + "end_line": 7023, + "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": 7036, + "end_line": 7081, + "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": 7086, + "end_line": 7090, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 5, + "top_nesting_level": 0 + }, + { + "name": "iter_coords_get", + "long_name": "iter_coords_get( PyArrayIterObject * self)", + "filename": "arrayobject.c", + "nloc": 15, + "complexity": 3, + "token_count": 91, + "parameters": [ + "self" + ], + "start_line": 7106, + "end_line": 7121, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 16, + "top_nesting_level": 0 + }, + { + "name": "_convert_obj", + "long_name": "_convert_obj( PyObject * obj , PyArrayIterObject ** iter)", + "filename": "arrayobject.c", + "nloc": 16, + "complexity": 5, + "token_count": 106, + "parameters": [ + "obj", + "iter" + ], + "start_line": 7186, + "end_line": 7202, + "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": 7209, + "end_line": 7278, + "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": 7282, + "end_line": 7319, + "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": 7325, + "end_line": 7369, + "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": 98, + "complexity": 21, + "token_count": 662, + "parameters": [ + "mit", + "arr" + ], + "start_line": 7387, + "end_line": 7515, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 129, + "top_nesting_level": 0 + }, + { + "name": "_nonzero_indices", + "long_name": "_nonzero_indices( PyObject * myBool , PyArrayIterObject ** iters)", + "filename": "arrayobject.c", + "nloc": 60, + "complexity": 15, + "token_count": 462, + "parameters": [ + "myBool", + "iters" + ], + "start_line": 7521, + "end_line": 7593, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 73, + "top_nesting_level": 0 + }, + { + "name": "PyArray_MapIterNew", + "long_name": "PyArray_MapIterNew( PyObject * indexobj , int oned , int fancy)", + "filename": "arrayobject.c", + "nloc": 104, + "complexity": 24, + "token_count": 726, + "parameters": [ + "indexobj", + "oned", + "fancy" + ], + "start_line": 7596, + "end_line": 7722, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 127, + "top_nesting_level": 0 + }, + { + "name": "arraymapiter_dealloc", + "long_name": "arraymapiter_dealloc( PyArrayMapIterObject * mit)", + "filename": "arrayobject.c", + "nloc": 10, + "complexity": 2, + "token_count": 62, + "parameters": [ + "mit" + ], + "start_line": 7726, + "end_line": 7735, + "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": 7806, + "end_line": 7855, + "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": 267, + "parameters": [ + "subtype", + "args", + "kwds" + ], + "start_line": 7858, + "end_line": 7903, + "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": 7906, + "end_line": 7925, + "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": 7928, + "end_line": 7935, + "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": 7938, + "end_line": 7948, + "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": 7951, + "end_line": 7961, + "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": 7964, + "end_line": 7967, + "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": 7970, + "end_line": 7982, + "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": 8012, + "end_line": 8019, + "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": 8078, + "end_line": 8087, + "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": 8105, + "end_line": 8127, + "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": 8133, + "end_line": 8143, + "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": 8162, + "end_line": 8170, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 9, + "top_nesting_level": 0 + }, + { + "name": "arraydescr_protocol_typestr_get", + "long_name": "arraydescr_protocol_typestr_get( PyArray_Descr * self)", + "filename": "arrayobject.c", + "nloc": 14, + "complexity": 4, + "token_count": 79, + "parameters": [ + "self" + ], + "start_line": 8173, + "end_line": 8188, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 16, + "top_nesting_level": 0 + }, + { + "name": "arraydescr_typename_get", + "long_name": "arraydescr_typename_get( PyArray_Descr * self)", + "filename": "arrayobject.c", + "nloc": 22, + "complexity": 5, + "token_count": 132, + "parameters": [ + "self" + ], + "start_line": 8191, + "end_line": 8213, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 23, + "top_nesting_level": 0 + }, + { + "name": "arraydescr_base_get", + "long_name": "arraydescr_base_get( PyArray_Descr * self)", + "filename": "arrayobject.c", + "nloc": 9, + "complexity": 2, + "token_count": 52, + "parameters": [ + "self" + ], + "start_line": 8216, + "end_line": 8224, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 9, + "top_nesting_level": 0 + }, + { + "name": "arraydescr_shape_get", + "long_name": "arraydescr_shape_get( PyArray_Descr * self)", + "filename": "arrayobject.c", + "nloc": 8, + "complexity": 2, + "token_count": 51, + "parameters": [ + "self" + ], + "start_line": 8227, + "end_line": 8234, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 8, + "top_nesting_level": 0 + }, + { + "name": "arraydescr_protocol_descr_get", + "long_name": "arraydescr_protocol_descr_get( PyArray_Descr * self)", + "filename": "arrayobject.c", + "nloc": 17, + "complexity": 5, + "token_count": 119, + "parameters": [ + "self" + ], + "start_line": 8237, + "end_line": 8256, + "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": 8263, + "end_line": 8270, + "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": 8273, + "end_line": 8280, + "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": 8283, + "end_line": 8290, + "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": 8338, + "end_line": 8390, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 53, + "top_nesting_level": 0 + }, + { + "name": "arraydescr_reduce", + "long_name": "arraydescr_reduce( PyArray_Descr * self , PyObject * args)", + "filename": "arrayobject.c", + "nloc": 54, + "complexity": 13, + "token_count": 395, + "parameters": [ + "self", + "args" + ], + "start_line": 8396, + "end_line": 8457, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 62, + "top_nesting_level": 0 + }, + { + "name": "arraydescr_setstate", + "long_name": "arraydescr_setstate( PyArray_Descr * self , PyObject * args)", + "filename": "arrayobject.c", + "nloc": 35, + "complexity": 8, + "token_count": 260, + "parameters": [ + "self", + "args" + ], + "start_line": 8465, + "end_line": 8507, + "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": 8527, + "end_line": 8593, + "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": 8604, + "end_line": 8612, + "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": 8627, + "end_line": 8672, + "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": 8675, + "end_line": 8684, + "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": 8687, + "end_line": 8697, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 11, + "top_nesting_level": 0 + }, + { + "name": "descr_length", + "long_name": "descr_length( PyArray_Descr * self)", + "filename": "arrayobject.c", + "nloc": 6, + "complexity": 3, + "token_count": 34, + "parameters": [ + "self" + ], + "start_line": 8704, + "end_line": 8711, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 8, + "top_nesting_level": 0 + }, + { + "name": "descr_subscript", + "long_name": "descr_subscript( PyArray_Descr * self , PyObject * op)", + "filename": "arrayobject.c", + "nloc": 31, + "complexity": 5, + "token_count": 126, + "parameters": [ + "self", + "op" + ], + "start_line": 8714, + "end_line": 8746, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 33, + "top_nesting_level": 0 + } + ], + "changed_methods": [ + { + "name": "PyArray_FromArray", + "long_name": "PyArray_FromArray( PyArrayObject * arr , PyArray_Descr * newtype , int flags)", + "filename": "arrayobject.c", + "nloc": 114, + "complexity": 33, + "token_count": 678, + "parameters": [ + "arr", + "newtype", + "flags" + ], + "start_line": 5653, + "end_line": 5782, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 130, + "top_nesting_level": 0 + } + ], + "nloc": 6970, + "complexity": 1492, + "token_count": 40851, + "diff_parsed": { + "added": [ + "\t\tif ((flags & FORCECAST) || PyArray_NDIM(arr)==0 ||" + ], + "deleted": [ + "\t\tif (flags & FORCECAST || PyArray_NDIM(arr)==0 ||" + ] + } + }, + { + "old_path": "numpy/core/src/multiarraymodule.c", + "new_path": "numpy/core/src/multiarraymodule.c", + "filename": "multiarraymodule.c", + "extension": "c", + "change_type": "MODIFY", + "diff": "@@ -2898,8 +2898,9 @@ PyArray_Put(PyArrayObject *self, PyObject* values0, PyObject *indices0)\n ni = PyArray_SIZE(indices);\n \n \tthistype = self->descr->type_num;\n- values = (PyArrayObject *)\\\n-\t\tPyArray_ContiguousFromAny(values0, thistype, 0, 0);\n+ Py_INCREF(self->descr);\n+ values = (PyArrayObject *)PyArray_FromAny(values0, self->descr, 0, 0,\n+ DEFAULT_FLAGS | FORCECAST, NULL);\n if (values == NULL) goto fail;\n nv = PyArray_SIZE(values);\n if (nv > 0) { /* nv == 0 for a null array */\n", + "added_lines": 3, + "deleted_lines": 2, + "source_code": "\n/*\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 extensively for numpy 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, \"dtype\");\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, \"dtype\",\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)) == 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\tif (mps[i]->ob_type != subtype) {\n\t\t\tprior2 = PyArray_GetPriority((PyObject *)(mps[i]), 0.0);\n\t\t\tif (prior2 > prior1) {\n\t\t\t\tprior1 = prior2;\n\t\t\t\tsubtype = mps[i]->ob_type;\n\t\t\t\tret = mps[i];\n\t\t\t}\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, NULL);\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 Make a new empty array, of the passed size, of a type that takes the\n priority of ap1 and ap2 into account.\n */\nstatic PyArrayObject *\nnew_array_for_sum(PyArrayObject *ap1, PyArrayObject *ap2,\n\t\t int nd, intp dimensions[], int typenum)\n{\n\tPyArrayObject *ret;\n\tPyTypeObject *subtype;\n\tdouble prior1, prior2;\n\t/* Need to choose an output array that can hold a sum \n\t -- use priority to determine which subtype.\n\t */\n\tif (ap2->ob_type != ap1->ob_type) {\n\t\tprior2 = PyArray_GetPriority((PyObject *)ap2, 0.0);\n\t\tprior1 = PyArray_GetPriority((PyObject *)ap1, 0.0);\n\n\t\tsubtype = (prior2 > prior1 ? ap2->ob_type : ap1->ob_type);\n\t} else {\n\t\tprior1 = prior2 = 0.0;\n\t\tsubtype = ap1->ob_type;\n\t}\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\treturn ret;\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\tPyArrayIterObject *it1, *it2;\n\tintp i, j, l;\n\tint typenum, nd;\n\tintp is1, is2, os;\n\tchar *op;\n\tintp dimensions[MAX_DIMS];\n\tPyArray_DotFunc *dot;\n\tPyArray_Descr *typec;\n\t\n\ttypenum = PyArray_ObjectType(op1, 0); \n\ttypenum = PyArray_ObjectType(op2, typenum);\n\n\ttypec = PyArray_DescrFromType(typenum);\n\tPy_INCREF(typec);\n\tap1 = (PyArrayObject *)PyArray_FromAny(op1, typec, 0, 0, \n\t\t\t\t\t BEHAVED_FLAGS, NULL);\n\tif (ap1 == NULL) {Py_DECREF(typec); return NULL;}\n\tap2 = (PyArrayObject *)PyArray_FromAny(op2, typec, 0, 0,\n\t\t\t\t\t BEHAVED_FLAGS, NULL);\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\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\tret = new_array_for_sum(ap1, ap2, nd, dimensions, typenum);\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\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\tit1 = (PyArrayIterObject *)\\\n\t\tPyArray_IterAllButAxis((PyObject *)ap1, ap1->nd-1);\n\tit2 = (PyArrayIterObject *)\\\n\t\tPyArray_IterAllButAxis((PyObject *)ap2, ap2->nd-1);\n\n\twhile(1) {\n\t\twhile(it2->index < it2->size) {\n\t\t\tdot(it1->dataptr, is1, it2->dataptr, is2, op, l, ret);\n\t\t\top += os;\n\t\t\tPyArray_ITER_NEXT(it2);\n\t\t}\n\t\tPyArray_ITER_NEXT(it1);\n\t\tif (it1->index >= it1->size) break;\n\t\tPyArray_ITER_RESET(it2);\n\t}\n\tPy_DECREF(it1);\n\tPy_DECREF(it2);\n\n\tif (PyErr_Occurred()) goto fail;\n\t\t\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/* just like inner product but does the swapaxes stuff on the fly */\n/*MULTIARRAY_API\n Numeric.matrixproduct(a,v)\n*/\nstatic PyObject *\nPyArray_MatrixProduct(PyObject *op1, PyObject *op2) \n{\n\tPyArrayObject *ap1, *ap2, *ret=NULL;\n\tPyArrayIterObject *it1, *it2;\n\tintp i, j, l;\n\tint typenum, nd;\n\tintp is1, is2, os;\n\tchar *op;\n\tintp dimensions[MAX_DIMS];\n\tPyArray_DotFunc *dot;\n\tintp matchDim;\n\tPyArray_Descr *typec;\n\n\ttypenum = PyArray_ObjectType(op1, 0); \n\ttypenum = PyArray_ObjectType(op2, typenum);\t\n\t\n\ttypec = PyArray_DescrFromType(typenum);\n\tPy_INCREF(typec);\n\tap1 = (PyArrayObject *)PyArray_FromAny(op1, typec, 0, 0, \n\t\t\t\t\t BEHAVED_FLAGS, NULL);\n\tif (ap1 == NULL) {Py_DECREF(typec); return NULL;}\n\tap2 = (PyArrayObject *)PyArray_FromAny(op2, typec, 0, 0,\n\t\t\t\t\t BEHAVED_FLAGS, NULL);\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\tif (ap2->nd > 1) {\n\t\tmatchDim = ap2->nd - 2;\n\t}\n\telse {\n\t\tmatchDim = 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\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; istrides[ap1->nd-1]; is2 = ap2->strides[matchDim];\n\n /* Choose which subtype to return */\n\tret = new_array_for_sum(ap1, ap2, nd, dimensions, typenum);\n\tif (ret == NULL) goto fail;\n\n\t/* Ensure that multiarray.dot([],[]) -> 0 */\n\tmemset(PyArray_DATA(ret), 0, PyArray_ITEMSIZE(ret));\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\top = ret->data; os = ret->descr->elsize;\n\n\tit1 = (PyArrayIterObject *)\\\n\t\tPyArray_IterAllButAxis((PyObject *)ap1, ap1->nd-1);\n\tit2 = (PyArrayIterObject *)\\\n\t\tPyArray_IterAllButAxis((PyObject *)ap2, matchDim);\n\n\twhile(1) {\n\t\twhile(it2->index < it2->size) {\n\t\t\tdot(it1->dataptr, is1, it2->dataptr, is2, op, l, ret);\n\t\t\top += os;\n\t\t\tPyArray_ITER_NEXT(it2);\n\t\t}\n\t\tPyArray_ITER_NEXT(it1);\n\t\tif (it1->index >= it1->size) break;\n\t\tPyArray_ITER_RESET(it2);\n\t}\n\tPy_DECREF(it1);\n\tPy_DECREF(it2);\n\tif (PyErr_Occurred()) goto fail; /* only for OBJECT arrays */\n\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/*MULTIARRAY_API\n Fast Copy and Transpose\n*/\nstatic PyObject *\nPyArray_CopyAndTranspose(PyObject *op) \n{\n\tPyObject *ret, *arr;\n\tint nd;\n\tintp dims[2];\n\tintp i,j;\n\tint elsize, str2;\n\tchar *iptr;\n\tchar *optr;\n\n\t/* make sure it is well-behaved */\n\tarr = PyArray_FromAny(op, NULL, 0, 0, CARRAY_FLAGS, NULL);\n\tnd = PyArray_NDIM(arr);\n\tif (nd == 1) { /* we will give in to old behavior */\n\t\tret = PyArray_Copy((PyArrayObject *)arr);\n\t\tPy_DECREF(arr);\n\t\treturn ret;\t\t\n\t}\n\telse if (nd != 2) {\n\t\tPy_DECREF(arr);\n\t\tPyErr_SetString(PyExc_ValueError, \n\t\t\t\t\"only 2-d arrays are allowed\");\n\t\treturn NULL;\n\t}\n\n\t/* Now construct output array */\n\tdims[0] = PyArray_DIM(arr,1);\n\tdims[1] = PyArray_DIM(arr,0);\n\telsize = PyArray_ITEMSIZE(arr);\n\t\n\tPy_INCREF(PyArray_DESCR(arr));\n\tret = PyArray_NewFromDescr(arr->ob_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\tret = new_array_for_sum(ap1, ap2, 1, &length, typenum);\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 Py_INCREF(self->descr);\n values = (PyArrayObject *)PyArray_FromAny(values0, self->descr, 0, 0,\n DEFAULT_FLAGS | FORCECAST, NULL);\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, NULL);\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\tif (type->type_num == PyArray_UNICODE)\n\t\t\ttype->elsize = itemsize << 2; \n\t\telse\n\t\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\tif (type->hasobject) newdescr->hasobject = 1;\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 int hasobject=0;\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; ihasobject)\n hasobject = 1;\n\t\ttup = PyTuple_New(2);\n\t\tPyTuple_SET_ITEM(tup, 0, (PyObject *)conv);\n\t\tPyTuple_SET_ITEM(tup, 1, PyInt_FromLong((long) totalsize));\n\t\ttotalsize += conv->elsize;\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 new->hasobject=hasobject;\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 int hasobject=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; ihasobject)\n\t\t\thasobject=1;\t\t\t\n\t\tPyTuple_SET_ITEM(tup, 0, (PyObject *)conv);\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\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\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 new->hasobject=hasobject;\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 int hasobject=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\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\tPyTuple_SET_ITEM(tup, 1, PyInt_FromLong(totalsize));\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\tif (PyDict_GetItem(fields, name) != NULL) {\n\t\t\tPyErr_SetString(PyExc_ValueError,\n\t\t\t\t\t\"two fields with the same name\");\n\t\t\tret = PY_FAIL;\n\t\t}\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 if (!hasobject && newdescr->hasobject)\n hasobject = 1;\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 new->hasobject=hasobject;\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 == '|' || (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\tint i;\n\t\t\telsize = atoi(type+1);\n\t\t\t/* check for commas present */\n\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\nstatic PyObject *\n_prepend_ones(PyArrayObject *arr, int nd, int ndmin)\n{\n\tintp newdims[MAX_DIMS];\n\tintp newstrides[MAX_DIMS];\n\tint i,k,num;\n\tPyObject *ret;\n\n\tnum = ndmin-nd;\n\tfor (i=0; idescr->elsize;\n\t}\n\tfor (i=num;idimensions[k];\n\t\tnewstrides[i] = arr->strides[k];\n\t}\n\tPy_INCREF(arr->descr);\n\tret = PyArray_NewFromDescr(arr->ob_type, arr->descr, ndmin,\n\t\t\t\t newdims, newstrides, arr->data, arr->flags,\n\t\t\t\t (PyObject *)arr);\n\t/* steals a reference to arr --- so don't increment\n\t here */\n\tPyArray_BASE(ret) = (PyObject *)arr;\n\treturn ret;\n}\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,ndmin=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\"\\\n\t\"The ndmin argument specifies how many dimensions the returned\\n\"\\\n\t\"array should have as a minimum. 1's will be pre-pended to the\\n\"\\\n\t\"shape as needed to meet this requirement.\";\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\t\t\t \"ndmin\", NULL};\n Bool subok=FALSE;\n\tBool copy=TRUE;\n\tint ndmin=0, nd;\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&i\", 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\t\t\t\t&ndmin)) \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\tret = op;\n\t\t\t\tgoto finish;\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\tgoto finish;\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\tret = op;\n\t\t\t\tgoto finish;\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\tgoto finish;\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_CheckFromAny(op, type, 0, 0, flags, NULL)) == NULL) \n\t\treturn NULL;\n\n finish:\n\n\tif ((nd=PyArray_NDIM(ret)) >= ndmin) return ret;\n\t/* create a new array from the same data with ones in the shape */\n\t/* steals a reference to ret */\n\treturn _prepend_ones((PyArrayObject *)ret, nd, ndmin);\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(dtype,obj) will return a new scalar array of the given type initialized with obj. Mainly for pickle support. The dtype must be a valid data-type descriptor. If dtype 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[] = {\"dtype\",\"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}; /* XXX ? */\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\nstatic int\n_skip_sep(char **ptr, char *sep)\n{\n\tchar *a;\n\tint n;\n\tn = strlen(sep);\n\ta = *ptr;\n\twhile(*a != '\\0' && (strncmp(a, sep, n) != 0))\n\t\ta++;\n\tif (*a == '\\0') return -1;\n\t*ptr = a+strlen(sep);\n\treturn 0;\n}\n\n/* steals a reference to dtype -- accepts NULL */\n/*OBJECT_API*/\nstatic PyObject *\nPyArray_FromString(char *data, intp slen, PyArray_Descr *dtype, \n\t\t intp n, char *sep)\n{\n\tint itemsize;\n\tPyArrayObject *ret;\n\tBool binary;\n\n\tif (dtype == NULL)\n\t\tdtype=PyArray_DescrFromType(PyArray_LONG);\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\n\tbinary = ((sep == NULL) || (strlen(sep) == 0));\t\n\n\tif (binary) {\n\t\tif (dtype == &OBJECT_Descr) {\n\t\t\tPyErr_SetString(PyExc_ValueError, \n\t\t\t\t\t\"Cannot create an object array from\"\\\n\t\t\t\t\t\" a binary string\");\n\t\t\tPy_DECREF(dtype);\n\t\t\treturn NULL;\n\t\t}\t\t\n\t\tif (n < 0 ) {\n\t\t\tif (slen % itemsize != 0) {\n\t\t\t\tPyErr_SetString(PyExc_ValueError, \n\t\t\t\t\t\t\"string size must be a \"\\\n\t\t\t\t\t\t\"multiple of element size\");\n\t\t\t\tPy_DECREF(dtype);\n\t\t\t\treturn NULL;\n\t\t\t}\n\t\t\tn = slen/itemsize;\n\t\t} else {\n\t\t\tif (slen < n*itemsize) {\n\t\t\t\tPyErr_SetString(PyExc_ValueError, \n\t\t\t\t\t\t\"string is smaller than \" \\\n\t\t\t\t\t\t\"requested size\");\n\t\t\t\tPy_DECREF(dtype);\n\t\t\t\treturn NULL;\n\t\t\t}\n\t\t}\n\t\n\t\tif ((ret = (PyArrayObject *)\\\n\t\t PyArray_NewFromDescr(&PyArray_Type, dtype,\n\t\t\t\t\t 1, &n, NULL, NULL,\n\t\t\t\t\t 0, NULL)) == NULL)\n\t\t\treturn NULL;\t\t\n\t\tmemcpy(ret->data, data, n*dtype->elsize);\n\t\treturn (PyObject *)ret;\n\t}\n\telse { /* read from character-based string */\n\t\tchar *ptr;\t\t\n\t\tPyArray_FromStrFunc *fromstr;\n\t\tchar *dptr;\n\t\tintp nread=0;\n\t\tintp index;\n\n\t\tfromstr = dtype->f->fromstr;\n\t\tif (fromstr == 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 strings for given \"\t\\\n\t\t\t\t\t\"array type\");\n\t\t\tPy_DECREF(dtype);\n\t\t\treturn NULL;\n\t\t}\n\n\t\tif (n!=-1) {\n\t\t\tret = (PyArrayObject *) \\\n\t\t\t\tPyArray_NewFromDescr(&PyArray_Type,\n\t\t\t\t\t\t dtype, 1, &n, NULL,\n\t\t\t\t\t\t NULL, 0, NULL);\n\t\t\tif (ret == NULL) return NULL;\n\t\t\tptr = data;\n\t\t\tdptr = ret->data;\n\t\t\tfor (index=0; index < n; index++) {\n\t\t\t\tif (fromstr(ptr, dptr, &ptr, ret) < 0)\n\t\t\t\t\tbreak;\n\t\t\t\tnread += 1;\n\t\t\t\tdptr += dtype->elsize;\n\t\t\t\tif (_skip_sep(&ptr, sep) < 0) \n\t\t\t\t\tbreak;\n\t\t\t}\n\t\t\tif (nread < n) {\n\t\t\t\tfprintf(stderr, \"%ld items requested but \"\\\n\t\t\t\t\t\"only %ld read\\n\", \n\t\t\t\t\t(long) n, (long) nread);\n\t\t\t\tret->data = \\\n\t\t\t\t\tPyDataMem_RENEW(ret->data, \n\t\t\t\t\t\t\tnread *\t\t\\\n\t\t\t\t\t\t\tret->descr->elsize);\n\t\t\t\tPyArray_DIM(ret,0) = nread;\n\t\t\t}\n\t\t}\n\t\telse {\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\t\t\tchar *end;\n\t\t\tint val;\n\n\t\t\tret = (PyArrayObject *)\\\n\t\t\t\tPyArray_NewFromDescr(&PyArray_Type, \n\t\t\t\t\t\t dtype,\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 (ret==NULL) return NULL;\n\t\t\ttotalbytes = bytes = size * dtype->elsize;\n\t\t\tdptr = ret->data;\n\t\t\tptr = data;\n\t\t\tend = data+slen;\n\t\t\twhile (ptr < end) {\n\t\t\t\tval = fromstr(ptr, dptr, &ptr, ret);\n\t\t\t\tif (val < 0) break;\n\t\t\t\tnread += 1;\n\t\t\t\tval = _skip_sep(&ptr, sep);\n\t\t\t\tif (val < 0) break;\n\t\t\t\tthisbuf += 1;\n\t\t\t\tdptr += dtype->elsize;\n\t\t\t\tif (thisbuf == size) {\n\t\t\t\t\ttotalbytes += bytes;\n\t\t\t\t\tret->data = PyDataMem_RENEW(ret->data, \n\t\t\t\t\t\t\t\t totalbytes);\n\t\t\t\t\tdptr = ret->data + \\\n\t\t\t\t\t\t(totalbytes - bytes);\n\t\t\t\t\tthisbuf = 0;\n\t\t\t\t}\n\t\t\t}\n\t\t\tret->data = PyDataMem_RENEW(ret->data, \n\t\t\t\t\t\t nread*ret->descr->elsize);\n\t\t\tPyArray_DIM(ret,0) = nread;\n#undef _FILEBUFNUM\n\t\t}\n\t}\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\tchar *sep=NULL;\n\tint s;\n\tstatic char *kwlist[] = {\"string\", \"dtype\", \"count\", \"sep\", NULL};\n\tPyArray_Descr *descr=NULL;\n\n\tif (!PyArg_ParseTupleAndKeywords(args, keywds, \"s#|O&Ls\", 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, &sep)) {\n\t\treturn NULL;\n\t}\n\n\treturn PyArray_FromString(data, (intp)s, descr, (intp)nin, sep);\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\tPy_DECREF(typecode);\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\tPy_DECREF(typecode);\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\tPy_DECREF(typecode);\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 platform-independent method of persistence. But it can be \\n\"\\\n\t\" useful to 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_BYTES(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_BYTES(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_DescrConverter2,\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/*MULTIARRAY_API\n GetNDArrayCVersion\n*/\nstatic unsigned int\nPyArray_GetNDArrayCVersion(void)\n{\n\treturn (unsigned int)NDARRAY_VERSION;\n}\n\nstatic char \ndoc__get_ndarray_c_version[] = \"_get_ndarray_c_version() gets the compile time NDARRAY_VERSION number\";\n\nstatic PyObject *\narray__get_ndarray_c_version(PyObject *dummy, PyObject *args, PyObject *kwds) \n{\n\tstatic char *kwlist[] = {NULL};\n\tif(!PyArg_ParseTupleAndKeywords(args, kwds, \"\", kwlist )) return NULL;\n\t\n\treturn PyInt_FromLong( (long) PyArray_GetNDArrayCVersion() );\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, NULL);\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{\"_get_ndarray_c_version\", (PyCFunction)array__get_ndarray_c_version, \n\t METH_VARARGS|METH_KEYWORDS, doc__get_ndarray_c_version},\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, \"dtype\", (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\tif (!PyErr_Occurred()) {\n\t\tPyErr_SetString(PyExc_RuntimeError, \n\t\t\t\t\"cannot load multiarray module.\");\n\t}\n\treturn;\n}\n\n", + "source_code_before": "\n/*\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 extensively for numpy 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, \"dtype\");\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, \"dtype\",\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)) == 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\tif (mps[i]->ob_type != subtype) {\n\t\t\tprior2 = PyArray_GetPriority((PyObject *)(mps[i]), 0.0);\n\t\t\tif (prior2 > prior1) {\n\t\t\t\tprior1 = prior2;\n\t\t\t\tsubtype = mps[i]->ob_type;\n\t\t\t\tret = mps[i];\n\t\t\t}\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, NULL);\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 Make a new empty array, of the passed size, of a type that takes the\n priority of ap1 and ap2 into account.\n */\nstatic PyArrayObject *\nnew_array_for_sum(PyArrayObject *ap1, PyArrayObject *ap2,\n\t\t int nd, intp dimensions[], int typenum)\n{\n\tPyArrayObject *ret;\n\tPyTypeObject *subtype;\n\tdouble prior1, prior2;\n\t/* Need to choose an output array that can hold a sum \n\t -- use priority to determine which subtype.\n\t */\n\tif (ap2->ob_type != ap1->ob_type) {\n\t\tprior2 = PyArray_GetPriority((PyObject *)ap2, 0.0);\n\t\tprior1 = PyArray_GetPriority((PyObject *)ap1, 0.0);\n\n\t\tsubtype = (prior2 > prior1 ? ap2->ob_type : ap1->ob_type);\n\t} else {\n\t\tprior1 = prior2 = 0.0;\n\t\tsubtype = ap1->ob_type;\n\t}\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\treturn ret;\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\tPyArrayIterObject *it1, *it2;\n\tintp i, j, l;\n\tint typenum, nd;\n\tintp is1, is2, os;\n\tchar *op;\n\tintp dimensions[MAX_DIMS];\n\tPyArray_DotFunc *dot;\n\tPyArray_Descr *typec;\n\t\n\ttypenum = PyArray_ObjectType(op1, 0); \n\ttypenum = PyArray_ObjectType(op2, typenum);\n\n\ttypec = PyArray_DescrFromType(typenum);\n\tPy_INCREF(typec);\n\tap1 = (PyArrayObject *)PyArray_FromAny(op1, typec, 0, 0, \n\t\t\t\t\t BEHAVED_FLAGS, NULL);\n\tif (ap1 == NULL) {Py_DECREF(typec); return NULL;}\n\tap2 = (PyArrayObject *)PyArray_FromAny(op2, typec, 0, 0,\n\t\t\t\t\t BEHAVED_FLAGS, NULL);\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\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\tret = new_array_for_sum(ap1, ap2, nd, dimensions, typenum);\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\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\tit1 = (PyArrayIterObject *)\\\n\t\tPyArray_IterAllButAxis((PyObject *)ap1, ap1->nd-1);\n\tit2 = (PyArrayIterObject *)\\\n\t\tPyArray_IterAllButAxis((PyObject *)ap2, ap2->nd-1);\n\n\twhile(1) {\n\t\twhile(it2->index < it2->size) {\n\t\t\tdot(it1->dataptr, is1, it2->dataptr, is2, op, l, ret);\n\t\t\top += os;\n\t\t\tPyArray_ITER_NEXT(it2);\n\t\t}\n\t\tPyArray_ITER_NEXT(it1);\n\t\tif (it1->index >= it1->size) break;\n\t\tPyArray_ITER_RESET(it2);\n\t}\n\tPy_DECREF(it1);\n\tPy_DECREF(it2);\n\n\tif (PyErr_Occurred()) goto fail;\n\t\t\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/* just like inner product but does the swapaxes stuff on the fly */\n/*MULTIARRAY_API\n Numeric.matrixproduct(a,v)\n*/\nstatic PyObject *\nPyArray_MatrixProduct(PyObject *op1, PyObject *op2) \n{\n\tPyArrayObject *ap1, *ap2, *ret=NULL;\n\tPyArrayIterObject *it1, *it2;\n\tintp i, j, l;\n\tint typenum, nd;\n\tintp is1, is2, os;\n\tchar *op;\n\tintp dimensions[MAX_DIMS];\n\tPyArray_DotFunc *dot;\n\tintp matchDim;\n\tPyArray_Descr *typec;\n\n\ttypenum = PyArray_ObjectType(op1, 0); \n\ttypenum = PyArray_ObjectType(op2, typenum);\t\n\t\n\ttypec = PyArray_DescrFromType(typenum);\n\tPy_INCREF(typec);\n\tap1 = (PyArrayObject *)PyArray_FromAny(op1, typec, 0, 0, \n\t\t\t\t\t BEHAVED_FLAGS, NULL);\n\tif (ap1 == NULL) {Py_DECREF(typec); return NULL;}\n\tap2 = (PyArrayObject *)PyArray_FromAny(op2, typec, 0, 0,\n\t\t\t\t\t BEHAVED_FLAGS, NULL);\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\tif (ap2->nd > 1) {\n\t\tmatchDim = ap2->nd - 2;\n\t}\n\telse {\n\t\tmatchDim = 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\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; istrides[ap1->nd-1]; is2 = ap2->strides[matchDim];\n\n /* Choose which subtype to return */\n\tret = new_array_for_sum(ap1, ap2, nd, dimensions, typenum);\n\tif (ret == NULL) goto fail;\n\n\t/* Ensure that multiarray.dot([],[]) -> 0 */\n\tmemset(PyArray_DATA(ret), 0, PyArray_ITEMSIZE(ret));\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\top = ret->data; os = ret->descr->elsize;\n\n\tit1 = (PyArrayIterObject *)\\\n\t\tPyArray_IterAllButAxis((PyObject *)ap1, ap1->nd-1);\n\tit2 = (PyArrayIterObject *)\\\n\t\tPyArray_IterAllButAxis((PyObject *)ap2, matchDim);\n\n\twhile(1) {\n\t\twhile(it2->index < it2->size) {\n\t\t\tdot(it1->dataptr, is1, it2->dataptr, is2, op, l, ret);\n\t\t\top += os;\n\t\t\tPyArray_ITER_NEXT(it2);\n\t\t}\n\t\tPyArray_ITER_NEXT(it1);\n\t\tif (it1->index >= it1->size) break;\n\t\tPyArray_ITER_RESET(it2);\n\t}\n\tPy_DECREF(it1);\n\tPy_DECREF(it2);\n\tif (PyErr_Occurred()) goto fail; /* only for OBJECT arrays */\n\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/*MULTIARRAY_API\n Fast Copy and Transpose\n*/\nstatic PyObject *\nPyArray_CopyAndTranspose(PyObject *op) \n{\n\tPyObject *ret, *arr;\n\tint nd;\n\tintp dims[2];\n\tintp i,j;\n\tint elsize, str2;\n\tchar *iptr;\n\tchar *optr;\n\n\t/* make sure it is well-behaved */\n\tarr = PyArray_FromAny(op, NULL, 0, 0, CARRAY_FLAGS, NULL);\n\tnd = PyArray_NDIM(arr);\n\tif (nd == 1) { /* we will give in to old behavior */\n\t\tret = PyArray_Copy((PyArrayObject *)arr);\n\t\tPy_DECREF(arr);\n\t\treturn ret;\t\t\n\t}\n\telse if (nd != 2) {\n\t\tPy_DECREF(arr);\n\t\tPyErr_SetString(PyExc_ValueError, \n\t\t\t\t\"only 2-d arrays are allowed\");\n\t\treturn NULL;\n\t}\n\n\t/* Now construct output array */\n\tdims[0] = PyArray_DIM(arr,1);\n\tdims[1] = PyArray_DIM(arr,0);\n\telsize = PyArray_ITEMSIZE(arr);\n\t\n\tPy_INCREF(PyArray_DESCR(arr));\n\tret = PyArray_NewFromDescr(arr->ob_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\tret = new_array_for_sum(ap1, ap2, 1, &length, typenum);\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, NULL);\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\tif (type->type_num == PyArray_UNICODE)\n\t\t\ttype->elsize = itemsize << 2; \n\t\telse\n\t\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\tif (type->hasobject) newdescr->hasobject = 1;\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 int hasobject=0;\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; ihasobject)\n hasobject = 1;\n\t\ttup = PyTuple_New(2);\n\t\tPyTuple_SET_ITEM(tup, 0, (PyObject *)conv);\n\t\tPyTuple_SET_ITEM(tup, 1, PyInt_FromLong((long) totalsize));\n\t\ttotalsize += conv->elsize;\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 new->hasobject=hasobject;\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 int hasobject=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; ihasobject)\n\t\t\thasobject=1;\t\t\t\n\t\tPyTuple_SET_ITEM(tup, 0, (PyObject *)conv);\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\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\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 new->hasobject=hasobject;\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 int hasobject=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\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\tPyTuple_SET_ITEM(tup, 1, PyInt_FromLong(totalsize));\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\tif (PyDict_GetItem(fields, name) != NULL) {\n\t\t\tPyErr_SetString(PyExc_ValueError,\n\t\t\t\t\t\"two fields with the same name\");\n\t\t\tret = PY_FAIL;\n\t\t}\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 if (!hasobject && newdescr->hasobject)\n hasobject = 1;\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 new->hasobject=hasobject;\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 == '|' || (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\tint i;\n\t\t\telsize = atoi(type+1);\n\t\t\t/* check for commas present */\n\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\nstatic PyObject *\n_prepend_ones(PyArrayObject *arr, int nd, int ndmin)\n{\n\tintp newdims[MAX_DIMS];\n\tintp newstrides[MAX_DIMS];\n\tint i,k,num;\n\tPyObject *ret;\n\n\tnum = ndmin-nd;\n\tfor (i=0; idescr->elsize;\n\t}\n\tfor (i=num;idimensions[k];\n\t\tnewstrides[i] = arr->strides[k];\n\t}\n\tPy_INCREF(arr->descr);\n\tret = PyArray_NewFromDescr(arr->ob_type, arr->descr, ndmin,\n\t\t\t\t newdims, newstrides, arr->data, arr->flags,\n\t\t\t\t (PyObject *)arr);\n\t/* steals a reference to arr --- so don't increment\n\t here */\n\tPyArray_BASE(ret) = (PyObject *)arr;\n\treturn ret;\n}\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,ndmin=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\"\\\n\t\"The ndmin argument specifies how many dimensions the returned\\n\"\\\n\t\"array should have as a minimum. 1's will be pre-pended to the\\n\"\\\n\t\"shape as needed to meet this requirement.\";\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\t\t\t \"ndmin\", NULL};\n Bool subok=FALSE;\n\tBool copy=TRUE;\n\tint ndmin=0, nd;\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&i\", 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\t\t\t\t&ndmin)) \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\tret = op;\n\t\t\t\tgoto finish;\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\tgoto finish;\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\tret = op;\n\t\t\t\tgoto finish;\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\tgoto finish;\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_CheckFromAny(op, type, 0, 0, flags, NULL)) == NULL) \n\t\treturn NULL;\n\n finish:\n\n\tif ((nd=PyArray_NDIM(ret)) >= ndmin) return ret;\n\t/* create a new array from the same data with ones in the shape */\n\t/* steals a reference to ret */\n\treturn _prepend_ones((PyArrayObject *)ret, nd, ndmin);\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(dtype,obj) will return a new scalar array of the given type initialized with obj. Mainly for pickle support. The dtype must be a valid data-type descriptor. If dtype 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[] = {\"dtype\",\"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}; /* XXX ? */\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\nstatic int\n_skip_sep(char **ptr, char *sep)\n{\n\tchar *a;\n\tint n;\n\tn = strlen(sep);\n\ta = *ptr;\n\twhile(*a != '\\0' && (strncmp(a, sep, n) != 0))\n\t\ta++;\n\tif (*a == '\\0') return -1;\n\t*ptr = a+strlen(sep);\n\treturn 0;\n}\n\n/* steals a reference to dtype -- accepts NULL */\n/*OBJECT_API*/\nstatic PyObject *\nPyArray_FromString(char *data, intp slen, PyArray_Descr *dtype, \n\t\t intp n, char *sep)\n{\n\tint itemsize;\n\tPyArrayObject *ret;\n\tBool binary;\n\n\tif (dtype == NULL)\n\t\tdtype=PyArray_DescrFromType(PyArray_LONG);\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\n\tbinary = ((sep == NULL) || (strlen(sep) == 0));\t\n\n\tif (binary) {\n\t\tif (dtype == &OBJECT_Descr) {\n\t\t\tPyErr_SetString(PyExc_ValueError, \n\t\t\t\t\t\"Cannot create an object array from\"\\\n\t\t\t\t\t\" a binary string\");\n\t\t\tPy_DECREF(dtype);\n\t\t\treturn NULL;\n\t\t}\t\t\n\t\tif (n < 0 ) {\n\t\t\tif (slen % itemsize != 0) {\n\t\t\t\tPyErr_SetString(PyExc_ValueError, \n\t\t\t\t\t\t\"string size must be a \"\\\n\t\t\t\t\t\t\"multiple of element size\");\n\t\t\t\tPy_DECREF(dtype);\n\t\t\t\treturn NULL;\n\t\t\t}\n\t\t\tn = slen/itemsize;\n\t\t} else {\n\t\t\tif (slen < n*itemsize) {\n\t\t\t\tPyErr_SetString(PyExc_ValueError, \n\t\t\t\t\t\t\"string is smaller than \" \\\n\t\t\t\t\t\t\"requested size\");\n\t\t\t\tPy_DECREF(dtype);\n\t\t\t\treturn NULL;\n\t\t\t}\n\t\t}\n\t\n\t\tif ((ret = (PyArrayObject *)\\\n\t\t PyArray_NewFromDescr(&PyArray_Type, dtype,\n\t\t\t\t\t 1, &n, NULL, NULL,\n\t\t\t\t\t 0, NULL)) == NULL)\n\t\t\treturn NULL;\t\t\n\t\tmemcpy(ret->data, data, n*dtype->elsize);\n\t\treturn (PyObject *)ret;\n\t}\n\telse { /* read from character-based string */\n\t\tchar *ptr;\t\t\n\t\tPyArray_FromStrFunc *fromstr;\n\t\tchar *dptr;\n\t\tintp nread=0;\n\t\tintp index;\n\n\t\tfromstr = dtype->f->fromstr;\n\t\tif (fromstr == 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 strings for given \"\t\\\n\t\t\t\t\t\"array type\");\n\t\t\tPy_DECREF(dtype);\n\t\t\treturn NULL;\n\t\t}\n\n\t\tif (n!=-1) {\n\t\t\tret = (PyArrayObject *) \\\n\t\t\t\tPyArray_NewFromDescr(&PyArray_Type,\n\t\t\t\t\t\t dtype, 1, &n, NULL,\n\t\t\t\t\t\t NULL, 0, NULL);\n\t\t\tif (ret == NULL) return NULL;\n\t\t\tptr = data;\n\t\t\tdptr = ret->data;\n\t\t\tfor (index=0; index < n; index++) {\n\t\t\t\tif (fromstr(ptr, dptr, &ptr, ret) < 0)\n\t\t\t\t\tbreak;\n\t\t\t\tnread += 1;\n\t\t\t\tdptr += dtype->elsize;\n\t\t\t\tif (_skip_sep(&ptr, sep) < 0) \n\t\t\t\t\tbreak;\n\t\t\t}\n\t\t\tif (nread < n) {\n\t\t\t\tfprintf(stderr, \"%ld items requested but \"\\\n\t\t\t\t\t\"only %ld read\\n\", \n\t\t\t\t\t(long) n, (long) nread);\n\t\t\t\tret->data = \\\n\t\t\t\t\tPyDataMem_RENEW(ret->data, \n\t\t\t\t\t\t\tnread *\t\t\\\n\t\t\t\t\t\t\tret->descr->elsize);\n\t\t\t\tPyArray_DIM(ret,0) = nread;\n\t\t\t}\n\t\t}\n\t\telse {\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\t\t\tchar *end;\n\t\t\tint val;\n\n\t\t\tret = (PyArrayObject *)\\\n\t\t\t\tPyArray_NewFromDescr(&PyArray_Type, \n\t\t\t\t\t\t dtype,\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 (ret==NULL) return NULL;\n\t\t\ttotalbytes = bytes = size * dtype->elsize;\n\t\t\tdptr = ret->data;\n\t\t\tptr = data;\n\t\t\tend = data+slen;\n\t\t\twhile (ptr < end) {\n\t\t\t\tval = fromstr(ptr, dptr, &ptr, ret);\n\t\t\t\tif (val < 0) break;\n\t\t\t\tnread += 1;\n\t\t\t\tval = _skip_sep(&ptr, sep);\n\t\t\t\tif (val < 0) break;\n\t\t\t\tthisbuf += 1;\n\t\t\t\tdptr += dtype->elsize;\n\t\t\t\tif (thisbuf == size) {\n\t\t\t\t\ttotalbytes += bytes;\n\t\t\t\t\tret->data = PyDataMem_RENEW(ret->data, \n\t\t\t\t\t\t\t\t totalbytes);\n\t\t\t\t\tdptr = ret->data + \\\n\t\t\t\t\t\t(totalbytes - bytes);\n\t\t\t\t\tthisbuf = 0;\n\t\t\t\t}\n\t\t\t}\n\t\t\tret->data = PyDataMem_RENEW(ret->data, \n\t\t\t\t\t\t nread*ret->descr->elsize);\n\t\t\tPyArray_DIM(ret,0) = nread;\n#undef _FILEBUFNUM\n\t\t}\n\t}\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\tchar *sep=NULL;\n\tint s;\n\tstatic char *kwlist[] = {\"string\", \"dtype\", \"count\", \"sep\", NULL};\n\tPyArray_Descr *descr=NULL;\n\n\tif (!PyArg_ParseTupleAndKeywords(args, keywds, \"s#|O&Ls\", 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, &sep)) {\n\t\treturn NULL;\n\t}\n\n\treturn PyArray_FromString(data, (intp)s, descr, (intp)nin, sep);\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\tPy_DECREF(typecode);\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\tPy_DECREF(typecode);\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\tPy_DECREF(typecode);\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 platform-independent method of persistence. But it can be \\n\"\\\n\t\" useful to 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_BYTES(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_BYTES(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_DescrConverter2,\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/*MULTIARRAY_API\n GetNDArrayCVersion\n*/\nstatic unsigned int\nPyArray_GetNDArrayCVersion(void)\n{\n\treturn (unsigned int)NDARRAY_VERSION;\n}\n\nstatic char \ndoc__get_ndarray_c_version[] = \"_get_ndarray_c_version() gets the compile time NDARRAY_VERSION number\";\n\nstatic PyObject *\narray__get_ndarray_c_version(PyObject *dummy, PyObject *args, PyObject *kwds) \n{\n\tstatic char *kwlist[] = {NULL};\n\tif(!PyArg_ParseTupleAndKeywords(args, kwds, \"\", kwlist )) return NULL;\n\t\n\treturn PyInt_FromLong( (long) PyArray_GetNDArrayCVersion() );\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, NULL);\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{\"_get_ndarray_c_version\", (PyCFunction)array__get_ndarray_c_version, \n\t METH_VARARGS|METH_KEYWORDS, doc__get_ndarray_c_version},\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, \"dtype\", (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\tif (!PyErr_Occurred()) {\n\t\tPyErr_SetString(PyExc_RuntimeError, \n\t\t\t\t\"cannot load multiarray module.\");\n\t}\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": 35, + "end_line": 50, + "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": 75, + "end_line": 80, + "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": 86, + "end_line": 91, + "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": 97, + "end_line": 105, + "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": 111, + "end_line": 123, + "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": 129, + "end_line": 136, + "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": 143, + "end_line": 173, + "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": 179, + "end_line": 196, + "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": 202, + "end_line": 237, + "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": 248, + "end_line": 257, + "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": 260, + "end_line": 286, + "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": 297, + "end_line": 384, + "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": 393, + "end_line": 428, + "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": 435, + "end_line": 456, + "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": 463, + "end_line": 522, + "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": 529, + "end_line": 539, + "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": 545, + "end_line": 555, + "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": 561, + "end_line": 571, + "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": 577, + "end_line": 588, + "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": 594, + "end_line": 605, + "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": 611, + "end_line": 622, + "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": 102, + "parameters": [ + "self", + "condition", + "axis" + ], + "start_line": 629, + "end_line": 649, + "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": 655, + "end_line": 714, + "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": 720, + "end_line": 750, + "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": 756, + "end_line": 792, + "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": 798, + "end_line": 808, + "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": 776, + "parameters": [ + "self", + "offset", + "axis1", + "axis2" + ], + "start_line": 814, + "end_line": 933, + "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": 402, + "parameters": [ + "op", + "ptr", + "dims", + "nd", + "typedescr" + ], + "start_line": 949, + "end_line": 1000, + "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": 1008, + "end_line": 1018, + "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": 1024, + "end_line": 1036, + "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": 1044, + "end_line": 1055, + "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": 1059, + "end_line": 1087, + "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": 94, + "complexity": 21, + "token_count": 630, + "parameters": [ + "op", + "axis" + ], + "start_line": 1099, + "end_line": 1205, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 107, + "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": 1211, + "end_line": 1252, + "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": 1258, + "end_line": 1311, + "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": 1317, + "end_line": 1412, + "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": 65, + "complexity": 13, + "token_count": 439, + "parameters": [ + "op", + "retn" + ], + "start_line": 1416, + "end_line": 1487, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 72, + "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": 1494, + "end_line": 1575, + "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": 1578, + "end_line": 1585, + "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": 1596, + "end_line": 1650, + "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": 1653, + "end_line": 1731, + "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": 1739, + "end_line": 1742, + "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": 355, + "parameters": [ + "op", + "axis", + "which" + ], + "start_line": 1797, + "end_line": 1863, + "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": 1869, + "end_line": 1877, + "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": 1883, + "end_line": 1963, + "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": 1975, + "end_line": 2119, + "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": 2123, + "end_line": 2158, + "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": 2164, + "end_line": 2209, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 46, + "top_nesting_level": 0 + }, + { + "name": "new_array_for_sum", + "long_name": "new_array_for_sum( PyArrayObject * ap1 , PyArrayObject * ap2 , int nd , intp dimensions [ ] , int typenum)", + "filename": "multiarraymodule.c", + "nloc": 20, + "complexity": 4, + "token_count": 147, + "parameters": [ + "ap1", + "ap2", + "nd", + "typenum" + ], + "start_line": 2216, + "end_line": 2240, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 25, + "top_nesting_level": 0 + }, + { + "name": "PyArray_InnerProduct", + "long_name": "PyArray_InnerProduct( PyObject * op1 , PyObject * op2)", + "filename": "multiarraymodule.c", + "nloc": 79, + "complexity": 15, + "token_count": 624, + "parameters": [ + "op1", + "op2" + ], + "start_line": 2249, + "end_line": 2347, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 99, + "top_nesting_level": 0 + }, + { + "name": "PyArray_MatrixProduct", + "long_name": "PyArray_MatrixProduct( PyObject * op1 , PyObject * op2)", + "filename": "multiarraymodule.c", + "nloc": 89, + "complexity": 17, + "token_count": 680, + "parameters": [ + "op1", + "op2" + ], + "start_line": 2355, + "end_line": 2466, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 112, + "top_nesting_level": 0 + }, + { + "name": "PyArray_CopyAndTranspose", + "long_name": "PyArray_CopyAndTranspose( PyObject * op)", + "filename": "multiarraymodule.c", + "nloc": 47, + "complexity": 6, + "token_count": 286, + "parameters": [ + "op" + ], + "start_line": 2472, + "end_line": 2526, + "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": 86, + "complexity": 13, + "token_count": 601, + "parameters": [ + "op1", + "op2", + "mode" + ], + "start_line": 2532, + "end_line": 2629, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 98, + "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": 2636, + "end_line": 2660, + "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": 2666, + "end_line": 2677, + "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": 2683, + "end_line": 2694, + "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": 2700, + "end_line": 2723, + "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": 2730, + "end_line": 2787, + "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": 2794, + "end_line": 2869, + "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": 64, + "complexity": 15, + "token_count": 479, + "parameters": [ + "self", + "values0", + "indices0" + ], + "start_line": 2875, + "end_line": 2945, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 71, + "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": 2951, + "end_line": 3022, + "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": 68, + "parameters": [ + "object", + "address" + ], + "start_line": 3038, + "end_line": 3050, + "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": 3056, + "end_line": 3064, + "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": 3071, + "end_line": 3186, + "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": 3204, + "end_line": 3229, + "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": 3244, + "end_line": 3280, + "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": 3298, + "end_line": 3331, + "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": 65, + "complexity": 16, + "token_count": 399, + "parameters": [ + "obj" + ], + "start_line": 3334, + "end_line": 3411, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 78, + "top_nesting_level": 0 + }, + { + "name": "_convert_from_array_descr", + "long_name": "_convert_from_array_descr( PyObject * obj)", + "filename": "multiarraymodule.c", + "nloc": 69, + "complexity": 14, + "token_count": 442, + "parameters": [ + "obj" + ], + "start_line": 3419, + "end_line": 3490, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 72, + "top_nesting_level": 0 + }, + { + "name": "_convert_from_list", + "long_name": "_convert_from_list( PyObject * obj , int align , int try_descr)", + "filename": "multiarraymodule.c", + "nloc": 70, + "complexity": 13, + "token_count": 428, + "parameters": [ + "obj", + "align", + "try_descr" + ], + "start_line": 3501, + "end_line": 3572, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 72, + "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": 3585, + "end_line": 3601, + "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": 3638, + "end_line": 3643, + "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": 102, + "complexity": 28, + "token_count": 689, + "parameters": [ + "obj", + "align" + ], + "start_line": 3646, + "end_line": 3757, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 112, + "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": 3775, + "end_line": 3782, + "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": 141, + "complexity": 55, + "token_count": 886, + "parameters": [ + "obj", + "at" + ], + "start_line": 3799, + "end_line": 3979, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 181, + "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": 3985, + "end_line": 4017, + "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": 4023, + "end_line": 4049, + "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": 4058, + "end_line": 4077, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 20, + "top_nesting_level": 0 + }, + { + "name": "_prepend_ones", + "long_name": "_prepend_ones( PyArrayObject * arr , int nd , int ndmin)", + "filename": "multiarraymodule.c", + "nloc": 23, + "complexity": 3, + "token_count": 175, + "parameters": [ + "arr", + "nd", + "ndmin" + ], + "start_line": 4082, + "end_line": 4107, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 26, + "top_nesting_level": 0 + }, + { + "name": "_array_fromobject", + "long_name": "_array_fromobject( PyObject * ignored , PyObject * args , PyObject * kws)", + "filename": "multiarraymodule.c", + "nloc": 66, + "complexity": 16, + "token_count": 380, + "parameters": [ + "ignored", + "args", + "kws" + ], + "start_line": 4129, + "end_line": 4204, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 76, + "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": 4212, + "end_line": 4227, + "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": 4233, + "end_line": 4257, + "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": 4262, + "end_line": 4320, + "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": 4329, + "end_line": 4353, + "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": 4359, + "end_line": 4383, + "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": 4390, + "end_line": 4399, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 10, + "top_nesting_level": 0 + }, + { + "name": "_skip_sep", + "long_name": "_skip_sep( char ** ptr , char * sep)", + "filename": "multiarraymodule.c", + "nloc": 12, + "complexity": 4, + "token_count": 78, + "parameters": [ + "ptr", + "sep" + ], + "start_line": 4402, + "end_line": 4413, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 12, + "top_nesting_level": 0 + }, + { + "name": "PyArray_FromString", + "long_name": "PyArray_FromString( char * data , intp slen , PyArray_Descr * dtype , intp n , char * sep)", + "filename": "multiarraymodule.c", + "nloc": 133, + "complexity": 22, + "token_count": 711, + "parameters": [ + "data", + "slen", + "dtype", + "n", + "sep" + ], + "start_line": 4418, + "end_line": 4560, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 143, + "top_nesting_level": 0 + }, + { + "name": "array_fromString", + "long_name": "array_fromString( PyObject * ignored , PyObject * args , PyObject * keywds)", + "filename": "multiarraymodule.c", + "nloc": 16, + "complexity": 2, + "token_count": 116, + "parameters": [ + "ignored", + "args", + "keywds" + ], + "start_line": 4565, + "end_line": 4582, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 18, + "top_nesting_level": 0 + }, + { + "name": "PyArray_FromFile", + "long_name": "PyArray_FromFile( FILE * fp , PyArray_Descr * typecode , intp num , char * sep)", + "filename": "multiarraymodule.c", + "nloc": 114, + "complexity": 22, + "token_count": 664, + "parameters": [ + "fp", + "typecode", + "num", + "sep" + ], + "start_line": 4596, + "end_line": 4724, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 129, + "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": 4742, + "end_line": 4780, + "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": 4784, + "end_line": 4877, + "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": 4893, + "end_line": 4910, + "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": 4916, + "end_line": 4927, + "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": 4934, + "end_line": 4940, + "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": 4947, + "end_line": 4953, + "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": 4957, + "end_line": 4963, + "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": 4967, + "end_line": 4976, + "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": 4983, + "end_line": 5034, + "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": 5040, + "end_line": 5072, + "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": 5079, + "end_line": 5163, + "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": 5169, + "end_line": 5181, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 13, + "top_nesting_level": 0 + }, + { + "name": "PyArray_GetNDArrayCVersion", + "long_name": "PyArray_GetNDArrayCVersion()", + "filename": "multiarraymodule.c", + "nloc": 4, + "complexity": 1, + "token_count": 13, + "parameters": [], + "start_line": 5187, + "end_line": 5190, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 0 + }, + { + "name": "array__get_ndarray_c_version", + "long_name": "array__get_ndarray_c_version( PyObject * dummy , PyObject * args , PyObject * kwds)", + "filename": "multiarraymodule.c", + "nloc": 6, + "complexity": 2, + "token_count": 55, + "parameters": [ + "dummy", + "args", + "kwds" + ], + "start_line": 5196, + "end_line": 5202, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 7, + "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": 5208, + "end_line": 5224, + "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": 5230, + "end_line": 5247, + "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": 233, + "parameters": [ + "condition", + "x", + "y" + ], + "start_line": 5254, + "end_line": 5294, + "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": 5302, + "end_line": 5310, + "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": 5322, + "end_line": 5332, + "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": 5341, + "end_line": 5352, + "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": 5359, + "end_line": 5382, + "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": 5389, + "end_line": 5397, + "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": 5406, + "end_line": 5424, + "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": 5490, + "end_line": 5603, + "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": 5608, + "end_line": 5632, + "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": 64, + "complexity": 15, + "token_count": 435, + "parameters": [], + "start_line": 5637, + "end_line": 5729, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 93, + "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": 35, + "end_line": 50, + "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": 75, + "end_line": 80, + "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": 86, + "end_line": 91, + "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": 97, + "end_line": 105, + "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": 111, + "end_line": 123, + "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": 129, + "end_line": 136, + "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": 143, + "end_line": 173, + "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": 179, + "end_line": 196, + "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": 202, + "end_line": 237, + "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": 248, + "end_line": 257, + "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": 260, + "end_line": 286, + "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": 297, + "end_line": 384, + "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": 393, + "end_line": 428, + "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": 435, + "end_line": 456, + "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": 463, + "end_line": 522, + "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": 529, + "end_line": 539, + "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": 545, + "end_line": 555, + "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": 561, + "end_line": 571, + "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": 577, + "end_line": 588, + "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": 594, + "end_line": 605, + "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": 611, + "end_line": 622, + "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": 102, + "parameters": [ + "self", + "condition", + "axis" + ], + "start_line": 629, + "end_line": 649, + "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": 655, + "end_line": 714, + "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": 720, + "end_line": 750, + "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": 756, + "end_line": 792, + "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": 798, + "end_line": 808, + "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": 776, + "parameters": [ + "self", + "offset", + "axis1", + "axis2" + ], + "start_line": 814, + "end_line": 933, + "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": 402, + "parameters": [ + "op", + "ptr", + "dims", + "nd", + "typedescr" + ], + "start_line": 949, + "end_line": 1000, + "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": 1008, + "end_line": 1018, + "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": 1024, + "end_line": 1036, + "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": 1044, + "end_line": 1055, + "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": 1059, + "end_line": 1087, + "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": 94, + "complexity": 21, + "token_count": 630, + "parameters": [ + "op", + "axis" + ], + "start_line": 1099, + "end_line": 1205, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 107, + "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": 1211, + "end_line": 1252, + "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": 1258, + "end_line": 1311, + "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": 1317, + "end_line": 1412, + "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": 65, + "complexity": 13, + "token_count": 439, + "parameters": [ + "op", + "retn" + ], + "start_line": 1416, + "end_line": 1487, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 72, + "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": 1494, + "end_line": 1575, + "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": 1578, + "end_line": 1585, + "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": 1596, + "end_line": 1650, + "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": 1653, + "end_line": 1731, + "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": 1739, + "end_line": 1742, + "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": 355, + "parameters": [ + "op", + "axis", + "which" + ], + "start_line": 1797, + "end_line": 1863, + "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": 1869, + "end_line": 1877, + "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": 1883, + "end_line": 1963, + "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": 1975, + "end_line": 2119, + "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": 2123, + "end_line": 2158, + "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": 2164, + "end_line": 2209, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 46, + "top_nesting_level": 0 + }, + { + "name": "new_array_for_sum", + "long_name": "new_array_for_sum( PyArrayObject * ap1 , PyArrayObject * ap2 , int nd , intp dimensions [ ] , int typenum)", + "filename": "multiarraymodule.c", + "nloc": 20, + "complexity": 4, + "token_count": 147, + "parameters": [ + "ap1", + "ap2", + "nd", + "typenum" + ], + "start_line": 2216, + "end_line": 2240, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 25, + "top_nesting_level": 0 + }, + { + "name": "PyArray_InnerProduct", + "long_name": "PyArray_InnerProduct( PyObject * op1 , PyObject * op2)", + "filename": "multiarraymodule.c", + "nloc": 79, + "complexity": 15, + "token_count": 624, + "parameters": [ + "op1", + "op2" + ], + "start_line": 2249, + "end_line": 2347, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 99, + "top_nesting_level": 0 + }, + { + "name": "PyArray_MatrixProduct", + "long_name": "PyArray_MatrixProduct( PyObject * op1 , PyObject * op2)", + "filename": "multiarraymodule.c", + "nloc": 89, + "complexity": 17, + "token_count": 680, + "parameters": [ + "op1", + "op2" + ], + "start_line": 2355, + "end_line": 2466, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 112, + "top_nesting_level": 0 + }, + { + "name": "PyArray_CopyAndTranspose", + "long_name": "PyArray_CopyAndTranspose( PyObject * op)", + "filename": "multiarraymodule.c", + "nloc": 47, + "complexity": 6, + "token_count": 286, + "parameters": [ + "op" + ], + "start_line": 2472, + "end_line": 2526, + "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": 86, + "complexity": 13, + "token_count": 601, + "parameters": [ + "op1", + "op2", + "mode" + ], + "start_line": 2532, + "end_line": 2629, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 98, + "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": 2636, + "end_line": 2660, + "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": 2666, + "end_line": 2677, + "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": 2683, + "end_line": 2694, + "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": 2700, + "end_line": 2723, + "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": 2730, + "end_line": 2787, + "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": 2794, + "end_line": 2869, + "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": 2875, + "end_line": 2944, + "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": 2950, + "end_line": 3021, + "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": 68, + "parameters": [ + "object", + "address" + ], + "start_line": 3037, + "end_line": 3049, + "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": 3055, + "end_line": 3063, + "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": 3070, + "end_line": 3185, + "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": 3203, + "end_line": 3228, + "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": 3243, + "end_line": 3279, + "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": 3297, + "end_line": 3330, + "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": 65, + "complexity": 16, + "token_count": 399, + "parameters": [ + "obj" + ], + "start_line": 3333, + "end_line": 3410, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 78, + "top_nesting_level": 0 + }, + { + "name": "_convert_from_array_descr", + "long_name": "_convert_from_array_descr( PyObject * obj)", + "filename": "multiarraymodule.c", + "nloc": 69, + "complexity": 14, + "token_count": 442, + "parameters": [ + "obj" + ], + "start_line": 3418, + "end_line": 3489, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 72, + "top_nesting_level": 0 + }, + { + "name": "_convert_from_list", + "long_name": "_convert_from_list( PyObject * obj , int align , int try_descr)", + "filename": "multiarraymodule.c", + "nloc": 70, + "complexity": 13, + "token_count": 428, + "parameters": [ + "obj", + "align", + "try_descr" + ], + "start_line": 3500, + "end_line": 3571, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 72, + "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": 3584, + "end_line": 3600, + "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": 3637, + "end_line": 3642, + "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": 102, + "complexity": 28, + "token_count": 689, + "parameters": [ + "obj", + "align" + ], + "start_line": 3645, + "end_line": 3756, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 112, + "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": 3774, + "end_line": 3781, + "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": 141, + "complexity": 55, + "token_count": 886, + "parameters": [ + "obj", + "at" + ], + "start_line": 3798, + "end_line": 3978, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 181, + "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": 3984, + "end_line": 4016, + "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": 4022, + "end_line": 4048, + "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": 4057, + "end_line": 4076, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 20, + "top_nesting_level": 0 + }, + { + "name": "_prepend_ones", + "long_name": "_prepend_ones( PyArrayObject * arr , int nd , int ndmin)", + "filename": "multiarraymodule.c", + "nloc": 23, + "complexity": 3, + "token_count": 175, + "parameters": [ + "arr", + "nd", + "ndmin" + ], + "start_line": 4081, + "end_line": 4106, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 26, + "top_nesting_level": 0 + }, + { + "name": "_array_fromobject", + "long_name": "_array_fromobject( PyObject * ignored , PyObject * args , PyObject * kws)", + "filename": "multiarraymodule.c", + "nloc": 66, + "complexity": 16, + "token_count": 380, + "parameters": [ + "ignored", + "args", + "kws" + ], + "start_line": 4128, + "end_line": 4203, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 76, + "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": 4211, + "end_line": 4226, + "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": 4232, + "end_line": 4256, + "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": 4261, + "end_line": 4319, + "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": 4328, + "end_line": 4352, + "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": 4358, + "end_line": 4382, + "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": 4389, + "end_line": 4398, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 10, + "top_nesting_level": 0 + }, + { + "name": "_skip_sep", + "long_name": "_skip_sep( char ** ptr , char * sep)", + "filename": "multiarraymodule.c", + "nloc": 12, + "complexity": 4, + "token_count": 78, + "parameters": [ + "ptr", + "sep" + ], + "start_line": 4401, + "end_line": 4412, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 12, + "top_nesting_level": 0 + }, + { + "name": "PyArray_FromString", + "long_name": "PyArray_FromString( char * data , intp slen , PyArray_Descr * dtype , intp n , char * sep)", + "filename": "multiarraymodule.c", + "nloc": 133, + "complexity": 22, + "token_count": 711, + "parameters": [ + "data", + "slen", + "dtype", + "n", + "sep" + ], + "start_line": 4417, + "end_line": 4559, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 143, + "top_nesting_level": 0 + }, + { + "name": "array_fromString", + "long_name": "array_fromString( PyObject * ignored , PyObject * args , PyObject * keywds)", + "filename": "multiarraymodule.c", + "nloc": 16, + "complexity": 2, + "token_count": 116, + "parameters": [ + "ignored", + "args", + "keywds" + ], + "start_line": 4564, + "end_line": 4581, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 18, + "top_nesting_level": 0 + }, + { + "name": "PyArray_FromFile", + "long_name": "PyArray_FromFile( FILE * fp , PyArray_Descr * typecode , intp num , char * sep)", + "filename": "multiarraymodule.c", + "nloc": 114, + "complexity": 22, + "token_count": 664, + "parameters": [ + "fp", + "typecode", + "num", + "sep" + ], + "start_line": 4595, + "end_line": 4723, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 129, + "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": 4741, + "end_line": 4779, + "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": 4783, + "end_line": 4876, + "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": 4892, + "end_line": 4909, + "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": 4915, + "end_line": 4926, + "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": 4933, + "end_line": 4939, + "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": 4946, + "end_line": 4952, + "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": 4956, + "end_line": 4962, + "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": 4966, + "end_line": 4975, + "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": 4982, + "end_line": 5033, + "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": 5039, + "end_line": 5071, + "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": 5078, + "end_line": 5162, + "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": 5168, + "end_line": 5180, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 13, + "top_nesting_level": 0 + }, + { + "name": "PyArray_GetNDArrayCVersion", + "long_name": "PyArray_GetNDArrayCVersion()", + "filename": "multiarraymodule.c", + "nloc": 4, + "complexity": 1, + "token_count": 13, + "parameters": [], + "start_line": 5186, + "end_line": 5189, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 0 + }, + { + "name": "array__get_ndarray_c_version", + "long_name": "array__get_ndarray_c_version( PyObject * dummy , PyObject * args , PyObject * kwds)", + "filename": "multiarraymodule.c", + "nloc": 6, + "complexity": 2, + "token_count": 55, + "parameters": [ + "dummy", + "args", + "kwds" + ], + "start_line": 5195, + "end_line": 5201, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 7, + "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": 5207, + "end_line": 5223, + "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": 5229, + "end_line": 5246, + "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": 233, + "parameters": [ + "condition", + "x", + "y" + ], + "start_line": 5253, + "end_line": 5293, + "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": 5301, + "end_line": 5309, + "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": 5321, + "end_line": 5331, + "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": 5340, + "end_line": 5351, + "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": 5358, + "end_line": 5381, + "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": 5388, + "end_line": 5396, + "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": 5405, + "end_line": 5423, + "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": 5489, + "end_line": 5602, + "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": 5607, + "end_line": 5631, + "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": 64, + "complexity": 15, + "token_count": 435, + "parameters": [], + "start_line": 5636, + "end_line": 5728, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 93, + "top_nesting_level": 0 + } + ], + "changed_methods": [ + { + "name": "PyArray_Put", + "long_name": "PyArray_Put( PyArrayObject * self , PyObject * values0 , PyObject * indices0)", + "filename": "multiarraymodule.c", + "nloc": 64, + "complexity": 15, + "token_count": 479, + "parameters": [ + "self", + "values0", + "indices0" + ], + "start_line": 2875, + "end_line": 2945, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 71, + "top_nesting_level": 0 + } + ], + "nloc": 4336, + "complexity": 943, + "token_count": 28210, + "diff_parsed": { + "added": [ + " Py_INCREF(self->descr);", + " values = (PyArrayObject *)PyArray_FromAny(values0, self->descr, 0, 0,", + " DEFAULT_FLAGS | FORCECAST, NULL);" + ], + "deleted": [ + " values = (PyArrayObject *)\\", + "\t\tPyArray_ContiguousFromAny(values0, thistype, 0, 0);" + ] + } + } + ] + }, + { + "hash": "8ee6df7668b3ae0568573620153e71e36c9c399a", + "msg": "Fixed UNICODE functions to handle misaligned and/or byte-swapped arrays.", + "author": { + "name": "Travis Oliphant", + "email": "oliphant@enthought.com" + }, + "committer": { + "name": "Travis Oliphant", + "email": "oliphant@enthought.com" + }, + "author_date": "2006-02-11T10:31:32+00:00", + "author_timezone": 0, + "committer_date": "2006-02-11T10:31:32+00:00", + "committer_timezone": 0, + "branches": [ + "main" + ], + "in_main_branch": true, + "merge": false, + "parents": [ + "6fc0e44e5daab7dcaae4a3250b7545a263d6bfcb" + ], + "project_name": "repo_copy", + "project_path": "/tmp/tmpdjwupkfu/repo_copy", + "deletions": 12, + "insertions": 52, + "lines": 64, + "files": 2, + "dmm_unit_size": 0.0, + "dmm_unit_complexity": 0.0, + "dmm_unit_interfacing": 0.0, + "modified_files": [ + { + "old_path": "numpy/core/src/arrayobject.c", + "new_path": "numpy/core/src/arrayobject.c", + "filename": "arrayobject.c", + "extension": "c", + "change_type": "MODIFY", + "diff": "@@ -868,8 +868,9 @@ PyArray_Scalar(void *data, PyArray_Descr *descr, PyObject *base)\n \t\telse if (type_num == PyArray_UNICODE) {\n \t\t\tPyUnicodeObject *uni = (PyUnicodeObject*)obj;\n \t\t\tint length = itemsize >> 2;\n-\n #ifndef Py_UNICODE_WIDE\n+\t\t\tchar *buffer;\n+\t\t\tint alloc=1;\n \t\t\tlength *= 2;\n #endif\n \t\t\t/* Need an extra slot and need to use \n@@ -887,15 +888,25 @@ PyArray_Scalar(void *data, PyArray_Descr *descr, PyObject *base)\n \t\t\tuni->hash = -1;\n \t\t\tuni->defenc = NULL;\n #ifndef Py_UNICODE_WIDE\n+\t\t\t/* need aligned data buffer */\n+\t\t\tif (!PyArray_ISBEHAVED(base)) {\n+\t\t\t\tbuffer = _pya_malloc(itemsize);\n+\t\t\t\tif (buffer == NULL)\n+\t\t\t\t\treturn PyErr_NoMemory();\n+\t\t\t\talloc = 1;\n+\t\t\t\tmemcpy(buffer, data, itemsize);\n+\t\t\t\tif (!PyArray_ISNOTSWAPPED(base)) {\n+\t\t\t\t\tbyte_swap_vector(buffer, itemsize >> 2, 4);\n+\t\t\t\t}\n+\t\t\t}\n+\t\t\telse buffer = data;\n+\n /* Allocated enough for 2-characters per itemsize.\n \t\t\t Now convert from the data-buffer\n */\n-\t\t\tif (!PyArray_ISNBO(descr->byteorder)) {\n-\t\t\t\t/* byteswap the data */\n-\t\t\t\tbyte_swap_vector(data, itemsize >> 2, 4);\n-\t\t\t}\n-\t\t\tlength = PyUCS2Buffer_FromUCS4(uni->str, (PyArray_UCS4 *)data,\n+\t\t\tlength = PyUCS2Buffer_FromUCS4(uni->str, (PyArray_UCS4 *)buffer,\n \t\t\t\t\t\t itemsize >> 2);\n+\t\t\tif (alloc) _pya_free(buffer);\n \t\t\t/* Resize the unicode result */\n \t\t\tif (MyPyUnicode_Resize(uni, length) < 0) {\n \t\t\t\tPy_DECREF(obj);\n", + "added_lines": 17, + "deleted_lines": 6, + "source_code": "/*\n Provide multidimensional arrays as a basic object type in python. \n\nBased on Original Numeric implementation\nCopyright (c) 1995, 1996, 1997 Jim Hugunin, hugunin@mit.edu\n\nwith contributions from many Numeric Python developers 1995-2004 \n\nHeavily modified in 2005 with inspiration from Numarray \n\nby\n\nTravis Oliphant\nAssistant Professor at\nBrigham Young University \n\nmaintainer email: oliphant.travis@ieee.org\n\nNumarray design (which provided guidance) by \nSpace Science Telescope Institute \n (J. Todd Miller, Perry Greenfield, Rick White)\n*/\n\n/*OBJECT_API\n Get Priority from object\n*/\nstatic double\nPyArray_GetPriority(PyObject *obj, double default_) \n{\n PyObject *ret;\n double priority=PyArray_PRIORITY;\n\n\tif (PyArray_CheckExact(obj))\n\t\treturn priority;\n 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\n\n#ifndef Py_UNICODE_WIDE\n#include \"ucsnarrow.c\"\n#endif\n\n\nstatic PyArray_Descr **userdescrs=NULL;\n#define error_converting(x) (((x) == -1) && PyErr_Occurred())\n\n/* Computer-generated arraytype and scalartype code */\n#include \"scalartypes.inc\"\n#include \"arraytypes.inc\"\n\n\n/* Helper functions */\n\n/*OBJECT_API*/\nstatic intp\nPyArray_PyIntAsIntp(PyObject *o)\n{\n\tlonglong long_value = -1;\n\tPyObject *obj;\n\tstatic char *msg = \"an integer is required\";\n\tPyObject *arr;\n\tPyArray_Descr *descr;\n\tintp ret;\n\n\tif (!o) {\n\t\tPyErr_SetString(PyExc_TypeError, msg);\n\t\treturn -1;\n\t}\n\n\tif (PyInt_Check(o)) {\n\t\tlong_value = (longlong) PyInt_AS_LONG(o);\n\t\tgoto finish;\n\t} else if (PyLong_Check(o)) {\n\t\tlong_value = (longlong) PyLong_AsLongLong(o);\n\t\tgoto finish;\n\t}\n\n#if SIZEOF_INTP == SIZEOF_LONG \n\tdescr = &LONG_Descr;\n#elif SIZEOF_INTP == SIZEOF_INT\n\tdescr = &INT_Descr;\n#else\n\tdescr = &LONGLONG_DESCR;\n#endif\n\tarr = NULL;\n\n\tif (PyArray_Check(o)) {\n\t\tif (PyArray_SIZE(o)!=1 || !PyArray_ISINTEGER(o)) {\n\t\t\tPyErr_SetString(PyExc_TypeError, msg);\n\t\t\treturn -1;\n\t\t}\n\t\tPy_INCREF(descr);\n\t\tarr = PyArray_CastToType((PyArrayObject *)o, descr, 0);\n\t}\n\telse if (PyArray_IsScalar(o, Integer)) {\n\t\tPy_INCREF(descr);\n\t\tarr = PyArray_FromScalar(o, descr);\n\t}\n\tif (arr != NULL) {\n\t\tret = *((intp *)PyArray_DATA(arr));\n\t\tPy_DECREF(arr);\n\t\treturn ret;\n\t}\t\t\n\tif (o->ob_type->tp_as_number != NULL &&\t\t\t\\\n\t o->ob_type->tp_as_number->nb_long != NULL) {\n\t\tobj = o->ob_type->tp_as_number->nb_long(o);\n\t\tif (obj != NULL) {\n\t\t\tlong_value = (longlong) PyLong_AsLongLong(obj);\n\t\t\tPy_DECREF(obj);\n\t\t}\n\t}\n\telse if (o->ob_type->tp_as_number != NULL &&\t\t\\\n\t\t o->ob_type->tp_as_number->nb_int != NULL) {\n\t\tobj = o->ob_type->tp_as_number->nb_int(o);\n\t\tif (obj != NULL) {\n\t\t\tlong_value = (longlong) PyLong_AsLongLong(obj);\n\t\t\tPy_DECREF(obj);\n\t\t}\n\t}\n\telse {\n\t\tPyErr_SetString(PyExc_NotImplementedError,\"\");\n\t}\n\t\n finish:\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_INTP)\n\tif ((long_value < MIN_INTP) || (long_value > MAX_INTP)) {\n\t\tPyErr_SetString(PyExc_ValueError,\n\t\t\t\t\"integer won't fit into a C intp\");\n\t\treturn -1;\n\t}\n#endif\n\treturn (intp) long_value;\n}\n\n\nstatic PyObject *array_int(PyArrayObject *v);\n\n/*OBJECT_API*/\nstatic int\nPyArray_PyIntAsInt(PyObject *o)\n{\n\tlong long_value = -1;\n\tPyObject *obj;\n\tstatic char *msg = \"an integer is required\";\n\tPyObject *arr;\n\tPyArray_Descr *descr;\n\tint ret;\n\n\t\n\tif (!o) {\n\t\tPyErr_SetString(PyExc_TypeError, msg);\n\t\treturn -1;\n\t}\n\n\tif (PyInt_Check(o)) {\n\t\tlong_value = (long) PyInt_AS_LONG(o);\n\t\tgoto finish;\n\t} else if (PyLong_Check(o)) {\n\t\tlong_value = (long) PyLong_AsLong(o);\n\t\tgoto finish;\n\t}\n\n\tdescr = &INT_Descr;\n\tarr=NULL;\n\tif (PyArray_Check(o)) {\n\t\tif (PyArray_SIZE(o)!=1 || !PyArray_ISINTEGER(o)) {\n\t\t\tPyErr_SetString(PyExc_TypeError, msg);\n\t\t\treturn -1;\n\t\t}\n\t\tPy_INCREF(descr);\n\t\tarr = PyArray_CastToType((PyArrayObject *)o, descr, 0);\n\t}\n\tif (PyArray_IsScalar(o, Integer)) {\n\t\tPy_INCREF(descr);\n\t\tarr = PyArray_FromScalar(o, descr);\n\t}\n\tif (arr != NULL) {\n\t\tret = *((int *)PyArray_DATA(arr));\n\t\tPy_DECREF(arr);\n\t\treturn ret;\n\t}\t\t\n\tif (o->ob_type->tp_as_number != NULL &&\t\t\\\n\t o->ob_type->tp_as_number->nb_int != NULL) {\n\t\tobj = o->ob_type->tp_as_number->nb_int(o);\n\t\tif (obj == NULL) return -1;\n\t\tlong_value = (long) PyLong_AsLong(obj);\n\t\tPy_DECREF(obj);\n\t}\n\telse if (o->ob_type->tp_as_number != NULL &&\t\t\t\\\n\t\t o->ob_type->tp_as_number->nb_long != NULL) {\n\t\tobj = o->ob_type->tp_as_number->nb_long(o);\n\t\tif (obj == NULL) return -1;\n\t\tlong_value = (long) PyLong_AsLong(obj);\n\t\tPy_DECREF(obj);\n\t}\t\t\n\telse {\n\t\tPyErr_SetString(PyExc_NotImplementedError,\"\");\n\t}\n\n finish:\n\tif error_converting(long_value) {\n\t\tPyErr_SetString(PyExc_TypeError, msg);\n\t\treturn -1;\n\t}\n\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\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 dest->descr, 0,\n dest->nd, FORTRAN_IF(dest), NULL);\n if (src == NULL) return -1;\n\n ret = PyArray_CopyInto(dest, src);\n Py_DECREF(src);\n return ret;\n}\n\n\n/* These are also old calls (should use PyArray_New) */\n\n/* They all zero-out the memory as previously done */\n\n/* steals reference to descr -- and enforces native byteorder on it.*/\n/*OBJECT_API\n Like FromDimsAndData but uses the Descr structure instead of typecode\n as input.\n*/\nstatic PyObject *\nPyArray_FromDimsAndDataAndDescr(int nd, int *d, \n PyArray_Descr *descr,\n char *data)\n{\n\tPyObject *ret;\n#if SIZEOF_INTP != SIZEOF_INT\n\tint i;\n\tintp newd[MAX_DIMS];\n#endif\n\n\tif (!PyArray_ISNBO(descr->byteorder))\n\t\tdescr->byteorder = '=';\n\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\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_BOOL)\n\t\tPyArrayScalar_RETURN_BOOL_FROM_LONG(*(Bool*)data);\n\telse if (type_num == PyArray_OBJECT) {\n\t\tPy_INCREF(*((PyObject **)data));\n\t\treturn *((PyObject **)data);\n\t}\n\titemsize = descr->elsize;\n type = descr->typeobj;\n copyswap = descr->f->copyswap;\n\tswap = !PyArray_ISNBO(descr->byteorder);\n\tif (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 >> 2;\n#ifndef Py_UNICODE_WIDE\n\t\t\tchar *buffer;\n\t\t\tint alloc=1;\n\t\t\tlength *= 2;\n#endif\n\t\t\t/* Need an extra slot and need to use \n\t\t\t Python memory manager */\n\t\t\tuni->str = NULL;\n\t\t\tdestptr = PyMem_NEW(Py_UNICODE, length+1);\n\t\t\tif (destptr == NULL) {\n Py_DECREF(obj);\n\t\t\t\treturn PyErr_NoMemory();\n\t\t\t}\n\t\t\tuni->str = (Py_UNICODE *)destptr;\n\t\t\tuni->str[0] = 0;\n\t\t\tuni->str[length] = 0;\n\t\t\tuni->length = length;\n\t\t\tuni->hash = -1;\n\t\t\tuni->defenc = NULL;\n#ifndef Py_UNICODE_WIDE\n\t\t\t/* need aligned data buffer */\n\t\t\tif (!PyArray_ISBEHAVED(base)) {\n\t\t\t\tbuffer = _pya_malloc(itemsize);\n\t\t\t\tif (buffer == NULL)\n\t\t\t\t\treturn PyErr_NoMemory();\n\t\t\t\talloc = 1;\n\t\t\t\tmemcpy(buffer, data, itemsize);\n\t\t\t\tif (!PyArray_ISNOTSWAPPED(base)) {\n\t\t\t\t\tbyte_swap_vector(buffer, itemsize >> 2, 4);\n\t\t\t\t}\n\t\t\t}\n\t\t\telse buffer = data;\n\n /* Allocated enough for 2-characters per itemsize.\n\t\t\t Now convert from the data-buffer\n */\n\t\t\tlength = PyUCS2Buffer_FromUCS4(uni->str, (PyArray_UCS4 *)buffer,\n\t\t\t\t\t\t itemsize >> 2);\n\t\t\tif (alloc) _pya_free(buffer);\n\t\t\t/* Resize the unicode result */\n\t\t\tif (MyPyUnicode_Resize(uni, length) < 0) {\n\t\t\t\tPy_DECREF(obj);\n\t\t\t\treturn NULL;\n\t\t\t}\n\t\t\treturn obj;\n#endif\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_XDECREF(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, 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, NULL);\n\tif (arr == NULL) return -1;\n\n\tif ((mit->subspace != NULL) && (mit->consec)) {\n\t\tif (mit->iteraxes[0] > 0) { /* then we need to swap */\n\t\t\t_swap_axes(mit, (PyArrayObject **)&arr);\n\t\t}\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\n/* This checks the args for any fancy indexing objects */\n\n#define SOBJ_NOTFANCY 0 \n#define SOBJ_ISFANCY 1\n#define SOBJ_BADARRAY 2\n#define SOBJ_TOOMANY 3\n#define SOBJ_LISTTUP 4\n\nstatic int\nfancy_indexing_check(PyObject *args)\n{\n\tint i, n;\n\tPyObject *obj;\n\tint retval = SOBJ_NOTFANCY;\n\n\tif (PyTuple_Check(args)) {\n\t\tn = PyTuple_GET_SIZE(args);\n\t\tif (n >= MAX_DIMS) return SOBJ_TOOMANY;\n\t\tfor (i=0; i=MAX_DIMS) return SOBJ_ISFANCY;\n\t\tfor (i=0; i SOBJ_ISFANCY) return retval;\n\t\t}\n\t}\n\n\treturn retval;\n}\n\n/* Called when treating array object like a mapping -- called first from \n Python when using a[object] unless object is a standard slice object\n (not an extended one). \n\n*/\n\n/* There are two situations: \n\n 1 - the subscript is a standard view and a reference to the \n array can be returned\n\n 2 - the subscript uses Boolean masks or integer indexing and\n therefore a new array is created and returned. \n\n*/\n\n/* Always returns arrays */\n\nstatic PyObject *iter_subscript(PyArrayIterObject *, PyObject *); \n\n\nstatic PyObject *\narray_subscript(PyArrayObject *self, PyObject *op) \n{\n intp dimensions[MAX_DIMS], strides[MAX_DIMS];\n\tintp offset;\n int nd, oned, fancy;\n\tintp i;\n PyArrayObject *other;\n\tPyArrayMapIterObject *mit;\n\n\tif (PyString_Check(op) || PyUnicode_Check(op)) {\n\t\tif (self->descr->fields) {\n\t\t\tPyObject *obj;\n\t\t\tobj = PyDict_GetItem(self->descr->fields, op);\n\t\t\tif (obj != NULL) {\n\t\t\t\tPyArray_Descr *descr;\n\t\t\t\tint offset;\n\t\t\t\tPyObject *title;\n\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\tfancy = fancy_indexing_check(op);\n\n\tif (fancy != SOBJ_NOTFANCY) { \n\t\toned = ((self->nd == 1) && !(PyTuple_Check(op) &&\t\\\n\t\t\t\t\t PyTuple_GET_SIZE(op) > 1));\n\n\t\t/* wrap arguments into a mapiter object */\n\t\tmit = (PyArrayMapIterObject *)\\\n\t\t\tPyArray_MapIterNew(op, oned, fancy);\n\t\tif (mit == NULL) return NULL;\n\t\tif (oned) {\n\t\t\tPyArrayIterObject *it;\n\t\t\tPyObject *rval;\n\t\t\tit = (PyArrayIterObject *)PyArray_IterNew((PyObject *)self);\n\t\t\tif (it == NULL) {Py_DECREF(mit); return NULL;}\n\t\t\trval = iter_subscript(it, mit->indexobj);\n\t\t\tPy_DECREF(it);\n\t\t\tPy_DECREF(mit);\n\t\t\treturn rval;\n\t\t}\n PyArray_MapIterBind(mit, self);\n other = (PyArrayObject *)PyArray_GetMap(mit);\n Py_DECREF(mit);\n return (PyObject *)other;\n }\n\n\ti = PyArray_PyIntAsIntp(op);\n\tif (!error_converting(i)) {\n\t\tif (i < 0 && self->nd > 0) i = i+self->dimensions[0];\n\t\treturn array_big_item(self, i);\n\t}\n\tPyErr_Clear();\n\n\t/* Standard (view-based) Indexing */\n if ((nd = parse_index(self, op, dimensions, strides, &offset)) \n == -1) \n return NULL;\n\n\t/* This will only work if new array will be a view */\n\tPy_INCREF(self->descr);\n\tif ((other = (PyArrayObject *)\t\t\t\t\t\\\n\t PyArray_NewFromDescr(self->ob_type, self->descr,\n\t\t\t\t nd, dimensions,\n\t\t\t\t strides, self->data+offset, \n\t\t\t\t self->flags,\n\t\t\t\t (PyObject *)self)) == NULL) \n\t\treturn NULL;\n\n\n\tother->base = (PyObject *)self;\n\tPy_INCREF(self);\n\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, fancy;\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\tfancy = fancy_indexing_check(index);\n\n\tif (fancy != SOBJ_NOTFANCY) { \n\t\toned = ((self->nd == 1) && !(PyTuple_Check(index) && \\\n\t\t\t\t\t PyTuple_GET_SIZE(index) > 1));\n\n\t\tmit = (PyArrayMapIterObject *)\t\t\t\\\n\t\t\tPyArray_MapIterNew(index, oned, fancy);\n\t\tif (mit == NULL) return -1;\n\t\tif (oned) {\n\t\t\tPyArrayIterObject *it;\n\t\t\tint rval;\n\t\t\tit = (PyArrayIterObject *)PyArray_IterNew((PyObject *)self);\n\t\t\tif (it == NULL) {Py_DECREF(mit); return -1;}\n\t\t\trval = iter_ass_subscript(it, mit->indexobj, op);\n\t\t\tPy_DECREF(it);\n\t\t\tPy_DECREF(mit);\n\t\t\treturn rval;\n\t\t}\n PyArray_MapIterBind(mit, self);\n ret = PyArray_SetMap(mit, op);\n Py_DECREF(mit);\n return ret;\n }\n\t\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\t\t\tif (other == Py_None) {\n\t\t\t\tPy_INCREF(Py_False);\n\t\t\t\treturn Py_False;\n\t\t\t}\n /* Try to convert other to an array */\n\t\t\tif (!PyArray_Check(other)) {\n\t\t\t\tarray_other = PyArray_FromObject(other, \n\t\t\t\t\t\t\t\t self->descr->type_num, 0, 0);\n\t\t\t\t/* If not successful, then return the integer\n\t\t\t\t object 0. This fixes code that used to\n\t\t\t\t allow equality comparisons between arrays\n\t\t\t\t and other objects which would give a result\n\t\t\t\t of 0\n\t\t\t\t*/\n\t\t\t\tif ((array_other == NULL) ||\t\\\n\t\t\t\t (array_other == Py_None)) {\n\t\t\t\t\tPy_XDECREF(array_other);\n\t\t\t\t\tPyErr_Clear();\n\t\t\t\t\tPy_INCREF(Py_False);\n\t\t\t\t\treturn Py_False;\n\t\t\t\t}\n\t\t\t}\n\t\t\telse {\n\t\t\t\tPy_INCREF(other);\n\t\t\t\tarray_other = other;\n\t\t\t}\n result = PyArray_GenericBinaryFunction(self, \n\t\t\t\t\t\t\t array_other, \n\t\t\t\t\t\t\t n_ops.equal);\n /* If the comparison results in NULL, then the \n\t\t\t two array objects can not be compared together so \n\t\t\t return zero \n */\n Py_DECREF(array_other);\n if (result == NULL) {\n PyErr_Clear();\n Py_INCREF(Py_False);\n return Py_False;\n }\n return result;\n case Py_NE:\n\t\t\tif (other == Py_None) {\n\t\t\t\tPy_INCREF(Py_True);\n\t\t\t\treturn Py_True;\n\t\t\t}\n /* Try to convert other to an array */\n\t\t\tif (!PyArray_Check(other)) {\n\t\t\t\tarray_other = PyArray_FromObject(other, \n\t\t\t\t\t\t\t\t self->descr->type_num, 0, 0);\n\t\t\t\t/* If not successful, then objects cannot be \n\t\t\t\t compared and cannot be equal, therefore, \n\t\t\t\t return True;\n\t\t\t\t*/\n\t\t\t\tif ((array_other == NULL) ||\t\\\n\t\t\t\t (array_other == Py_None)) {\n\t\t\t\t\tPy_XDECREF(array_other);\n\t\t\t\t\tPyErr_Clear();\n\t\t\t\t\tPy_INCREF(Py_True);\n\t\t\t\t\treturn Py_True;\n\t\t\t\t}\n\t\t\t}\n\t\t\telse {\n\t\t\t\tPy_INCREF(other);\n\t\t\t\tarray_other = other;\n\t\t\t}\n\t\t\tresult = PyArray_GenericBinaryFunction(self, \n\t\t\t\t\t\t\t array_other, \n\t\t\t\t\t\t\t n_ops.not_equal);\n\t\t\tPy_DECREF(array_other);\n if (result == NULL) {\n PyErr_Clear();\n Py_INCREF(Py_True);\n return Py_True;\n }\n 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 = PyArray_NDIM(temp)-1;\n\t\treturn temp;\n\t}\n\telse {\n\t\tif (flags) {\n\t\t\ttemp = PyArray_CheckFromAny((PyObject *)arr, NULL, \n 0, 0, flags, NULL);\n\t\t\tif (temp == NULL) return NULL;\n\t\t}\n\t\telse {\n\t\t\tPy_INCREF(arr);\n\t\t\ttemp = (PyObject *)arr;\n\t\t}\n\t}\n\tif (*axis < 0) *axis += n;\n\tif ((*axis < 0) || (*axis >= n)) {\n\t\tPyErr_Format(PyExc_ValueError, \n\t\t\t \"axis(=%d) out of bounds\", *axis);\n\t\tPy_DECREF(temp);\n\t\treturn NULL;\n\t}\n\treturn temp;\n}\n\n#include \"arraymethods.c\"\n\n/* Lifted from numarray */\nstatic PyObject *\nPyArray_IntTupleFromIntp(int len, intp *vals)\n{\n\tint i;\n PyObject *intTuple = PyTuple_New(len);\n if (!intTuple) goto fail;\n for(i=0; i= SIZEOF_INTP\n\t\tif (!(op = PyNumber_Int(seq))) return -1;\n#else\n\t\tif (!(op = PyNumber_Long(seq))) return -1;\n#endif\n\t\tnd = 1;\n#if SIZEOF_LONG >= SIZEOF_INTP\n\t\tvals[0] = (intp ) PyInt_AsLong(op);\n#else\n\t\tvals[0] = (intp ) PyLong_AsLongLong(op);\n#endif\n\t\tPy_DECREF(op);\n\t} else {\n\t\tfor(i=0; i < MIN(nd,maxvals); i++) {\n\t\t\top = PySequence_GetItem(seq, i);\n\t\t\tif (op == NULL) return -1;\n#if SIZEOF_LONG >= SIZEOF_INTP\n\t\t\tvals[i]=(intp )PyInt_AsLong(op);\n#else\n\t\t\tvals[i]=(intp )PyLong_AsLongLong(op);\n#endif\n\t\t\tPy_DECREF(op);\n\t\t\tif(PyErr_Occurred()) return -1;\n\t\t}\n\t}\n\treturn nd;\n}\n\n\n/* Check whether the given array is stored contiguously (row-wise) in\n memory. */\nstatic int\n_IsContiguous(PyArrayObject *ap) \n{\n\tregister intp sd;\n\tregister intp dim;\n\tregister int i;\n \n\n\tif (ap->nd == 0) return 1;\n\tsd = ap->descr->elsize;\n\tif (ap->nd == 1) return (ap->dimensions[0] == 1 || \\\n\t\t\t\t sd == ap->strides[0]);\n\tfor (i = ap->nd-1; i >= 0; --i) {\n\t\tdim = ap->dimensions[i];\n\t\t/* contiguous by definition */\n\t\tif (dim == 0) return 1;\n\t\tif (ap->strides[i] != sd) return 0;\n\t\tsd *= dim;\n\t}\n\treturn 1;\n}\n\n\nstatic int \n_IsFortranContiguous(PyArrayObject *ap) \n{\n\tregister intp sd;\n\tregister intp dim;\n\tregister int i;\n\t\n\tif (ap->nd == 0) return 1;\n\tsd = ap->descr->elsize;\n\tif (ap->nd == 1) return (ap->dimensions[0] == 1 || \\\n\t\t\t\t sd == ap->strides[0]);\n\tfor (i=0; i< ap->nd; ++i) {\n\t\tdim = ap->dimensions[i];\n\t\t/* contiguous by definition */\n\t\tif (dim == 0) return 1; \n\t\tif (ap->strides[i] != sd) return 0;\n\t\tsd *= dim;\n\t}\n\treturn 1;\n}\n\nstatic int\n_IsAligned(PyArrayObject *ap) \n{\n\tint i, alignment, aligned=1;\n\tintp ptr;\n\tint type = ap->descr->type_num;\n\n\tif ((type == PyArray_STRING) || (type == PyArray_VOID))\n\t\treturn 1;\n\n\talignment = ap->descr->alignment;\n\tif (alignment == 1) return 1;\n\n\tptr = (intp) ap->data;\n aligned = (ptr % alignment) == 0;\n for (i=0; i nd; i++)\n aligned &= ((ap->strides[i] % alignment) == 0);\n return aligned != 0;\n}\n\nstatic Bool\n_IsWriteable(PyArrayObject *ap)\n{\n\tPyObject *base=ap->base;\n\tvoid *dummy;\n\tint n;\n\n\t/* If we own our own data, then no-problem */\n\tif ((base == NULL) || (ap->flags & OWN_DATA)) return TRUE;\n\n\t/* Get to the final base object \n\t If it is a writeable array, then return TRUE\n\t If we can find an array object \n\t or a writeable buffer object as the final base object\n\t or a string object (for pickling support memory savings).\n\t - this last could be removed if a proper pickleable \n\t buffer was added to Python.\n\t*/\n\n\twhile(PyArray_Check(base)) {\n\t\tif (PyArray_CHKFLAGS(base, OWN_DATA)) \n\t\t\treturn (Bool) (PyArray_ISWRITEABLE(base));\n\t\tbase = PyArray_BASE(base);\n\t}\n\n\t/* here so pickle support works seamlessly \n\t and unpickled array can be set and reset writeable \n\t -- could be abused -- */\n\tif PyString_Check(base) return TRUE;\n\n\tif (PyObject_AsWriteBuffer(base, &dummy, &n) < 0)\n\t\treturn FALSE;\n\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 For axes with a positive stride this function checks for a walk\n beyond the right end of the buffer, for axes with a negative stride,\n it checks for a walk beyond the left end of the buffer. Zero strides\n are disallowed.\n*/\n/*OBJECT_API*/\nstatic Bool\nPyArray_CheckStrides(int elsize, int nd, intp numbytes, intp offset,\n\t\t intp *dims, intp *newstrides)\n{\n\tint i;\n\t\n\tif (numbytes == 0) \n\t\tnumbytes = PyArray_MultiplyList(dims, nd) * elsize;\n\t\n\tfor (i=0; i 0) {\n\t\t\t/* The last stride does not need to be fully inside\n\t\t\t the buffer, only its first elsize bytes */\n\t\t\tif (offset + stride*(dims[i]-1)+elsize > numbytes) {\n\t\t\t\treturn FALSE;\n\t\t\t}\n\t\t}\n\t\telse if (stride < 0) {\n\t\t\tif (offset + stride*dims[i] < 0) {\n\t\t\t\treturn FALSE;\n\t\t\t}\n\t\t} else {\n\t\t\t/* XXX: Zero strides may be useful, but currently \n\t\t\t XXX: allowing them would lead to strange results,\n\t\t\t XXX: for example :\n\t\t\t XXX: >>> x = arange(5)\n\t\t\t XXX: >>> x.strides = 0\n\t\t\t XXX: >>> x += 1\n\t\t\t XXX: >>> x\n\t\t\t XXX: array([5, 5, 5, 5, 5]) */\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 /* which could also be sub-fields of a VOID array */\n\t\tif (descr->hasobject) {\n if (descr != &OBJECT_Descr) {\n PyErr_SetString(PyExc_TypeError,\n \"fields with object members \" \\\n \"not yet supported.\");\n goto fail;\n }\n\t\t\tmemset(data, 0, sd);\n\t\t}\n\t}\n\telse {\n self->flags &= ~OWN_DATA; /* If data is passed in, \n\t\t\t\t\t this object won't own it \n\t\t\t\t\t by default.\n\t\t\t\t\t Caller must arrange for \n\t\t\t\t\t this to be reset if truly\n\t\t\t\t\t desired */\n }\n self->data = data;\n\n /* call the __array_finalize__\n\t method if a subtype 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, NULL);\n\tif (newarr == NULL) return -1;\n\tfromptr = PyArray_DATA(newarr);\n\tsize=PyArray_SIZE(arr);\n\tswap=!PyArray_ISNOTSWAPPED(arr);\n\tcopyswap = arr->descr->f->copyswap;\n\tif (PyArray_ISONESEGMENT(arr)) {\n\t\tchar *toptr=PyArray_DATA(arr);\n\t\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\", /* XXX ? */\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 strides.ptr, NULL, fortran, NULL);\n if (ret == NULL) {descr=NULL;goto fail;}\n if (type_num == PyArray_OBJECT) { /* place Py_None */\n PyArray_FillObjectArray(ret, Py_None);\n }\n }\n else { /* buffer given -- use it */\n if (dims.len == 1 && dims.ptr[0] == -1) {\n dims.ptr[offset] = 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, offset,\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 offset + (char *)buffer.ptr, \n\t\t\t\t\t buffer.flags, NULL); \n if (ret == NULL) {descr=NULL; goto fail;}\n PyArray_UpdateFlags(ret, UPDATE_ALL_FLAGS);\n ret->base = buffer.base;\n Py_INCREF(buffer.base); \n }\n\n PyDimMem_FREE(dims.ptr);\n if (strides.ptr) PyDimMem_FREE(strides.ptr);\n return (PyObject *)ret;\n \n fail:\n\tPy_XDECREF(descr);\n if (dims.ptr) PyDimMem_FREE(dims.ptr);\n if (strides.ptr) PyDimMem_FREE(strides.ptr);\n return NULL;\n}\n\n\nstatic PyObject *\narray_iter(PyArrayObject *arr)\n{\n\tif (arr->nd == 0) {\n\t\tPyErr_SetString(PyExc_TypeError,\n\t\t\t\t\"iteration over a scalar (0-dim array)\");\n\t\treturn NULL;\n\t}\n\treturn PySeqIter_New((PyObject *)arr);\n}\n\n\n/******************* array attribute get and set routines ******************/\n\nstatic PyObject *\narray_ndim_get(PyArrayObject *self)\n{\n\treturn PyInt_FromLong(self->nd);\n}\n\nstatic PyObject *\narray_flags_get(PyArrayObject *self)\n{\n return 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->data - new->data,\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 *arraydescr_protocol_typestr_get(PyArray_Descr *);\n\nstatic PyObject *\narray_typestr_get(PyArrayObject *self)\n{\n\treturn arraydescr_protocol_typestr_get(self->descr);\n}\n\nstatic PyObject *\narray_descr_get(PyArrayObject *self) \n{\n\tPy_INCREF(self->descr);\n\treturn (PyObject *)self->descr;\n}\n\n\n/* If the type is changed. \n Also needing change: strides, itemsize\n\n Either itemsize is exactly the same\n or the array is single-segment (contiguous or fortran) with\n compatibile dimensions\n\n The shape and strides will be adjusted in that case as well.\n*/\n\nstatic int\narray_descr_set(PyArrayObject *self, PyObject *arg)\n{\n PyArray_Descr *newtype=NULL;\n intp newdim;\n int index;\n char *msg = \"new type not compatible with array.\";\n\n if (!(PyArray_DescrConverter(arg, &newtype)) ||\n newtype == NULL) {\n PyErr_SetString(PyExc_TypeError, \"invalid data-type for array\");\n\t\treturn -1;\n }\n\tif (newtype->type_num == PyArray_OBJECT || \\\n\t self->descr->type_num == PyArray_OBJECT) {\n\t\tPyErr_SetString(PyExc_TypeError, \\\n\t\t\t\t\"Cannot change descriptor for object\"\\\n\t\t\t\t\"array.\");\n\t\tPy_DECREF(newtype);\n\t\treturn -1;\n\t}\n\n\tif ((newtype->elsize != self->descr->elsize) &&\t\t\\\n\t (self->nd == 0 || !PyArray_ISONESEGMENT(self) || \\\n\t newtype->subarray)) goto fail;\n\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\t/* We would decref newtype here --- temp will \n\t\t steal a reference to it */\n\t\ttemp = (PyArrayObject *)\t\t\t\t\\\n\t\t\tPyArray_NewFromDescr(&PyArray_Type, newtype, self->nd,\n\t\t\t\t\t self->dimensions, self->strides,\n\t\t\t\t\t self->data, self->flags, NULL);\n\t\tPyDimMem_FREE(self->dimensions);\n\t\tself->dimensions = temp->dimensions;\n\t\tself->nd = temp->nd;\n\t\tself->strides = temp->strides;\n\t\tnewtype = temp->descr;\n\t\t/* Fool deallocator not to delete these*/\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, \"descr\");\n\tif (res) return res;\n\tPyErr_Clear();\n\n\t/* get default */\n\tdobj = PyTuple_New(2);\n\tif (dobj == NULL) return NULL;\n\tPyTuple_SET_ITEM(dobj, 0, PyString_FromString(\"\"));\n\tPyTuple_SET_ITEM(dobj, 1, array_typestr_get(self));\n\tres = PyList_New(1);\n\tif (res == NULL) {Py_DECREF(dobj); return NULL;}\n\tPyList_SET_ITEM(res, 0, dobj);\n\treturn res;\n}\n\nstatic PyObject *\narray_struct_get(PyArrayObject *self)\n{\n PyArrayInterface *inter;\n \n inter = (PyArrayInterface *)_pya_malloc(sizeof(PyArrayInterface));\n inter->version = 2;\n inter->nd = self->nd;\n inter->typekind = self->descr->kind;\n inter->itemsize = self->descr->elsize;\n inter->flags = self->flags;\n /* reset unused flags */\n\tinter->flags &= ~(UPDATEIFCOPY | OWNDATA); \n\tif (PyArray_ISNOTSWAPPED(self)) inter->flags |= NOTSWAPPED;\n inter->strides = self->strides;\n inter->shape = self->dimensions;\n inter->data = self->data;\n\tPy_INCREF(self);\n return PyCObject_FromVoidPtrAndDesc(inter, self, gentype_struct_free);\n}\n\nstatic PyObject *\narray_base_get(PyArrayObject *self)\n{\n\tif (self->base == NULL) {\n\t\tPy_INCREF(Py_None);\n\t\treturn Py_None;\n\t}\n\telse {\n\t\tPy_INCREF(self->base);\n\t\treturn self->base;\n\t}\n}\n\n\nstatic PyObject *\narray_real_get(PyArrayObject *self)\n{\n\tPyArrayObject *ret;\n\n\tif (PyArray_ISCOMPLEX(self)) {\n\t\tret = (PyArrayObject *)PyArray_New(self->ob_type,\n\t\t\t\t\t\t self->nd,\n\t\t\t\t\t\t self->dimensions,\n\t\t\t\t\t\t self->descr->type_num - \\\n\t\t\t\t\t\t PyArray_NUM_FLOATTYPE,\n\t\t\t\t\t\t self->strides,\n\t\t\t\t\t\t self->data,\n\t\t\t\t\t\t 0,\n\t\t\t\t\t\t self->flags, (PyObject *)self);\n\t\tif (ret == NULL) return NULL;\n\t\tret->flags &= ~CONTIGUOUS;\n\t\tret->flags &= ~FORTRAN;\n\t\tPy_INCREF(self);\n\t\tret->base = (PyObject *)self;\n\t\treturn (PyObject *)ret;\n\t}\n\telse {\n\t\tPy_INCREF(self);\n\t\treturn (PyObject *)self;\n\t}\n}\n\n\nstatic int\narray_real_set(PyArrayObject *self, PyObject *val)\n{\n\tPyArrayObject *ret;\n\tPyArrayObject *new;\n\tint rint;\n\n\tnew = (PyArrayObject *)PyArray_FromAny(val, NULL, 0, 0, 0, NULL);\n\tif (new == NULL) return -1;\n\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, NULL); \n\t\tif (new == NULL) return -1;\n\t\tret = (PyArrayObject *)PyArray_New(self->ob_type,\n\t\t\t\t\t\t self->nd,\n\t\t\t\t\t\t self->dimensions,\n\t\t\t\t\t\t self->descr->type_num - \\\n\t\t\t\t\t\t PyArray_NUM_FLOATTYPE,\n\t\t\t\t\t\t self->strides,\n \t\t\t\t\t\t self->data +\t\t\\\n\t\t\t\t\t\t (self->descr->elsize >> 1),\n\t\t\t\t\t\t 0,\n\t\t\t\t\t\t self->flags, (PyObject *)self);\n\t\tif (ret == NULL) {\n\t\t\tPy_DECREF(new); \n\t\t\treturn -1;\n\t\t}\n\t\tret->flags &= ~CONTIGUOUS;\n\t\tret->flags &= ~FORTRAN;\n\t\tPy_INCREF(self);\n\t\tret->base = (PyObject *)self;\n\t\trint = PyArray_CopyInto(ret, new);\n\t\tPy_DECREF(ret);\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), NULL);\n\tif (arr == NULL) return -1;\n\tarrit = (PyArrayIterObject *)PyArray_IterNew(arr);\n\tif (arrit == NULL) goto exit;\n\tselfit = (PyArrayIterObject *)PyArray_IterNew((PyObject *)self);\n\tif (selfit == NULL) goto exit;\n\n swap = PyArray_ISNOTSWAPPED(self) != PyArray_ISNOTSWAPPED(arr);\n copyswap = self->descr->f->copyswap;\n if (PyArray_ISOBJECT(self)) {\n while(selfit->index < selfit->size) {\n Py_XDECREF(*((PyObject **)selfit->dataptr));\n Py_INCREF(*((PyObject **)arrit->dataptr)); \n memmove(selfit->dataptr, arrit->dataptr, \n sizeof(PyObject *));\n PyArray_ITER_NEXT(selfit);\n PyArray_ITER_NEXT(arrit);\n if (arrit->index == arrit->size) \n PyArray_ITER_RESET(arrit);\n }\n retval = 0; \n goto exit;\n }\n\n\twhile(selfit->index < selfit->size) {\n\t\tmemmove(selfit->dataptr, arrit->dataptr, self->descr->elsize);\n copyswap(selfit->dataptr, NULL, swap, self->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\t{\"dtype\",\n\t (getter)array_descr_get,\n\t (setter)array_descr_set,\n\t \"get(set) data-type-descriptor for array\"},\n {\"real\", \n\t (getter)array_real_get, \n\t (setter)array_real_set, \n\t \"real part of array\"},\n {\"imag\", \n\t (getter)array_imag_get, \n\t (setter)array_imag_set, \n\t \"imaginary part of array\"},\n\t{\"flat\", \n\t (getter)array_flat_get, \n\t (setter)array_flat_set, \n\t \"a 1-d view of a contiguous array\"}, \n\t{\"__array_data__\", \n\t (getter)array_dataptr_get,\n\t NULL,\n\t \"Array protocol: data\"},\n\t{\"__array_typestr__\",\n\t (getter)array_typestr_get,\n\t NULL,\n\t \"Array protocol: typestr\"},\n\t{\"__array_descr__\",\n\t (getter)array_protocol_descr_get,\n\t NULL,\n\t \"Array protocol: descr\"},\n\t{\"__array_shape__\", \n\t (getter)array_shape_get,\n\t NULL,\n\t \"Array protocol: shape\"},\n\t{\"__array_strides__\",\n\t (getter)array_protocol_strides_get,\n\t NULL,\n\t \"Array protocol: strides\"},\n {\"__array_struct__\",\n (getter)array_struct_get,\n NULL,\n \"Array protocol: struct\"},\n\t{\"__array_priority__\",\n\t (getter)array_priority_get,\n\t NULL,\n\t \"Array priority\"},\n \t{NULL, NULL, NULL, NULL}, /* Sentinel */\n};\n\n/****************** end of attribute get and set routines *******************/\n\n\nstatic PyObject *\narray_alloc(PyTypeObject *type, int nitems)\n{\n PyObject *obj;\n /* nitems will always be 0 */ \n obj = (PyObject *)_pya_malloc(sizeof(PyArrayObject));\n PyObject_Init(obj, type);\n return obj;\n}\n\n\nstatic char Arraytype__doc__[] = \n \"A array object represents a multidimensional, homogeneous array\\n\"\n\t\" of fixed-size items. An associated data-type-descriptor object\\n\"\n\t\" details the data-type in an array (including byteorder and any\\n\"\n\t\" fields). An array can be constructed using the numpy.array\\n\"\n\t\" command. Arrays are sequence, mapping and numeric objects.\\n\"\n\t\" More information is available in the numpy module and by looking\\n\"\n\t\" at the methods and attributes of an array.\\n\\n\"\n\t\" ndarray.__new__(subtype, shape=, dtype=int_, buffer=None, \\n\"\n\t\" offset=0, strides=None, fortran=False)\\n\\n\"\n\t\" There are two modes of creating an array using __new__:\\n\"\n\t\" 1) If buffer is None, then only shape, dtype, and fortran \\n\"\n\t\" are used\\n\"\n\t\" 2) If buffer is an object exporting the buffer interface, then\\n\"\n\t\" all keywords are interpreted.\\n\"\n\t\" The dtype parameter can be any object that can be interpreted \\n\"\n\t\" as a numpy.dtype object.\\n\\n\"\n\t\" No __init__ method is needed because the array is fully \\n\"\n\t\" initialized after the __new__ method.\";\n\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, 4*n);\n\t\telse\n\t\t\t*itemsize = MAX(*itemsize, n);\n\t\treturn 0;\n\t}\n\tfor (i=0; i n_lower) n_lower = d[1];\n }\n d[1] = n_lower;\n\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, 4*minsize);\n\t\t}\n\t\telse {\n\t\t\ttestsize = MAX(chksize, minsize);\n\t\t}\n\t\tif (testsize != outtype->elsize) {\n\t\t\tPyArray_DESCR_REPLACE(outtype);\n\t\t\touttype->elsize = testsize;\n\t\t\tPy_XDECREF(outtype->fields);\n\t\t\touttype->fields = NULL;\n\t\t}\n\t}\n\treturn outtype;\n}\n\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#ifndef Py_UNICODE_WIDE\n\t\tchktype->elsize <<= 1;\n#endif\t\t\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\t} else if (PyLong_Check(op)) {\n\t\t/* if integer can fit into a longlong then return that\n\t\t*/\n\t\tif ((PyLong_AsLongLong(op) == -1) && PyErr_Occurred()) {\n\t\t\tPyErr_Clear();\n\t\t\tgoto deflt;\n\t\t}\n\t\tchktype = PyArray_DescrFromType(PyArray_LONGLONG);\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 *= 4;\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\tif (ret->nd > 0) {\n\t\tPyErr_SetString(PyExc_ValueError,\n\t\t\t\t\"shape-mismatch on array construction\");\n\t\tPy_DECREF(ret);\n\t\treturn NULL;\n\t}\n\n ret->descr->f->setitem(op, ret->data, ret);\n\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 */\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\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\t\tgoto fail;\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\t\tgoto fail;\n }\n\t\n\tif(discover_dimensions(s,nd,d, !stop_at_string) == -1) goto fail;\n\n\tif (itemsize == 0 && PyTypeNum_ISEXTENDED(type)) {\n\t\tif (discover_itemsize(s, nd, &itemsize) == -1) goto fail;\n\t\tif (type == PyArray_UNICODE) itemsize*=4;\n\t}\n\n\tif (itemsize != typecode->elsize) {\n\t\tPyArray_DESCR_REPLACE(typecode);\n\t\ttypecode->elsize = itemsize;\n\t}\n\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) return NULL;\n if(Assign_Array(r,s) == -1) {\n\t\tPy_DECREF(r);\n\t\treturn NULL;\n\t}\n return (PyObject*)r;\n\n fail:\n\tPy_DECREF(typecode);\n\treturn NULL;\n}\n\n\n/*OBJECT_API\n Is the typenum valid?\n*/\nstatic int \nPyArray_ValidType(int type) \n{\n\tPyArray_Descr *descr;\n\tint res=TRUE;\n\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 << 2;\n\t\tif (mpd->type_num == PyArray_UNICODE &&\n\t\t at->type_num == PyArray_STRING) \n\t\t\tat->elsize = mpd->elsize >> 2;\n\t\tif (at->type_num == PyArray_VOID)\n\t\t\tat->elsize = mpd->elsize;\n\t}\n\n\tout = PyArray_NewFromDescr(mp->ob_type, at,\n\t\t\t\t mp->nd, \n\t\t\t\t mp->dimensions, \n\t\t\t\t NULL, NULL, \n\t\t\t\t fortran,\n\t\t\t\t (PyObject *)mp);\n\n\tif (out == NULL) return NULL;\n\tret = PyArray_CastTo((PyArrayObject *)out, mp);\n\tif (ret != -1) return out;\n\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 */\n/*OBJECT_API*/\nstatic PyObject *\nPyArray_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 break;\n\tcase PyArray_STRINGLTR:\n\t\ttype_num = PyArray_STRING;\n\t\tbreak;\n\tcase PyArray_UNICODELTR:\n\t\ttype_num = PyArray_UNICODE;\n\t\tsize <<= 2;\n\t\tbreak;\n\tcase 'V':\n\t\ttype_num = PyArray_VOID;\n\t\tbreak;\n\tdefault:\n\t\t_MY_FAIL\n\t}\n\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/* OBJECT_API */\nstatic PyObject *\nPyArray_FromStructInterface(PyObject *input)\n{\n\tPyArray_Descr *thetype;\n\tchar buf[40];\n\tPyArrayInterface *inter;\n\tPyObject *attr, *r;\n\tchar endian = PyArray_NATBYTE;\n \n attr = PyObject_GetAttrString(input, \"__array_struct__\");\n if (attr == NULL) {\n\t\tPyErr_Clear();\n\t\treturn Py_NotImplemented;\n\t}\n if (!PyCObject_Check(attr) || \\\n ((inter=((PyArrayInterface *)\\\n\t\t PyCObject_AsVoidPtr(attr)))->version != 2)) {\n PyErr_SetString(PyExc_ValueError, \"invalid __array_struct__\");\n\t\tPy_DECREF(attr);\n return NULL;\n }\n\tif ((inter->flags & NOTSWAPPED) != NOTSWAPPED) {\n\t\tendian = PyArray_OPPBYTE;\n\t\tinter->flags &= ~NOTSWAPPED;\n\t}\n\n snprintf(buf, 40, \"%c%c%d\", endian, inter->typekind, inter->itemsize);\n if (!(thetype=_array_typedescr_fromstr(buf))) {\n\t\tPy_DECREF(attr);\n return NULL;\n }\n\n r = PyArray_NewFromDescr(&PyArray_Type, thetype,\n\t\t\t\t inter->nd, inter->shape,\n\t\t\t\t inter->strides, inter->data,\n\t\t\t\t inter->flags, NULL);\n\tPy_INCREF(input);\n\tPyArray_BASE(r) = input;\n Py_DECREF(attr);\n PyArray_UpdateFlags((PyArrayObject *)r, UPDATE_ALL_FLAGS);\n return r;\n}\n\n/*OBJECT_API*/\nstatic PyObject *\nPyArray_FromInterface(PyObject *input)\n{\n\tPyObject *attr=NULL, *item=NULL;\n PyObject *tstr=NULL, *shape=NULL; \n PyArrayObject *ret;\n\tPyArray_Descr *type=NULL;\n\tchar *data;\n\tint buffer_len;\n\tint res, i, n;\n\tintp dims[MAX_DIMS], strides[MAX_DIMS];\n\tint dataflags = BEHAVED_FLAGS;\n\n\t/* Get the memory from __array_data__ and __array_offset__ */\n\t/* Get the shape */\n\t/* Get the typestring -- ignore array_descr */\n\t/* Get the strides */\n\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\treturn NULL;\n\t\t}\n\t\tif (n != PyTuple_GET_SIZE(attr)) {\n\t\t\tPyErr_SetString(PyExc_ValueError, \n\t\t\t\t\t\"mismatch in length of \"\\\n\t\t\t\t\t\"__array_strides__ and \"\\\n\t\t\t\t\t\"__array_shape__\");\n\t\t\tPy_DECREF(attr);\n\t\t\tPy_DECREF(ret);\n\t\t\treturn NULL;\n\t\t}\n\t\tfor (i=0; istrides, strides, n*sizeof(intp));\n\t}\n\telse PyErr_Clear();\n\tPyArray_UpdateFlags(ret, UPDATE_ALL_FLAGS);\n\treturn (PyObject *)ret;\n\n fail:\n\tPy_XDECREF(attr);\n\tPy_XDECREF(shape);\n\tPy_XDECREF(tstr);\n\treturn NULL;\n}\n\n/* OBJECT_API*/\nstatic PyObject *\nPyArray_FromArrayAttr(PyObject *op, PyArray_Descr *typecode, PyObject *context) \n{\n PyObject *new;\n PyObject *array_meth;\n\n array_meth = PyObject_GetAttrString(op, \"__array__\");\n if (array_meth == NULL) {PyErr_Clear(); return Py_NotImplemented;}\n if (context == NULL) {\n if (typecode == NULL) new = PyObject_CallFunction(array_meth, NULL);\n else new = PyObject_CallFunction(array_meth, \"O\", typecode);\n }\n else {\n if (typecode == NULL) {\n new = PyObject_CallFunction(array_meth, \"OO\", Py_None, context);\n if (new == NULL && PyErr_ExceptionMatches(PyExc_TypeError)) {\n PyErr_Clear();\n new = PyObject_CallFunction(array_meth, \"\");\n }\n }\n else {\n new = PyObject_CallFunction(array_meth, \"OO\", typecode, context);\n if (new == NULL && PyErr_ExceptionMatches(PyExc_TypeError)) {\n PyErr_Clear();\n new = PyObject_CallFunction(array_meth, \"O\", typecode);\n }\n }\n }\n Py_DECREF(array_meth);\n if (new == NULL) return NULL;\n if (!PyArray_Check(new)) {\n PyErr_SetString(PyExc_ValueError, \n \"object __array__ method not \" \\\n \"producing an array\");\n Py_DECREF(new);\n return NULL;\n }\n return new;\n} \n\n/* Does not check for ENSURECOPY and NOTSWAPPED in flags */\n/* Steals a reference to newtype --- which can be NULL */\n/*OBJECT_API*/\nstatic PyObject *\nPyArray_FromAny(PyObject *op, PyArray_Descr *newtype, int min_depth, \n int max_depth, int flags, PyObject *context) \n{\n /* This is the main code to make a NumPy array from a Python\n Object. It is called from lot's of different places which\n is why there are so many checks. The comments try to\n explain some of the checks. */\n\n PyObject *r=NULL;\n int seq = FALSE;\n \n\t/* Is input object already an array? */\n\t/* This is where the flags are used */\n if (PyArray_Check(op)) \n\t\tr = PyArray_FromArray((PyArrayObject *)op, newtype, flags);\n\telse if (PyArray_IsScalar(op, Generic)) {\n\t\tr = PyArray_FromScalar(op, newtype);\n\t}\n else if (((r = PyArray_FromStructInterface(op))!=Py_NotImplemented)|| \\\n ((r = PyArray_FromInterface(op)) != Py_NotImplemented) || \\\n ((r = PyArray_FromArrayAttr(op, newtype, context)) \\\n != Py_NotImplemented)) {\n PyObject *new;\n if (r == NULL) return NULL;\n if (newtype != NULL || flags != 0) {\n new = PyArray_FromArray((PyArrayObject *)r, newtype, flags);\n Py_DECREF(r);\n r = new;\n }\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\n\t\t\tPy_INCREF(newtype);\n\t\t\tr = Array_FromSequence(op, newtype, flags & FORTRAN,\n\t\t\t\t\t min_depth, max_depth);\n\t\t\tif (PyErr_Occurred() && r == NULL) {\n /* It wasn't really a sequence after all.\n * Try interpreting it as a scalar */\n\t\t\t\tPyErr_Clear();\n\t\t\t}\n else {\n\t\t\t\tseq = TRUE;\n\t\t\t\tPy_DECREF(newtype);\n\t\t\t}\n }\n if (!seq)\n\t\t\tr = Array_FromScalar(op, newtype);\n\t}\n\n /* If we didn't succeed return NULL */\n if (r == NULL) return NULL;\n\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: PyArray_FromAny \"\\\n\t\t\t\t\"not producing an array\");\n\t\tPy_DECREF(r);\n return NULL;\n }\n\n if (min_depth != 0 && ((PyArrayObject *)r)->nd < min_depth) {\n PyErr_SetString(PyExc_ValueError, \n \"object of too small depth for desired array\");\n Py_DECREF(r);\n return NULL;\n }\n if (max_depth != 0 && ((PyArrayObject *)r)->nd > max_depth) {\n PyErr_SetString(PyExc_ValueError, \n \"object too deep for desired array\");\n Py_DECREF(r);\n return NULL;\n }\n return r;\n}\n\n/* new reference -- accepts NULL for mintype*/\n/*OBJECT_API*/\nstatic PyArray_Descr *\nPyArray_DescrFromObject(PyObject *op, PyArray_Descr *mintype)\n{\n\treturn _array_find_type(op, mintype, MAX_DIMS);\n}\n\n/*OBJECT_API\n Return the typecode of the array a Python object would be converted\n to\n*/\nstatic int \nPyArray_ObjectType(PyObject *op, int minimum_type) \n{\n\tPyArray_Descr *intype;\n\tPyArray_Descr *outtype;\n\tint ret;\n\n\tintype = PyArray_DescrFromType(minimum_type);\n\tif (intype == NULL) PyErr_Clear();\n\touttype = _array_find_type(op, intype, MAX_DIMS);\n\tret = outtype->type_num;\n\tPy_DECREF(outtype);\n\tPy_DECREF(intype);\n\treturn ret;\n}\n\n\n/* flags is any of \n CONTIGUOUS, \n FORTRAN,\n ALIGNED, \n WRITEABLE, \n NOTSWAPPED,\n ENSURECOPY, \n UPDATEIFCOPY,\n FORCECAST,\n ENSUREARRAY\n\n or'd (|) together\n\n Any of these flags present means that the returned array should \n guarantee that aspect of the array. Otherwise the returned array\n won't guarantee it -- it will depend on the object as to whether or \n not it has such features. \n\n Note that ENSURECOPY is enough\n to guarantee CONTIGUOUS, ALIGNED and WRITEABLE\n and therefore it is redundant to include those as well. \n\n BEHAVED_FLAGS == ALIGNED | WRITEABLE\n CARRAY_FLAGS = CONTIGUOUS | BEHAVED_FLAGS\n FARRAY_FLAGS = FORTRAN | BEHAVED_FLAGS\n \n FORTRAN can be set in the FLAGS to request a FORTRAN array. \n Fortran arrays are always behaved (aligned, \n notswapped, and writeable) and not (C) CONTIGUOUS (if > 1d). \n\n UPDATEIFCOPY flag sets this flag in the returned array if a copy is\n made and the base argument points to the (possibly) misbehaved array.\n When the new array is deallocated, the original array held in base\n is updated with the contents of the new array. \n\n FORCECAST will cause a cast to occur regardless of whether or not\n it is safe. \n*/\n\n\n/* steals a reference to descr -- accepts NULL */\n/*OBJECT_API*/\nstatic PyObject *\nPyArray_CheckFromAny(PyObject *op, PyArray_Descr *descr, int min_depth, \n int max_depth, int requires, PyObject *context) \n{\n\tif (requires & NOTSWAPPED) {\n\t\tif (!descr && PyArray_Check(op) && \\\n\t\t !PyArray_ISNBO(PyArray_DESCR(op)->byteorder)) {\n\t\t\tdescr = PyArray_DescrNew(PyArray_DESCR(op));\n\t\t}\n\t\telse if ((descr && !PyArray_ISNBO(descr->byteorder))) {\n\t\t\tPyArray_DESCR_REPLACE(descr);\n\t\t}\n\t\tdescr->byteorder = PyArray_NATIVE;\n\t}\n\n\treturn PyArray_FromAny(op, descr, min_depth, max_depth,\n requires, context);\n}\n\n/* This is a quick wrapper around PyArray_FromAny(op, NULL, 0, 0, \n ENSUREARRAY) */\n/* that special cases Arrays and PyArray_Scalars up front */\n/* It *steals a reference* to the object */\n/* It also guarantees that the result is PyArray_Type 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_FromAny(op, NULL, 0, 0, ENSUREARRAY, NULL);\n Py_DECREF(op);\n return new;\n}\n\n/*OBJECT_API\n Check the type coercion rules.\n*/\nstatic int \nPyArray_CanCastSafely(int fromtype, int totype) \n{\n\tPyArray_Descr *from, *to;\n\tregister int felsize, telsize;\n\n if (fromtype == totype) return 1;\n if (fromtype == PyArray_BOOL) return 1;\n\tif (totype == PyArray_BOOL) return 0;\n if (totype == PyArray_OBJECT || totype == PyArray_VOID) return 1;\n\tif (fromtype == PyArray_OBJECT || fromtype == PyArray_VOID) return 0;\n\n\tfrom = PyArray_DescrFromType(fromtype);\n\tto = PyArray_DescrFromType(totype);\n\ttelsize = to->elsize;\n\tfelsize = from->elsize;\n\tPy_DECREF(from);\n\tPy_DECREF(to);\n\n switch(fromtype) {\n case PyArray_BYTE:\n\tcase PyArray_SHORT:\n case PyArray_INT:\n case PyArray_LONG:\n\tcase PyArray_LONGLONG:\n\t\tif (PyTypeNum_ISINTEGER(totype)) {\n\t\t\tif (PyTypeNum_ISUNSIGNED(totype)) {\n\t\t\t\treturn (telsize > felsize);\n\t\t\t}\n\t\t\telse {\n\t\t\t\treturn (telsize >= felsize);\n\t\t\t}\n\t\t}\n\t\telse if (PyTypeNum_ISFLOAT(totype)) {\n if (felsize < 8)\n return (telsize > felsize);\n else\n return (telsize >= felsize);\n\t\t}\n\t\telse if (PyTypeNum_ISCOMPLEX(totype)) {\n if (felsize < 8)\n return ((telsize >> 1) > felsize);\n else\n return ((telsize >> 1) >= felsize);\n\t\t}\n\t\telse return totype > fromtype;\n case PyArray_UBYTE:\n case PyArray_USHORT:\n case PyArray_UINT:\n\tcase PyArray_ULONG:\n\tcase PyArray_ULONGLONG:\n\t\tif (PyTypeNum_ISINTEGER(totype)) {\n\t\t\tif (PyTypeNum_ISSIGNED(totype)) {\n\t\t\t\treturn (telsize > felsize);\n\t\t\t}\n\t\t\telse {\n\t\t\t\treturn (telsize >= felsize);\n\t\t\t}\n\t\t}\n\t\telse if (PyTypeNum_ISFLOAT(totype)) {\n if (felsize < 8)\n return (telsize > felsize);\n else\n return (telsize >= felsize);\n\t\t}\n\t\telse if (PyTypeNum_ISCOMPLEX(totype)) {\n if (felsize < 8)\n return ((telsize >> 1) > felsize);\n else\n return ((telsize >> 1) >= felsize);\n\t\t}\n\t\telse return totype > fromtype;\n case PyArray_FLOAT:\n case PyArray_DOUBLE:\n\tcase PyArray_LONGDOUBLE:\n\t\tif (PyTypeNum_ISCOMPLEX(totype)) \n\t\t\treturn ((telsize >> 1) >= felsize);\n\t\telse\n\t\t\treturn (totype > fromtype);\n case PyArray_CFLOAT:\n case PyArray_CDOUBLE:\n\tcase PyArray_CLONGDOUBLE:\n\t\treturn (totype > fromtype);\n\tcase PyArray_STRING:\n\tcase PyArray_UNICODE:\n\t\treturn (totype > fromtype);\n default:\n return 0;\n }\n}\n\n/* leaves reference count alone --- cannot be NULL*/\n/*OBJECT_API*/\nstatic Bool\nPyArray_CanCastTo(PyArray_Descr *from, PyArray_Descr *to)\n{\n\tint fromtype=from->type_num;\n\tint totype=to->type_num;\n\tBool ret;\n\n\tret = (Bool) PyArray_CanCastSafely(fromtype, totype);\n\tif (ret) { /* Check String and Unicode more closely */\n\t\tif (fromtype == PyArray_STRING) {\n\t\t\tif (totype == PyArray_STRING) {\n\t\t\t\tret = (from->elsize <= to->elsize);\n\t\t\t}\n\t\t\telse if (totype == PyArray_UNICODE) {\n\t\t\t\tret = (from->elsize << 2 \\\n\t\t\t\t <= to->elsize);\n\t\t\t}\n\t\t}\n\t\telse if (fromtype == PyArray_UNICODE) {\n\t\t\tif (totype == PyArray_UNICODE) {\n\t\t\t\tret = (from->elsize <= to->elsize);\n\t\t\t}\n\t\t}\n\t\t/* TODO: If totype is STRING or unicode \n\t\t see if the length is long enough to hold the\n\t\t stringified value of the object.\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, NULL);\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 FORCECAST | ALIGNED, NULL);\n\t\t\tif (new==NULL) goto fail;\n Py_DECREF(obj);\n\t\t\tobj = new;\n\t\t\tr = iter_subscript_int(self, (PyArrayObject *)obj);\n\t\t}\n\t\telse {\n\t\t\tgoto fail;\n\t\t}\n\t\tPy_DECREF(obj);\n\t\treturn r;\n\t}\n\telse Py_DECREF(indtype);\n\n\n fail:\n\tif (!PyErr_Occurred())\n\t\tPyErr_SetString(PyExc_IndexError, \"unsupported iterator index\");\n\tPy_XDECREF(indtype);\n\tPy_XDECREF(obj);\n\treturn NULL;\n\n}\n\n\nstatic int\niter_ass_sub_Bool(PyArrayIterObject *self, PyArrayObject *ind,\n\t\t PyArrayIterObject *val, int swap)\n{\n\tint index, strides, itemsize;\n\tchar *dptr;\n PyArray_CopySwapFunc *copyswap;\n\n\tif (ind->nd != 1) {\n\t\tPyErr_SetString(PyExc_ValueError, \n\t\t\t\t\"boolean index array should have 1 dimension\");\n\t\treturn -1;\n\t}\n\titemsize = self->ao->descr->elsize;\n\tindex = ind->dimensions[0];\n\tstrides = ind->strides[0];\n\tdptr = ind->data;\n\tPyArray_ITER_RESET(self);\n\t/* Loop over Boolean array */\n copyswap = self->ao->descr->f->copyswap;\n\twhile(index--) {\n\t\tif (*((Bool *)dptr) != 0) {\n copyswap(self->dataptr, val->dataptr, swap,\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, NULL);\n\tif (arrval==NULL) return -1;\n\tval_it = (PyArrayIterObject *)PyArray_IterNew(arrval);\n\tif (val_it==NULL) goto finish;\n\n\t/* Check for Boolean -- this is first becasue\n\t Bool is a subclass of Int */\n\n copyswap = PyArray_DESCR(arrval)->f->copyswap;\n\tswap = (PyArray_ISNOTSWAPPED(self->ao)!=PyArray_ISNOTSWAPPED(arrval));\n\tif (PyBool_Check(ind)) {\n\t\tif (PyObject_IsTrue(ind)) {\n copyswap(self->dataptr, PyArray_DATA(arrval), \n swap, 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, NULL);\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_CheckFromAny(obj, indtype, 0, 0, \n FORCECAST | BEHAVED_NS_FLAGS, NULL);\n\t\t\tPy_DECREF(obj);\n\t\t\tobj = new;\n\t\t\tif (new==NULL) goto finish;\n\t\t\tif (iter_ass_sub_int(self, (PyArrayObject *)obj,\n\t\t\t\t\t val_it, swap) < 0)\n\t\t\t\tgoto finish;\n\t\t\tretval=0;\n\t\t}\n\t}\n\n finish:\n\tif (!PyErr_Occurred() && retval < 0)\n\t\tPyErr_SetString(PyExc_IndexError, \n\t\t\t\t\"unsupported iterator index\");\n\tPy_XDECREF(indtype);\n\tPy_XDECREF(obj);\n\tPy_XDECREF(val_it);\n\tPy_XDECREF(arrval);\n\treturn retval;\n\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 {\"index\", T_INT, offsetof(PyArrayIterObject, index), RO, NULL},\n\t{NULL},\n};\n\nstatic PyObject *\niter_coords_get(PyArrayIterObject *self)\n{\n int nd;\n nd = self->ao->nd;\n if (self->contiguous) { /* coordinates not kept track of --- need to generate\n from index */\n intp val;\n int i;\n val = self->index;\n for (i=0;icoordinates[i] = val / self->factors[i];\n val = val % self->factors[i];\n }\n }\n return PyArray_IntTupleFromIntp(nd, self->coordinates);\n}\n\nstatic PyGetSetDef iter_getsets[] = {\n\t{\"coords\", \n\t (getter)iter_coords_get,\n\t NULL,\n\t \"An N-d tuple of current coordinates.\"},\n\t{NULL, NULL, NULL, NULL},\n};\n\nstatic PyTypeObject PyArrayIter_Type = {\n PyObject_HEAD_INIT(NULL)\n 0,\t\t\t\t\t /* ob_size */\n \"numpy.flatiter\",\t\t /* tp_name */\n sizeof(PyArrayIterObject), /* tp_basicsize */\n 0,\t\t\t\t\t /* tp_itemsize */\n /* methods */\n (destructor)arrayiter_dealloc,\t\t/* tp_dealloc */\n 0,\t\t\t\t\t/* tp_print */\n 0,\t\t\t\t\t/* tp_getattr */\n 0,\t\t\t\t\t/* tp_setattr */\n 0,\t\t\t\t\t/* tp_compare */\n 0,\t\t\t\t\t/* tp_repr */\n 0,\t\t\t\t\t/* tp_as_number */\n 0, \t\t\t /* tp_as_sequence */\n &iter_as_mapping, \t /* tp_as_mapping */\n 0,\t\t\t\t\t/* tp_hash */\n 0,\t\t\t\t\t/* tp_call */\n 0,\t\t\t\t\t/* tp_str */\n 0,\t \t/* tp_getattro */\n 0,\t\t\t\t\t/* tp_setattro */\n 0,\t\t\t\t\t/* tp_as_buffer */\n Py_TPFLAGS_DEFAULT, /* tp_flags */\n 0,\t\t\t\t\t/* tp_doc */\n 0, \t /* tp_traverse */\n 0,\t\t\t\t\t/* tp_clear */\n 0,\t\t\t\t\t/* tp_richcompare */\n 0,\t\t\t\t\t/* tp_weaklistoffset */\n 0, \t /* tp_iter */\n (iternextfunc)arrayiter_next,\t\t/* tp_iternext */\n iter_methods,\t\t\t\t/* tp_methods */\n iter_members,\t \t /* tp_members */\n iter_getsets, /* tp_getset */\n\n};\n\n/** END of Array Iterator **/\n\n\n\n/*********************** Subscript Array Iterator *************************\n * *\n * This object handles subscript behavior for array objects. *\n * It is an iterator object with a next method *\n * It abstracts the n-dimensional mapping behavior to make the looping *\n * code more understandable (maybe) *\n * and so that indexing can be set up ahead of time *\n */ \n\n/* convert an indexing object to an INTP indexing array iterator\n if possible -- otherwise, it is a Slice or Ellipsis object\n and has to be interpreted on bind to a particular \n array so leave it NULL for now.\n */\nstatic int\n_convert_obj(PyObject *obj, PyArrayIterObject **iter)\n{\n\tPyArray_Descr *indtype;\n\tPyObject *arr;\n\n\tif (PySlice_Check(obj) || (obj == Py_Ellipsis))\n\t\t*iter = NULL;\n\telse {\n\t\tindtype = PyArray_DescrFromType(PyArray_INTP);\n\t\tarr = PyArray_FromAny(obj, indtype, 0, 0, FORCECAST, NULL);\n\t\tif (arr == NULL) return -1;\n\t\t*iter = (PyArrayIterObject *)PyArray_IterNew(arr);\n\t\tPy_DECREF(arr);\n\t\tif (*iter == NULL) return -1;\n\t}\n\treturn 0;\n}\n\n/* Adjust dimensionality and strides for index object iterators \n --- i.e. broadcast\n */\n/*OBJECT_API*/\nstatic int\nPyArray_Broadcast(PyArrayMultiIterObject *mit)\n{\n\tint i, nd, k, j;\n\tintp tmp;\n\tPyArrayIterObject *it;\n\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\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, NULL);\n\tif (ba == NULL) return -1;\n\tnd = ba->nd;\n\tfor (j=0; jdata;\n\tcount = 0;\n\n\t/* pre-determine how many nonzero entries there are */\n\tfor (i=0; iao->data;\n\t\tcoords[j] = 0;\n\t\tdims_m1[j] = ba->dimensions[j]-1;\n\t}\n\n\tptr = (Bool *)ba->data;\n\n\tif (count == 0) goto finish;\n\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->index = 0;\n \tmit->ait = NULL;\n \tmit->subspace = NULL;\n\tmit->numiter = 0;\n\tmit->consec = 1;\n\tPy_INCREF(indexobj);\n\tmit->indexobj = indexobj;\n\n\tif (fancy == SOBJ_LISTTUP) {\n\t\tPyObject *newobj;\n\t\tnewobj = PySequence_Tuple(indexobj);\n\t\tif (newobj == NULL) goto fail;\n\t\tPy_DECREF(indexobj);\n\t\tindexobj = newobj;\n\t\tmit->indexobj = indexobj;\n\t}\n\n#undef SOBJ_NOTFANCY \n#undef SOBJ_ISFANCY \n#undef SOBJ_BADARRAY \n#undef SOBJ_TOOMANY \n#undef SOBJ_LISTTUP \n \n\tif (oned) return (PyObject *)mit;\n\n\t/* Must have some kind of fancy indexing if we are here */\n\t/* indexobj is either a list, an arrayobject, or a tuple \n\t (with at least 1 list or arrayobject or Bool object), */\n\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, NULL);\n\t\tif (arr == NULL) goto fail;\n\t\tmit->iters[0] = (PyArrayIterObject *)PyArray_IterNew(arr);\n\t\tif (mit->iters[0] == NULL) {Py_DECREF(arr); goto fail;}\n\t\tmit->nd = PyArray_NDIM(arr);\n\t\tmemcpy(mit->dimensions,PyArray_DIMS(arr),mit->nd*sizeof(intp));\n\t\tmit->size = PyArray_SIZE(arr);\n\t\tPy_DECREF(arr);\n\t\tPy_DECREF(mit->indexobj);\n\t\tmit->indexobj = Py_BuildValue(\"(N)\", PyInt_FromLong(0));\n\t}\n\telse { /* must be a tuple */\n\t\tPyObject *obj;\n\t\tPyArrayIterObject *iter;\n\t\tPyObject *new;\n\t\t/* Make a copy of the tuple -- we will be replacing \n\t\t index objects with 0's */\n\t\tn = PyTuple_GET_SIZE(indexobj);\n\t\tnew = PyTuple_New(n);\n\t\tif (new == NULL) goto fail;\n\t\tstarted = 0;\n\t\tnonindex = 0;\n\t\tfor (i=0; iconsec = 0;\n\t\t\t\tmit->iters[(mit->numiter)++] = iter;\n\t\t\t\tPyTuple_SET_ITEM(new,i,\n\t\t\t\t\t\t PyInt_FromLong(0));\n\t\t\t}\n\t\t\telse {\n\t\t\t\tif (started) nonindex = 1;\n\t\t\t\tPy_INCREF(obj);\n\t\t\t\tPyTuple_SET_ITEM(new,i,obj);\n\t\t\t}\n\t\t}\n\t\tPy_DECREF(mit->indexobj);\n\t\tmit->indexobj = new;\n\t\t/* Store the number of iterators actually converted */\n\t\t/* These will be mapped to actual axes at bind time */\n\t\tif (PyArray_Broadcast((PyArrayMultiIterObject *)mit) < 0)\n\t\t\tgoto fail;\n\t}\n\n return (PyObject *)mit;\n \n fail:\n Py_DECREF(mit);\n\treturn NULL;\n}\n\n\nstatic void\narraymapiter_dealloc(PyArrayMapIterObject *mit)\n{\n\tint i;\n\tPy_XDECREF(mit->indexobj);\n Py_XDECREF(mit->ait);\n\tPy_XDECREF(mit->subspace);\n\tfor (i=0; inumiter; i++)\n\t\tPy_XDECREF(mit->iters[i]);\n _pya_free(mit);\n}\n\n/* The mapiter object must be created new each time. It does not work\n to bind to a new array, and continue.\n\n This was the orginal intention, but currently that does not work. \n Do not expose the MapIter_Type to Python.\n\n It's not very useful anyway, since mapiter(indexobj); mapiter.bind(a); \n mapiter is equivalent to a[indexobj].flat but the latter gets to use \n slice syntax.\n*/\n\nstatic PyTypeObject PyArrayMapIter_Type = {\n PyObject_HEAD_INIT(NULL)\n 0,\t\t\t\t\t /* ob_size */\n \"numpy.mapiter\",\t\t \t/* tp_name */\n sizeof(PyArrayIterObject), /* tp_basicsize */\n 0,\t\t\t\t\t /* tp_itemsize */\n /* methods */\n (destructor)arraymapiter_dealloc,\t/* tp_dealloc */\n 0,\t\t\t\t\t/* tp_print */\n 0,\t\t\t\t\t/* tp_getattr */\n 0,\t\t\t\t\t/* tp_setattr */\n 0,\t\t\t\t\t/* tp_compare */\n 0,\t\t\t\t\t/* tp_repr */\n 0,\t\t\t\t\t/* tp_as_number */\n 0,\t\t\t\t\t/* tp_as_sequence */\n 0,\t\t\t\t\t/* tp_as_mapping */\n 0,\t\t\t\t\t/* tp_hash */\n 0,\t\t\t\t\t/* tp_call */\n 0,\t\t\t\t\t/* tp_str */\n 0, \t\t/* tp_getattro */\n 0,\t\t\t\t\t/* tp_setattro */\n 0,\t\t\t\t\t/* tp_as_buffer */\n Py_TPFLAGS_DEFAULT, /* tp_flags */\n 0,\t\t\t\t\t/* tp_doc */\n (traverseproc)0, \t /* tp_traverse */\n 0,\t\t\t\t\t/* tp_clear */\n 0,\t\t\t\t\t/* tp_richcompare */\n 0,\t\t\t\t\t/* tp_weaklistoffset */\n 0,\t\t \t /* tp_iter */\n (iternextfunc)0, \t /* tp_iternext */\n 0, \t /* tp_methods */\n 0,\t\t\t\t\t /* tp_members */\n 0,\t\t\t /* tp_getset */\n 0,\t\t\t\t\t /* tp_base */\n 0,\t\t\t\t\t /* tp_dict */\n 0,\t\t\t\t\t /* tp_descr_get */\n 0,\t\t\t\t\t /* tp_descr_set */\n 0,\t\t\t\t\t /* tp_dictoffset */\n (initproc)0,\t \t /* tp_init */\n 0, \t /* tp_alloc */\n 0,\t /* tp_new */\n 0,\t /* tp_free */\n 0,\t\t\t\t\t /* tp_is_gc */\n 0,\t\t\t\t\t /* tp_bases */\n 0,\t\t\t\t\t /* tp_mro */\n 0,\t\t\t\t\t /* tp_cache */\n 0,\t\t\t\t\t /* tp_subclasses */\n 0\t\t\t\t\t /* tp_weaklist */\n\n};\n\n/** END of Subscript Iterator **/\n\n\n/*OBJECT_API\n Get MultiIterator,\n*/\nstatic PyObject *\nPyArray_MultiIterNew(int n, ...)\n{\n va_list va;\n\tPyArrayMultiIterObject *multi;\n\tPyObject *current;\n\tPyObject *arr;\n\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 dtype objects can be set. \n*/\nstatic PyMemberDef arraydescr_members[] = {\n\t{\"type\", T_OBJECT, offsetof(PyArray_Descr, typeobj), RO, NULL},\n\t{\"kind\", T_CHAR, offsetof(PyArray_Descr, kind), RO, NULL},\n\t{\"char\", T_CHAR, offsetof(PyArray_Descr, type), RO, NULL},\n\t{\"num\", T_INT, offsetof(PyArray_Descr, type_num), RO, NULL},\n\t{\"byteorder\", T_CHAR, offsetof(PyArray_Descr, byteorder), RO, NULL},\n\t{\"itemsize\", T_INT, offsetof(PyArray_Descr, elsize), RO, NULL},\n\t{\"alignment\", T_INT, offsetof(PyArray_Descr, alignment), RO, NULL},\n {\"hasobject\", T_UBYTE, offsetof(PyArray_Descr, hasobject), RO, NULL},\n\t{NULL}, \n};\n\nstatic PyObject *\narraydescr_subdescr_get(PyArray_Descr *self)\n{\n\tif (self->subarray == NULL) {\n\t\tPy_INCREF(Py_None);\n\t\treturn Py_None;\n\t}\n\treturn Py_BuildValue(\"OO\", (PyObject *)self->subarray->base, \n\t\t\t self->subarray->shape);\n}\n\nstatic PyObject *\narraydescr_protocol_typestr_get(PyArray_Descr *self)\n{\n char basic_=self->kind;\n char endian = self->byteorder;\n\tint size=self->elsize;\n\n if (endian == '=') {\n endian = '<';\n if (!PyArray_IsNativeByteOrder(endian)) endian = '>';\n }\n \n\tif (self->type_num == PyArray_UNICODE) {\n\t\tsize >>= 2;\n\t}\n return PyString_FromFormat(\"%c%c%d\", endian, basic_, size);\n}\n\nstatic PyObject *\narraydescr_typename_get(PyArray_Descr *self)\n{\n int len;\n PyTypeObject *typeobj = self->typeobj;\n\tPyObject *res;\n\tstatic int suffix_len=0;\n\n\tif (PyTypeNum_ISUSERDEF(self->type_num)) {\n\t\tres = PyString_FromString(typeobj->tp_name);\n\t}\n\telse {\n\t\tif (suffix_len == 0) \n\t\t\tsuffix_len = strlen(\"scalar\");\n\t\tlen = strlen(typeobj->tp_name) - suffix_len;\n\t\tres = PyString_FromStringAndSize(typeobj->tp_name, len);\n\t}\n\tif (PyTypeNum_ISEXTENDED(self->type_num) && self->elsize != 0) {\n\t\tPyObject *p;\n\t\tp = PyString_FromFormat(\"%d\", self->elsize * 8);\n\t\tPyString_ConcatAndDel(&res, p);\n\t}\n\treturn res;\t\t\t\t\t\t \n}\n\nstatic PyObject *\narraydescr_base_get(PyArray_Descr *self)\n{\n\tif (self->subarray == NULL) {\n\t\tPy_INCREF(self);\n return (PyObject *)self;\n\t}\n Py_INCREF(self->subarray->base);\n return (PyObject *)(self->subarray->base);\n}\n\nstatic PyObject *\narraydescr_shape_get(PyArray_Descr *self)\n{\n\tif (self->subarray == NULL) {\n return Py_BuildValue(\"(N)\", PyInt_FromLong(1));\n\t}\n Py_INCREF(self->subarray->shape);\n return (PyObject *)(self->subarray->shape);\n}\n\nstatic PyObject *\narraydescr_protocol_descr_get(PyArray_Descr *self)\n{\n\tPyObject *dobj, *res;\n\n\tif (self->fields == NULL || self->fields == Py_None) {\n\t\t/* get default */\n\t\tdobj = PyTuple_New(2);\n\t\tif (dobj == NULL) return NULL;\n\t\tPyTuple_SET_ITEM(dobj, 0, PyString_FromString(\"\"));\n\t\tPyTuple_SET_ITEM(dobj, 1, \\\n\t\t\t\t arraydescr_protocol_typestr_get(self));\n\t\tres = PyList_New(1);\n\t\tif (res == NULL) {Py_DECREF(dobj); return NULL;}\n\t\tPyList_SET_ITEM(res, 0, dobj);\n\t\treturn res;\n\t}\n\n return PyObject_CallMethod(_numpy_internal, \"_array_descr\", \n\t\t\t\t \"O\", self);\n}\n\n/* returns 1 for a builtin type\n and 2 for a user-defined data-type descriptor\n return 0 if neither (i.e. it's a copy of one)\n*/\nstatic PyObject *\narraydescr_isbuiltin_get(PyArray_Descr *self) \n{\n\tlong val;\n\tval = 0;\n\tif (self->fields == Py_None) val = 1;\n\tif (PyTypeNum_ISUSERDEF(self->type_num)) val = 2;\n\treturn PyInt_FromLong(val);\n}\n\nstatic PyObject *\narraydescr_isnative_get(PyArray_Descr *self)\n{\n\tPyObject *ret;\n\n\tret = (PyArray_ISNBO(self->byteorder) ? Py_True : Py_False);\n\tPy_INCREF(ret);\n\treturn ret;\n}\n\nstatic PyObject *\narraydescr_fields_get(PyArray_Descr *self)\n{\n\tif (self->fields == NULL || self->fields == Py_None) {\n\t\tPy_INCREF(Py_None);\n\t\treturn Py_None;\n\t}\n\treturn PyDictProxy_New(self->fields);\n}\n\nstatic PyGetSetDef arraydescr_getsets[] = {\n\t{\"subdtype\", \n\t (getter)arraydescr_subdescr_get,\n\t NULL,\n\t \"A tuple of (descr, shape) or None.\"},\n\t{\"descr\",\n\t (getter)arraydescr_protocol_descr_get,\n\t NULL,\n\t \"The array_protocol type descriptor.\"},\n\t{\"str\",\n\t (getter)arraydescr_protocol_typestr_get,\n\t NULL,\n\t \"The array_protocol typestring.\"},\n {\"name\",\n (getter)arraydescr_typename_get,\n NULL,\n \"The name of the true data-type\"},\n\t{\"base\",\n\t (getter)arraydescr_base_get,\n\t NULL,\n\t \"The base data-type or self if no subdtype\"},\n {\"shape\",\n (getter)arraydescr_shape_get,\n NULL,\n \"The shape of the subdtype or (1,)\"},\n \t{\"isbuiltin\",\n\t (getter)arraydescr_isbuiltin_get,\n\t NULL,\n\t \"Is this a buillt-in data-type descriptor?\"},\n\t{\"isnative\",\n\t (getter)arraydescr_isnative_get,\n\t NULL,\n\t \"Is the byte-order of this descriptor native?\"},\n\t{\"fields\",\n\t (getter)arraydescr_fields_get,\n\t NULL,\n\t NULL},\n\t{NULL, NULL, NULL, NULL},\n};\n\nstatic PyArray_Descr *_convert_from_list(PyObject *obj, int align, int try_descr);\nstatic PyArray_Descr *_convert_from_dict(PyObject *obj, int align);\nstatic PyArray_Descr *_convert_from_commastring(PyObject *obj, int align);\nstatic PyArray_Descr *_convert_from_array_descr(PyObject *obj);\n\nstatic PyObject *\narraydescr_new(PyTypeObject *subtype, PyObject *args, PyObject *kwds)\n{\n\tPyObject *odescr;\n\tPyArray_Descr *descr, *conv;\n\tint align=0;\n\tBool copy=FALSE;\n\tstatic char *kwlist[] = {\"dtype\", \"align\", \"copy\", NULL};\n\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, \"dtype\");\n\tPy_DECREF(mod);\n\tif (obj == NULL) {Py_DECREF(ret); return NULL;}\n\tPyTuple_SET_ITEM(ret, 0, obj);\n\tif (PyTypeNum_ISUSERDEF(self->type_num) ||\t\t\\\n\t ((self->type_num == PyArray_VOID &&\t\t\t\\\n\t self->typeobj != &PyVoidArrType_Type))) {\n\t\tobj = (PyObject *)self->typeobj;\n\t\tPy_INCREF(obj);\n\t}\n\telse {\n\t\telsize = self->elsize;\n\t\tif (self->type_num == PyArray_UNICODE) {\n\t\t\telsize >>= 2;\n\t\t}\n\t\tobj = PyString_FromFormat(\"%c%d\",self->kind, elsize);\n\t}\n\tPyTuple_SET_ITEM(ret, 1, Py_BuildValue(\"(Nii)\", obj, 0, 1));\n\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 dtype object\\n\"\n\t\" with altered byteorders. If is not given all byteorders\\n\"\n\t\" are swapped. Otherwise endian can be '>', '<', or '=' to force\\n\"\n\t\" a byteorder. Descriptors in all fields are also updated in the\\n\"\n\t\" new dtype object.\";\n\nstatic PyObject *\narraydescr_newbyteorder(PyArray_Descr *self, PyObject *args) \n{\n\tchar endian=PyArray_SWAP;\n\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);\n\t\tif (self->type_num != PyArray_VOID) {\n\t\t\tPyObject *p;\n\t\t\tPyObject *t=PyString_FromString(\"'\");\n\t\t\tp = arraydescr_protocol_typestr_get(self);\n\t\t\tPyString_Concat(&p, t);\n\t\t\tPyString_ConcatAndDel(&t, p);\n\t\t\tp = PyString_FromString(\"(\");\n\t\t\tPyString_ConcatAndDel(&p, t);\n\t\t\tPyString_ConcatAndDel(&p, PyString_FromString(\", \"));\n\t\t\tPyString_ConcatAndDel(&p, sub);\n\t\t\tPyString_ConcatAndDel(&p, PyString_FromString(\")\"));\n\t\t\tsub = p;\n\t\t}\n\t}\n\telse if (self->subarray) {\n\t\tPyObject *p;\n\t\tPyObject *t = PyString_FromString(\"(\");\n\t\tp = arraydescr_str(self->subarray->base);\n\t\tPyString_ConcatAndDel(&t, p);\n\t\tPyString_ConcatAndDel(&t, PyString_FromString(\",\"));\n\t\tPyString_ConcatAndDel(&t, PyObject_Str(self->subarray->shape));\n\t\tPyString_ConcatAndDel(&t, PyString_FromString(\")\"));\n\t\tsub = t;\n\t}\n\telse {\n\t\tPyObject *t=PyString_FromString(\"'\");\n\t\tsub = arraydescr_protocol_typestr_get(self);\n\t\tPyString_Concat(&sub, t);\n\t\tPyString_ConcatAndDel(&t, sub);\n\t\tsub = t;\n\t}\n\treturn sub;\n}\n\nstatic PyObject *\narraydescr_repr(PyArray_Descr *self)\n{\n\tPyObject *sub, *s;\n\ts = PyString_FromString(\"dtype(\");\n sub = arraydescr_str(self);\n\tPyString_ConcatAndDel(&s, sub);\n\tsub = PyString_FromString(\")\");\n\tPyString_ConcatAndDel(&s, sub);\n\treturn s;\n}\n\nstatic int\narraydescr_compare(PyArray_Descr *self, PyObject *other)\n{\n \tif (!PyArray_DescrCheck(other)) {\n\t\tPyErr_SetString(PyExc_TypeError,\n\t\t\t\t\"not a dtype object.\");\n\t\treturn -1;\n\t}\n\tif (PyArray_EquivTypes(self, (PyArray_Descr *)other)) return 0;\n\tif (PyArray_CanCastTo(self, (PyArray_Descr *)other)) return -1;\n\treturn 1;\n}\n\n/*************************************************************************\n **************** Implement Mapping Protocol ***************************\n *************************************************************************/\n\nstatic int \ndescr_length(PyArray_Descr *self) \n{\n\n\tif (self->fields && self->fields != Py_None)\n\t\t/* Remove the last entry (root) */\n\t\treturn PyDict_Size(self->fields) - 1;\n\telse return 0;\n}\n\nstatic PyObject *\ndescr_subscript(PyArray_Descr *self, PyObject *op) \n{\n\n\tif (self->fields) {\n\t\tif (PyString_Check(op) || PyUnicode_Check(op)) {\n\t\t\tPyObject *obj;\n\t\t\tobj = PyDict_GetItem(self->fields, op);\n\t\t\tif (obj != NULL) {\n\t\t\t\tPyObject *descr;\n\t\t\t\tdescr = PyTuple_GET_ITEM(obj, 0);\n\t\t\t\tPy_INCREF(descr);\n\t\t\t\treturn descr;\n\t\t\t}\n\t\t\telse {\n\t\t\t\tPyErr_Format(PyExc_KeyError, \n\t\t\t\t\t \"field named \\'%s\\' not found.\",\n\t\t\t\t\t PyString_AsString(op));\n\t\t\t}\n\t\t}\n\t\telse {\n\t\t PyErr_SetString(PyExc_ValueError, \n\t\t\t\t \"only strings or unicode values allowed \" \\\n\t\t\t\t \"for getting fields.\");\n\t\t}\n\t}\n\telse {\n\t\tPyErr_Format(PyExc_KeyError, \n\t\t\t \"there are no fields in dtype %s.\",\n\t\t\t PyString_AsString(arraydescr_str(self)));\n\t}\n\n\treturn NULL;\n}\n\nstatic PyMappingMethods descr_as_mapping = {\n (inquiry)descr_length,\t\t /*mp_length*/\n (binaryfunc)descr_subscript,\t /*mp_subscript*/\n (objobjargproc)NULL,\t /*mp_ass_subscript*/\n};\n\n/****************** End of Mapping Protocol ******************************/\n\n\nstatic PyTypeObject PyArrayDescr_Type = {\n PyObject_HEAD_INIT(NULL)\n 0,\t\t\t\t\t /* ob_size */\n \"numpy.dtype\",\t\t \t /* tp_name */\n sizeof(PyArray_Descr), /* tp_basicsize */\n 0,\t\t\t\t\t /* tp_itemsize */\n /* methods */\n (destructor)arraydescr_dealloc,\t\t/* tp_dealloc */\n 0,\t\t\t\t\t/* tp_print */\n 0,\t\t\t\t\t/* tp_getattr */\n 0,\t\t\t\t\t/* tp_setattr */\n\t(cmpfunc)arraydescr_compare,\t\t/* tp_compare */\n (reprfunc)arraydescr_repr,\t /* tp_repr */\n 0,\t\t\t\t\t/* tp_as_number */\n 0, \t\t\t /* tp_as_sequence */\n &descr_as_mapping, \t /* tp_as_mapping */\n 0,\t\t\t\t\t/* tp_hash */\n 0,\t\t\t\t\t/* tp_call */\n (reprfunc)arraydescr_str, /* tp_str */\n 0,\t \t/* tp_getattro */\n 0,\t\t\t\t\t/* tp_setattro */\n 0,\t\t\t\t\t/* tp_as_buffer */\n Py_TPFLAGS_DEFAULT, /* tp_flags */\n 0,\t\t\t\t\t/* tp_doc */\n 0, \t /* tp_traverse */\n 0,\t\t\t\t\t/* tp_clear */\n 0,\t\t\t\t\t/* tp_richcompare */\n 0,\t\t\t\t\t/* tp_weaklistoffset */\n 0, \t /* tp_iter */\n 0,\t \t/* tp_iternext */\n arraydescr_methods,\t \t /* tp_methods */\n arraydescr_members,\t /* tp_members */\n arraydescr_getsets, /* tp_getset */\n 0,\t\t\t\t\t /* tp_base */\n 0,\t\t\t\t\t /* tp_dict */\n 0,\t\t\t\t\t /* tp_descr_get */\n 0,\t\t\t\t\t /* tp_descr_set */\n 0,\t\t\t\t\t /* tp_dictoffset */\n 0, \t \t /* tp_init */\n 0, \t /* tp_alloc */\n arraydescr_new,\t /* tp_new */\n 0,\t /* tp_free */\n 0,\t\t\t\t\t /* tp_is_gc */\n 0,\t\t\t\t\t /* tp_bases */\n 0,\t\t\t\t\t /* tp_mro */\n 0,\t\t\t\t\t /* tp_cache */\n 0,\t\t\t\t\t /* tp_subclasses */\n 0\t\t\t\t\t /* tp_weaklist */\n};\n", + "source_code_before": "/*\n Provide multidimensional arrays as a basic object type in python. \n\nBased on Original Numeric implementation\nCopyright (c) 1995, 1996, 1997 Jim Hugunin, hugunin@mit.edu\n\nwith contributions from many Numeric Python developers 1995-2004 \n\nHeavily modified in 2005 with inspiration from Numarray \n\nby\n\nTravis Oliphant\nAssistant Professor at\nBrigham Young University \n\nmaintainer email: oliphant.travis@ieee.org\n\nNumarray design (which provided guidance) by \nSpace Science Telescope Institute \n (J. Todd Miller, Perry Greenfield, Rick White)\n*/\n\n/*OBJECT_API\n Get Priority from object\n*/\nstatic double\nPyArray_GetPriority(PyObject *obj, double default_) \n{\n PyObject *ret;\n double priority=PyArray_PRIORITY;\n\n\tif (PyArray_CheckExact(obj))\n\t\treturn priority;\n 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\n\n#ifndef Py_UNICODE_WIDE\n#include \"ucsnarrow.c\"\n#endif\n\n\nstatic PyArray_Descr **userdescrs=NULL;\n#define error_converting(x) (((x) == -1) && PyErr_Occurred())\n\n/* Computer-generated arraytype and scalartype code */\n#include \"scalartypes.inc\"\n#include \"arraytypes.inc\"\n\n\n/* Helper functions */\n\n/*OBJECT_API*/\nstatic intp\nPyArray_PyIntAsIntp(PyObject *o)\n{\n\tlonglong long_value = -1;\n\tPyObject *obj;\n\tstatic char *msg = \"an integer is required\";\n\tPyObject *arr;\n\tPyArray_Descr *descr;\n\tintp ret;\n\n\tif (!o) {\n\t\tPyErr_SetString(PyExc_TypeError, msg);\n\t\treturn -1;\n\t}\n\n\tif (PyInt_Check(o)) {\n\t\tlong_value = (longlong) PyInt_AS_LONG(o);\n\t\tgoto finish;\n\t} else if (PyLong_Check(o)) {\n\t\tlong_value = (longlong) PyLong_AsLongLong(o);\n\t\tgoto finish;\n\t}\n\n#if SIZEOF_INTP == SIZEOF_LONG \n\tdescr = &LONG_Descr;\n#elif SIZEOF_INTP == SIZEOF_INT\n\tdescr = &INT_Descr;\n#else\n\tdescr = &LONGLONG_DESCR;\n#endif\n\tarr = NULL;\n\n\tif (PyArray_Check(o)) {\n\t\tif (PyArray_SIZE(o)!=1 || !PyArray_ISINTEGER(o)) {\n\t\t\tPyErr_SetString(PyExc_TypeError, msg);\n\t\t\treturn -1;\n\t\t}\n\t\tPy_INCREF(descr);\n\t\tarr = PyArray_CastToType((PyArrayObject *)o, descr, 0);\n\t}\n\telse if (PyArray_IsScalar(o, Integer)) {\n\t\tPy_INCREF(descr);\n\t\tarr = PyArray_FromScalar(o, descr);\n\t}\n\tif (arr != NULL) {\n\t\tret = *((intp *)PyArray_DATA(arr));\n\t\tPy_DECREF(arr);\n\t\treturn ret;\n\t}\t\t\n\tif (o->ob_type->tp_as_number != NULL &&\t\t\t\\\n\t o->ob_type->tp_as_number->nb_long != NULL) {\n\t\tobj = o->ob_type->tp_as_number->nb_long(o);\n\t\tif (obj != NULL) {\n\t\t\tlong_value = (longlong) PyLong_AsLongLong(obj);\n\t\t\tPy_DECREF(obj);\n\t\t}\n\t}\n\telse if (o->ob_type->tp_as_number != NULL &&\t\t\\\n\t\t o->ob_type->tp_as_number->nb_int != NULL) {\n\t\tobj = o->ob_type->tp_as_number->nb_int(o);\n\t\tif (obj != NULL) {\n\t\t\tlong_value = (longlong) PyLong_AsLongLong(obj);\n\t\t\tPy_DECREF(obj);\n\t\t}\n\t}\n\telse {\n\t\tPyErr_SetString(PyExc_NotImplementedError,\"\");\n\t}\n\t\n finish:\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_INTP)\n\tif ((long_value < MIN_INTP) || (long_value > MAX_INTP)) {\n\t\tPyErr_SetString(PyExc_ValueError,\n\t\t\t\t\"integer won't fit into a C intp\");\n\t\treturn -1;\n\t}\n#endif\n\treturn (intp) long_value;\n}\n\n\nstatic PyObject *array_int(PyArrayObject *v);\n\n/*OBJECT_API*/\nstatic int\nPyArray_PyIntAsInt(PyObject *o)\n{\n\tlong long_value = -1;\n\tPyObject *obj;\n\tstatic char *msg = \"an integer is required\";\n\tPyObject *arr;\n\tPyArray_Descr *descr;\n\tint ret;\n\n\t\n\tif (!o) {\n\t\tPyErr_SetString(PyExc_TypeError, msg);\n\t\treturn -1;\n\t}\n\n\tif (PyInt_Check(o)) {\n\t\tlong_value = (long) PyInt_AS_LONG(o);\n\t\tgoto finish;\n\t} else if (PyLong_Check(o)) {\n\t\tlong_value = (long) PyLong_AsLong(o);\n\t\tgoto finish;\n\t}\n\n\tdescr = &INT_Descr;\n\tarr=NULL;\n\tif (PyArray_Check(o)) {\n\t\tif (PyArray_SIZE(o)!=1 || !PyArray_ISINTEGER(o)) {\n\t\t\tPyErr_SetString(PyExc_TypeError, msg);\n\t\t\treturn -1;\n\t\t}\n\t\tPy_INCREF(descr);\n\t\tarr = PyArray_CastToType((PyArrayObject *)o, descr, 0);\n\t}\n\tif (PyArray_IsScalar(o, Integer)) {\n\t\tPy_INCREF(descr);\n\t\tarr = PyArray_FromScalar(o, descr);\n\t}\n\tif (arr != NULL) {\n\t\tret = *((int *)PyArray_DATA(arr));\n\t\tPy_DECREF(arr);\n\t\treturn ret;\n\t}\t\t\n\tif (o->ob_type->tp_as_number != NULL &&\t\t\\\n\t o->ob_type->tp_as_number->nb_int != NULL) {\n\t\tobj = o->ob_type->tp_as_number->nb_int(o);\n\t\tif (obj == NULL) return -1;\n\t\tlong_value = (long) PyLong_AsLong(obj);\n\t\tPy_DECREF(obj);\n\t}\n\telse if (o->ob_type->tp_as_number != NULL &&\t\t\t\\\n\t\t o->ob_type->tp_as_number->nb_long != NULL) {\n\t\tobj = o->ob_type->tp_as_number->nb_long(o);\n\t\tif (obj == NULL) return -1;\n\t\tlong_value = (long) PyLong_AsLong(obj);\n\t\tPy_DECREF(obj);\n\t}\t\t\n\telse {\n\t\tPyErr_SetString(PyExc_NotImplementedError,\"\");\n\t}\n\n finish:\n\tif error_converting(long_value) {\n\t\tPyErr_SetString(PyExc_TypeError, msg);\n\t\treturn -1;\n\t}\n\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\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 dest->descr, 0,\n dest->nd, FORTRAN_IF(dest), NULL);\n if (src == NULL) return -1;\n\n ret = PyArray_CopyInto(dest, src);\n Py_DECREF(src);\n return ret;\n}\n\n\n/* These are also old calls (should use PyArray_New) */\n\n/* They all zero-out the memory as previously done */\n\n/* steals reference to descr -- and enforces native byteorder on it.*/\n/*OBJECT_API\n Like FromDimsAndData but uses the Descr structure instead of typecode\n as input.\n*/\nstatic PyObject *\nPyArray_FromDimsAndDataAndDescr(int nd, int *d, \n PyArray_Descr *descr,\n char *data)\n{\n\tPyObject *ret;\n#if SIZEOF_INTP != SIZEOF_INT\n\tint i;\n\tintp newd[MAX_DIMS];\n#endif\n\n\tif (!PyArray_ISNBO(descr->byteorder))\n\t\tdescr->byteorder = '=';\n\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\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_BOOL)\n\t\tPyArrayScalar_RETURN_BOOL_FROM_LONG(*(Bool*)data);\n\telse if (type_num == PyArray_OBJECT) {\n\t\tPy_INCREF(*((PyObject **)data));\n\t\treturn *((PyObject **)data);\n\t}\n\titemsize = descr->elsize;\n type = descr->typeobj;\n copyswap = descr->f->copyswap;\n\tswap = !PyArray_ISNBO(descr->byteorder);\n\tif (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 >> 2;\n\n#ifndef Py_UNICODE_WIDE\n\t\t\tlength *= 2;\n#endif\n\t\t\t/* Need an extra slot and need to use \n\t\t\t Python memory manager */\n\t\t\tuni->str = NULL;\n\t\t\tdestptr = PyMem_NEW(Py_UNICODE, length+1);\n\t\t\tif (destptr == NULL) {\n Py_DECREF(obj);\n\t\t\t\treturn PyErr_NoMemory();\n\t\t\t}\n\t\t\tuni->str = (Py_UNICODE *)destptr;\n\t\t\tuni->str[0] = 0;\n\t\t\tuni->str[length] = 0;\n\t\t\tuni->length = length;\n\t\t\tuni->hash = -1;\n\t\t\tuni->defenc = NULL;\n#ifndef Py_UNICODE_WIDE\n /* Allocated enough for 2-characters per itemsize.\n\t\t\t Now convert from the data-buffer\n */\n\t\t\tif (!PyArray_ISNBO(descr->byteorder)) {\n\t\t\t\t/* byteswap the data */\n\t\t\t\tbyte_swap_vector(data, itemsize >> 2, 4);\n\t\t\t}\n\t\t\tlength = PyUCS2Buffer_FromUCS4(uni->str, (PyArray_UCS4 *)data,\n\t\t\t\t\t\t itemsize >> 2);\n\t\t\t/* Resize the unicode result */\n\t\t\tif (MyPyUnicode_Resize(uni, length) < 0) {\n\t\t\t\tPy_DECREF(obj);\n\t\t\t\treturn NULL;\n\t\t\t}\n\t\t\treturn obj;\n#endif\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_XDECREF(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, 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, NULL);\n\tif (arr == NULL) return -1;\n\n\tif ((mit->subspace != NULL) && (mit->consec)) {\n\t\tif (mit->iteraxes[0] > 0) { /* then we need to swap */\n\t\t\t_swap_axes(mit, (PyArrayObject **)&arr);\n\t\t}\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\n/* This checks the args for any fancy indexing objects */\n\n#define SOBJ_NOTFANCY 0 \n#define SOBJ_ISFANCY 1\n#define SOBJ_BADARRAY 2\n#define SOBJ_TOOMANY 3\n#define SOBJ_LISTTUP 4\n\nstatic int\nfancy_indexing_check(PyObject *args)\n{\n\tint i, n;\n\tPyObject *obj;\n\tint retval = SOBJ_NOTFANCY;\n\n\tif (PyTuple_Check(args)) {\n\t\tn = PyTuple_GET_SIZE(args);\n\t\tif (n >= MAX_DIMS) return SOBJ_TOOMANY;\n\t\tfor (i=0; i=MAX_DIMS) return SOBJ_ISFANCY;\n\t\tfor (i=0; i SOBJ_ISFANCY) return retval;\n\t\t}\n\t}\n\n\treturn retval;\n}\n\n/* Called when treating array object like a mapping -- called first from \n Python when using a[object] unless object is a standard slice object\n (not an extended one). \n\n*/\n\n/* There are two situations: \n\n 1 - the subscript is a standard view and a reference to the \n array can be returned\n\n 2 - the subscript uses Boolean masks or integer indexing and\n therefore a new array is created and returned. \n\n*/\n\n/* Always returns arrays */\n\nstatic PyObject *iter_subscript(PyArrayIterObject *, PyObject *); \n\n\nstatic PyObject *\narray_subscript(PyArrayObject *self, PyObject *op) \n{\n intp dimensions[MAX_DIMS], strides[MAX_DIMS];\n\tintp offset;\n int nd, oned, fancy;\n\tintp i;\n PyArrayObject *other;\n\tPyArrayMapIterObject *mit;\n\n\tif (PyString_Check(op) || PyUnicode_Check(op)) {\n\t\tif (self->descr->fields) {\n\t\t\tPyObject *obj;\n\t\t\tobj = PyDict_GetItem(self->descr->fields, op);\n\t\t\tif (obj != NULL) {\n\t\t\t\tPyArray_Descr *descr;\n\t\t\t\tint offset;\n\t\t\t\tPyObject *title;\n\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\tfancy = fancy_indexing_check(op);\n\n\tif (fancy != SOBJ_NOTFANCY) { \n\t\toned = ((self->nd == 1) && !(PyTuple_Check(op) &&\t\\\n\t\t\t\t\t PyTuple_GET_SIZE(op) > 1));\n\n\t\t/* wrap arguments into a mapiter object */\n\t\tmit = (PyArrayMapIterObject *)\\\n\t\t\tPyArray_MapIterNew(op, oned, fancy);\n\t\tif (mit == NULL) return NULL;\n\t\tif (oned) {\n\t\t\tPyArrayIterObject *it;\n\t\t\tPyObject *rval;\n\t\t\tit = (PyArrayIterObject *)PyArray_IterNew((PyObject *)self);\n\t\t\tif (it == NULL) {Py_DECREF(mit); return NULL;}\n\t\t\trval = iter_subscript(it, mit->indexobj);\n\t\t\tPy_DECREF(it);\n\t\t\tPy_DECREF(mit);\n\t\t\treturn rval;\n\t\t}\n PyArray_MapIterBind(mit, self);\n other = (PyArrayObject *)PyArray_GetMap(mit);\n Py_DECREF(mit);\n return (PyObject *)other;\n }\n\n\ti = PyArray_PyIntAsIntp(op);\n\tif (!error_converting(i)) {\n\t\tif (i < 0 && self->nd > 0) i = i+self->dimensions[0];\n\t\treturn array_big_item(self, i);\n\t}\n\tPyErr_Clear();\n\n\t/* Standard (view-based) Indexing */\n if ((nd = parse_index(self, op, dimensions, strides, &offset)) \n == -1) \n return NULL;\n\n\t/* This will only work if new array will be a view */\n\tPy_INCREF(self->descr);\n\tif ((other = (PyArrayObject *)\t\t\t\t\t\\\n\t PyArray_NewFromDescr(self->ob_type, self->descr,\n\t\t\t\t nd, dimensions,\n\t\t\t\t strides, self->data+offset, \n\t\t\t\t self->flags,\n\t\t\t\t (PyObject *)self)) == NULL) \n\t\treturn NULL;\n\n\n\tother->base = (PyObject *)self;\n\tPy_INCREF(self);\n\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, fancy;\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\tfancy = fancy_indexing_check(index);\n\n\tif (fancy != SOBJ_NOTFANCY) { \n\t\toned = ((self->nd == 1) && !(PyTuple_Check(index) && \\\n\t\t\t\t\t PyTuple_GET_SIZE(index) > 1));\n\n\t\tmit = (PyArrayMapIterObject *)\t\t\t\\\n\t\t\tPyArray_MapIterNew(index, oned, fancy);\n\t\tif (mit == NULL) return -1;\n\t\tif (oned) {\n\t\t\tPyArrayIterObject *it;\n\t\t\tint rval;\n\t\t\tit = (PyArrayIterObject *)PyArray_IterNew((PyObject *)self);\n\t\t\tif (it == NULL) {Py_DECREF(mit); return -1;}\n\t\t\trval = iter_ass_subscript(it, mit->indexobj, op);\n\t\t\tPy_DECREF(it);\n\t\t\tPy_DECREF(mit);\n\t\t\treturn rval;\n\t\t}\n PyArray_MapIterBind(mit, self);\n ret = PyArray_SetMap(mit, op);\n Py_DECREF(mit);\n return ret;\n }\n\t\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\t\t\tif (other == Py_None) {\n\t\t\t\tPy_INCREF(Py_False);\n\t\t\t\treturn Py_False;\n\t\t\t}\n /* Try to convert other to an array */\n\t\t\tif (!PyArray_Check(other)) {\n\t\t\t\tarray_other = PyArray_FromObject(other, \n\t\t\t\t\t\t\t\t self->descr->type_num, 0, 0);\n\t\t\t\t/* If not successful, then return the integer\n\t\t\t\t object 0. This fixes code that used to\n\t\t\t\t allow equality comparisons between arrays\n\t\t\t\t and other objects which would give a result\n\t\t\t\t of 0\n\t\t\t\t*/\n\t\t\t\tif ((array_other == NULL) ||\t\\\n\t\t\t\t (array_other == Py_None)) {\n\t\t\t\t\tPy_XDECREF(array_other);\n\t\t\t\t\tPyErr_Clear();\n\t\t\t\t\tPy_INCREF(Py_False);\n\t\t\t\t\treturn Py_False;\n\t\t\t\t}\n\t\t\t}\n\t\t\telse {\n\t\t\t\tPy_INCREF(other);\n\t\t\t\tarray_other = other;\n\t\t\t}\n result = PyArray_GenericBinaryFunction(self, \n\t\t\t\t\t\t\t array_other, \n\t\t\t\t\t\t\t n_ops.equal);\n /* If the comparison results in NULL, then the \n\t\t\t two array objects can not be compared together so \n\t\t\t return zero \n */\n Py_DECREF(array_other);\n if (result == NULL) {\n PyErr_Clear();\n Py_INCREF(Py_False);\n return Py_False;\n }\n return result;\n case Py_NE:\n\t\t\tif (other == Py_None) {\n\t\t\t\tPy_INCREF(Py_True);\n\t\t\t\treturn Py_True;\n\t\t\t}\n /* Try to convert other to an array */\n\t\t\tif (!PyArray_Check(other)) {\n\t\t\t\tarray_other = PyArray_FromObject(other, \n\t\t\t\t\t\t\t\t self->descr->type_num, 0, 0);\n\t\t\t\t/* If not successful, then objects cannot be \n\t\t\t\t compared and cannot be equal, therefore, \n\t\t\t\t return True;\n\t\t\t\t*/\n\t\t\t\tif ((array_other == NULL) ||\t\\\n\t\t\t\t (array_other == Py_None)) {\n\t\t\t\t\tPy_XDECREF(array_other);\n\t\t\t\t\tPyErr_Clear();\n\t\t\t\t\tPy_INCREF(Py_True);\n\t\t\t\t\treturn Py_True;\n\t\t\t\t}\n\t\t\t}\n\t\t\telse {\n\t\t\t\tPy_INCREF(other);\n\t\t\t\tarray_other = other;\n\t\t\t}\n\t\t\tresult = PyArray_GenericBinaryFunction(self, \n\t\t\t\t\t\t\t array_other, \n\t\t\t\t\t\t\t n_ops.not_equal);\n\t\t\tPy_DECREF(array_other);\n if (result == NULL) {\n PyErr_Clear();\n Py_INCREF(Py_True);\n return Py_True;\n }\n 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 = PyArray_NDIM(temp)-1;\n\t\treturn temp;\n\t}\n\telse {\n\t\tif (flags) {\n\t\t\ttemp = PyArray_CheckFromAny((PyObject *)arr, NULL, \n 0, 0, flags, NULL);\n\t\t\tif (temp == NULL) return NULL;\n\t\t}\n\t\telse {\n\t\t\tPy_INCREF(arr);\n\t\t\ttemp = (PyObject *)arr;\n\t\t}\n\t}\n\tif (*axis < 0) *axis += n;\n\tif ((*axis < 0) || (*axis >= n)) {\n\t\tPyErr_Format(PyExc_ValueError, \n\t\t\t \"axis(=%d) out of bounds\", *axis);\n\t\tPy_DECREF(temp);\n\t\treturn NULL;\n\t}\n\treturn temp;\n}\n\n#include \"arraymethods.c\"\n\n/* Lifted from numarray */\nstatic PyObject *\nPyArray_IntTupleFromIntp(int len, intp *vals)\n{\n\tint i;\n PyObject *intTuple = PyTuple_New(len);\n if (!intTuple) goto fail;\n for(i=0; i= SIZEOF_INTP\n\t\tif (!(op = PyNumber_Int(seq))) return -1;\n#else\n\t\tif (!(op = PyNumber_Long(seq))) return -1;\n#endif\n\t\tnd = 1;\n#if SIZEOF_LONG >= SIZEOF_INTP\n\t\tvals[0] = (intp ) PyInt_AsLong(op);\n#else\n\t\tvals[0] = (intp ) PyLong_AsLongLong(op);\n#endif\n\t\tPy_DECREF(op);\n\t} else {\n\t\tfor(i=0; i < MIN(nd,maxvals); i++) {\n\t\t\top = PySequence_GetItem(seq, i);\n\t\t\tif (op == NULL) return -1;\n#if SIZEOF_LONG >= SIZEOF_INTP\n\t\t\tvals[i]=(intp )PyInt_AsLong(op);\n#else\n\t\t\tvals[i]=(intp )PyLong_AsLongLong(op);\n#endif\n\t\t\tPy_DECREF(op);\n\t\t\tif(PyErr_Occurred()) return -1;\n\t\t}\n\t}\n\treturn nd;\n}\n\n\n/* Check whether the given array is stored contiguously (row-wise) in\n memory. */\nstatic int\n_IsContiguous(PyArrayObject *ap) \n{\n\tregister intp sd;\n\tregister intp dim;\n\tregister int i;\n \n\n\tif (ap->nd == 0) return 1;\n\tsd = ap->descr->elsize;\n\tif (ap->nd == 1) return (ap->dimensions[0] == 1 || \\\n\t\t\t\t sd == ap->strides[0]);\n\tfor (i = ap->nd-1; i >= 0; --i) {\n\t\tdim = ap->dimensions[i];\n\t\t/* contiguous by definition */\n\t\tif (dim == 0) return 1;\n\t\tif (ap->strides[i] != sd) return 0;\n\t\tsd *= dim;\n\t}\n\treturn 1;\n}\n\n\nstatic int \n_IsFortranContiguous(PyArrayObject *ap) \n{\n\tregister intp sd;\n\tregister intp dim;\n\tregister int i;\n\t\n\tif (ap->nd == 0) return 1;\n\tsd = ap->descr->elsize;\n\tif (ap->nd == 1) return (ap->dimensions[0] == 1 || \\\n\t\t\t\t sd == ap->strides[0]);\n\tfor (i=0; i< ap->nd; ++i) {\n\t\tdim = ap->dimensions[i];\n\t\t/* contiguous by definition */\n\t\tif (dim == 0) return 1; \n\t\tif (ap->strides[i] != sd) return 0;\n\t\tsd *= dim;\n\t}\n\treturn 1;\n}\n\nstatic int\n_IsAligned(PyArrayObject *ap) \n{\n\tint i, alignment, aligned=1;\n\tintp ptr;\n\tint type = ap->descr->type_num;\n\n\tif ((type == PyArray_STRING) || (type == PyArray_VOID))\n\t\treturn 1;\n\n\talignment = ap->descr->alignment;\n\tif (alignment == 1) return 1;\n\n\tptr = (intp) ap->data;\n aligned = (ptr % alignment) == 0;\n for (i=0; i nd; i++)\n aligned &= ((ap->strides[i] % alignment) == 0);\n return aligned != 0;\n}\n\nstatic Bool\n_IsWriteable(PyArrayObject *ap)\n{\n\tPyObject *base=ap->base;\n\tvoid *dummy;\n\tint n;\n\n\t/* If we own our own data, then no-problem */\n\tif ((base == NULL) || (ap->flags & OWN_DATA)) return TRUE;\n\n\t/* Get to the final base object \n\t If it is a writeable array, then return TRUE\n\t If we can find an array object \n\t or a writeable buffer object as the final base object\n\t or a string object (for pickling support memory savings).\n\t - this last could be removed if a proper pickleable \n\t buffer was added to Python.\n\t*/\n\n\twhile(PyArray_Check(base)) {\n\t\tif (PyArray_CHKFLAGS(base, OWN_DATA)) \n\t\t\treturn (Bool) (PyArray_ISWRITEABLE(base));\n\t\tbase = PyArray_BASE(base);\n\t}\n\n\t/* here so pickle support works seamlessly \n\t and unpickled array can be set and reset writeable \n\t -- could be abused -- */\n\tif PyString_Check(base) return TRUE;\n\n\tif (PyObject_AsWriteBuffer(base, &dummy, &n) < 0)\n\t\treturn FALSE;\n\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 For axes with a positive stride this function checks for a walk\n beyond the right end of the buffer, for axes with a negative stride,\n it checks for a walk beyond the left end of the buffer. Zero strides\n are disallowed.\n*/\n/*OBJECT_API*/\nstatic Bool\nPyArray_CheckStrides(int elsize, int nd, intp numbytes, intp offset,\n\t\t intp *dims, intp *newstrides)\n{\n\tint i;\n\t\n\tif (numbytes == 0) \n\t\tnumbytes = PyArray_MultiplyList(dims, nd) * elsize;\n\t\n\tfor (i=0; i 0) {\n\t\t\t/* The last stride does not need to be fully inside\n\t\t\t the buffer, only its first elsize bytes */\n\t\t\tif (offset + stride*(dims[i]-1)+elsize > numbytes) {\n\t\t\t\treturn FALSE;\n\t\t\t}\n\t\t}\n\t\telse if (stride < 0) {\n\t\t\tif (offset + stride*dims[i] < 0) {\n\t\t\t\treturn FALSE;\n\t\t\t}\n\t\t} else {\n\t\t\t/* XXX: Zero strides may be useful, but currently \n\t\t\t XXX: allowing them would lead to strange results,\n\t\t\t XXX: for example :\n\t\t\t XXX: >>> x = arange(5)\n\t\t\t XXX: >>> x.strides = 0\n\t\t\t XXX: >>> x += 1\n\t\t\t XXX: >>> x\n\t\t\t XXX: array([5, 5, 5, 5, 5]) */\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 /* which could also be sub-fields of a VOID array */\n\t\tif (descr->hasobject) {\n if (descr != &OBJECT_Descr) {\n PyErr_SetString(PyExc_TypeError,\n \"fields with object members \" \\\n \"not yet supported.\");\n goto fail;\n }\n\t\t\tmemset(data, 0, sd);\n\t\t}\n\t}\n\telse {\n self->flags &= ~OWN_DATA; /* If data is passed in, \n\t\t\t\t\t this object won't own it \n\t\t\t\t\t by default.\n\t\t\t\t\t Caller must arrange for \n\t\t\t\t\t this to be reset if truly\n\t\t\t\t\t desired */\n }\n self->data = data;\n\n /* call the __array_finalize__\n\t method if a subtype 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, NULL);\n\tif (newarr == NULL) return -1;\n\tfromptr = PyArray_DATA(newarr);\n\tsize=PyArray_SIZE(arr);\n\tswap=!PyArray_ISNOTSWAPPED(arr);\n\tcopyswap = arr->descr->f->copyswap;\n\tif (PyArray_ISONESEGMENT(arr)) {\n\t\tchar *toptr=PyArray_DATA(arr);\n\t\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\", /* XXX ? */\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 strides.ptr, NULL, fortran, NULL);\n if (ret == NULL) {descr=NULL;goto fail;}\n if (type_num == PyArray_OBJECT) { /* place Py_None */\n PyArray_FillObjectArray(ret, Py_None);\n }\n }\n else { /* buffer given -- use it */\n if (dims.len == 1 && dims.ptr[0] == -1) {\n dims.ptr[offset] = 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, offset,\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 offset + (char *)buffer.ptr, \n\t\t\t\t\t buffer.flags, NULL); \n if (ret == NULL) {descr=NULL; goto fail;}\n PyArray_UpdateFlags(ret, UPDATE_ALL_FLAGS);\n ret->base = buffer.base;\n Py_INCREF(buffer.base); \n }\n\n PyDimMem_FREE(dims.ptr);\n if (strides.ptr) PyDimMem_FREE(strides.ptr);\n return (PyObject *)ret;\n \n fail:\n\tPy_XDECREF(descr);\n if (dims.ptr) PyDimMem_FREE(dims.ptr);\n if (strides.ptr) PyDimMem_FREE(strides.ptr);\n return NULL;\n}\n\n\nstatic PyObject *\narray_iter(PyArrayObject *arr)\n{\n\tif (arr->nd == 0) {\n\t\tPyErr_SetString(PyExc_TypeError,\n\t\t\t\t\"iteration over a scalar (0-dim array)\");\n\t\treturn NULL;\n\t}\n\treturn PySeqIter_New((PyObject *)arr);\n}\n\n\n/******************* array attribute get and set routines ******************/\n\nstatic PyObject *\narray_ndim_get(PyArrayObject *self)\n{\n\treturn PyInt_FromLong(self->nd);\n}\n\nstatic PyObject *\narray_flags_get(PyArrayObject *self)\n{\n return 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->data - new->data,\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 *arraydescr_protocol_typestr_get(PyArray_Descr *);\n\nstatic PyObject *\narray_typestr_get(PyArrayObject *self)\n{\n\treturn arraydescr_protocol_typestr_get(self->descr);\n}\n\nstatic PyObject *\narray_descr_get(PyArrayObject *self) \n{\n\tPy_INCREF(self->descr);\n\treturn (PyObject *)self->descr;\n}\n\n\n/* If the type is changed. \n Also needing change: strides, itemsize\n\n Either itemsize is exactly the same\n or the array is single-segment (contiguous or fortran) with\n compatibile dimensions\n\n The shape and strides will be adjusted in that case as well.\n*/\n\nstatic int\narray_descr_set(PyArrayObject *self, PyObject *arg)\n{\n PyArray_Descr *newtype=NULL;\n intp newdim;\n int index;\n char *msg = \"new type not compatible with array.\";\n\n if (!(PyArray_DescrConverter(arg, &newtype)) ||\n newtype == NULL) {\n PyErr_SetString(PyExc_TypeError, \"invalid data-type for array\");\n\t\treturn -1;\n }\n\tif (newtype->type_num == PyArray_OBJECT || \\\n\t self->descr->type_num == PyArray_OBJECT) {\n\t\tPyErr_SetString(PyExc_TypeError, \\\n\t\t\t\t\"Cannot change descriptor for object\"\\\n\t\t\t\t\"array.\");\n\t\tPy_DECREF(newtype);\n\t\treturn -1;\n\t}\n\n\tif ((newtype->elsize != self->descr->elsize) &&\t\t\\\n\t (self->nd == 0 || !PyArray_ISONESEGMENT(self) || \\\n\t newtype->subarray)) goto fail;\n\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\t/* We would decref newtype here --- temp will \n\t\t steal a reference to it */\n\t\ttemp = (PyArrayObject *)\t\t\t\t\\\n\t\t\tPyArray_NewFromDescr(&PyArray_Type, newtype, self->nd,\n\t\t\t\t\t self->dimensions, self->strides,\n\t\t\t\t\t self->data, self->flags, NULL);\n\t\tPyDimMem_FREE(self->dimensions);\n\t\tself->dimensions = temp->dimensions;\n\t\tself->nd = temp->nd;\n\t\tself->strides = temp->strides;\n\t\tnewtype = temp->descr;\n\t\t/* Fool deallocator not to delete these*/\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, \"descr\");\n\tif (res) return res;\n\tPyErr_Clear();\n\n\t/* get default */\n\tdobj = PyTuple_New(2);\n\tif (dobj == NULL) return NULL;\n\tPyTuple_SET_ITEM(dobj, 0, PyString_FromString(\"\"));\n\tPyTuple_SET_ITEM(dobj, 1, array_typestr_get(self));\n\tres = PyList_New(1);\n\tif (res == NULL) {Py_DECREF(dobj); return NULL;}\n\tPyList_SET_ITEM(res, 0, dobj);\n\treturn res;\n}\n\nstatic PyObject *\narray_struct_get(PyArrayObject *self)\n{\n PyArrayInterface *inter;\n \n inter = (PyArrayInterface *)_pya_malloc(sizeof(PyArrayInterface));\n inter->version = 2;\n inter->nd = self->nd;\n inter->typekind = self->descr->kind;\n inter->itemsize = self->descr->elsize;\n inter->flags = self->flags;\n /* reset unused flags */\n\tinter->flags &= ~(UPDATEIFCOPY | OWNDATA); \n\tif (PyArray_ISNOTSWAPPED(self)) inter->flags |= NOTSWAPPED;\n inter->strides = self->strides;\n inter->shape = self->dimensions;\n inter->data = self->data;\n\tPy_INCREF(self);\n return PyCObject_FromVoidPtrAndDesc(inter, self, gentype_struct_free);\n}\n\nstatic PyObject *\narray_base_get(PyArrayObject *self)\n{\n\tif (self->base == NULL) {\n\t\tPy_INCREF(Py_None);\n\t\treturn Py_None;\n\t}\n\telse {\n\t\tPy_INCREF(self->base);\n\t\treturn self->base;\n\t}\n}\n\n\nstatic PyObject *\narray_real_get(PyArrayObject *self)\n{\n\tPyArrayObject *ret;\n\n\tif (PyArray_ISCOMPLEX(self)) {\n\t\tret = (PyArrayObject *)PyArray_New(self->ob_type,\n\t\t\t\t\t\t self->nd,\n\t\t\t\t\t\t self->dimensions,\n\t\t\t\t\t\t self->descr->type_num - \\\n\t\t\t\t\t\t PyArray_NUM_FLOATTYPE,\n\t\t\t\t\t\t self->strides,\n\t\t\t\t\t\t self->data,\n\t\t\t\t\t\t 0,\n\t\t\t\t\t\t self->flags, (PyObject *)self);\n\t\tif (ret == NULL) return NULL;\n\t\tret->flags &= ~CONTIGUOUS;\n\t\tret->flags &= ~FORTRAN;\n\t\tPy_INCREF(self);\n\t\tret->base = (PyObject *)self;\n\t\treturn (PyObject *)ret;\n\t}\n\telse {\n\t\tPy_INCREF(self);\n\t\treturn (PyObject *)self;\n\t}\n}\n\n\nstatic int\narray_real_set(PyArrayObject *self, PyObject *val)\n{\n\tPyArrayObject *ret;\n\tPyArrayObject *new;\n\tint rint;\n\n\tnew = (PyArrayObject *)PyArray_FromAny(val, NULL, 0, 0, 0, NULL);\n\tif (new == NULL) return -1;\n\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, NULL); \n\t\tif (new == NULL) return -1;\n\t\tret = (PyArrayObject *)PyArray_New(self->ob_type,\n\t\t\t\t\t\t self->nd,\n\t\t\t\t\t\t self->dimensions,\n\t\t\t\t\t\t self->descr->type_num - \\\n\t\t\t\t\t\t PyArray_NUM_FLOATTYPE,\n\t\t\t\t\t\t self->strides,\n \t\t\t\t\t\t self->data +\t\t\\\n\t\t\t\t\t\t (self->descr->elsize >> 1),\n\t\t\t\t\t\t 0,\n\t\t\t\t\t\t self->flags, (PyObject *)self);\n\t\tif (ret == NULL) {\n\t\t\tPy_DECREF(new); \n\t\t\treturn -1;\n\t\t}\n\t\tret->flags &= ~CONTIGUOUS;\n\t\tret->flags &= ~FORTRAN;\n\t\tPy_INCREF(self);\n\t\tret->base = (PyObject *)self;\n\t\trint = PyArray_CopyInto(ret, new);\n\t\tPy_DECREF(ret);\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), NULL);\n\tif (arr == NULL) return -1;\n\tarrit = (PyArrayIterObject *)PyArray_IterNew(arr);\n\tif (arrit == NULL) goto exit;\n\tselfit = (PyArrayIterObject *)PyArray_IterNew((PyObject *)self);\n\tif (selfit == NULL) goto exit;\n\n swap = PyArray_ISNOTSWAPPED(self) != PyArray_ISNOTSWAPPED(arr);\n copyswap = self->descr->f->copyswap;\n if (PyArray_ISOBJECT(self)) {\n while(selfit->index < selfit->size) {\n Py_XDECREF(*((PyObject **)selfit->dataptr));\n Py_INCREF(*((PyObject **)arrit->dataptr)); \n memmove(selfit->dataptr, arrit->dataptr, \n sizeof(PyObject *));\n PyArray_ITER_NEXT(selfit);\n PyArray_ITER_NEXT(arrit);\n if (arrit->index == arrit->size) \n PyArray_ITER_RESET(arrit);\n }\n retval = 0; \n goto exit;\n }\n\n\twhile(selfit->index < selfit->size) {\n\t\tmemmove(selfit->dataptr, arrit->dataptr, self->descr->elsize);\n copyswap(selfit->dataptr, NULL, swap, self->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\t{\"dtype\",\n\t (getter)array_descr_get,\n\t (setter)array_descr_set,\n\t \"get(set) data-type-descriptor for array\"},\n {\"real\", \n\t (getter)array_real_get, \n\t (setter)array_real_set, \n\t \"real part of array\"},\n {\"imag\", \n\t (getter)array_imag_get, \n\t (setter)array_imag_set, \n\t \"imaginary part of array\"},\n\t{\"flat\", \n\t (getter)array_flat_get, \n\t (setter)array_flat_set, \n\t \"a 1-d view of a contiguous array\"}, \n\t{\"__array_data__\", \n\t (getter)array_dataptr_get,\n\t NULL,\n\t \"Array protocol: data\"},\n\t{\"__array_typestr__\",\n\t (getter)array_typestr_get,\n\t NULL,\n\t \"Array protocol: typestr\"},\n\t{\"__array_descr__\",\n\t (getter)array_protocol_descr_get,\n\t NULL,\n\t \"Array protocol: descr\"},\n\t{\"__array_shape__\", \n\t (getter)array_shape_get,\n\t NULL,\n\t \"Array protocol: shape\"},\n\t{\"__array_strides__\",\n\t (getter)array_protocol_strides_get,\n\t NULL,\n\t \"Array protocol: strides\"},\n {\"__array_struct__\",\n (getter)array_struct_get,\n NULL,\n \"Array protocol: struct\"},\n\t{\"__array_priority__\",\n\t (getter)array_priority_get,\n\t NULL,\n\t \"Array priority\"},\n \t{NULL, NULL, NULL, NULL}, /* Sentinel */\n};\n\n/****************** end of attribute get and set routines *******************/\n\n\nstatic PyObject *\narray_alloc(PyTypeObject *type, int nitems)\n{\n PyObject *obj;\n /* nitems will always be 0 */ \n obj = (PyObject *)_pya_malloc(sizeof(PyArrayObject));\n PyObject_Init(obj, type);\n return obj;\n}\n\n\nstatic char Arraytype__doc__[] = \n \"A array object represents a multidimensional, homogeneous array\\n\"\n\t\" of fixed-size items. An associated data-type-descriptor object\\n\"\n\t\" details the data-type in an array (including byteorder and any\\n\"\n\t\" fields). An array can be constructed using the numpy.array\\n\"\n\t\" command. Arrays are sequence, mapping and numeric objects.\\n\"\n\t\" More information is available in the numpy module and by looking\\n\"\n\t\" at the methods and attributes of an array.\\n\\n\"\n\t\" ndarray.__new__(subtype, shape=, dtype=int_, buffer=None, \\n\"\n\t\" offset=0, strides=None, fortran=False)\\n\\n\"\n\t\" There are two modes of creating an array using __new__:\\n\"\n\t\" 1) If buffer is None, then only shape, dtype, and fortran \\n\"\n\t\" are used\\n\"\n\t\" 2) If buffer is an object exporting the buffer interface, then\\n\"\n\t\" all keywords are interpreted.\\n\"\n\t\" The dtype parameter can be any object that can be interpreted \\n\"\n\t\" as a numpy.dtype object.\\n\\n\"\n\t\" No __init__ method is needed because the array is fully \\n\"\n\t\" initialized after the __new__ method.\";\n\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, 4*n);\n\t\telse\n\t\t\t*itemsize = MAX(*itemsize, n);\n\t\treturn 0;\n\t}\n\tfor (i=0; i n_lower) n_lower = d[1];\n }\n d[1] = n_lower;\n\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, 4*minsize);\n\t\t}\n\t\telse {\n\t\t\ttestsize = MAX(chksize, minsize);\n\t\t}\n\t\tif (testsize != outtype->elsize) {\n\t\t\tPyArray_DESCR_REPLACE(outtype);\n\t\t\touttype->elsize = testsize;\n\t\t\tPy_XDECREF(outtype->fields);\n\t\t\touttype->fields = NULL;\n\t\t}\n\t}\n\treturn outtype;\n}\n\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#ifndef Py_UNICODE_WIDE\n\t\tchktype->elsize <<= 1;\n#endif\t\t\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\t} else if (PyLong_Check(op)) {\n\t\t/* if integer can fit into a longlong then return that\n\t\t*/\n\t\tif ((PyLong_AsLongLong(op) == -1) && PyErr_Occurred()) {\n\t\t\tPyErr_Clear();\n\t\t\tgoto deflt;\n\t\t}\n\t\tchktype = PyArray_DescrFromType(PyArray_LONGLONG);\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 *= 4;\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\tif (ret->nd > 0) {\n\t\tPyErr_SetString(PyExc_ValueError,\n\t\t\t\t\"shape-mismatch on array construction\");\n\t\tPy_DECREF(ret);\n\t\treturn NULL;\n\t}\n\n ret->descr->f->setitem(op, ret->data, ret);\n\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 */\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\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\t\tgoto fail;\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\t\tgoto fail;\n }\n\t\n\tif(discover_dimensions(s,nd,d, !stop_at_string) == -1) goto fail;\n\n\tif (itemsize == 0 && PyTypeNum_ISEXTENDED(type)) {\n\t\tif (discover_itemsize(s, nd, &itemsize) == -1) goto fail;\n\t\tif (type == PyArray_UNICODE) itemsize*=4;\n\t}\n\n\tif (itemsize != typecode->elsize) {\n\t\tPyArray_DESCR_REPLACE(typecode);\n\t\ttypecode->elsize = itemsize;\n\t}\n\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) return NULL;\n if(Assign_Array(r,s) == -1) {\n\t\tPy_DECREF(r);\n\t\treturn NULL;\n\t}\n return (PyObject*)r;\n\n fail:\n\tPy_DECREF(typecode);\n\treturn NULL;\n}\n\n\n/*OBJECT_API\n Is the typenum valid?\n*/\nstatic int \nPyArray_ValidType(int type) \n{\n\tPyArray_Descr *descr;\n\tint res=TRUE;\n\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 << 2;\n\t\tif (mpd->type_num == PyArray_UNICODE &&\n\t\t at->type_num == PyArray_STRING) \n\t\t\tat->elsize = mpd->elsize >> 2;\n\t\tif (at->type_num == PyArray_VOID)\n\t\t\tat->elsize = mpd->elsize;\n\t}\n\n\tout = PyArray_NewFromDescr(mp->ob_type, at,\n\t\t\t\t mp->nd, \n\t\t\t\t mp->dimensions, \n\t\t\t\t NULL, NULL, \n\t\t\t\t fortran,\n\t\t\t\t (PyObject *)mp);\n\n\tif (out == NULL) return NULL;\n\tret = PyArray_CastTo((PyArrayObject *)out, mp);\n\tif (ret != -1) return out;\n\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 */\n/*OBJECT_API*/\nstatic PyObject *\nPyArray_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 break;\n\tcase PyArray_STRINGLTR:\n\t\ttype_num = PyArray_STRING;\n\t\tbreak;\n\tcase PyArray_UNICODELTR:\n\t\ttype_num = PyArray_UNICODE;\n\t\tsize <<= 2;\n\t\tbreak;\n\tcase 'V':\n\t\ttype_num = PyArray_VOID;\n\t\tbreak;\n\tdefault:\n\t\t_MY_FAIL\n\t}\n\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/* OBJECT_API */\nstatic PyObject *\nPyArray_FromStructInterface(PyObject *input)\n{\n\tPyArray_Descr *thetype;\n\tchar buf[40];\n\tPyArrayInterface *inter;\n\tPyObject *attr, *r;\n\tchar endian = PyArray_NATBYTE;\n \n attr = PyObject_GetAttrString(input, \"__array_struct__\");\n if (attr == NULL) {\n\t\tPyErr_Clear();\n\t\treturn Py_NotImplemented;\n\t}\n if (!PyCObject_Check(attr) || \\\n ((inter=((PyArrayInterface *)\\\n\t\t PyCObject_AsVoidPtr(attr)))->version != 2)) {\n PyErr_SetString(PyExc_ValueError, \"invalid __array_struct__\");\n\t\tPy_DECREF(attr);\n return NULL;\n }\n\tif ((inter->flags & NOTSWAPPED) != NOTSWAPPED) {\n\t\tendian = PyArray_OPPBYTE;\n\t\tinter->flags &= ~NOTSWAPPED;\n\t}\n\n snprintf(buf, 40, \"%c%c%d\", endian, inter->typekind, inter->itemsize);\n if (!(thetype=_array_typedescr_fromstr(buf))) {\n\t\tPy_DECREF(attr);\n return NULL;\n }\n\n r = PyArray_NewFromDescr(&PyArray_Type, thetype,\n\t\t\t\t inter->nd, inter->shape,\n\t\t\t\t inter->strides, inter->data,\n\t\t\t\t inter->flags, NULL);\n\tPy_INCREF(input);\n\tPyArray_BASE(r) = input;\n Py_DECREF(attr);\n PyArray_UpdateFlags((PyArrayObject *)r, UPDATE_ALL_FLAGS);\n return r;\n}\n\n/*OBJECT_API*/\nstatic PyObject *\nPyArray_FromInterface(PyObject *input)\n{\n\tPyObject *attr=NULL, *item=NULL;\n PyObject *tstr=NULL, *shape=NULL; \n PyArrayObject *ret;\n\tPyArray_Descr *type=NULL;\n\tchar *data;\n\tint buffer_len;\n\tint res, i, n;\n\tintp dims[MAX_DIMS], strides[MAX_DIMS];\n\tint dataflags = BEHAVED_FLAGS;\n\n\t/* Get the memory from __array_data__ and __array_offset__ */\n\t/* Get the shape */\n\t/* Get the typestring -- ignore array_descr */\n\t/* Get the strides */\n\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\treturn NULL;\n\t\t}\n\t\tif (n != PyTuple_GET_SIZE(attr)) {\n\t\t\tPyErr_SetString(PyExc_ValueError, \n\t\t\t\t\t\"mismatch in length of \"\\\n\t\t\t\t\t\"__array_strides__ and \"\\\n\t\t\t\t\t\"__array_shape__\");\n\t\t\tPy_DECREF(attr);\n\t\t\tPy_DECREF(ret);\n\t\t\treturn NULL;\n\t\t}\n\t\tfor (i=0; istrides, strides, n*sizeof(intp));\n\t}\n\telse PyErr_Clear();\n\tPyArray_UpdateFlags(ret, UPDATE_ALL_FLAGS);\n\treturn (PyObject *)ret;\n\n fail:\n\tPy_XDECREF(attr);\n\tPy_XDECREF(shape);\n\tPy_XDECREF(tstr);\n\treturn NULL;\n}\n\n/* OBJECT_API*/\nstatic PyObject *\nPyArray_FromArrayAttr(PyObject *op, PyArray_Descr *typecode, PyObject *context) \n{\n PyObject *new;\n PyObject *array_meth;\n\n array_meth = PyObject_GetAttrString(op, \"__array__\");\n if (array_meth == NULL) {PyErr_Clear(); return Py_NotImplemented;}\n if (context == NULL) {\n if (typecode == NULL) new = PyObject_CallFunction(array_meth, NULL);\n else new = PyObject_CallFunction(array_meth, \"O\", typecode);\n }\n else {\n if (typecode == NULL) {\n new = PyObject_CallFunction(array_meth, \"OO\", Py_None, context);\n if (new == NULL && PyErr_ExceptionMatches(PyExc_TypeError)) {\n PyErr_Clear();\n new = PyObject_CallFunction(array_meth, \"\");\n }\n }\n else {\n new = PyObject_CallFunction(array_meth, \"OO\", typecode, context);\n if (new == NULL && PyErr_ExceptionMatches(PyExc_TypeError)) {\n PyErr_Clear();\n new = PyObject_CallFunction(array_meth, \"O\", typecode);\n }\n }\n }\n Py_DECREF(array_meth);\n if (new == NULL) return NULL;\n if (!PyArray_Check(new)) {\n PyErr_SetString(PyExc_ValueError, \n \"object __array__ method not \" \\\n \"producing an array\");\n Py_DECREF(new);\n return NULL;\n }\n return new;\n} \n\n/* Does not check for ENSURECOPY and NOTSWAPPED in flags */\n/* Steals a reference to newtype --- which can be NULL */\n/*OBJECT_API*/\nstatic PyObject *\nPyArray_FromAny(PyObject *op, PyArray_Descr *newtype, int min_depth, \n int max_depth, int flags, PyObject *context) \n{\n /* This is the main code to make a NumPy array from a Python\n Object. It is called from lot's of different places which\n is why there are so many checks. The comments try to\n explain some of the checks. */\n\n PyObject *r=NULL;\n int seq = FALSE;\n \n\t/* Is input object already an array? */\n\t/* This is where the flags are used */\n if (PyArray_Check(op)) \n\t\tr = PyArray_FromArray((PyArrayObject *)op, newtype, flags);\n\telse if (PyArray_IsScalar(op, Generic)) {\n\t\tr = PyArray_FromScalar(op, newtype);\n\t}\n else if (((r = PyArray_FromStructInterface(op))!=Py_NotImplemented)|| \\\n ((r = PyArray_FromInterface(op)) != Py_NotImplemented) || \\\n ((r = PyArray_FromArrayAttr(op, newtype, context)) \\\n != Py_NotImplemented)) {\n PyObject *new;\n if (r == NULL) return NULL;\n if (newtype != NULL || flags != 0) {\n new = PyArray_FromArray((PyArrayObject *)r, newtype, flags);\n Py_DECREF(r);\n r = new;\n }\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\n\t\t\tPy_INCREF(newtype);\n\t\t\tr = Array_FromSequence(op, newtype, flags & FORTRAN,\n\t\t\t\t\t min_depth, max_depth);\n\t\t\tif (PyErr_Occurred() && r == NULL) {\n /* It wasn't really a sequence after all.\n * Try interpreting it as a scalar */\n\t\t\t\tPyErr_Clear();\n\t\t\t}\n else {\n\t\t\t\tseq = TRUE;\n\t\t\t\tPy_DECREF(newtype);\n\t\t\t}\n }\n if (!seq)\n\t\t\tr = Array_FromScalar(op, newtype);\n\t}\n\n /* If we didn't succeed return NULL */\n if (r == NULL) return NULL;\n\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: PyArray_FromAny \"\\\n\t\t\t\t\"not producing an array\");\n\t\tPy_DECREF(r);\n return NULL;\n }\n\n if (min_depth != 0 && ((PyArrayObject *)r)->nd < min_depth) {\n PyErr_SetString(PyExc_ValueError, \n \"object of too small depth for desired array\");\n Py_DECREF(r);\n return NULL;\n }\n if (max_depth != 0 && ((PyArrayObject *)r)->nd > max_depth) {\n PyErr_SetString(PyExc_ValueError, \n \"object too deep for desired array\");\n Py_DECREF(r);\n return NULL;\n }\n return r;\n}\n\n/* new reference -- accepts NULL for mintype*/\n/*OBJECT_API*/\nstatic PyArray_Descr *\nPyArray_DescrFromObject(PyObject *op, PyArray_Descr *mintype)\n{\n\treturn _array_find_type(op, mintype, MAX_DIMS);\n}\n\n/*OBJECT_API\n Return the typecode of the array a Python object would be converted\n to\n*/\nstatic int \nPyArray_ObjectType(PyObject *op, int minimum_type) \n{\n\tPyArray_Descr *intype;\n\tPyArray_Descr *outtype;\n\tint ret;\n\n\tintype = PyArray_DescrFromType(minimum_type);\n\tif (intype == NULL) PyErr_Clear();\n\touttype = _array_find_type(op, intype, MAX_DIMS);\n\tret = outtype->type_num;\n\tPy_DECREF(outtype);\n\tPy_DECREF(intype);\n\treturn ret;\n}\n\n\n/* flags is any of \n CONTIGUOUS, \n FORTRAN,\n ALIGNED, \n WRITEABLE, \n NOTSWAPPED,\n ENSURECOPY, \n UPDATEIFCOPY,\n FORCECAST,\n ENSUREARRAY\n\n or'd (|) together\n\n Any of these flags present means that the returned array should \n guarantee that aspect of the array. Otherwise the returned array\n won't guarantee it -- it will depend on the object as to whether or \n not it has such features. \n\n Note that ENSURECOPY is enough\n to guarantee CONTIGUOUS, ALIGNED and WRITEABLE\n and therefore it is redundant to include those as well. \n\n BEHAVED_FLAGS == ALIGNED | WRITEABLE\n CARRAY_FLAGS = CONTIGUOUS | BEHAVED_FLAGS\n FARRAY_FLAGS = FORTRAN | BEHAVED_FLAGS\n \n FORTRAN can be set in the FLAGS to request a FORTRAN array. \n Fortran arrays are always behaved (aligned, \n notswapped, and writeable) and not (C) CONTIGUOUS (if > 1d). \n\n UPDATEIFCOPY flag sets this flag in the returned array if a copy is\n made and the base argument points to the (possibly) misbehaved array.\n When the new array is deallocated, the original array held in base\n is updated with the contents of the new array. \n\n FORCECAST will cause a cast to occur regardless of whether or not\n it is safe. \n*/\n\n\n/* steals a reference to descr -- accepts NULL */\n/*OBJECT_API*/\nstatic PyObject *\nPyArray_CheckFromAny(PyObject *op, PyArray_Descr *descr, int min_depth, \n int max_depth, int requires, PyObject *context) \n{\n\tif (requires & NOTSWAPPED) {\n\t\tif (!descr && PyArray_Check(op) && \\\n\t\t !PyArray_ISNBO(PyArray_DESCR(op)->byteorder)) {\n\t\t\tdescr = PyArray_DescrNew(PyArray_DESCR(op));\n\t\t}\n\t\telse if ((descr && !PyArray_ISNBO(descr->byteorder))) {\n\t\t\tPyArray_DESCR_REPLACE(descr);\n\t\t}\n\t\tdescr->byteorder = PyArray_NATIVE;\n\t}\n\n\treturn PyArray_FromAny(op, descr, min_depth, max_depth,\n requires, context);\n}\n\n/* This is a quick wrapper around PyArray_FromAny(op, NULL, 0, 0, \n ENSUREARRAY) */\n/* that special cases Arrays and PyArray_Scalars up front */\n/* It *steals a reference* to the object */\n/* It also guarantees that the result is PyArray_Type 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_FromAny(op, NULL, 0, 0, ENSUREARRAY, NULL);\n Py_DECREF(op);\n return new;\n}\n\n/*OBJECT_API\n Check the type coercion rules.\n*/\nstatic int \nPyArray_CanCastSafely(int fromtype, int totype) \n{\n\tPyArray_Descr *from, *to;\n\tregister int felsize, telsize;\n\n if (fromtype == totype) return 1;\n if (fromtype == PyArray_BOOL) return 1;\n\tif (totype == PyArray_BOOL) return 0;\n if (totype == PyArray_OBJECT || totype == PyArray_VOID) return 1;\n\tif (fromtype == PyArray_OBJECT || fromtype == PyArray_VOID) return 0;\n\n\tfrom = PyArray_DescrFromType(fromtype);\n\tto = PyArray_DescrFromType(totype);\n\ttelsize = to->elsize;\n\tfelsize = from->elsize;\n\tPy_DECREF(from);\n\tPy_DECREF(to);\n\n switch(fromtype) {\n case PyArray_BYTE:\n\tcase PyArray_SHORT:\n case PyArray_INT:\n case PyArray_LONG:\n\tcase PyArray_LONGLONG:\n\t\tif (PyTypeNum_ISINTEGER(totype)) {\n\t\t\tif (PyTypeNum_ISUNSIGNED(totype)) {\n\t\t\t\treturn (telsize > felsize);\n\t\t\t}\n\t\t\telse {\n\t\t\t\treturn (telsize >= felsize);\n\t\t\t}\n\t\t}\n\t\telse if (PyTypeNum_ISFLOAT(totype)) {\n if (felsize < 8)\n return (telsize > felsize);\n else\n return (telsize >= felsize);\n\t\t}\n\t\telse if (PyTypeNum_ISCOMPLEX(totype)) {\n if (felsize < 8)\n return ((telsize >> 1) > felsize);\n else\n return ((telsize >> 1) >= felsize);\n\t\t}\n\t\telse return totype > fromtype;\n case PyArray_UBYTE:\n case PyArray_USHORT:\n case PyArray_UINT:\n\tcase PyArray_ULONG:\n\tcase PyArray_ULONGLONG:\n\t\tif (PyTypeNum_ISINTEGER(totype)) {\n\t\t\tif (PyTypeNum_ISSIGNED(totype)) {\n\t\t\t\treturn (telsize > felsize);\n\t\t\t}\n\t\t\telse {\n\t\t\t\treturn (telsize >= felsize);\n\t\t\t}\n\t\t}\n\t\telse if (PyTypeNum_ISFLOAT(totype)) {\n if (felsize < 8)\n return (telsize > felsize);\n else\n return (telsize >= felsize);\n\t\t}\n\t\telse if (PyTypeNum_ISCOMPLEX(totype)) {\n if (felsize < 8)\n return ((telsize >> 1) > felsize);\n else\n return ((telsize >> 1) >= felsize);\n\t\t}\n\t\telse return totype > fromtype;\n case PyArray_FLOAT:\n case PyArray_DOUBLE:\n\tcase PyArray_LONGDOUBLE:\n\t\tif (PyTypeNum_ISCOMPLEX(totype)) \n\t\t\treturn ((telsize >> 1) >= felsize);\n\t\telse\n\t\t\treturn (totype > fromtype);\n case PyArray_CFLOAT:\n case PyArray_CDOUBLE:\n\tcase PyArray_CLONGDOUBLE:\n\t\treturn (totype > fromtype);\n\tcase PyArray_STRING:\n\tcase PyArray_UNICODE:\n\t\treturn (totype > fromtype);\n default:\n return 0;\n }\n}\n\n/* leaves reference count alone --- cannot be NULL*/\n/*OBJECT_API*/\nstatic Bool\nPyArray_CanCastTo(PyArray_Descr *from, PyArray_Descr *to)\n{\n\tint fromtype=from->type_num;\n\tint totype=to->type_num;\n\tBool ret;\n\n\tret = (Bool) PyArray_CanCastSafely(fromtype, totype);\n\tif (ret) { /* Check String and Unicode more closely */\n\t\tif (fromtype == PyArray_STRING) {\n\t\t\tif (totype == PyArray_STRING) {\n\t\t\t\tret = (from->elsize <= to->elsize);\n\t\t\t}\n\t\t\telse if (totype == PyArray_UNICODE) {\n\t\t\t\tret = (from->elsize << 2 \\\n\t\t\t\t <= to->elsize);\n\t\t\t}\n\t\t}\n\t\telse if (fromtype == PyArray_UNICODE) {\n\t\t\tif (totype == PyArray_UNICODE) {\n\t\t\t\tret = (from->elsize <= to->elsize);\n\t\t\t}\n\t\t}\n\t\t/* TODO: If totype is STRING or unicode \n\t\t see if the length is long enough to hold the\n\t\t stringified value of the object.\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, NULL);\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 FORCECAST | ALIGNED, NULL);\n\t\t\tif (new==NULL) goto fail;\n Py_DECREF(obj);\n\t\t\tobj = new;\n\t\t\tr = iter_subscript_int(self, (PyArrayObject *)obj);\n\t\t}\n\t\telse {\n\t\t\tgoto fail;\n\t\t}\n\t\tPy_DECREF(obj);\n\t\treturn r;\n\t}\n\telse Py_DECREF(indtype);\n\n\n fail:\n\tif (!PyErr_Occurred())\n\t\tPyErr_SetString(PyExc_IndexError, \"unsupported iterator index\");\n\tPy_XDECREF(indtype);\n\tPy_XDECREF(obj);\n\treturn NULL;\n\n}\n\n\nstatic int\niter_ass_sub_Bool(PyArrayIterObject *self, PyArrayObject *ind,\n\t\t PyArrayIterObject *val, int swap)\n{\n\tint index, strides, itemsize;\n\tchar *dptr;\n PyArray_CopySwapFunc *copyswap;\n\n\tif (ind->nd != 1) {\n\t\tPyErr_SetString(PyExc_ValueError, \n\t\t\t\t\"boolean index array should have 1 dimension\");\n\t\treturn -1;\n\t}\n\titemsize = self->ao->descr->elsize;\n\tindex = ind->dimensions[0];\n\tstrides = ind->strides[0];\n\tdptr = ind->data;\n\tPyArray_ITER_RESET(self);\n\t/* Loop over Boolean array */\n copyswap = self->ao->descr->f->copyswap;\n\twhile(index--) {\n\t\tif (*((Bool *)dptr) != 0) {\n copyswap(self->dataptr, val->dataptr, swap,\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, NULL);\n\tif (arrval==NULL) return -1;\n\tval_it = (PyArrayIterObject *)PyArray_IterNew(arrval);\n\tif (val_it==NULL) goto finish;\n\n\t/* Check for Boolean -- this is first becasue\n\t Bool is a subclass of Int */\n\n copyswap = PyArray_DESCR(arrval)->f->copyswap;\n\tswap = (PyArray_ISNOTSWAPPED(self->ao)!=PyArray_ISNOTSWAPPED(arrval));\n\tif (PyBool_Check(ind)) {\n\t\tif (PyObject_IsTrue(ind)) {\n copyswap(self->dataptr, PyArray_DATA(arrval), \n swap, 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, NULL);\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_CheckFromAny(obj, indtype, 0, 0, \n FORCECAST | BEHAVED_NS_FLAGS, NULL);\n\t\t\tPy_DECREF(obj);\n\t\t\tobj = new;\n\t\t\tif (new==NULL) goto finish;\n\t\t\tif (iter_ass_sub_int(self, (PyArrayObject *)obj,\n\t\t\t\t\t val_it, swap) < 0)\n\t\t\t\tgoto finish;\n\t\t\tretval=0;\n\t\t}\n\t}\n\n finish:\n\tif (!PyErr_Occurred() && retval < 0)\n\t\tPyErr_SetString(PyExc_IndexError, \n\t\t\t\t\"unsupported iterator index\");\n\tPy_XDECREF(indtype);\n\tPy_XDECREF(obj);\n\tPy_XDECREF(val_it);\n\tPy_XDECREF(arrval);\n\treturn retval;\n\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 {\"index\", T_INT, offsetof(PyArrayIterObject, index), RO, NULL},\n\t{NULL},\n};\n\nstatic PyObject *\niter_coords_get(PyArrayIterObject *self)\n{\n int nd;\n nd = self->ao->nd;\n if (self->contiguous) { /* coordinates not kept track of --- need to generate\n from index */\n intp val;\n int i;\n val = self->index;\n for (i=0;icoordinates[i] = val / self->factors[i];\n val = val % self->factors[i];\n }\n }\n return PyArray_IntTupleFromIntp(nd, self->coordinates);\n}\n\nstatic PyGetSetDef iter_getsets[] = {\n\t{\"coords\", \n\t (getter)iter_coords_get,\n\t NULL,\n\t \"An N-d tuple of current coordinates.\"},\n\t{NULL, NULL, NULL, NULL},\n};\n\nstatic PyTypeObject PyArrayIter_Type = {\n PyObject_HEAD_INIT(NULL)\n 0,\t\t\t\t\t /* ob_size */\n \"numpy.flatiter\",\t\t /* tp_name */\n sizeof(PyArrayIterObject), /* tp_basicsize */\n 0,\t\t\t\t\t /* tp_itemsize */\n /* methods */\n (destructor)arrayiter_dealloc,\t\t/* tp_dealloc */\n 0,\t\t\t\t\t/* tp_print */\n 0,\t\t\t\t\t/* tp_getattr */\n 0,\t\t\t\t\t/* tp_setattr */\n 0,\t\t\t\t\t/* tp_compare */\n 0,\t\t\t\t\t/* tp_repr */\n 0,\t\t\t\t\t/* tp_as_number */\n 0, \t\t\t /* tp_as_sequence */\n &iter_as_mapping, \t /* tp_as_mapping */\n 0,\t\t\t\t\t/* tp_hash */\n 0,\t\t\t\t\t/* tp_call */\n 0,\t\t\t\t\t/* tp_str */\n 0,\t \t/* tp_getattro */\n 0,\t\t\t\t\t/* tp_setattro */\n 0,\t\t\t\t\t/* tp_as_buffer */\n Py_TPFLAGS_DEFAULT, /* tp_flags */\n 0,\t\t\t\t\t/* tp_doc */\n 0, \t /* tp_traverse */\n 0,\t\t\t\t\t/* tp_clear */\n 0,\t\t\t\t\t/* tp_richcompare */\n 0,\t\t\t\t\t/* tp_weaklistoffset */\n 0, \t /* tp_iter */\n (iternextfunc)arrayiter_next,\t\t/* tp_iternext */\n iter_methods,\t\t\t\t/* tp_methods */\n iter_members,\t \t /* tp_members */\n iter_getsets, /* tp_getset */\n\n};\n\n/** END of Array Iterator **/\n\n\n\n/*********************** Subscript Array Iterator *************************\n * *\n * This object handles subscript behavior for array objects. *\n * It is an iterator object with a next method *\n * It abstracts the n-dimensional mapping behavior to make the looping *\n * code more understandable (maybe) *\n * and so that indexing can be set up ahead of time *\n */ \n\n/* convert an indexing object to an INTP indexing array iterator\n if possible -- otherwise, it is a Slice or Ellipsis object\n and has to be interpreted on bind to a particular \n array so leave it NULL for now.\n */\nstatic int\n_convert_obj(PyObject *obj, PyArrayIterObject **iter)\n{\n\tPyArray_Descr *indtype;\n\tPyObject *arr;\n\n\tif (PySlice_Check(obj) || (obj == Py_Ellipsis))\n\t\t*iter = NULL;\n\telse {\n\t\tindtype = PyArray_DescrFromType(PyArray_INTP);\n\t\tarr = PyArray_FromAny(obj, indtype, 0, 0, FORCECAST, NULL);\n\t\tif (arr == NULL) return -1;\n\t\t*iter = (PyArrayIterObject *)PyArray_IterNew(arr);\n\t\tPy_DECREF(arr);\n\t\tif (*iter == NULL) return -1;\n\t}\n\treturn 0;\n}\n\n/* Adjust dimensionality and strides for index object iterators \n --- i.e. broadcast\n */\n/*OBJECT_API*/\nstatic int\nPyArray_Broadcast(PyArrayMultiIterObject *mit)\n{\n\tint i, nd, k, j;\n\tintp tmp;\n\tPyArrayIterObject *it;\n\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\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, NULL);\n\tif (ba == NULL) return -1;\n\tnd = ba->nd;\n\tfor (j=0; jdata;\n\tcount = 0;\n\n\t/* pre-determine how many nonzero entries there are */\n\tfor (i=0; iao->data;\n\t\tcoords[j] = 0;\n\t\tdims_m1[j] = ba->dimensions[j]-1;\n\t}\n\n\tptr = (Bool *)ba->data;\n\n\tif (count == 0) goto finish;\n\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->index = 0;\n \tmit->ait = NULL;\n \tmit->subspace = NULL;\n\tmit->numiter = 0;\n\tmit->consec = 1;\n\tPy_INCREF(indexobj);\n\tmit->indexobj = indexobj;\n\n\tif (fancy == SOBJ_LISTTUP) {\n\t\tPyObject *newobj;\n\t\tnewobj = PySequence_Tuple(indexobj);\n\t\tif (newobj == NULL) goto fail;\n\t\tPy_DECREF(indexobj);\n\t\tindexobj = newobj;\n\t\tmit->indexobj = indexobj;\n\t}\n\n#undef SOBJ_NOTFANCY \n#undef SOBJ_ISFANCY \n#undef SOBJ_BADARRAY \n#undef SOBJ_TOOMANY \n#undef SOBJ_LISTTUP \n \n\tif (oned) return (PyObject *)mit;\n\n\t/* Must have some kind of fancy indexing if we are here */\n\t/* indexobj is either a list, an arrayobject, or a tuple \n\t (with at least 1 list or arrayobject or Bool object), */\n\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, NULL);\n\t\tif (arr == NULL) goto fail;\n\t\tmit->iters[0] = (PyArrayIterObject *)PyArray_IterNew(arr);\n\t\tif (mit->iters[0] == NULL) {Py_DECREF(arr); goto fail;}\n\t\tmit->nd = PyArray_NDIM(arr);\n\t\tmemcpy(mit->dimensions,PyArray_DIMS(arr),mit->nd*sizeof(intp));\n\t\tmit->size = PyArray_SIZE(arr);\n\t\tPy_DECREF(arr);\n\t\tPy_DECREF(mit->indexobj);\n\t\tmit->indexobj = Py_BuildValue(\"(N)\", PyInt_FromLong(0));\n\t}\n\telse { /* must be a tuple */\n\t\tPyObject *obj;\n\t\tPyArrayIterObject *iter;\n\t\tPyObject *new;\n\t\t/* Make a copy of the tuple -- we will be replacing \n\t\t index objects with 0's */\n\t\tn = PyTuple_GET_SIZE(indexobj);\n\t\tnew = PyTuple_New(n);\n\t\tif (new == NULL) goto fail;\n\t\tstarted = 0;\n\t\tnonindex = 0;\n\t\tfor (i=0; iconsec = 0;\n\t\t\t\tmit->iters[(mit->numiter)++] = iter;\n\t\t\t\tPyTuple_SET_ITEM(new,i,\n\t\t\t\t\t\t PyInt_FromLong(0));\n\t\t\t}\n\t\t\telse {\n\t\t\t\tif (started) nonindex = 1;\n\t\t\t\tPy_INCREF(obj);\n\t\t\t\tPyTuple_SET_ITEM(new,i,obj);\n\t\t\t}\n\t\t}\n\t\tPy_DECREF(mit->indexobj);\n\t\tmit->indexobj = new;\n\t\t/* Store the number of iterators actually converted */\n\t\t/* These will be mapped to actual axes at bind time */\n\t\tif (PyArray_Broadcast((PyArrayMultiIterObject *)mit) < 0)\n\t\t\tgoto fail;\n\t}\n\n return (PyObject *)mit;\n \n fail:\n Py_DECREF(mit);\n\treturn NULL;\n}\n\n\nstatic void\narraymapiter_dealloc(PyArrayMapIterObject *mit)\n{\n\tint i;\n\tPy_XDECREF(mit->indexobj);\n Py_XDECREF(mit->ait);\n\tPy_XDECREF(mit->subspace);\n\tfor (i=0; inumiter; i++)\n\t\tPy_XDECREF(mit->iters[i]);\n _pya_free(mit);\n}\n\n/* The mapiter object must be created new each time. It does not work\n to bind to a new array, and continue.\n\n This was the orginal intention, but currently that does not work. \n Do not expose the MapIter_Type to Python.\n\n It's not very useful anyway, since mapiter(indexobj); mapiter.bind(a); \n mapiter is equivalent to a[indexobj].flat but the latter gets to use \n slice syntax.\n*/\n\nstatic PyTypeObject PyArrayMapIter_Type = {\n PyObject_HEAD_INIT(NULL)\n 0,\t\t\t\t\t /* ob_size */\n \"numpy.mapiter\",\t\t \t/* tp_name */\n sizeof(PyArrayIterObject), /* tp_basicsize */\n 0,\t\t\t\t\t /* tp_itemsize */\n /* methods */\n (destructor)arraymapiter_dealloc,\t/* tp_dealloc */\n 0,\t\t\t\t\t/* tp_print */\n 0,\t\t\t\t\t/* tp_getattr */\n 0,\t\t\t\t\t/* tp_setattr */\n 0,\t\t\t\t\t/* tp_compare */\n 0,\t\t\t\t\t/* tp_repr */\n 0,\t\t\t\t\t/* tp_as_number */\n 0,\t\t\t\t\t/* tp_as_sequence */\n 0,\t\t\t\t\t/* tp_as_mapping */\n 0,\t\t\t\t\t/* tp_hash */\n 0,\t\t\t\t\t/* tp_call */\n 0,\t\t\t\t\t/* tp_str */\n 0, \t\t/* tp_getattro */\n 0,\t\t\t\t\t/* tp_setattro */\n 0,\t\t\t\t\t/* tp_as_buffer */\n Py_TPFLAGS_DEFAULT, /* tp_flags */\n 0,\t\t\t\t\t/* tp_doc */\n (traverseproc)0, \t /* tp_traverse */\n 0,\t\t\t\t\t/* tp_clear */\n 0,\t\t\t\t\t/* tp_richcompare */\n 0,\t\t\t\t\t/* tp_weaklistoffset */\n 0,\t\t \t /* tp_iter */\n (iternextfunc)0, \t /* tp_iternext */\n 0, \t /* tp_methods */\n 0,\t\t\t\t\t /* tp_members */\n 0,\t\t\t /* tp_getset */\n 0,\t\t\t\t\t /* tp_base */\n 0,\t\t\t\t\t /* tp_dict */\n 0,\t\t\t\t\t /* tp_descr_get */\n 0,\t\t\t\t\t /* tp_descr_set */\n 0,\t\t\t\t\t /* tp_dictoffset */\n (initproc)0,\t \t /* tp_init */\n 0, \t /* tp_alloc */\n 0,\t /* tp_new */\n 0,\t /* tp_free */\n 0,\t\t\t\t\t /* tp_is_gc */\n 0,\t\t\t\t\t /* tp_bases */\n 0,\t\t\t\t\t /* tp_mro */\n 0,\t\t\t\t\t /* tp_cache */\n 0,\t\t\t\t\t /* tp_subclasses */\n 0\t\t\t\t\t /* tp_weaklist */\n\n};\n\n/** END of Subscript Iterator **/\n\n\n/*OBJECT_API\n Get MultiIterator,\n*/\nstatic PyObject *\nPyArray_MultiIterNew(int n, ...)\n{\n va_list va;\n\tPyArrayMultiIterObject *multi;\n\tPyObject *current;\n\tPyObject *arr;\n\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 dtype objects can be set. \n*/\nstatic PyMemberDef arraydescr_members[] = {\n\t{\"type\", T_OBJECT, offsetof(PyArray_Descr, typeobj), RO, NULL},\n\t{\"kind\", T_CHAR, offsetof(PyArray_Descr, kind), RO, NULL},\n\t{\"char\", T_CHAR, offsetof(PyArray_Descr, type), RO, NULL},\n\t{\"num\", T_INT, offsetof(PyArray_Descr, type_num), RO, NULL},\n\t{\"byteorder\", T_CHAR, offsetof(PyArray_Descr, byteorder), RO, NULL},\n\t{\"itemsize\", T_INT, offsetof(PyArray_Descr, elsize), RO, NULL},\n\t{\"alignment\", T_INT, offsetof(PyArray_Descr, alignment), RO, NULL},\n {\"hasobject\", T_UBYTE, offsetof(PyArray_Descr, hasobject), RO, NULL},\n\t{NULL}, \n};\n\nstatic PyObject *\narraydescr_subdescr_get(PyArray_Descr *self)\n{\n\tif (self->subarray == NULL) {\n\t\tPy_INCREF(Py_None);\n\t\treturn Py_None;\n\t}\n\treturn Py_BuildValue(\"OO\", (PyObject *)self->subarray->base, \n\t\t\t self->subarray->shape);\n}\n\nstatic PyObject *\narraydescr_protocol_typestr_get(PyArray_Descr *self)\n{\n char basic_=self->kind;\n char endian = self->byteorder;\n\tint size=self->elsize;\n\n if (endian == '=') {\n endian = '<';\n if (!PyArray_IsNativeByteOrder(endian)) endian = '>';\n }\n \n\tif (self->type_num == PyArray_UNICODE) {\n\t\tsize >>= 2;\n\t}\n return PyString_FromFormat(\"%c%c%d\", endian, basic_, size);\n}\n\nstatic PyObject *\narraydescr_typename_get(PyArray_Descr *self)\n{\n int len;\n PyTypeObject *typeobj = self->typeobj;\n\tPyObject *res;\n\tstatic int suffix_len=0;\n\n\tif (PyTypeNum_ISUSERDEF(self->type_num)) {\n\t\tres = PyString_FromString(typeobj->tp_name);\n\t}\n\telse {\n\t\tif (suffix_len == 0) \n\t\t\tsuffix_len = strlen(\"scalar\");\n\t\tlen = strlen(typeobj->tp_name) - suffix_len;\n\t\tres = PyString_FromStringAndSize(typeobj->tp_name, len);\n\t}\n\tif (PyTypeNum_ISEXTENDED(self->type_num) && self->elsize != 0) {\n\t\tPyObject *p;\n\t\tp = PyString_FromFormat(\"%d\", self->elsize * 8);\n\t\tPyString_ConcatAndDel(&res, p);\n\t}\n\treturn res;\t\t\t\t\t\t \n}\n\nstatic PyObject *\narraydescr_base_get(PyArray_Descr *self)\n{\n\tif (self->subarray == NULL) {\n\t\tPy_INCREF(self);\n return (PyObject *)self;\n\t}\n Py_INCREF(self->subarray->base);\n return (PyObject *)(self->subarray->base);\n}\n\nstatic PyObject *\narraydescr_shape_get(PyArray_Descr *self)\n{\n\tif (self->subarray == NULL) {\n return Py_BuildValue(\"(N)\", PyInt_FromLong(1));\n\t}\n Py_INCREF(self->subarray->shape);\n return (PyObject *)(self->subarray->shape);\n}\n\nstatic PyObject *\narraydescr_protocol_descr_get(PyArray_Descr *self)\n{\n\tPyObject *dobj, *res;\n\n\tif (self->fields == NULL || self->fields == Py_None) {\n\t\t/* get default */\n\t\tdobj = PyTuple_New(2);\n\t\tif (dobj == NULL) return NULL;\n\t\tPyTuple_SET_ITEM(dobj, 0, PyString_FromString(\"\"));\n\t\tPyTuple_SET_ITEM(dobj, 1, \\\n\t\t\t\t arraydescr_protocol_typestr_get(self));\n\t\tres = PyList_New(1);\n\t\tif (res == NULL) {Py_DECREF(dobj); return NULL;}\n\t\tPyList_SET_ITEM(res, 0, dobj);\n\t\treturn res;\n\t}\n\n return PyObject_CallMethod(_numpy_internal, \"_array_descr\", \n\t\t\t\t \"O\", self);\n}\n\n/* returns 1 for a builtin type\n and 2 for a user-defined data-type descriptor\n return 0 if neither (i.e. it's a copy of one)\n*/\nstatic PyObject *\narraydescr_isbuiltin_get(PyArray_Descr *self) \n{\n\tlong val;\n\tval = 0;\n\tif (self->fields == Py_None) val = 1;\n\tif (PyTypeNum_ISUSERDEF(self->type_num)) val = 2;\n\treturn PyInt_FromLong(val);\n}\n\nstatic PyObject *\narraydescr_isnative_get(PyArray_Descr *self)\n{\n\tPyObject *ret;\n\n\tret = (PyArray_ISNBO(self->byteorder) ? Py_True : Py_False);\n\tPy_INCREF(ret);\n\treturn ret;\n}\n\nstatic PyObject *\narraydescr_fields_get(PyArray_Descr *self)\n{\n\tif (self->fields == NULL || self->fields == Py_None) {\n\t\tPy_INCREF(Py_None);\n\t\treturn Py_None;\n\t}\n\treturn PyDictProxy_New(self->fields);\n}\n\nstatic PyGetSetDef arraydescr_getsets[] = {\n\t{\"subdtype\", \n\t (getter)arraydescr_subdescr_get,\n\t NULL,\n\t \"A tuple of (descr, shape) or None.\"},\n\t{\"descr\",\n\t (getter)arraydescr_protocol_descr_get,\n\t NULL,\n\t \"The array_protocol type descriptor.\"},\n\t{\"str\",\n\t (getter)arraydescr_protocol_typestr_get,\n\t NULL,\n\t \"The array_protocol typestring.\"},\n {\"name\",\n (getter)arraydescr_typename_get,\n NULL,\n \"The name of the true data-type\"},\n\t{\"base\",\n\t (getter)arraydescr_base_get,\n\t NULL,\n\t \"The base data-type or self if no subdtype\"},\n {\"shape\",\n (getter)arraydescr_shape_get,\n NULL,\n \"The shape of the subdtype or (1,)\"},\n \t{\"isbuiltin\",\n\t (getter)arraydescr_isbuiltin_get,\n\t NULL,\n\t \"Is this a buillt-in data-type descriptor?\"},\n\t{\"isnative\",\n\t (getter)arraydescr_isnative_get,\n\t NULL,\n\t \"Is the byte-order of this descriptor native?\"},\n\t{\"fields\",\n\t (getter)arraydescr_fields_get,\n\t NULL,\n\t NULL},\n\t{NULL, NULL, NULL, NULL},\n};\n\nstatic PyArray_Descr *_convert_from_list(PyObject *obj, int align, int try_descr);\nstatic PyArray_Descr *_convert_from_dict(PyObject *obj, int align);\nstatic PyArray_Descr *_convert_from_commastring(PyObject *obj, int align);\nstatic PyArray_Descr *_convert_from_array_descr(PyObject *obj);\n\nstatic PyObject *\narraydescr_new(PyTypeObject *subtype, PyObject *args, PyObject *kwds)\n{\n\tPyObject *odescr;\n\tPyArray_Descr *descr, *conv;\n\tint align=0;\n\tBool copy=FALSE;\n\tstatic char *kwlist[] = {\"dtype\", \"align\", \"copy\", NULL};\n\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, \"dtype\");\n\tPy_DECREF(mod);\n\tif (obj == NULL) {Py_DECREF(ret); return NULL;}\n\tPyTuple_SET_ITEM(ret, 0, obj);\n\tif (PyTypeNum_ISUSERDEF(self->type_num) ||\t\t\\\n\t ((self->type_num == PyArray_VOID &&\t\t\t\\\n\t self->typeobj != &PyVoidArrType_Type))) {\n\t\tobj = (PyObject *)self->typeobj;\n\t\tPy_INCREF(obj);\n\t}\n\telse {\n\t\telsize = self->elsize;\n\t\tif (self->type_num == PyArray_UNICODE) {\n\t\t\telsize >>= 2;\n\t\t}\n\t\tobj = PyString_FromFormat(\"%c%d\",self->kind, elsize);\n\t}\n\tPyTuple_SET_ITEM(ret, 1, Py_BuildValue(\"(Nii)\", obj, 0, 1));\n\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 dtype object\\n\"\n\t\" with altered byteorders. If is not given all byteorders\\n\"\n\t\" are swapped. Otherwise endian can be '>', '<', or '=' to force\\n\"\n\t\" a byteorder. Descriptors in all fields are also updated in the\\n\"\n\t\" new dtype object.\";\n\nstatic PyObject *\narraydescr_newbyteorder(PyArray_Descr *self, PyObject *args) \n{\n\tchar endian=PyArray_SWAP;\n\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);\n\t\tif (self->type_num != PyArray_VOID) {\n\t\t\tPyObject *p;\n\t\t\tPyObject *t=PyString_FromString(\"'\");\n\t\t\tp = arraydescr_protocol_typestr_get(self);\n\t\t\tPyString_Concat(&p, t);\n\t\t\tPyString_ConcatAndDel(&t, p);\n\t\t\tp = PyString_FromString(\"(\");\n\t\t\tPyString_ConcatAndDel(&p, t);\n\t\t\tPyString_ConcatAndDel(&p, PyString_FromString(\", \"));\n\t\t\tPyString_ConcatAndDel(&p, sub);\n\t\t\tPyString_ConcatAndDel(&p, PyString_FromString(\")\"));\n\t\t\tsub = p;\n\t\t}\n\t}\n\telse if (self->subarray) {\n\t\tPyObject *p;\n\t\tPyObject *t = PyString_FromString(\"(\");\n\t\tp = arraydescr_str(self->subarray->base);\n\t\tPyString_ConcatAndDel(&t, p);\n\t\tPyString_ConcatAndDel(&t, PyString_FromString(\",\"));\n\t\tPyString_ConcatAndDel(&t, PyObject_Str(self->subarray->shape));\n\t\tPyString_ConcatAndDel(&t, PyString_FromString(\")\"));\n\t\tsub = t;\n\t}\n\telse {\n\t\tPyObject *t=PyString_FromString(\"'\");\n\t\tsub = arraydescr_protocol_typestr_get(self);\n\t\tPyString_Concat(&sub, t);\n\t\tPyString_ConcatAndDel(&t, sub);\n\t\tsub = t;\n\t}\n\treturn sub;\n}\n\nstatic PyObject *\narraydescr_repr(PyArray_Descr *self)\n{\n\tPyObject *sub, *s;\n\ts = PyString_FromString(\"dtype(\");\n sub = arraydescr_str(self);\n\tPyString_ConcatAndDel(&s, sub);\n\tsub = PyString_FromString(\")\");\n\tPyString_ConcatAndDel(&s, sub);\n\treturn s;\n}\n\nstatic int\narraydescr_compare(PyArray_Descr *self, PyObject *other)\n{\n \tif (!PyArray_DescrCheck(other)) {\n\t\tPyErr_SetString(PyExc_TypeError,\n\t\t\t\t\"not a dtype object.\");\n\t\treturn -1;\n\t}\n\tif (PyArray_EquivTypes(self, (PyArray_Descr *)other)) return 0;\n\tif (PyArray_CanCastTo(self, (PyArray_Descr *)other)) return -1;\n\treturn 1;\n}\n\n/*************************************************************************\n **************** Implement Mapping Protocol ***************************\n *************************************************************************/\n\nstatic int \ndescr_length(PyArray_Descr *self) \n{\n\n\tif (self->fields && self->fields != Py_None)\n\t\t/* Remove the last entry (root) */\n\t\treturn PyDict_Size(self->fields) - 1;\n\telse return 0;\n}\n\nstatic PyObject *\ndescr_subscript(PyArray_Descr *self, PyObject *op) \n{\n\n\tif (self->fields) {\n\t\tif (PyString_Check(op) || PyUnicode_Check(op)) {\n\t\t\tPyObject *obj;\n\t\t\tobj = PyDict_GetItem(self->fields, op);\n\t\t\tif (obj != NULL) {\n\t\t\t\tPyObject *descr;\n\t\t\t\tdescr = PyTuple_GET_ITEM(obj, 0);\n\t\t\t\tPy_INCREF(descr);\n\t\t\t\treturn descr;\n\t\t\t}\n\t\t\telse {\n\t\t\t\tPyErr_Format(PyExc_KeyError, \n\t\t\t\t\t \"field named \\'%s\\' not found.\",\n\t\t\t\t\t PyString_AsString(op));\n\t\t\t}\n\t\t}\n\t\telse {\n\t\t PyErr_SetString(PyExc_ValueError, \n\t\t\t\t \"only strings or unicode values allowed \" \\\n\t\t\t\t \"for getting fields.\");\n\t\t}\n\t}\n\telse {\n\t\tPyErr_Format(PyExc_KeyError, \n\t\t\t \"there are no fields in dtype %s.\",\n\t\t\t PyString_AsString(arraydescr_str(self)));\n\t}\n\n\treturn NULL;\n}\n\nstatic PyMappingMethods descr_as_mapping = {\n (inquiry)descr_length,\t\t /*mp_length*/\n (binaryfunc)descr_subscript,\t /*mp_subscript*/\n (objobjargproc)NULL,\t /*mp_ass_subscript*/\n};\n\n/****************** End of Mapping Protocol ******************************/\n\n\nstatic PyTypeObject PyArrayDescr_Type = {\n PyObject_HEAD_INIT(NULL)\n 0,\t\t\t\t\t /* ob_size */\n \"numpy.dtype\",\t\t \t /* tp_name */\n sizeof(PyArray_Descr), /* tp_basicsize */\n 0,\t\t\t\t\t /* tp_itemsize */\n /* methods */\n (destructor)arraydescr_dealloc,\t\t/* tp_dealloc */\n 0,\t\t\t\t\t/* tp_print */\n 0,\t\t\t\t\t/* tp_getattr */\n 0,\t\t\t\t\t/* tp_setattr */\n\t(cmpfunc)arraydescr_compare,\t\t/* tp_compare */\n (reprfunc)arraydescr_repr,\t /* tp_repr */\n 0,\t\t\t\t\t/* tp_as_number */\n 0, \t\t\t /* tp_as_sequence */\n &descr_as_mapping, \t /* tp_as_mapping */\n 0,\t\t\t\t\t/* tp_hash */\n 0,\t\t\t\t\t/* tp_call */\n (reprfunc)arraydescr_str, /* tp_str */\n 0,\t \t/* tp_getattro */\n 0,\t\t\t\t\t/* tp_setattro */\n 0,\t\t\t\t\t/* tp_as_buffer */\n Py_TPFLAGS_DEFAULT, /* tp_flags */\n 0,\t\t\t\t\t/* tp_doc */\n 0, \t /* tp_traverse */\n 0,\t\t\t\t\t/* tp_clear */\n 0,\t\t\t\t\t/* tp_richcompare */\n 0,\t\t\t\t\t/* tp_weaklistoffset */\n 0, \t /* tp_iter */\n 0,\t \t/* tp_iternext */\n arraydescr_methods,\t \t /* tp_methods */\n arraydescr_members,\t /* tp_members */\n arraydescr_getsets, /* tp_getset */\n 0,\t\t\t\t\t /* tp_base */\n 0,\t\t\t\t\t /* tp_dict */\n 0,\t\t\t\t\t /* tp_descr_get */\n 0,\t\t\t\t\t /* tp_descr_set */\n 0,\t\t\t\t\t /* tp_dictoffset */\n 0, \t \t /* tp_init */\n 0, \t /* tp_alloc */\n arraydescr_new,\t /* tp_new */\n 0,\t /* tp_free */\n 0,\t\t\t\t\t /* tp_is_gc */\n 0,\t\t\t\t\t /* tp_bases */\n 0,\t\t\t\t\t /* tp_mro */\n 0,\t\t\t\t\t /* tp_cache */\n 0,\t\t\t\t\t /* tp_subclasses */\n 0\t\t\t\t\t /* tp_weaklist */\n};\n", + "methods": [ + { + "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": 28, + "end_line": 46, + "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": 67, + "end_line": 95, + "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": 101, + "end_line": 130, + "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": 136, + "end_line": 186, + "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": 209, + "end_line": 240, + "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": 243, + "end_line": 277, + "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": 293, + "end_line": 315, + "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": 321, + "end_line": 342, + "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": 346, + "end_line": 384, + "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": 389, + "end_line": 409, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 21, + "top_nesting_level": 0 + }, + { + "name": "PyArray_PyIntAsIntp", + "long_name": "PyArray_PyIntAsIntp( PyObject * o)", + "filename": "arrayobject.c", + "nloc": 71, + "complexity": 21, + "token_count": 413, + "parameters": [ + "o" + ], + "start_line": 429, + "end_line": 511, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 83, + "top_nesting_level": 0 + }, + { + "name": "PyArray_PyIntAsInt", + "long_name": "PyArray_PyIntAsInt( PyObject * o)", + "filename": "arrayobject.c", + "nloc": 67, + "complexity": 19, + "token_count": 406, + "parameters": [ + "o" + ], + "start_line": 518, + "end_line": 592, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 75, + "top_nesting_level": 0 + }, + { + "name": "index2ptr", + "long_name": "index2ptr( PyArrayObject * mp , intp i)", + "filename": "arrayobject.c", + "nloc": 15, + "complexity": 7, + "token_count": 98, + "parameters": [ + "mp", + "i" + ], + "start_line": 595, + "end_line": 610, + "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": 616, + "end_line": 624, + "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": 640, + "end_line": 720, + "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": 81, + "parameters": [ + "dest", + "src_object" + ], + "start_line": 724, + "end_line": 738, + "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": 751, + "end_line": 777, + "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": 783, + "end_line": 797, + "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": 806, + "end_line": 826, + "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": 103, + "complexity": 17, + "token_count": 616, + "parameters": [ + "data", + "descr", + "base" + ], + "start_line": 835, + "end_line": 951, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 117, + "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": 967, + "end_line": 970, + "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": 980, + "end_line": 1002, + "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": 1016, + "end_line": 1056, + "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": 1071, + "end_line": 1112, + "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": 1119, + "end_line": 1210, + "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": 1216, + "end_line": 1245, + "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": 1248, + "end_line": 1284, + "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": 1293, + "end_line": 1330, + "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": 1337, + "end_line": 1345, + "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": 1348, + "end_line": 1373, + "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": 1376, + "end_line": 1379, + "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": 1383, + "end_line": 1418, + "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": 1424, + "end_line": 1427, + "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": 1433, + "end_line": 1441, + "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": 1447, + "end_line": 1497, + "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": 1504, + "end_line": 1549, + "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": 1553, + "end_line": 1647, + "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": 1650, + "end_line": 1687, + "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": 1699, + "end_line": 1752, + "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": 382, + "parameters": [ + "mit", + "op" + ], + "start_line": 1755, + "end_line": 1815, + "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": 1818, + "end_line": 1845, + "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": 1848, + "end_line": 1867, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 20, + "top_nesting_level": 0 + }, + { + "name": "fancy_indexing_check", + "long_name": "fancy_indexing_check( PyObject * args)", + "filename": "arrayobject.c", + "nloc": 56, + "complexity": 22, + "token_count": 295, + "parameters": [ + "args" + ], + "start_line": 1879, + "end_line": 1941, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 63, + "top_nesting_level": 0 + }, + { + "name": "array_subscript", + "long_name": "array_subscript( PyArrayObject * self , PyObject * op)", + "filename": "arrayobject.c", + "nloc": 103, + "complexity": 28, + "token_count": 666, + "parameters": [ + "self", + "op" + ], + "start_line": 1965, + "end_line": 2083, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 119, + "top_nesting_level": 0 + }, + { + "name": "array_ass_sub", + "long_name": "array_ass_sub( PyArrayObject * self , PyObject * index , PyObject * op)", + "filename": "arrayobject.c", + "nloc": 93, + "complexity": 28, + "token_count": 588, + "parameters": [ + "self", + "index", + "op" + ], + "start_line": 2098, + "end_line": 2203, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 106, + "top_nesting_level": 0 + }, + { + "name": "array_subscript_nice", + "long_name": "array_subscript_nice( PyArrayObject * self , PyObject * op)", + "filename": "arrayobject.c", + "nloc": 4, + "complexity": 1, + "token_count": 27, + "parameters": [ + "self", + "op" + ], + "start_line": 2212, + "end_line": 2215, + "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": 2234, + "end_line": 2246, + "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": 2249, + "end_line": 2264, + "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": 2268, + "end_line": 2277, + "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": 2280, + "end_line": 2291, + "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": 2362, + "end_line": 2395, + "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": 2405, + "end_line": 2444, + "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": 2447, + "end_line": 2470, + "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": 2474, + "end_line": 2497, + "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": 2501, + "end_line": 2508, + "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": 2511, + "end_line": 2518, + "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": 2521, + "end_line": 2529, + "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": 2532, + "end_line": 2535, + "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": 2538, + "end_line": 2541, + "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": 2544, + "end_line": 2547, + "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": 2550, + "end_line": 2553, + "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": 2556, + "end_line": 2559, + "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": 2562, + "end_line": 2565, + "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": 2568, + "end_line": 2571, + "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": 2574, + "end_line": 2577, + "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": 2580, + "end_line": 2583, + "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": 2586, + "end_line": 2589, + "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": 2592, + "end_line": 2595, + "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": 2598, + "end_line": 2601, + "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": 2604, + "end_line": 2607, + "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": 2610, + "end_line": 2613, + "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": 2616, + "end_line": 2619, + "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": 2622, + "end_line": 2625, + "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": 2628, + "end_line": 2631, + "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": 2634, + "end_line": 2637, + "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": 2640, + "end_line": 2643, + "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": 2646, + "end_line": 2649, + "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": 2652, + "end_line": 2655, + "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": 2658, + "end_line": 2661, + "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": 2664, + "end_line": 2667, + "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": 2670, + "end_line": 2673, + "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": 2676, + "end_line": 2679, + "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": 2682, + "end_line": 2685, + "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": 2688, + "end_line": 2691, + "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": 2694, + "end_line": 2698, + "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": 2701, + "end_line": 2705, + "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": 2709, + "end_line": 2727, + "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": 2730, + "end_line": 2747, + "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": 2752, + "end_line": 2767, + "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": 2771, + "end_line": 2797, + "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": 2800, + "end_line": 2825, + "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": 2828, + "end_line": 2850, + "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": 2853, + "end_line": 2875, + "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": 2878, + "end_line": 2900, + "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": 2903, + "end_line": 2907, + "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": 2968, + "end_line": 3008, + "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": 3012, + "end_line": 3033, + "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": 3036, + "end_line": 3048, + "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": 3069, + "end_line": 3116, + "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": 3119, + "end_line": 3155, + "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": 3164, + "end_line": 3181, + "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": 3184, + "end_line": 3196, + "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": 3199, + "end_line": 3211, + "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": 81, + "complexity": 17, + "token_count": 357, + "parameters": [ + "self", + "other", + "cmp_op" + ], + "start_line": 3214, + "end_line": 3311, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 98, + "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": 171, + "parameters": [ + "arr", + "axis", + "flags" + ], + "start_line": 3314, + "end_line": 3343, + "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": 3349, + "end_line": 3369, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 21, + "top_nesting_level": 0 + }, + { + "name": "PyArray_IntpFromSequence", + "long_name": "PyArray_IntpFromSequence( PyObject * seq , intp * vals , int maxvals)", + "filename": "arrayobject.c", + "nloc": 24, + "complexity": 11, + "token_count": 203, + "parameters": [ + "seq", + "vals", + "maxvals" + ], + "start_line": 3377, + "end_line": 3412, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 36, + "top_nesting_level": 0 + }, + { + "name": "_IsContiguous", + "long_name": "_IsContiguous( PyArrayObject * ap)", + "filename": "arrayobject.c", + "nloc": 17, + "complexity": 7, + "token_count": 128, + "parameters": [ + "ap" + ], + "start_line": 3418, + "end_line": 3437, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 20, + "top_nesting_level": 0 + }, + { + "name": "_IsFortranContiguous", + "long_name": "_IsFortranContiguous( PyArrayObject * ap)", + "filename": "arrayobject.c", + "nloc": 17, + "complexity": 7, + "token_count": 126, + "parameters": [ + "ap" + ], + "start_line": 3441, + "end_line": 3459, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 19, + "top_nesting_level": 0 + }, + { + "name": "_IsAligned", + "long_name": "_IsAligned( PyArrayObject * ap)", + "filename": "arrayobject.c", + "nloc": 15, + "complexity": 5, + "token_count": 119, + "parameters": [ + "ap" + ], + "start_line": 3462, + "end_line": 3479, + "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": 3482, + "end_line": 3515, + "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": 3522, + "end_line": 3549, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 28, + "top_nesting_level": 0 + }, + { + "name": "PyArray_CheckStrides", + "long_name": "PyArray_CheckStrides( int elsize , int nd , intp numbytes , intp offset , intp * dims , intp * newstrides)", + "filename": "arrayobject.c", + "nloc": 23, + "complexity": 7, + "token_count": 135, + "parameters": [ + "elsize", + "nd", + "numbytes", + "offset", + "dims", + "newstrides" + ], + "start_line": 3563, + "end_line": 3598, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 36, + "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": 3618, + "end_line": 3642, + "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": 3648, + "end_line": 3670, + "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": 3674, + "end_line": 3716, + "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": 136, + "complexity": 27, + "token_count": 781, + "parameters": [ + "subtype", + "descr", + "nd", + "dims", + "strides", + "data", + "flags", + "obj" + ], + "start_line": 3724, + "end_line": 3889, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 166, + "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": 3898, + "end_line": 3996, + "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": 4002, + "end_line": 4019, + "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": 231, + "parameters": [ + "arr", + "obj" + ], + "start_line": 4023, + "end_line": 4065, + "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": 19, + "token_count": 577, + "parameters": [ + "subtype", + "args", + "kwds" + ], + "start_line": 4068, + "end_line": 4185, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 118, + "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": 4189, + "end_line": 4197, + "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": 4203, + "end_line": 4206, + "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": 4209, + "end_line": 4213, + "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": 4216, + "end_line": 4219, + "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": 4223, + "end_line": 4252, + "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": 4256, + "end_line": 4259, + "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": 37, + "complexity": 7, + "token_count": 239, + "parameters": [ + "self", + "obj" + ], + "start_line": 4262, + "end_line": 4301, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 40, + "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": 4305, + "end_line": 4312, + "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": 4315, + "end_line": 4323, + "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": 4327, + "end_line": 4333, + "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": 4336, + "end_line": 4350, + "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": 4353, + "end_line": 4397, + "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": 4401, + "end_line": 4404, + "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": 4407, + "end_line": 4418, + "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": 4421, + "end_line": 4432, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 12, + "top_nesting_level": 0 + }, + { + "name": "array_typestr_get", + "long_name": "array_typestr_get( PyArrayObject * self)", + "filename": "arrayobject.c", + "nloc": 4, + "complexity": 1, + "token_count": 16, + "parameters": [ + "self" + ], + "start_line": 4438, + "end_line": 4441, + "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": 4444, + "end_line": 4448, + "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": 62, + "complexity": 15, + "token_count": 438, + "parameters": [ + "self", + "arg" + ], + "start_line": 4462, + "end_line": 4548, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 87, + "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": 4551, + "end_line": 4569, + "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": 4572, + "end_line": 4590, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 19, + "top_nesting_level": 0 + }, + { + "name": "array_base_get", + "long_name": "array_base_get( PyArrayObject * self)", + "filename": "arrayobject.c", + "nloc": 11, + "complexity": 2, + "token_count": 41, + "parameters": [ + "self" + ], + "start_line": 4593, + "end_line": 4603, + "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": 4607, + "end_line": 4632, + "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": 191, + "parameters": [ + "self", + "val" + ], + "start_line": 4636, + "end_line": 4669, + "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": 4672, + "end_line": 4705, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 34, + "top_nesting_level": 0 + }, + { + "name": "array_imag_set", + "long_name": "array_imag_set( PyArrayObject * self , PyObject * val)", + "filename": "arrayobject.c", + "nloc": 37, + "complexity": 4, + "token_count": 207, + "parameters": [ + "self", + "val" + ], + "start_line": 4708, + "end_line": 4745, + "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": 4748, + "end_line": 4751, + "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": 348, + "parameters": [ + "self", + "val" + ], + "start_line": 4754, + "end_line": 4804, + "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": 4894, + "end_line": 4901, + "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": 5003, + "end_line": 5036, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 34, + "top_nesting_level": 0 + }, + { + "name": "discover_itemsize", + "long_name": "discover_itemsize( PyObject * s , int nd , int * itemsize)", + "filename": "arrayobject.c", + "nloc": 21, + "complexity": 9, + "token_count": 158, + "parameters": [ + "s", + "nd", + "itemsize" + ], + "start_line": 5039, + "end_line": 5061, + "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": 5068, + "end_line": 5094, + "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": 5100, + "end_line": 5132, + "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": 128, + "complexity": 34, + "token_count": 742, + "parameters": [ + "op", + "minitype", + "max" + ], + "start_line": 5144, + "end_line": 5292, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 149, + "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": 5295, + "end_line": 5318, + "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": 29, + "complexity": 7, + "token_count": 168, + "parameters": [ + "op", + "typecode" + ], + "start_line": 5323, + "end_line": 5357, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 35, + "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": 54, + "complexity": 21, + "token_count": 352, + "parameters": [ + "s", + "typecode", + "fortran", + "min_depth", + "max_depth" + ], + "start_line": 5362, + "end_line": 5425, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 64, + "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": 5432, + "end_line": 5441, + "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": 5447, + "end_line": 5540, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 94, + "top_nesting_level": 0 + }, + { + "name": "PyArray_CastToType", + "long_name": "PyArray_CastToType( PyArrayObject * mp , PyArray_Descr * at , int fortran)", + "filename": "arrayobject.c", + "nloc": 40, + "complexity": 16, + "token_count": 276, + "parameters": [ + "mp", + "at", + "fortran" + ], + "start_line": 5550, + "end_line": 5596, + "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": 5606, + "end_line": 5659, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 54, + "top_nesting_level": 0 + }, + { + "name": "PyArray_FromArray", + "long_name": "PyArray_FromArray( PyArrayObject * arr , PyArray_Descr * newtype , int flags)", + "filename": "arrayobject.c", + "nloc": 114, + "complexity": 33, + "token_count": 676, + "parameters": [ + "arr", + "newtype", + "flags" + ], + "start_line": 5664, + "end_line": 5793, + "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": 501, + "parameters": [ + "str" + ], + "start_line": 5797, + "end_line": 5905, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 109, + "top_nesting_level": 0 + }, + { + "name": "PyArray_FromStructInterface", + "long_name": "PyArray_FromStructInterface( PyObject * input)", + "filename": "arrayobject.c", + "nloc": 38, + "complexity": 6, + "token_count": 234, + "parameters": [ + "input" + ], + "start_line": 5909, + "end_line": 5949, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 41, + "top_nesting_level": 0 + }, + { + "name": "PyArray_FromInterface", + "long_name": "PyArray_FromInterface( PyObject * input)", + "filename": "arrayobject.c", + "nloc": 129, + "complexity": 28, + "token_count": 793, + "parameters": [ + "input" + ], + "start_line": 5953, + "end_line": 6091, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 139, + "top_nesting_level": 0 + }, + { + "name": "PyArray_FromArrayAttr", + "long_name": "PyArray_FromArrayAttr( PyObject * op , PyArray_Descr * typecode , PyObject * context)", + "filename": "arrayobject.c", + "nloc": 37, + "complexity": 11, + "token_count": 221, + "parameters": [ + "op", + "typecode", + "context" + ], + "start_line": 6095, + "end_line": 6132, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 38, + "top_nesting_level": 0 + }, + { + "name": "PyArray_FromAny", + "long_name": "PyArray_FromAny( PyObject * op , PyArray_Descr * newtype , int min_depth , int max_depth , int flags , PyObject * context)", + "filename": "arrayobject.c", + "nloc": 63, + "complexity": 20, + "token_count": 383, + "parameters": [ + "op", + "newtype", + "min_depth", + "max_depth", + "flags", + "context" + ], + "start_line": 6138, + "end_line": 6218, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 81, + "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": 6223, + "end_line": 6226, + "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": 6233, + "end_line": 6246, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 14, + "top_nesting_level": 0 + }, + { + "name": "PyArray_CheckFromAny", + "long_name": "PyArray_CheckFromAny( PyObject * op , PyArray_Descr * descr , int min_depth , int max_depth , int requires , PyObject * context)", + "filename": "arrayobject.c", + "nloc": 16, + "complexity": 7, + "token_count": 111, + "parameters": [ + "op", + "descr", + "min_depth", + "max_depth", + "requires", + "context" + ], + "start_line": 6292, + "end_line": 6308, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 17, + "top_nesting_level": 0 + }, + { + "name": "PyArray_EnsureArray", + "long_name": "PyArray_EnsureArray( PyObject * op)", + "filename": "arrayobject.c", + "nloc": 14, + "complexity": 5, + "token_count": 89, + "parameters": [ + "op" + ], + "start_line": 6321, + "end_line": 6337, + "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": 6343, + "end_line": 6431, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 89, + "top_nesting_level": 0 + }, + { + "name": "PyArray_CanCastTo", + "long_name": "PyArray_CanCastTo( PyArray_Descr * from , PyArray_Descr * to)", + "filename": "arrayobject.c", + "nloc": 24, + "complexity": 7, + "token_count": 132, + "parameters": [ + "from", + "to" + ], + "start_line": 6436, + "end_line": 6464, + "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": 6477, + "end_line": 6515, + "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": 6523, + "end_line": 6540, + "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": 6545, + "end_line": 6555, + "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": 6558, + "end_line": 6562, + "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": 6565, + "end_line": 6568, + "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": 6572, + "end_line": 6622, + "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": 6625, + "end_line": 6679, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 55, + "top_nesting_level": 0 + }, + { + "name": "iter_subscript", + "long_name": "iter_subscript( PyArrayIterObject * self , PyObject * ind)", + "filename": "arrayobject.c", + "nloc": 113, + "complexity": 23, + "token_count": 668, + "parameters": [ + "self", + "ind" + ], + "start_line": 6683, + "end_line": 6816, + "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": 6820, + "end_line": 6852, + "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": 6855, + "end_line": 6897, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 43, + "top_nesting_level": 0 + }, + { + "name": "iter_ass_subscript", + "long_name": "iter_ass_subscript( PyArrayIterObject * self , PyObject * ind , PyObject * val)", + "filename": "arrayobject.c", + "nloc": 115, + "complexity": 27, + "token_count": 698, + "parameters": [ + "self", + "ind", + "val" + ], + "start_line": 6900, + "end_line": 7034, + "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": 7047, + "end_line": 7092, + "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": 7097, + "end_line": 7101, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 5, + "top_nesting_level": 0 + }, + { + "name": "iter_coords_get", + "long_name": "iter_coords_get( PyArrayIterObject * self)", + "filename": "arrayobject.c", + "nloc": 15, + "complexity": 3, + "token_count": 91, + "parameters": [ + "self" + ], + "start_line": 7117, + "end_line": 7132, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 16, + "top_nesting_level": 0 + }, + { + "name": "_convert_obj", + "long_name": "_convert_obj( PyObject * obj , PyArrayIterObject ** iter)", + "filename": "arrayobject.c", + "nloc": 16, + "complexity": 5, + "token_count": 106, + "parameters": [ + "obj", + "iter" + ], + "start_line": 7197, + "end_line": 7213, + "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": 7220, + "end_line": 7289, + "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": 7293, + "end_line": 7330, + "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": 7336, + "end_line": 7380, + "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": 98, + "complexity": 21, + "token_count": 662, + "parameters": [ + "mit", + "arr" + ], + "start_line": 7398, + "end_line": 7526, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 129, + "top_nesting_level": 0 + }, + { + "name": "_nonzero_indices", + "long_name": "_nonzero_indices( PyObject * myBool , PyArrayIterObject ** iters)", + "filename": "arrayobject.c", + "nloc": 60, + "complexity": 15, + "token_count": 462, + "parameters": [ + "myBool", + "iters" + ], + "start_line": 7532, + "end_line": 7604, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 73, + "top_nesting_level": 0 + }, + { + "name": "PyArray_MapIterNew", + "long_name": "PyArray_MapIterNew( PyObject * indexobj , int oned , int fancy)", + "filename": "arrayobject.c", + "nloc": 104, + "complexity": 24, + "token_count": 726, + "parameters": [ + "indexobj", + "oned", + "fancy" + ], + "start_line": 7607, + "end_line": 7733, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 127, + "top_nesting_level": 0 + }, + { + "name": "arraymapiter_dealloc", + "long_name": "arraymapiter_dealloc( PyArrayMapIterObject * mit)", + "filename": "arrayobject.c", + "nloc": 10, + "complexity": 2, + "token_count": 62, + "parameters": [ + "mit" + ], + "start_line": 7737, + "end_line": 7746, + "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": 7817, + "end_line": 7866, + "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": 267, + "parameters": [ + "subtype", + "args", + "kwds" + ], + "start_line": 7869, + "end_line": 7914, + "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": 7917, + "end_line": 7936, + "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": 7939, + "end_line": 7946, + "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": 7949, + "end_line": 7959, + "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": 7962, + "end_line": 7972, + "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": 7975, + "end_line": 7978, + "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": 7981, + "end_line": 7993, + "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": 8023, + "end_line": 8030, + "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": 8089, + "end_line": 8098, + "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": 8116, + "end_line": 8138, + "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": 8144, + "end_line": 8154, + "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": 8173, + "end_line": 8181, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 9, + "top_nesting_level": 0 + }, + { + "name": "arraydescr_protocol_typestr_get", + "long_name": "arraydescr_protocol_typestr_get( PyArray_Descr * self)", + "filename": "arrayobject.c", + "nloc": 14, + "complexity": 4, + "token_count": 79, + "parameters": [ + "self" + ], + "start_line": 8184, + "end_line": 8199, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 16, + "top_nesting_level": 0 + }, + { + "name": "arraydescr_typename_get", + "long_name": "arraydescr_typename_get( PyArray_Descr * self)", + "filename": "arrayobject.c", + "nloc": 22, + "complexity": 5, + "token_count": 132, + "parameters": [ + "self" + ], + "start_line": 8202, + "end_line": 8224, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 23, + "top_nesting_level": 0 + }, + { + "name": "arraydescr_base_get", + "long_name": "arraydescr_base_get( PyArray_Descr * self)", + "filename": "arrayobject.c", + "nloc": 9, + "complexity": 2, + "token_count": 52, + "parameters": [ + "self" + ], + "start_line": 8227, + "end_line": 8235, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 9, + "top_nesting_level": 0 + }, + { + "name": "arraydescr_shape_get", + "long_name": "arraydescr_shape_get( PyArray_Descr * self)", + "filename": "arrayobject.c", + "nloc": 8, + "complexity": 2, + "token_count": 51, + "parameters": [ + "self" + ], + "start_line": 8238, + "end_line": 8245, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 8, + "top_nesting_level": 0 + }, + { + "name": "arraydescr_protocol_descr_get", + "long_name": "arraydescr_protocol_descr_get( PyArray_Descr * self)", + "filename": "arrayobject.c", + "nloc": 17, + "complexity": 5, + "token_count": 119, + "parameters": [ + "self" + ], + "start_line": 8248, + "end_line": 8267, + "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": 8274, + "end_line": 8281, + "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": 8284, + "end_line": 8291, + "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": 8294, + "end_line": 8301, + "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": 8349, + "end_line": 8401, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 53, + "top_nesting_level": 0 + }, + { + "name": "arraydescr_reduce", + "long_name": "arraydescr_reduce( PyArray_Descr * self , PyObject * args)", + "filename": "arrayobject.c", + "nloc": 54, + "complexity": 13, + "token_count": 395, + "parameters": [ + "self", + "args" + ], + "start_line": 8407, + "end_line": 8468, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 62, + "top_nesting_level": 0 + }, + { + "name": "arraydescr_setstate", + "long_name": "arraydescr_setstate( PyArray_Descr * self , PyObject * args)", + "filename": "arrayobject.c", + "nloc": 35, + "complexity": 8, + "token_count": 260, + "parameters": [ + "self", + "args" + ], + "start_line": 8476, + "end_line": 8518, + "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": 8538, + "end_line": 8604, + "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": 8615, + "end_line": 8623, + "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": 8638, + "end_line": 8683, + "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": 8686, + "end_line": 8695, + "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": 8698, + "end_line": 8708, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 11, + "top_nesting_level": 0 + }, + { + "name": "descr_length", + "long_name": "descr_length( PyArray_Descr * self)", + "filename": "arrayobject.c", + "nloc": 6, + "complexity": 3, + "token_count": 34, + "parameters": [ + "self" + ], + "start_line": 8715, + "end_line": 8722, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 8, + "top_nesting_level": 0 + }, + { + "name": "descr_subscript", + "long_name": "descr_subscript( PyArray_Descr * self , PyObject * op)", + "filename": "arrayobject.c", + "nloc": 31, + "complexity": 5, + "token_count": 126, + "parameters": [ + "self", + "op" + ], + "start_line": 8725, + "end_line": 8757, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 33, + "top_nesting_level": 0 + } + ], + "methods_before": [ + { + "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": 28, + "end_line": 46, + "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": 67, + "end_line": 95, + "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": 101, + "end_line": 130, + "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": 136, + "end_line": 186, + "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": 209, + "end_line": 240, + "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": 243, + "end_line": 277, + "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": 293, + "end_line": 315, + "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": 321, + "end_line": 342, + "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": 346, + "end_line": 384, + "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": 389, + "end_line": 409, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 21, + "top_nesting_level": 0 + }, + { + "name": "PyArray_PyIntAsIntp", + "long_name": "PyArray_PyIntAsIntp( PyObject * o)", + "filename": "arrayobject.c", + "nloc": 71, + "complexity": 21, + "token_count": 413, + "parameters": [ + "o" + ], + "start_line": 429, + "end_line": 511, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 83, + "top_nesting_level": 0 + }, + { + "name": "PyArray_PyIntAsInt", + "long_name": "PyArray_PyIntAsInt( PyObject * o)", + "filename": "arrayobject.c", + "nloc": 67, + "complexity": 19, + "token_count": 406, + "parameters": [ + "o" + ], + "start_line": 518, + "end_line": 592, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 75, + "top_nesting_level": 0 + }, + { + "name": "index2ptr", + "long_name": "index2ptr( PyArrayObject * mp , intp i)", + "filename": "arrayobject.c", + "nloc": 15, + "complexity": 7, + "token_count": 98, + "parameters": [ + "mp", + "i" + ], + "start_line": 595, + "end_line": 610, + "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": 616, + "end_line": 624, + "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": 640, + "end_line": 720, + "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": 81, + "parameters": [ + "dest", + "src_object" + ], + "start_line": 724, + "end_line": 738, + "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": 751, + "end_line": 777, + "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": 783, + "end_line": 797, + "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": 806, + "end_line": 826, + "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": 92, + "complexity": 14, + "token_count": 554, + "parameters": [ + "data", + "descr", + "base" + ], + "start_line": 835, + "end_line": 940, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 106, + "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": 956, + "end_line": 959, + "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": 969, + "end_line": 991, + "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": 1005, + "end_line": 1045, + "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": 1060, + "end_line": 1101, + "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": 1108, + "end_line": 1199, + "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": 1205, + "end_line": 1234, + "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": 1237, + "end_line": 1273, + "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": 1282, + "end_line": 1319, + "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": 1326, + "end_line": 1334, + "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": 1337, + "end_line": 1362, + "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": 1365, + "end_line": 1368, + "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": 1372, + "end_line": 1407, + "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": 1413, + "end_line": 1416, + "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": 1422, + "end_line": 1430, + "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": 1436, + "end_line": 1486, + "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": 1493, + "end_line": 1538, + "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": 1542, + "end_line": 1636, + "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": 1639, + "end_line": 1676, + "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": 1688, + "end_line": 1741, + "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": 382, + "parameters": [ + "mit", + "op" + ], + "start_line": 1744, + "end_line": 1804, + "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": 1807, + "end_line": 1834, + "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": 1837, + "end_line": 1856, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 20, + "top_nesting_level": 0 + }, + { + "name": "fancy_indexing_check", + "long_name": "fancy_indexing_check( PyObject * args)", + "filename": "arrayobject.c", + "nloc": 56, + "complexity": 22, + "token_count": 295, + "parameters": [ + "args" + ], + "start_line": 1868, + "end_line": 1930, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 63, + "top_nesting_level": 0 + }, + { + "name": "array_subscript", + "long_name": "array_subscript( PyArrayObject * self , PyObject * op)", + "filename": "arrayobject.c", + "nloc": 103, + "complexity": 28, + "token_count": 666, + "parameters": [ + "self", + "op" + ], + "start_line": 1954, + "end_line": 2072, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 119, + "top_nesting_level": 0 + }, + { + "name": "array_ass_sub", + "long_name": "array_ass_sub( PyArrayObject * self , PyObject * index , PyObject * op)", + "filename": "arrayobject.c", + "nloc": 93, + "complexity": 28, + "token_count": 588, + "parameters": [ + "self", + "index", + "op" + ], + "start_line": 2087, + "end_line": 2192, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 106, + "top_nesting_level": 0 + }, + { + "name": "array_subscript_nice", + "long_name": "array_subscript_nice( PyArrayObject * self , PyObject * op)", + "filename": "arrayobject.c", + "nloc": 4, + "complexity": 1, + "token_count": 27, + "parameters": [ + "self", + "op" + ], + "start_line": 2201, + "end_line": 2204, + "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": 2223, + "end_line": 2235, + "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": 2238, + "end_line": 2253, + "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": 2257, + "end_line": 2266, + "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": 2269, + "end_line": 2280, + "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": 2351, + "end_line": 2384, + "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": 2394, + "end_line": 2433, + "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": 2436, + "end_line": 2459, + "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": 2463, + "end_line": 2486, + "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": 2490, + "end_line": 2497, + "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": 2500, + "end_line": 2507, + "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": 2510, + "end_line": 2518, + "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": 2521, + "end_line": 2524, + "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": 2527, + "end_line": 2530, + "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": 2533, + "end_line": 2536, + "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": 2539, + "end_line": 2542, + "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": 2545, + "end_line": 2548, + "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": 2551, + "end_line": 2554, + "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": 2557, + "end_line": 2560, + "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": 2563, + "end_line": 2566, + "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": 2569, + "end_line": 2572, + "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": 2575, + "end_line": 2578, + "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": 2581, + "end_line": 2584, + "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": 2587, + "end_line": 2590, + "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": 2593, + "end_line": 2596, + "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": 2599, + "end_line": 2602, + "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": 2605, + "end_line": 2608, + "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": 2611, + "end_line": 2614, + "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": 2617, + "end_line": 2620, + "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": 2623, + "end_line": 2626, + "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": 2629, + "end_line": 2632, + "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": 2635, + "end_line": 2638, + "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": 2641, + "end_line": 2644, + "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": 2647, + "end_line": 2650, + "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": 2653, + "end_line": 2656, + "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": 2659, + "end_line": 2662, + "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": 2665, + "end_line": 2668, + "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": 2671, + "end_line": 2674, + "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": 2677, + "end_line": 2680, + "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": 2683, + "end_line": 2687, + "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": 2690, + "end_line": 2694, + "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": 2698, + "end_line": 2716, + "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": 2719, + "end_line": 2736, + "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": 2741, + "end_line": 2756, + "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": 2760, + "end_line": 2786, + "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": 2789, + "end_line": 2814, + "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": 2817, + "end_line": 2839, + "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": 2842, + "end_line": 2864, + "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": 2867, + "end_line": 2889, + "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": 2892, + "end_line": 2896, + "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": 2957, + "end_line": 2997, + "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": 3001, + "end_line": 3022, + "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": 3025, + "end_line": 3037, + "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": 3058, + "end_line": 3105, + "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": 3108, + "end_line": 3144, + "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": 3153, + "end_line": 3170, + "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": 3173, + "end_line": 3185, + "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": 3188, + "end_line": 3200, + "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": 81, + "complexity": 17, + "token_count": 357, + "parameters": [ + "self", + "other", + "cmp_op" + ], + "start_line": 3203, + "end_line": 3300, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 98, + "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": 171, + "parameters": [ + "arr", + "axis", + "flags" + ], + "start_line": 3303, + "end_line": 3332, + "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": 3338, + "end_line": 3358, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 21, + "top_nesting_level": 0 + }, + { + "name": "PyArray_IntpFromSequence", + "long_name": "PyArray_IntpFromSequence( PyObject * seq , intp * vals , int maxvals)", + "filename": "arrayobject.c", + "nloc": 24, + "complexity": 11, + "token_count": 203, + "parameters": [ + "seq", + "vals", + "maxvals" + ], + "start_line": 3366, + "end_line": 3401, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 36, + "top_nesting_level": 0 + }, + { + "name": "_IsContiguous", + "long_name": "_IsContiguous( PyArrayObject * ap)", + "filename": "arrayobject.c", + "nloc": 17, + "complexity": 7, + "token_count": 128, + "parameters": [ + "ap" + ], + "start_line": 3407, + "end_line": 3426, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 20, + "top_nesting_level": 0 + }, + { + "name": "_IsFortranContiguous", + "long_name": "_IsFortranContiguous( PyArrayObject * ap)", + "filename": "arrayobject.c", + "nloc": 17, + "complexity": 7, + "token_count": 126, + "parameters": [ + "ap" + ], + "start_line": 3430, + "end_line": 3448, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 19, + "top_nesting_level": 0 + }, + { + "name": "_IsAligned", + "long_name": "_IsAligned( PyArrayObject * ap)", + "filename": "arrayobject.c", + "nloc": 15, + "complexity": 5, + "token_count": 119, + "parameters": [ + "ap" + ], + "start_line": 3451, + "end_line": 3468, + "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": 3471, + "end_line": 3504, + "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": 3511, + "end_line": 3538, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 28, + "top_nesting_level": 0 + }, + { + "name": "PyArray_CheckStrides", + "long_name": "PyArray_CheckStrides( int elsize , int nd , intp numbytes , intp offset , intp * dims , intp * newstrides)", + "filename": "arrayobject.c", + "nloc": 23, + "complexity": 7, + "token_count": 135, + "parameters": [ + "elsize", + "nd", + "numbytes", + "offset", + "dims", + "newstrides" + ], + "start_line": 3552, + "end_line": 3587, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 36, + "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": 3607, + "end_line": 3631, + "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": 3637, + "end_line": 3659, + "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": 3663, + "end_line": 3705, + "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": 136, + "complexity": 27, + "token_count": 781, + "parameters": [ + "subtype", + "descr", + "nd", + "dims", + "strides", + "data", + "flags", + "obj" + ], + "start_line": 3713, + "end_line": 3878, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 166, + "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": 3887, + "end_line": 3985, + "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": 3991, + "end_line": 4008, + "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": 231, + "parameters": [ + "arr", + "obj" + ], + "start_line": 4012, + "end_line": 4054, + "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": 19, + "token_count": 577, + "parameters": [ + "subtype", + "args", + "kwds" + ], + "start_line": 4057, + "end_line": 4174, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 118, + "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": 4178, + "end_line": 4186, + "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": 4192, + "end_line": 4195, + "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": 4198, + "end_line": 4202, + "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": 4205, + "end_line": 4208, + "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": 4212, + "end_line": 4241, + "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": 4245, + "end_line": 4248, + "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": 37, + "complexity": 7, + "token_count": 239, + "parameters": [ + "self", + "obj" + ], + "start_line": 4251, + "end_line": 4290, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 40, + "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": 4294, + "end_line": 4301, + "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": 4304, + "end_line": 4312, + "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": 4316, + "end_line": 4322, + "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": 4325, + "end_line": 4339, + "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": 4342, + "end_line": 4386, + "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": 4390, + "end_line": 4393, + "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": 4396, + "end_line": 4407, + "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": 4410, + "end_line": 4421, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 12, + "top_nesting_level": 0 + }, + { + "name": "array_typestr_get", + "long_name": "array_typestr_get( PyArrayObject * self)", + "filename": "arrayobject.c", + "nloc": 4, + "complexity": 1, + "token_count": 16, + "parameters": [ + "self" + ], + "start_line": 4427, + "end_line": 4430, + "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": 4433, + "end_line": 4437, + "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": 62, + "complexity": 15, + "token_count": 438, + "parameters": [ + "self", + "arg" + ], + "start_line": 4451, + "end_line": 4537, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 87, + "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": 4540, + "end_line": 4558, + "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": 4561, + "end_line": 4579, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 19, + "top_nesting_level": 0 + }, + { + "name": "array_base_get", + "long_name": "array_base_get( PyArrayObject * self)", + "filename": "arrayobject.c", + "nloc": 11, + "complexity": 2, + "token_count": 41, + "parameters": [ + "self" + ], + "start_line": 4582, + "end_line": 4592, + "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": 4596, + "end_line": 4621, + "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": 191, + "parameters": [ + "self", + "val" + ], + "start_line": 4625, + "end_line": 4658, + "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": 4661, + "end_line": 4694, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 34, + "top_nesting_level": 0 + }, + { + "name": "array_imag_set", + "long_name": "array_imag_set( PyArrayObject * self , PyObject * val)", + "filename": "arrayobject.c", + "nloc": 37, + "complexity": 4, + "token_count": 207, + "parameters": [ + "self", + "val" + ], + "start_line": 4697, + "end_line": 4734, + "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": 4737, + "end_line": 4740, + "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": 348, + "parameters": [ + "self", + "val" + ], + "start_line": 4743, + "end_line": 4793, + "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": 4883, + "end_line": 4890, + "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": 4992, + "end_line": 5025, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 34, + "top_nesting_level": 0 + }, + { + "name": "discover_itemsize", + "long_name": "discover_itemsize( PyObject * s , int nd , int * itemsize)", + "filename": "arrayobject.c", + "nloc": 21, + "complexity": 9, + "token_count": 158, + "parameters": [ + "s", + "nd", + "itemsize" + ], + "start_line": 5028, + "end_line": 5050, + "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": 5057, + "end_line": 5083, + "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": 5089, + "end_line": 5121, + "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": 128, + "complexity": 34, + "token_count": 742, + "parameters": [ + "op", + "minitype", + "max" + ], + "start_line": 5133, + "end_line": 5281, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 149, + "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": 5284, + "end_line": 5307, + "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": 29, + "complexity": 7, + "token_count": 168, + "parameters": [ + "op", + "typecode" + ], + "start_line": 5312, + "end_line": 5346, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 35, + "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": 54, + "complexity": 21, + "token_count": 352, + "parameters": [ + "s", + "typecode", + "fortran", + "min_depth", + "max_depth" + ], + "start_line": 5351, + "end_line": 5414, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 64, + "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": 5421, + "end_line": 5430, + "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": 5436, + "end_line": 5529, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 94, + "top_nesting_level": 0 + }, + { + "name": "PyArray_CastToType", + "long_name": "PyArray_CastToType( PyArrayObject * mp , PyArray_Descr * at , int fortran)", + "filename": "arrayobject.c", + "nloc": 40, + "complexity": 16, + "token_count": 276, + "parameters": [ + "mp", + "at", + "fortran" + ], + "start_line": 5539, + "end_line": 5585, + "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": 5595, + "end_line": 5648, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 54, + "top_nesting_level": 0 + }, + { + "name": "PyArray_FromArray", + "long_name": "PyArray_FromArray( PyArrayObject * arr , PyArray_Descr * newtype , int flags)", + "filename": "arrayobject.c", + "nloc": 114, + "complexity": 33, + "token_count": 676, + "parameters": [ + "arr", + "newtype", + "flags" + ], + "start_line": 5653, + "end_line": 5782, + "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": 501, + "parameters": [ + "str" + ], + "start_line": 5786, + "end_line": 5894, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 109, + "top_nesting_level": 0 + }, + { + "name": "PyArray_FromStructInterface", + "long_name": "PyArray_FromStructInterface( PyObject * input)", + "filename": "arrayobject.c", + "nloc": 38, + "complexity": 6, + "token_count": 234, + "parameters": [ + "input" + ], + "start_line": 5898, + "end_line": 5938, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 41, + "top_nesting_level": 0 + }, + { + "name": "PyArray_FromInterface", + "long_name": "PyArray_FromInterface( PyObject * input)", + "filename": "arrayobject.c", + "nloc": 129, + "complexity": 28, + "token_count": 793, + "parameters": [ + "input" + ], + "start_line": 5942, + "end_line": 6080, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 139, + "top_nesting_level": 0 + }, + { + "name": "PyArray_FromArrayAttr", + "long_name": "PyArray_FromArrayAttr( PyObject * op , PyArray_Descr * typecode , PyObject * context)", + "filename": "arrayobject.c", + "nloc": 37, + "complexity": 11, + "token_count": 221, + "parameters": [ + "op", + "typecode", + "context" + ], + "start_line": 6084, + "end_line": 6121, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 38, + "top_nesting_level": 0 + }, + { + "name": "PyArray_FromAny", + "long_name": "PyArray_FromAny( PyObject * op , PyArray_Descr * newtype , int min_depth , int max_depth , int flags , PyObject * context)", + "filename": "arrayobject.c", + "nloc": 63, + "complexity": 20, + "token_count": 383, + "parameters": [ + "op", + "newtype", + "min_depth", + "max_depth", + "flags", + "context" + ], + "start_line": 6127, + "end_line": 6207, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 81, + "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": 6212, + "end_line": 6215, + "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": 6222, + "end_line": 6235, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 14, + "top_nesting_level": 0 + }, + { + "name": "PyArray_CheckFromAny", + "long_name": "PyArray_CheckFromAny( PyObject * op , PyArray_Descr * descr , int min_depth , int max_depth , int requires , PyObject * context)", + "filename": "arrayobject.c", + "nloc": 16, + "complexity": 7, + "token_count": 111, + "parameters": [ + "op", + "descr", + "min_depth", + "max_depth", + "requires", + "context" + ], + "start_line": 6281, + "end_line": 6297, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 17, + "top_nesting_level": 0 + }, + { + "name": "PyArray_EnsureArray", + "long_name": "PyArray_EnsureArray( PyObject * op)", + "filename": "arrayobject.c", + "nloc": 14, + "complexity": 5, + "token_count": 89, + "parameters": [ + "op" + ], + "start_line": 6310, + "end_line": 6326, + "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": 6332, + "end_line": 6420, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 89, + "top_nesting_level": 0 + }, + { + "name": "PyArray_CanCastTo", + "long_name": "PyArray_CanCastTo( PyArray_Descr * from , PyArray_Descr * to)", + "filename": "arrayobject.c", + "nloc": 24, + "complexity": 7, + "token_count": 132, + "parameters": [ + "from", + "to" + ], + "start_line": 6425, + "end_line": 6453, + "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": 6466, + "end_line": 6504, + "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": 6512, + "end_line": 6529, + "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": 6534, + "end_line": 6544, + "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": 6547, + "end_line": 6551, + "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": 6554, + "end_line": 6557, + "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": 6561, + "end_line": 6611, + "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": 6614, + "end_line": 6668, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 55, + "top_nesting_level": 0 + }, + { + "name": "iter_subscript", + "long_name": "iter_subscript( PyArrayIterObject * self , PyObject * ind)", + "filename": "arrayobject.c", + "nloc": 113, + "complexity": 23, + "token_count": 668, + "parameters": [ + "self", + "ind" + ], + "start_line": 6672, + "end_line": 6805, + "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": 6809, + "end_line": 6841, + "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": 6844, + "end_line": 6886, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 43, + "top_nesting_level": 0 + }, + { + "name": "iter_ass_subscript", + "long_name": "iter_ass_subscript( PyArrayIterObject * self , PyObject * ind , PyObject * val)", + "filename": "arrayobject.c", + "nloc": 115, + "complexity": 27, + "token_count": 698, + "parameters": [ + "self", + "ind", + "val" + ], + "start_line": 6889, + "end_line": 7023, + "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": 7036, + "end_line": 7081, + "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": 7086, + "end_line": 7090, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 5, + "top_nesting_level": 0 + }, + { + "name": "iter_coords_get", + "long_name": "iter_coords_get( PyArrayIterObject * self)", + "filename": "arrayobject.c", + "nloc": 15, + "complexity": 3, + "token_count": 91, + "parameters": [ + "self" + ], + "start_line": 7106, + "end_line": 7121, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 16, + "top_nesting_level": 0 + }, + { + "name": "_convert_obj", + "long_name": "_convert_obj( PyObject * obj , PyArrayIterObject ** iter)", + "filename": "arrayobject.c", + "nloc": 16, + "complexity": 5, + "token_count": 106, + "parameters": [ + "obj", + "iter" + ], + "start_line": 7186, + "end_line": 7202, + "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": 7209, + "end_line": 7278, + "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": 7282, + "end_line": 7319, + "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": 7325, + "end_line": 7369, + "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": 98, + "complexity": 21, + "token_count": 662, + "parameters": [ + "mit", + "arr" + ], + "start_line": 7387, + "end_line": 7515, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 129, + "top_nesting_level": 0 + }, + { + "name": "_nonzero_indices", + "long_name": "_nonzero_indices( PyObject * myBool , PyArrayIterObject ** iters)", + "filename": "arrayobject.c", + "nloc": 60, + "complexity": 15, + "token_count": 462, + "parameters": [ + "myBool", + "iters" + ], + "start_line": 7521, + "end_line": 7593, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 73, + "top_nesting_level": 0 + }, + { + "name": "PyArray_MapIterNew", + "long_name": "PyArray_MapIterNew( PyObject * indexobj , int oned , int fancy)", + "filename": "arrayobject.c", + "nloc": 104, + "complexity": 24, + "token_count": 726, + "parameters": [ + "indexobj", + "oned", + "fancy" + ], + "start_line": 7596, + "end_line": 7722, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 127, + "top_nesting_level": 0 + }, + { + "name": "arraymapiter_dealloc", + "long_name": "arraymapiter_dealloc( PyArrayMapIterObject * mit)", + "filename": "arrayobject.c", + "nloc": 10, + "complexity": 2, + "token_count": 62, + "parameters": [ + "mit" + ], + "start_line": 7726, + "end_line": 7735, + "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": 7806, + "end_line": 7855, + "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": 267, + "parameters": [ + "subtype", + "args", + "kwds" + ], + "start_line": 7858, + "end_line": 7903, + "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": 7906, + "end_line": 7925, + "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": 7928, + "end_line": 7935, + "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": 7938, + "end_line": 7948, + "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": 7951, + "end_line": 7961, + "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": 7964, + "end_line": 7967, + "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": 7970, + "end_line": 7982, + "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": 8012, + "end_line": 8019, + "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": 8078, + "end_line": 8087, + "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": 8105, + "end_line": 8127, + "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": 8133, + "end_line": 8143, + "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": 8162, + "end_line": 8170, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 9, + "top_nesting_level": 0 + }, + { + "name": "arraydescr_protocol_typestr_get", + "long_name": "arraydescr_protocol_typestr_get( PyArray_Descr * self)", + "filename": "arrayobject.c", + "nloc": 14, + "complexity": 4, + "token_count": 79, + "parameters": [ + "self" + ], + "start_line": 8173, + "end_line": 8188, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 16, + "top_nesting_level": 0 + }, + { + "name": "arraydescr_typename_get", + "long_name": "arraydescr_typename_get( PyArray_Descr * self)", + "filename": "arrayobject.c", + "nloc": 22, + "complexity": 5, + "token_count": 132, + "parameters": [ + "self" + ], + "start_line": 8191, + "end_line": 8213, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 23, + "top_nesting_level": 0 + }, + { + "name": "arraydescr_base_get", + "long_name": "arraydescr_base_get( PyArray_Descr * self)", + "filename": "arrayobject.c", + "nloc": 9, + "complexity": 2, + "token_count": 52, + "parameters": [ + "self" + ], + "start_line": 8216, + "end_line": 8224, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 9, + "top_nesting_level": 0 + }, + { + "name": "arraydescr_shape_get", + "long_name": "arraydescr_shape_get( PyArray_Descr * self)", + "filename": "arrayobject.c", + "nloc": 8, + "complexity": 2, + "token_count": 51, + "parameters": [ + "self" + ], + "start_line": 8227, + "end_line": 8234, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 8, + "top_nesting_level": 0 + }, + { + "name": "arraydescr_protocol_descr_get", + "long_name": "arraydescr_protocol_descr_get( PyArray_Descr * self)", + "filename": "arrayobject.c", + "nloc": 17, + "complexity": 5, + "token_count": 119, + "parameters": [ + "self" + ], + "start_line": 8237, + "end_line": 8256, + "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": 8263, + "end_line": 8270, + "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": 8273, + "end_line": 8280, + "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": 8283, + "end_line": 8290, + "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": 8338, + "end_line": 8390, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 53, + "top_nesting_level": 0 + }, + { + "name": "arraydescr_reduce", + "long_name": "arraydescr_reduce( PyArray_Descr * self , PyObject * args)", + "filename": "arrayobject.c", + "nloc": 54, + "complexity": 13, + "token_count": 395, + "parameters": [ + "self", + "args" + ], + "start_line": 8396, + "end_line": 8457, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 62, + "top_nesting_level": 0 + }, + { + "name": "arraydescr_setstate", + "long_name": "arraydescr_setstate( PyArray_Descr * self , PyObject * args)", + "filename": "arrayobject.c", + "nloc": 35, + "complexity": 8, + "token_count": 260, + "parameters": [ + "self", + "args" + ], + "start_line": 8465, + "end_line": 8507, + "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": 8527, + "end_line": 8593, + "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": 8604, + "end_line": 8612, + "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": 8627, + "end_line": 8672, + "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": 8675, + "end_line": 8684, + "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": 8687, + "end_line": 8697, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 11, + "top_nesting_level": 0 + }, + { + "name": "descr_length", + "long_name": "descr_length( PyArray_Descr * self)", + "filename": "arrayobject.c", + "nloc": 6, + "complexity": 3, + "token_count": 34, + "parameters": [ + "self" + ], + "start_line": 8704, + "end_line": 8711, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 8, + "top_nesting_level": 0 + }, + { + "name": "descr_subscript", + "long_name": "descr_subscript( PyArray_Descr * self , PyObject * op)", + "filename": "arrayobject.c", + "nloc": 31, + "complexity": 5, + "token_count": 126, + "parameters": [ + "self", + "op" + ], + "start_line": 8714, + "end_line": 8746, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 33, + "top_nesting_level": 0 + } + ], + "changed_methods": [ + { + "name": "PyArray_Scalar", + "long_name": "PyArray_Scalar( * data , PyArray_Descr * descr , PyObject * base)", + "filename": "arrayobject.c", + "nloc": 103, + "complexity": 17, + "token_count": 616, + "parameters": [ + "data", + "descr", + "base" + ], + "start_line": 835, + "end_line": 951, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 117, + "top_nesting_level": 0 + } + ], + "nloc": 6981, + "complexity": 1495, + "token_count": 40911, + "diff_parsed": { + "added": [ + "\t\t\tchar *buffer;", + "\t\t\tint alloc=1;", + "\t\t\t/* need aligned data buffer */", + "\t\t\tif (!PyArray_ISBEHAVED(base)) {", + "\t\t\t\tbuffer = _pya_malloc(itemsize);", + "\t\t\t\tif (buffer == NULL)", + "\t\t\t\t\treturn PyErr_NoMemory();", + "\t\t\t\talloc = 1;", + "\t\t\t\tmemcpy(buffer, data, itemsize);", + "\t\t\t\tif (!PyArray_ISNOTSWAPPED(base)) {", + "\t\t\t\t\tbyte_swap_vector(buffer, itemsize >> 2, 4);", + "\t\t\t\t}", + "\t\t\t}", + "\t\t\telse buffer = data;", + "", + "\t\t\tlength = PyUCS2Buffer_FromUCS4(uni->str, (PyArray_UCS4 *)buffer,", + "\t\t\tif (alloc) _pya_free(buffer);" + ], + "deleted": [ + "", + "\t\t\tif (!PyArray_ISNBO(descr->byteorder)) {", + "\t\t\t\t/* byteswap the data */", + "\t\t\t\tbyte_swap_vector(data, itemsize >> 2, 4);", + "\t\t\t}", + "\t\t\tlength = PyUCS2Buffer_FromUCS4(uni->str, (PyArray_UCS4 *)data," + ] + } + }, + { + "old_path": "numpy/core/src/arraytypes.inc.src", + "new_path": "numpy/core/src/arraytypes.inc.src", + "filename": "arraytypes.inc.src", + "extension": "src", + "change_type": "MODIFY", + "diff": "@@ -220,28 +220,40 @@ UNICODE_getitem(char *ip, PyArrayObject *ap)\n \tPyObject *obj;\n \tint mysize;\n \tPyArray_UCS4 *dptr;\n+\tchar *buffer;\n+\tint alloc=0;\n \n \tmysize = ap->descr->elsize >> 2;\n \tdptr = (PyArray_UCS4 *)ip + mysize-1;\n \twhile(mysize > 0 && *dptr-- == 0) mysize--;\n-\tif (!PyArray_ISNOTSWAPPED(ap) && (obj != NULL)) {\n-\t\tbyte_swap_vector(PyArray_BYTES(ap), mysize, 4);\n+\tif (!PyArray_ISBEHAVED(ap)) {\n+\t\tbuffer = _pya_malloc(mysize << 2);\n+\t\tif (buffer == NULL)\n+\t\t\treturn PyErr_NoMemory();\n+\t\talloc = 1;\n+\t\tmemcpy(buffer, ip, mysize << 2);\n+\t\tif (!PyArray_ISNOTSWAPPED(ap)) {\n+\t\t\tbyte_swap_vector(buffer, mysize, 4);\n+\t\t}\n \t}\n+\telse buffer = ip;\n #ifdef Py_UNICODE_WIDE\n-\tobj = PyUnicode_FromUnicode((const PyArray_UCS4 *)ip, mysize);\n+\tobj = PyUnicode_FromUnicode((const PyArray_UCS4 *)buffer, mysize);\n #else\n \t/* create new empty unicode object of length mysize*2 */\n \tobj = MyPyUnicode_New(mysize*2);\n \tif (obj == NULL) return obj;\n \tmysize = PyUCS2Buffer_FromUCS4(((PyUnicodeObject *)obj)->str, \n-\t\t\t\t (PyArray_UCS4 *)ip, mysize);\n+\t\t\t\t (PyArray_UCS4 *)buffer, mysize);\n \t/* reset length of unicode object to ucs2size */\n \tif (MyPyUnicode_Resize((PyUnicodeObject *)obj, mysize) < 0) {\n+\t\tif (alloc) _pya_free(buffer);\n \t\tPy_DECREF(obj);\n \t\treturn NULL;\n \t}\n #endif\n-\n+\tif (alloc) _pya_free(buffer);\n+\t\n \treturn obj;\n }\n \n@@ -251,6 +263,9 @@ UNICODE_setitem(PyObject *op, char *ov, PyArrayObject *ap)\n PyObject *temp;\n \tPy_UNICODE *ptr;\n \tint datalen;\n+#ifndef Py_UNICODE_WIDE\n+\tchar *buffer;\n+#endif\t\n \n \tif ((temp=PyObject_Unicode(op)) == NULL) return -1;\n \tptr = PyUnicode_AS_UNICODE(temp);\n@@ -263,9 +278,23 @@ UNICODE_setitem(PyObject *op, char *ov, PyArrayObject *ap)\n #ifdef Py_UNICODE_WIDE\n \tmemcpy(ov, ptr, MIN(ap->descr->elsize, datalen));\n #else\n- datalen = PyUCS2Buffer_AsUCS4(ptr, (PyArray_UCS4 *)ov, datalen >> 1,\n+\tif (!PyArray_ISALIGNED(ap)) {\n+\t\tbuffer = _pya_malloc(ap->descr->elsize);\n+\t\tif (buffer == NULL) {\n+\t\t\tPy_DECREF(temp);\n+\t\t\tPyErr_NoMemory();\n+\t\t\treturn -1;\n+\t\t}\n+\t}\n+\telse buffer = ov;\n+ datalen = PyUCS2Buffer_AsUCS4(ptr, (PyArray_UCS4 *)buffer, \n+\t\t\t\t datalen >> 1,\n \t\t\t\t ap->descr->elsize >> 2);\n \tdatalen <<= 2;\n+\tif (!PyArray_ISALIGNED(ap)) {\n+\t\tmemcpy(ov, buffer, datalen);\n+\t\t_pya_free(buffer);\n+\t}\n #endif\n \t/* Fill in the rest of the space with 0 */\n \tif (ap->descr->elsize > datalen) {\n", + "added_lines": 35, + "deleted_lines": 6, + "source_code": "/* -*- c -*- */\n\n/**begin repeat\n#name=UnsignedLong,UnsignedLongLong,LongLong#\n#type=ulong,ulonglong,longlong#\n */\nstatic @type@\nMyPyLong_As@name@(PyObject *vv)\n{\n\t@type@ ret;\n\n\tif (!PyLong_Check(vv)) {\n\t\tPyObject *mylong;\n\t\tmylong = PyNumber_Long(vv);\n\t\tif (mylong == NULL) return (@type@) -1;\n\t\tvv = mylong;\n\t}\n\telse Py_INCREF(vv);\n\n\tret = PyLong_As@name@(vv);\n\tPy_DECREF(vv);\n\treturn ret;\n}\n/**end repeat**/\n\n\nstatic double \n_getNAN(void) {\n#ifdef NAN\n return NAN;\n#else\n static double nan=0;\n \n if (nan == 0) {\n\t\tdouble mul = 1e100;\n\t\tdouble tmp = 0.0;\n\t\tdouble pinf=0;\n pinf = mul;\n for (;;) {\n pinf *= mul;\n if (pinf == tmp) break;\n tmp = pinf;\n }\n nan = pinf / pinf;\n }\n return nan;\n#endif\n}\n\nstatic double\nMyPyFloat_AsDouble(PyObject *obj)\n{\n if (obj == Py_None) return _getNAN();\n return PyFloat_AsDouble(obj); \n}\n\n\n/****************** getitem and setitem **********************/\n\n/**begin repeat\n\n#TYP=BOOL,BYTE,UBYTE,SHORT,USHORT,INT,LONG,UINT,ULONG,LONGLONG,ULONGLONG,FLOAT,DOUBLE#\n#func1=PyBool_FromLong, PyInt_FromLong*6, PyLong_FromUnsignedLong*2, PyLong_FromLongLong, PyLong_FromUnsignedLongLong, PyFloat_FromDouble*2#\n#func2=PyObject_IsTrue, PyInt_AsLong*6, MyPyLong_AsUnsignedLong*2, MyPyLong_AsLongLong, MyPyLong_AsUnsignedLongLong, MyPyFloat_AsDouble*2#\n#typ=Bool, byte, ubyte, short, ushort, int, long, uint, ulong, longlong, ulonglong, float, double#\n#typ1=long*7, ulong*2, longlong, ulonglong, float, double#\n#kind=Bool, Byte, UByte, Short, UShort, Int, Long, UInt, ULong, LongLong, ULongLong, Float, Double#\n*/\n\nstatic PyObject * \n@TYP@_getitem(char *ip, PyArrayObject *ap) {\n @typ@ t1;\n\n\tif ((ap==NULL) || PyArray_ISBEHAVED_RO(ap)) {\n t1 = *((@typ@ *)ip);\n return @func1@((@typ1@)t1);\n\t}\n\telse {\n ap->descr->f->copyswap(&t1, ip, !PyArray_ISNOTSWAPPED(ap),\n\t\t\t\t ap->descr->elsize);\n return @func1@((@typ1@)t1);\n\t}\n}\n\nstatic int \n@TYP@_setitem(PyObject *op, char *ov, PyArrayObject *ap) {\n @typ@ temp; /* ensures alignment */\n\n if (PyArray_IsScalar(op, @kind@)) {\n temp = ((Py@kind@ScalarObject *)op)->obval;\n }\n else {\n temp = (@typ@)@func2@(op);\n }\n if (PyErr_Occurred()) return -1;\n if (ap == NULL || PyArray_ISBEHAVED(ap)) \n *((@typ@ *)ov)=temp;\n else {\n ap->descr->f->copyswap(ov, &temp, !PyArray_ISNOTSWAPPED(ap), \n\t\t\t\t ap->descr->elsize);\n }\n \n return 0;\n}\n\n/**end repeat**/\n\n\n/**begin repeat \n\n#TYP=CFLOAT,CDOUBLE#\n#typ=float, double#\n*/\n\nstatic PyObject * \n@TYP@_getitem(char *ip, PyArrayObject *ap) {\n @typ@ t1, t2;\n\n if ((ap==NULL) || PyArray_ISBEHAVED_RO(ap)) { \n return PyComplex_FromDoubles((double)((@typ@ *)ip)[0], \n (double)((@typ@ *)ip)[1]);\n }\n else {\n\t\tint size = sizeof(@typ@);\n\t\tBool swap = !PyArray_ISNOTSWAPPED(ap);\n copy_and_swap(&t1, ip, size, 1, 0, swap);\n copy_and_swap(&t2, ip+size, size, 1, 0, swap);\n return PyComplex_FromDoubles((double)t1, (double)t2);\n }\n}\n/**end repeat**/\n\n/**begin repeat \n\n#TYP=CFLOAT, CDOUBLE, CLONGDOUBLE#\n#typ=float, double, longdouble#\n#kind=CFloat, CDouble, CLongDouble#\n*/\nstatic int \n@TYP@_setitem(PyObject *op, char *ov, PyArrayObject *ap) \n{\n Py_complex oop;\n PyObject *op2;\n c@typ@ temp;\n\tint rsize;\n \n if (!(PyArray_IsScalar(op, @kind@))) {\n if (PyArray_Check(op) && (PyArray_NDIM(op)==0)) {\n op2 = ((PyArrayObject *)op)->descr->f->getitem \\\n (((PyArrayObject *)op)->data, \n (PyArrayObject *)op);\n\t\t}\n\t\telse { \n op2 = op; Py_INCREF(op);\n }\n if (op2 == Py_None) {\n oop.real = oop.imag = _getNAN();\n }\n else {\n oop = PyComplex_AsCComplex (op2);\n }\n Py_DECREF(op2);\n if (PyErr_Occurred()) return -1;\n temp.real = (@typ@) oop.real;\n temp.imag = (@typ@) oop.imag; \n }\n\telse {\n temp = ((Py@kind@ScalarObject *)op)->obval;\n }\n\t\n memcpy(ov, &temp, ap->descr->elsize);\n if (!PyArray_ISNOTSWAPPED(ap))\n byte_swap_vector(ov, 2, sizeof(@typ@));\n\t\n\trsize = sizeof(@typ@);\n\tcopy_and_swap(ov, &temp, rsize, 2, rsize, !PyArray_ISNOTSWAPPED(ap));\n return 0;\n}\n/**end repeat**/\n\nstatic PyObject * \nLONGDOUBLE_getitem(char *ip, PyArrayObject *ap) \n{\n return PyArray_Scalar(ip, ap->descr, NULL);\n}\n\nstatic int \nLONGDOUBLE_setitem(PyObject *op, char *ov, PyArrayObject *ap) {\n longdouble temp; /* ensures alignment */\n\n if (PyArray_IsScalar(op, LongDouble)) {\n temp = ((PyLongDoubleScalarObject *)op)->obval;\n }\n else {\n if (op == Py_None) temp = (longdouble)_getNAN();\n else temp = (longdouble)PyFloat_AsDouble(op);\n }\n if (PyErr_Occurred()) return -1;\n if (ap == NULL || PyArray_ISBEHAVED(ap)) \n *((longdouble *)ov)=temp;\n else {\n copy_and_swap(ov, &temp, ap->descr->elsize, 1, 0,\n !PyArray_ISNOTSWAPPED(ap));\n }\n \n return 0;\n}\n\nstatic PyObject * \nCLONGDOUBLE_getitem(char *ip, PyArrayObject *ap) \n{\n return PyArray_Scalar(ip, ap->descr, NULL);\n}\n\n\n/* UNICODE */\nstatic PyObject * \nUNICODE_getitem(char *ip, PyArrayObject *ap) \n{\n\tPyObject *obj;\n\tint mysize;\n\tPyArray_UCS4 *dptr;\n\tchar *buffer;\n\tint alloc=0;\n\n\tmysize = ap->descr->elsize >> 2;\n\tdptr = (PyArray_UCS4 *)ip + mysize-1;\n\twhile(mysize > 0 && *dptr-- == 0) mysize--;\n\tif (!PyArray_ISBEHAVED(ap)) {\n\t\tbuffer = _pya_malloc(mysize << 2);\n\t\tif (buffer == NULL)\n\t\t\treturn PyErr_NoMemory();\n\t\talloc = 1;\n\t\tmemcpy(buffer, ip, mysize << 2);\n\t\tif (!PyArray_ISNOTSWAPPED(ap)) {\n\t\t\tbyte_swap_vector(buffer, mysize, 4);\n\t\t}\n\t}\n\telse buffer = ip;\n#ifdef Py_UNICODE_WIDE\n\tobj = PyUnicode_FromUnicode((const PyArray_UCS4 *)buffer, mysize);\n#else\n\t/* create new empty unicode object of length mysize*2 */\n\tobj = MyPyUnicode_New(mysize*2);\n\tif (obj == NULL) return obj;\n\tmysize = PyUCS2Buffer_FromUCS4(((PyUnicodeObject *)obj)->str, \n\t\t\t\t (PyArray_UCS4 *)buffer, mysize);\n\t/* reset length of unicode object to ucs2size */\n\tif (MyPyUnicode_Resize((PyUnicodeObject *)obj, mysize) < 0) {\n\t\tif (alloc) _pya_free(buffer);\n\t\tPy_DECREF(obj);\n\t\treturn NULL;\n\t}\n#endif\n\tif (alloc) _pya_free(buffer);\n\t\n\treturn obj;\n}\n\nstatic int \nUNICODE_setitem(PyObject *op, char *ov, PyArrayObject *ap) \n{\n PyObject *temp;\n\tPy_UNICODE *ptr;\n\tint datalen;\n#ifndef Py_UNICODE_WIDE\n\tchar *buffer;\n#endif\t\n\n\tif ((temp=PyObject_Unicode(op)) == NULL) return -1;\n\tptr = PyUnicode_AS_UNICODE(temp);\n\tif ((ptr == NULL) || (PyErr_Occurred())) {\n\t\tPy_DECREF(temp);\n\t\treturn -1;\n\t}\n\tdatalen = PyUnicode_GET_DATA_SIZE(temp);\n\n#ifdef Py_UNICODE_WIDE\n\tmemcpy(ov, ptr, MIN(ap->descr->elsize, datalen));\n#else\n\tif (!PyArray_ISALIGNED(ap)) {\n\t\tbuffer = _pya_malloc(ap->descr->elsize);\n\t\tif (buffer == NULL) {\n\t\t\tPy_DECREF(temp);\n\t\t\tPyErr_NoMemory();\n\t\t\treturn -1;\n\t\t}\n\t}\n\telse buffer = ov;\n datalen = PyUCS2Buffer_AsUCS4(ptr, (PyArray_UCS4 *)buffer, \n\t\t\t\t datalen >> 1,\n\t\t\t\t ap->descr->elsize >> 2);\n\tdatalen <<= 2;\n\tif (!PyArray_ISALIGNED(ap)) {\n\t\tmemcpy(ov, buffer, datalen);\n\t\t_pya_free(buffer);\n\t}\n#endif\n\t/* Fill in the rest of the space with 0 */\n\tif (ap->descr->elsize > datalen) {\n\t\tmemset(ov + datalen, 0, (ap->descr->elsize - datalen));\n\t}\n\t\n\tif (!PyArray_ISNOTSWAPPED(ap)) \n\t\tbyte_swap_vector(ov, ap->descr->elsize >> 2, 4);\n\tPy_DECREF(temp);\n\treturn 0;\n}\n\n/* STRING -- can handle both NULL-terminated and not NULL-terminated cases */\nstatic PyObject * \nSTRING_getitem(char *ip, PyArrayObject *ap) \n{\n\tif (ip[ap->descr->elsize-1])\n\t\treturn PyString_FromStringAndSize(ip,ap->descr->elsize);\n\telse\n\t\treturn PyString_FromString(ip);\n}\n\nstatic int \nSTRING_setitem(PyObject *op, char *ov, PyArrayObject *ap) \n{\n\tchar *ptr;\n\tint len;\n\tPyObject *temp=PyObject_Str(op);\n\t\n\tif (temp == NULL) return -1;\n\t\n\tif (PyString_AsStringAndSize(temp, &ptr, &len) == -1) {\n\t\tPy_DECREF(temp);\n\t\treturn -1;\n\t}\n\tmemcpy(ov, ptr, MIN(ap->descr->elsize,len));\n\tif (ap->descr->elsize > len) {\n\t\tmemset(ov + len, 0, (ap->descr->elsize - len));\n\t}\n\tPy_DECREF(temp);\n\treturn 0;\n}\n\n/* OBJECT */\n\nstatic PyObject * \nOBJECT_getitem(char *ip, PyArrayObject *ap) \n{\n\tPy_INCREF(*(PyObject **)ip);\n\treturn *(PyObject **)ip;\n}\n\nstatic int \nOBJECT_setitem(PyObject *op, char *ov, PyArrayObject *ap) \n{\n\tPy_XDECREF(*(PyObject **)ov);\n\tPy_INCREF(op);\n\t*(PyObject **)ov = op;\n\treturn PyErr_Occurred() ? -1:0;\n}\n\n/* VOID */\n\nstatic PyObject *\nVOID_getitem(char *ip, PyArrayObject *ap)\n{\n PyObject *u=NULL;\n\tPyArray_Descr* descr;\n int itemsize;\n\n\tdescr = ap->descr;\n\tif (descr->fields && descr->fields != Py_None) {\n\t\tPyObject *key;\n\t\tPyObject *names;\n\t\tint i, n;\n\t\tPyObject *ret;\n\t\tPyObject *tup, *title;\n\t\tPyArray_Descr *new;\n\t\tint offset;\n\t\tint savedflags;\n\n\t\t/* get the names from the fields dictionary*/\n\t\tkey = PyInt_FromLong(-1);\n\t\tnames = PyDict_GetItem(descr->fields, key);\n\t\tPy_DECREF(key);\n\t\tif (!names) goto finish;\n\t\tn = PyList_GET_SIZE(names);\n\t\tret = PyTuple_New(n);\n\t\tsavedflags = ap->flags;\n\t\tfor (i=0; ifields, key);\n\t\t\tif (!PyArg_ParseTuple(tup, \"Oi|O\", &new, &offset, \n\t\t\t\t\t &title)) {\n\t\t\t\tPy_DECREF(ret); \n\t\t\t\tap->descr = descr;\n\t\t\t\treturn NULL;\n\t\t\t}\n\t\t\tap->descr = new;\n\t\t\t/* update alignment based on offset */\n\t\t\tif ((new->alignment > 1) &&\t\t\t\\\n\t\t\t ((((intp)(ip+offset)) % new->alignment) != 0))\n\t\t\t\tap->flags &= ~ALIGNED;\n\t\t\telse\n\t\t\t\tap->flags |= ALIGNED;\n\n\t\t\tPyTuple_SET_ITEM(ret, i,\t\t\t\\\n\t\t\t\t\t new->f->getitem(ip+offset, ap));\n\t\t\tap->flags = savedflags;\n\t\t}\n\t\tap->descr = descr;\n\t\treturn ret;\n\t}\n\n\tif (descr->subarray) {\n\t\t/* return an array of the basic type */\n\t\tPyArray_Dims shape={NULL,-1};\n\t\tPyObject *ret;\n\t\tif (!(PyArray_IntpConverter(descr->subarray->shape, \n\t\t\t\t\t &shape))) {\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\treturn NULL;\n\t\t}\n Py_INCREF(descr->subarray->base);\n\t\tret = PyArray_NewFromDescr(&PyArray_Type,\n\t\t\t\t\t descr->subarray->base,\n\t\t\t\t\t shape.len, shape.ptr,\n\t\t\t\t\t NULL, ip, ap->flags, NULL);\n\t\tPyDimMem_FREE(shape.ptr);\n\t\tif (!ret) return NULL;\n\t\tPyArray_BASE(ret) = (PyObject *)ap;\n\t\tPy_INCREF(ap);\n\t\tPyArray_UpdateFlags((PyArrayObject *)ret, UPDATE_ALL_FLAGS);\n\t\treturn ret;\n\t}\n\n finish:\n\titemsize=ap->descr->elsize;\n\tif (PyArray_ISWRITEABLE(ap))\n\t\tu = PyBuffer_FromReadWriteMemory(ip, itemsize);\n\telse\n\t\tu = PyBuffer_FromMemory(ip, itemsize);\n\tif (u==NULL) goto fail;\n\n\t/* default is to return buffer object pointing to current item */\n\t/* a view of it */\n\treturn u; \n\t\n fail:\n return NULL;\n}\n\n\n\nstatic int PyArray_CopyObject(PyArrayObject *, PyObject *);\n\nstatic int\nVOID_setitem(PyObject *op, char *ip, PyArrayObject *ap)\n{\n\tPyArray_Descr* descr;\n int itemsize=ap->descr->elsize;\n\tint res;\n\n\tdescr = ap->descr;\n\tif (descr->fields && (descr->fields != Py_None) && \\\n\t PyTuple_Check(op)) {\n\t\tPyObject *key;\n\t\tPyObject *names;\n\t\tint i, n;\n\t\tPyObject *tup, *title;\n\t\tPyArray_Descr *new;\n\t\tint offset;\n\t\tint savedflags;\n\t\tres = -1;\n\t\t/* get the names from the fields dictionary*/\n\t\tkey = PyInt_FromLong(-1);\n\t\tnames = PyDict_GetItem(descr->fields, key);\n\t\tPy_DECREF(key);\n\t\tif (!names) goto finish;\n\t\tn = PyList_GET_SIZE(names);\n\t\tif (PyTuple_GET_SIZE(op) != n) {\n\t\t\tPyErr_SetString(PyExc_ValueError, \n\t\t\t\t\t\"size of tuple must match\"\\\n\t\t\t\t\t\"number of fields.\");\n\t\t\treturn -1;\n\t\t}\n\t\tsavedflags = ap->flags;\n\t\tfor (i=0; ifields, key);\n\t\t\tif (!PyArg_ParseTuple(tup, \"Oi|O\", &new, &offset, \n\t\t\t\t\t &title)) {\n\t\t\t\tap->descr = descr;\n\t\t\t\treturn -1;\n\t\t\t}\n\t\t\tap->descr = new;\n\t\t\t/* remember to update alignment flags */\n\t\t\tif ((new->alignment > 1) &&\t\t\t\\\n\t\t\t ((((intp)(ip+offset)) % new->alignment) != 0))\n\t\t\t\tap->flags &= ~ALIGNED;\n\t\t\telse\n\t\t\t\tap->flags |= ALIGNED;\n\n\t\t\tres = new->f->setitem(PyTuple_GET_ITEM(op, i),\n\t\t\t\t\t ip+offset, ap);\n\t\t\tap->flags = savedflags;\n\t\t\tif (res < 0) break;\n\t\t}\n\t\tap->descr = descr;\n\t\treturn res;\n\t}\n\n\tif (descr->subarray) {\n\t\t/* copy into an array of the same basic type */\n\t\tPyArray_Dims shape={NULL,-1};\n\t\tPyObject *ret;\n\t\tif (!(PyArray_IntpConverter(descr->subarray->shape, \n\t\t\t\t\t &shape))) {\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\treturn -1;\n\t\t}\n Py_INCREF(descr->subarray->base);\n\t\tret = PyArray_NewFromDescr(&PyArray_Type,\n\t\t\t\t\t descr->subarray->base,\n\t\t\t\t\t shape.len, shape.ptr,\n\t\t\t\t\t NULL, ip, ap->flags, NULL);\n\t\tPyDimMem_FREE(shape.ptr);\n\t\tif (!ret) return -1;\n\t\tPyArray_BASE(ret) = (PyObject *)ap;\n\t\tPy_INCREF(ap);\n\t\tPyArray_UpdateFlags((PyArrayObject *)ret, UPDATE_ALL_FLAGS);\n\t\tres = PyArray_CopyObject((PyArrayObject *)ret, op);\n\t\tPy_DECREF(ret);\n\t\treturn res;\n\t}\n\n finish:\n\t/* Default is to use buffer interface to set item */\n\t{\n\t\tconst void *buffer;\n\t\tint buflen;\n\t\tres = PyObject_AsReadBuffer(op, &buffer, &buflen);\n\t\tif (res == -1) goto fail;\n\t\tmemcpy(ip, buffer, MIN(buflen, itemsize));\n }\n\treturn 0;\n\n fail:\n return -1; \n}\n\n\n/****************** XXX_to_YYY *******************************/ \n\n/* Assumes contiguous, and aligned, from and to */\n\n\n/**begin repeat\n#to=(BYTE,UBYTE,SHORT,USHORT,INT,UINT,LONG,ULONG,LONGLONG,ULONGLONG,FLOAT,DOUBLE,LONGDOUBLE)*16#\n#from=BYTE*13,UBYTE*13,SHORT*13,USHORT*13,INT*13,UINT*13,LONG*13,ULONG*13,LONGLONG*13,ULONGLONG*13,FLOAT*13,DOUBLE*13,LONGDOUBLE*13,CFLOAT*13,CDOUBLE*13,CLONGDOUBLE*13#\n#totyp=(byte, ubyte, short, ushort, int, uint, long, ulong, longlong, ulonglong, float, double, longdouble)*16#\n#fromtyp=byte*13, ubyte*13, short*13, ushort*13, int*13, uint*13, long*13, ulong*13, longlong*13, ulonglong*13, float*13, double*13, longdouble*13, float*13, double*13, longdouble*13#\n#incr= ip++*169,ip+=2*39#\n*/\nstatic void \n@from@_to_@to@(@fromtyp@ *ip, @totyp@ *op, intp n, PyArrayObject *aip, \n\t PyArrayObject *aop) {\n\tregister intp i; \n\tfor(i=0;idescr->elsize*3, 1#\n*/\nstatic void \n@from@_to_OBJECT(@fromtyp@ *ip, PyObject **op, intp n, PyArrayObject *aip,\n\t\t PyArrayObject *aop)\n{\n\tregister intp i; \n\tint skip=@skip@;\n\tfor(i=0;idescr->elsize*3#\n*/\nstatic void \nOBJECT_to_@to@(PyObject **ip, @totyp@ *op, intp n, PyArrayObject *aip,\n\t\t PyArrayObject *aop)\n{\n\tregister intp i; \n\tint skip=@skip@;\n\tfor(i=0;idescr->elsize*3)*3#\n#convert=1*17,0*3,1*17,0*3,0*20#\n#convstr=(Int*9,Long*2,Float*3,Complex*3,Tuple*3)*3#\n*/\nstatic void\n@from@_to_@to@(@fromtyp@ *ip, @totyp@ *op, intp n, PyArrayObject *aip, \n\t PyArrayObject *aop)\n{\n\tregister intp i;\n\tPyObject *temp=NULL;\n\tint skip=aip->descr->elsize;\n\tint oskip=@oskip@;\n\tfor(i=0; idescr->elsize;\n\tfor(i=0; i= 0x02040000) || defined(PyOS_ascii_strtod)\nstatic int\n@fname@_fromstr(char *str, @type@ *ip, char **endptr, void *ignore)\n{\n\tdouble result;\n\n\tresult = PyOS_ascii_strtod(str, endptr);\n\t*ip = (@type@) result;\n\treturn 0;\n}\n#else\n#define @fname@_fromstr NULL\n#endif\n/**end repeat**/\n\n\n\n/**begin repeat\n#fname=BOOL,CFLOAT,CDOUBLE,CLONGDOUBLE,OBJECT,STRING,UNICODE,VOID#\n*/\n#define @fname@_fromstr NULL\n/**end repeat**/\n\n\n/****************** copyswapn *************************************/\n\n/**begin repeat\n\n#fname=SHORT,USHORT,INT,UINT,LONG,ULONG,LONGLONG,ULONGLONG,FLOAT,DOUBLE,LONGDOUBLE#\n#fsize=SHORT,SHORT,INT,INT,LONG,LONG,LONGLONG,LONGLONG,FLOAT,DOUBLE,LONGDOUBLE#\n#type=short,ushort,int,uint,long,ulong,longlong,ulonglong,float,double,longdouble#\n*/\nstatic void\n@fname@_copyswapn (void *dst, void *src, intp n, int swap, int itemsize)\n{\n\tif (src != NULL) /* copy first if needed */\n\t\tmemcpy(dst, src, n*sizeof(@type@));\n\n\tif (swap) {\n\t\tregister char *a, *b, c;\n\t\tfor (a = (char *)dst; n>0; n--) {\n#if SIZEOF_@fsize@ == 2\n\t\t\tb = a + 1;\n\t\t\tc = *a; *a++ = *b; *b = c;\n\t\t\ta += 1;\n#elif SIZEOF_@fsize@ == 4\n\t\t\tb = a + 3;\n c = *a; *a++ = *b; *b-- = c;\n c = *a; *a++ = *b; *b = c;\n\t\t\ta += 2;\n#elif SIZEOF_@fsize@ == 8\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\t\t\ta += 4;\n#elif SIZEOF_@fsize@ == 10\n b = a + 9;\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 c = *a; *a++ = *b; *b = c;\n\t\t\ta += 5;\n#elif SIZEOF_@fsize@ == 12\n b = a + 11;\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 c = *a; *a++ = *b; *b-- = c;\n c = *a; *a++ = *b; *b = c;\n\t\t\ta += 6;\n#elif SIZEOF_@fsize@ == 16\n b = a + 15;\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 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\t\t\ta += 8;\n#else\n\t\t\tregister int i, nn;\n b = a + (SIZEOF_@fsize@-1);\n\t\t\tnn = SIZEOF_@fsize@ / 2;\n for (i=0; i0; nn--) {\n#if SIZEOF_@fsize@ == 4\n\t\t\tb = a + 3;\n c = *a; *a++ = *b; *b-- = c;\n c = *a; *a++ = *b; *b = c;\n\t\t\ta += 2;\n#elif SIZEOF_@fsize@ == 8\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\t\t\ta += 4;\n#elif SIZEOF_@fsize@ == 10\n b = a + 9;\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 c = *a; *a++ = *b; *b = c;\n\t\t\ta += 5;\n#elif SIZEOF_@fsize@ == 12\n b = a + 11;\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 c = *a; *a++ = *b; *b-- = c;\n c = *a; *a++ = *b; *b = c;\n\t\t\ta += 6;\n#elif SIZEOF_@fsize@ == 16\n b = a + 15;\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 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\t\t\ta += 8;\n#else\n\t\t\tregister int i, kn;\n\n b = a + (SIZEOF_@fsize@-1);\n\t\t\tkn = SIZEOF_@fsize@ / 2;\n for (i=0; i0; n--) {\n\t\t\tb = a + 3;\n\t\t\tc=*a; *a++ = *b; *b-- = c;\n\t\t\tc=*a; *a++ = *b; *b-- = c;\n\t\t\ta += 1;\n\t\t}\n\t}\n}\n\n\nstatic void\nOBJECT_copyswap (PyObject **dst, PyObject **src, int swap, int itemsize)\n{\n OBJECT_copyswapn(dst, src, 1, swap, itemsize);\n}\n\nstatic void\nSTRING_copyswap (char *dst, char *src, int swap, int itemsize)\n{\n\tif (src != NULL) \n\t\tmemcpy(dst, src, itemsize);\n\t\n}\n\n/* ignore swap */\nstatic void\nVOID_copyswap (char *dst, char *src, int swap, int itemsize)\n{\n\tif (src != NULL) \n\t\tmemcpy(dst, src, itemsize);\t\n\treturn;\n}\n\nstatic void\nUNICODE_copyswap (char *dst, char *src, int swap, int itemsize)\n{\n\n\tif (src != NULL) \n\t\tmemcpy(dst, src, itemsize);\n\t\n\tif (swap) {\n\t\tregister char *a, *b, c;\n a = (char *)dst;\n b = a + 3;\n\t\tc=*a; *a++ = *b; *b-- = c;\n\t\tc=*a; *a++ = *b; *b-- = c;\n\t}\n}\n\n\n/****************** nonzero **********************************/\n\n/**begin repeat\n#fname=BOOL,BYTE,UBYTE,SHORT,USHORT,INT,UINT,LONG,ULONG,LONGLONG,ULONGLONG,FLOAT,DOUBLE,LONGDOUBLE#\n#type=Bool, byte, ubyte, short, ushort, int, uint, long, ulong, longlong, ulonglong, float, double, longdouble#\n*/\nstatic Bool \n@fname@_nonzero (@type@ *ip, PyArrayObject *ap)\n{\n\t@type@ t1;\n\tif (ap==NULL || PyArray_ISBEHAVED_RO(ap))\n\t\treturn (Bool) (*ip != 0);\n\telse {\n\t\t/* don't worry about swap, since we are just testing\n\t\t whether or not equal to 0 */\n\t\tmemcpy(&t1, ip, sizeof(@type@));\n\t\treturn (Bool) (t1 != 0);\n\t}\n}\n/**end repeat**/\n\n/**begin repeat\n#fname=CFLOAT,CDOUBLE,CLONGDOUBLE#\n#type=cfloat, cdouble, clongdouble#\n*/\nstatic Bool \n@fname@_nonzero (@type@ *ip, PyArrayObject *ap)\n{\n\t@type@ t1;\n\tif (ap==NULL || PyArray_ISBEHAVED_RO(ap))\n\t\treturn (Bool) ((ip->real != 0) || (ip->imag != 0));\n\telse {\n\t\t/* don't worry about swap, since we are just testing\n\t\t whether or not equal to 0 */\n\t\tmemcpy(&t1, ip, sizeof(@type@));\n\t\treturn (Bool) ((t1.real != 0) || (t1.imag != 0));\n\t}\n}\n/**end repeat**/\n\n\n\n#define WHITESPACE \" \\t\\n\\r\\v\\f\"\n#define WHITELEN 6\n\nstatic Bool\nPy_STRING_ISSPACE(char ch) \n{\n\tchar white[] = WHITESPACE;\n\tint j;\n\tBool space=FALSE;\n\tfor (j=0; jdescr->elsize;\n\tint i;\n\tBool nonz = FALSE;\n\n\tfor (i=0; idescr->elsize >> 2;\n\tint i;\n\tBool nonz = FALSE;\n\tchar *buffer=NULL;\t\n\n\tif ((!PyArray_ISNOTSWAPPED(ap)) || \\\n\t (!PyArray_ISALIGNED(ap))) {\n\t\tbuffer = _pya_malloc(ap->descr->elsize);\n\t\tif (buffer == NULL) {\n\t\t\treturn nonz;\n\t\t}\n\t\tmemcpy(buffer, ip, ap->descr->elsize);\n\t\tif (!PyArray_ISNOTSWAPPED(ap)) {\n\t\t\tbyte_swap_vector(buffer, len, 4);\n\t\t}\n\t\tip = (PyArray_UCS4 *)buffer;\n\t}\n\n\tfor (i=0; idescr->elsize;\n\tBool nonz = FALSE;\n\t\n\tfor (i=0; idescr->elsize);\n}\n\n/* taken from Python */\nstatic int \nUNICODE_compare(register PyArray_UCS4 *ip1, register PyArray_UCS4 *ip2, \n\t\tPyArrayObject *ap)\n{\n register int itemsize=ap->descr->elsize;\n\tregister PyArray_UCS4 c1, c2;\n\n\tif (itemsize < 0) return 0;\n\t\n\twhile(itemsize-- > 0) {\n\t\tc1 = *ip1++;\n\t\tc2 = *ip2++;\n\t\t\n\t\tif (c1 != c2) \n\t\t\treturn (c1 < c2) ? -1 : 1;\n\t}\n\treturn 0;\n}\n\n/* possibly redefine compare in terms of fields and subarrays if any */\n\n/* as it is, it compares raw-bytes as it they were strings */\n#define VOID_compare STRING_compare\n\n/****************** argfunc **********************************/\n\n/**begin repeat\n\n#fname= BOOL,BYTE, UBYTE, SHORT, USHORT, INT, UINT, LONG, ULONG, LONGLONG, ULONGLONG, FLOAT, DOUBLE, LONGDOUBLE, CFLOAT, CDOUBLE, CLONGDOUBLE#\n#type= Bool, byte, ubyte, short, ushort, int, uint, long, ulong, longlong, ulonglong, float, double, longdouble, float, double, longdouble#\n#incr= ip++*14, ip+=2*3#\n*/\n\nstatic int\n@fname@_argmax(@type@ *ip, intp n, intp *max_ind, PyArrayObject *aip)\n{\n\tregister intp i;\n\t@type@ mp=*ip;\n\t*max_ind=0;\n\tfor (i=1; i mp) {\n\t\t\tmp = *ip;\n\t\t\t*max_ind = i;\n\t\t}\n\t}\n\treturn 0;\n}\n\n/**end repeat**/\n\nstatic int \nOBJECT_argmax(PyObject **ip, intp n, intp *max_ind, PyArrayObject *aip) \n{\n\tregister intp i; \n\tPyObject *mp=ip[0]; *max_ind=0;\n\tfor(i=1; i 0) { \n\t\t\tmp = *ip; \n\t\t\t*max_ind=i;\n\t\t} \n\t} \n\treturn 0;\n}\n\n/**begin repeat\n\n#fname= STRING, UNICODE#\n#type= char, PyArray_UCS4#\n\n*/\nstatic int \n@fname@_argmax(@type@ *ip, intp n, intp *max_ind, PyArrayObject *aip) \n{\n\tregister intp i; \n\tint elsize = aip->descr->elsize;\n\t@type@ *mp = (@type@ *)_pya_malloc(elsize);\n\t\n\tif (mp==NULL) return 0;\n\tmemcpy(mp, ip, elsize);\n\t*max_ind = 0;\n\tfor(i=1; i 0) { \n\t\t\tmemcpy(mp, ip, elsize);\n\t\t\t*max_ind=i;\n\t\t} \n\t} \n\t_pya_free(mp);\n\treturn 0;\n}\n\n/**end repeat**/\n\n#define VOID_argmax NULL\n\nstatic void\nBOOL_dot(char *ip1, intp is1, char *ip2, intp is2, char *op, intp n, \n void *ignore)\n{\n\tregister Bool tmp=FALSE;\n\tregister intp i;\n\tfor(i=0;ireal;\n\tstart.imag = buffer->imag;\n\tdelta.real = buffer[1].real;\n\tdelta.imag = buffer[1].imag;\n\tdelta.real -= start.real;\n\tdelta.imag -= start.imag;\n\tbuffer += 2;\n\tfor (i=2; ireal = start.real + i*delta.real;\n\t\tbuffer->imag = start.imag + i*delta.imag;\n\t}\n}\n/**end repeat**/\n\n\n#define _ALIGN(type) offsetof(struct {char c; type v;},v)\n\n/**begin repeat\n\n#from= VOID, STRING, UNICODE#\n#align= char, char, PyArray_UCS4#\n#NAME= Void, String, Unicode#\n#endian= |, |, =#\n*/\n\nstatic PyArray_ArrFuncs _Py@NAME@_ArrFuncs = {\n\t{\n\t\t(PyArray_VectorUnaryFunc*)@from@_to_BOOL, \n\t\t(PyArray_VectorUnaryFunc*)@from@_to_BYTE, \n\t\t(PyArray_VectorUnaryFunc*)@from@_to_UBYTE, \n\t\t(PyArray_VectorUnaryFunc*)@from@_to_SHORT, \n\t\t(PyArray_VectorUnaryFunc*)@from@_to_USHORT, \n\t\t(PyArray_VectorUnaryFunc*)@from@_to_INT, \n\t\t(PyArray_VectorUnaryFunc*)@from@_to_UINT, \n\t\t(PyArray_VectorUnaryFunc*)@from@_to_LONG,\n\t\t(PyArray_VectorUnaryFunc*)@from@_to_ULONG, \n\t\t(PyArray_VectorUnaryFunc*)@from@_to_LONGLONG, \n\t\t(PyArray_VectorUnaryFunc*)@from@_to_ULONGLONG, \n\t\t(PyArray_VectorUnaryFunc*)@from@_to_FLOAT, \n\t\t(PyArray_VectorUnaryFunc*)@from@_to_DOUBLE, \n\t\t(PyArray_VectorUnaryFunc*)@from@_to_LONGDOUBLE, \n\t\t(PyArray_VectorUnaryFunc*)@from@_to_CFLOAT, \n\t\t(PyArray_VectorUnaryFunc*)@from@_to_CDOUBLE, \n\t\t(PyArray_VectorUnaryFunc*)@from@_to_CLONGDOUBLE, \n\t\t(PyArray_VectorUnaryFunc*)@from@_to_OBJECT, \n\t\t(PyArray_VectorUnaryFunc*)@from@_to_STRING, \n\t\t(PyArray_VectorUnaryFunc*)@from@_to_UNICODE, \n\t\t(PyArray_VectorUnaryFunc*)@from@_to_VOID\n\t},\n\t(PyArray_GetItemFunc*)@from@_getitem, \n\t(PyArray_SetItemFunc*)@from@_setitem,\n\t(PyArray_CopySwapNFunc*)@from@_copyswapn,\n\t(PyArray_CopySwapFunc*)@from@_copyswap,\n\t(PyArray_CompareFunc*)@from@_compare, \n\t(PyArray_ArgFunc*)@from@_argmax,\n\t(PyArray_DotFunc*)NULL, \n\t(PyArray_ScanFunc*)@from@_scan,\n\t(PyArray_FromStrFunc*)@from@_fromstr,\n\t(PyArray_NonzeroFunc*)@from@_nonzero,\n\t(PyArray_FillFunc*)NULL,\n\t{\n\t\tNULL, NULL, NULL, NULL\n\t},\n\t{\n\t\tNULL, NULL, NULL, NULL\n\t}\n};\n\nstatic PyArray_Descr @from@_Descr = { \n\tPyObject_HEAD_INIT(&PyArrayDescr_Type)\n\t&Py@NAME@ArrType_Type,\n\tPyArray_@from@LTR,\n\tPyArray_@from@LTR,\n\t'@endian@', 0,\n\tPyArray_@from@, 0,\n\t_ALIGN(@align@),\n\tNULL,\n\tNULL,\n\t&_Py@NAME@_ArrFuncs,\n};\n\n/**end repeat**/\n\n\n/**begin repeat\n\n#from= BOOL,BYTE,UBYTE,SHORT,USHORT,INT,UINT,LONG,ULONG,LONGLONG,ULONGLONG,FLOAT,DOUBLE,LONGDOUBLE,CFLOAT,CDOUBLE,CLONGDOUBLE,OBJECT#\n#num= 1*14,2*3,1#\n#fromtyp= Bool, byte, ubyte, short, ushort, int, uint, long, ulong, longlong, ulonglong, float, double, longdouble, float, double, longdouble, PyObject *#\n#NAME= Bool, Byte, UByte, Short, UShort, Int, UInt, Long, ULong, LongLong, ULongLong, Float, Double, LongDouble, CFloat, CDouble, CLongDouble, Object#\n#kind= GENBOOL, SIGNED, UNSIGNED, SIGNED, UNSIGNED, SIGNED, UNSIGNED, SIGNED, UNSIGNED, SIGNED, UNSIGNED, FLOATING, FLOATING, FLOATING, COMPLEX, COMPLEX, COMPLEX, OBJECT#\n#endian= |*3, =*14, |#\n#isobject= 0*17,1#\n*/\n\nstatic PyArray_ArrFuncs _Py@NAME@_ArrFuncs = {\n\t{\n\t\t(PyArray_VectorUnaryFunc*)@from@_to_BOOL, \n\t\t(PyArray_VectorUnaryFunc*)@from@_to_BYTE,\n\t\t(PyArray_VectorUnaryFunc*)@from@_to_UBYTE, \n\t\t(PyArray_VectorUnaryFunc*)@from@_to_SHORT, \n\t\t(PyArray_VectorUnaryFunc*)@from@_to_USHORT, \n\t\t(PyArray_VectorUnaryFunc*)@from@_to_INT, \n\t\t(PyArray_VectorUnaryFunc*)@from@_to_UINT, \n\t\t(PyArray_VectorUnaryFunc*)@from@_to_LONG,\n\t\t(PyArray_VectorUnaryFunc*)@from@_to_ULONG, \n\t\t(PyArray_VectorUnaryFunc*)@from@_to_LONGLONG, \n\t\t(PyArray_VectorUnaryFunc*)@from@_to_ULONGLONG, \n\t\t(PyArray_VectorUnaryFunc*)@from@_to_FLOAT, \n\t\t(PyArray_VectorUnaryFunc*)@from@_to_DOUBLE, \n\t\t(PyArray_VectorUnaryFunc*)@from@_to_LONGDOUBLE, \n\t\t(PyArray_VectorUnaryFunc*)@from@_to_CFLOAT, \n\t\t(PyArray_VectorUnaryFunc*)@from@_to_CDOUBLE, \n\t\t(PyArray_VectorUnaryFunc*)@from@_to_CLONGDOUBLE, \n\t\t(PyArray_VectorUnaryFunc*)@from@_to_OBJECT, \n\t\t(PyArray_VectorUnaryFunc*)@from@_to_STRING, \n\t\t(PyArray_VectorUnaryFunc*)@from@_to_UNICODE, \n\t\t(PyArray_VectorUnaryFunc*)@from@_to_VOID\n\t},\n\t(PyArray_GetItemFunc*)@from@_getitem, \n\t(PyArray_SetItemFunc*)@from@_setitem,\n\t(PyArray_CopySwapNFunc*)@from@_copyswapn,\n\t(PyArray_CopySwapFunc*)@from@_copyswap,\n\t(PyArray_CompareFunc*)@from@_compare, \n\t(PyArray_ArgFunc*)@from@_argmax,\n\t(PyArray_DotFunc*)@from@_dot, \n\t(PyArray_ScanFunc*)@from@_scan,\n\t(PyArray_FromStrFunc*)@from@_fromstr,\n\t(PyArray_NonzeroFunc*)@from@_nonzero,\n\t(PyArray_FillFunc*)@from@_fill,\n\t{\n\t\tNULL, NULL, NULL, NULL\n\t},\n\t{\n\t\tNULL, NULL, NULL, NULL\n\t}\n};\n\nstatic PyArray_Descr @from@_Descr = { \n\tPyObject_HEAD_INIT(&PyArrayDescr_Type)\n\t&Py@NAME@ArrType_Type,\n\tPyArray_@kind@LTR,\n\tPyArray_@from@LTR,\n\t'@endian@', @isobject@,\n\tPyArray_@from@, \n\t@num@*sizeof(@fromtyp@), \n\t_ALIGN(@fromtyp@),\n\tNULL,\n\tNULL,\n\t&_Py@NAME@_ArrFuncs,\n};\n\n/**end repeat**/\n\n#define _MAX_LETTER 128\nstatic char _letter_to_num[_MAX_LETTER];\n\nstatic PyArray_Descr *_builtin_descrs[] = {\n\t&BOOL_Descr,\n\t&BYTE_Descr,\n\t&UBYTE_Descr,\n\t&SHORT_Descr, \n\t&USHORT_Descr, \n\t&INT_Descr, \n\t&UINT_Descr, \n\t&LONG_Descr, \n\t&ULONG_Descr,\n\t&LONGLONG_Descr,\n\t&ULONGLONG_Descr,\n\t&FLOAT_Descr, \n\t&DOUBLE_Descr,\n\t&LONGDOUBLE_Descr,\n\t&CFLOAT_Descr, \n\t&CDOUBLE_Descr, \n\t&CLONGDOUBLE_Descr,\n\t&OBJECT_Descr, \n\t&STRING_Descr, \n\t&UNICODE_Descr,\n\t&VOID_Descr,\n};\n\n/*OBJECT_API\n Get the PyArray_Descr structure for a type.\n*/\nstatic PyArray_Descr *\nPyArray_DescrFromType(int type)\n{\n\tPyArray_Descr *ret=NULL;\n\n\tif (type < PyArray_NTYPES) {\n\t\tret = _builtin_descrs[type];\n\t}\n\telse if (type == PyArray_NOTYPE) {\n\t\t/* This needs to not raise an error so\n\t\t that PyArray_DescrFromType(PyArray_NOTYPE)\n\t\t works for backwards-compatible C-API \n\t\t*/\t\t\n\t\treturn NULL;\n\t}\n\telse if PyTypeNum_ISUSERDEF(type) {\n\t\tret = userdescrs[type-PyArray_USERDEF];\n\t} \n\telse {\n\t\tint num=PyArray_NTYPES;\n\t\tif (type < _MAX_LETTER) \n\t\t\tnum = (int) _letter_to_num[type];\n\t\tif (num >= PyArray_NTYPES)\n\t\t\tret = NULL;\n\t\telse\n\t\t\tret = _builtin_descrs[num];\n\t}\n\tif (ret==NULL) {\n\t\tPyErr_SetString(PyExc_ValueError, \n\t\t\t\t\"Invalid data-type for array\"); \n\t}\n\telse Py_INCREF(ret);\n\treturn ret;\n}\n\n\nstatic int\nset_typeinfo(PyObject *dict)\n{\n\tPyObject *infodict, *s;\n\tint i;\n\n\tfor (i=0; i<_MAX_LETTER; i++) {\n\t\t_letter_to_num[i] = PyArray_NTYPES;\n\t}\n\n/**begin repeat\n#name=BOOL,BYTE,UBYTE,SHORT,USHORT,INT,UINT,INTP,UINTP,LONG,ULONG,LONGLONG,ULONGLONG,FLOAT,DOUBLE,LONGDOUBLE,CFLOAT,CDOUBLE,CLONGDOUBLE,OBJECT,STRING,UNICODE,VOID#\n*/\n\t_letter_to_num[PyArray_@name@LTR] = PyArray_@name@;\n/**end repeat**/\n\t_letter_to_num[PyArray_STRINGLTR2] = PyArray_STRING;\n\n/**begin repeat\n#name=BOOL,BYTE,UBYTE,SHORT,USHORT,INT,UINT,LONG,ULONG,LONGLONG,ULONGLONG,FLOAT,DOUBLE,LONGDOUBLE,CFLOAT,CDOUBLE,CLONGDOUBLE,OBJECT,STRING,UNICODE,VOID#\n*/\n\t@name@_Descr.fields = Py_None;\n/**end repeat**/\n\t\n\t/* Set a dictionary with type information */\n\tinfodict = PyDict_New();\n\tif (infodict == NULL) return -1;\n\n#define BITSOF_INTP CHAR_BIT*SIZEOF_PY_INTPTR_T\n#define BITSOF_BYTE CHAR_BIT\n\n/**begin repeat \n\n#name=BOOL,BYTE,UBYTE,SHORT,USHORT,INT,UINT,INTP,UINTP,LONG,ULONG,LONGLONG,ULONGLONG#\n#uname=BOOL,BYTE*2,SHORT*2,INT*2,INTP*2,LONG*2,LONGLONG*2#\n#Name=Bool,Byte,UByte,Short,UShort,Int,UInt,Intp,UIntp,Long,ULong,LongLong,ULongLong#\n#type=Bool,byte,ubyte,short,ushort,int,uint,intp,uintp,long,ulong,longlong,ulonglong#\n#max=1,MAX_BYTE,MAX_UBYTE,MAX_SHORT,MAX_USHORT,MAX_INT,PyLong_FromUnsignedLong(MAX_UINT),PyLong_FromLongLong((longlong) MAX_INTP),PyLong_FromUnsignedLongLong((ulonglong) MAX_UINTP),MAX_LONG,PyLong_FromUnsignedLong((unsigned long) MAX_ULONG),PyLong_FromLongLong((longlong) MAX_LONGLONG), PyLong_FromUnsignedLongLong((ulonglong) MAX_ULONGLONG)#\n#min=0,MIN_BYTE,0,MIN_SHORT,0,MIN_INT,0,PyLong_FromLongLong((longlong) MIN_INTP),0,MIN_LONG,0,PyLong_FromLongLong((longlong) MIN_LONGLONG),0#\n#cx=i*6,N,N,N,l,N,N,N#\n#cn=i*7,N,i,l,i,N,i#\n*/\n \tPyDict_SetItemString(infodict, \"@name@\", \n\t\t\t s=Py_BuildValue(\"ciii@cx@@cn@O\", \n\t\t\t\t\t PyArray_@name@LTR, \n\t\t\t\t\t PyArray_@name@,\n\t\t\t\t\t BITSOF_@uname@,\n\t\t\t\t\t _ALIGN(@type@),\n\t\t\t\t\t @max@, @min@,\n\t\t\t\t (PyObject *)&Py@Name@ArrType_Type));\n\tPy_DECREF(s); \n/**end repeat**/\n\n#define BITSOF_CFLOAT 2*BITSOF_FLOAT\n#define BITSOF_CDOUBLE 2*BITSOF_DOUBLE\n#define BITSOF_CLONGDOUBLE 2*BITSOF_LONGDOUBLE\n\n/**begin repeat\n\n#type=float,double,longdouble,cfloat,cdouble,clongdouble#\n#name=FLOAT, DOUBLE, LONGDOUBLE, CFLOAT, CDOUBLE, CLONGDOUBLE#\n#Name=Float,Double,LongDouble,CFloat,CDouble,CLongDouble#\n*/\n \tPyDict_SetItemString(infodict, \"@name@\", \n\t\t\t s=Py_BuildValue(\"ciiiO\", PyArray_@name@LTR, \n\t\t\t\t\t PyArray_@name@, BITSOF_@name@,\n\t\t\t\t\t _ALIGN(@type@),\n (PyObject *)\\\n &Py@Name@ArrType_Type));\n\tPy_DECREF(s);\n/**end repeat**/\n\t\n\tPyDict_SetItemString(infodict, \"OBJECT\", \n\t\t\t s=Py_BuildValue(\"ciiiO\", PyArray_OBJECTLTR, \n\t\t\t\t\t PyArray_OBJECT, \n\t\t\t\t\t sizeof(PyObject *)*CHAR_BIT,\n\t\t\t\t\t _ALIGN(PyObject *),\n (PyObject *)\\\n &PyObjectArrType_Type));\n\tPy_DECREF(s);\n\tPyDict_SetItemString(infodict, \"STRING\", \n\t\t\t s=Py_BuildValue(\"ciiiO\", PyArray_STRINGLTR, \n\t\t\t\t\t PyArray_STRING, 0,\n\t\t\t\t\t _ALIGN(char),\n (PyObject *)\\\n &PyStringArrType_Type));\n\tPy_DECREF(s);\n\tPyDict_SetItemString(infodict, \"UNICODE\", \n\t\t\t s=Py_BuildValue(\"ciiiO\", PyArray_UNICODELTR, \n\t\t\t\t\t PyArray_UNICODE, 0,\n\t\t\t\t\t _ALIGN(PyArray_UCS4),\n (PyObject *)\\\n &PyUnicodeArrType_Type));\t\n\tPy_DECREF(s);\n\tPyDict_SetItemString(infodict, \"VOID\", \n\t\t\t s=Py_BuildValue(\"ciiiO\", PyArray_VOIDLTR, \n\t\t\t\t\t PyArray_VOID, 0,\n\t\t\t\t\t _ALIGN(char),\n (PyObject *)\\\n &PyVoidArrType_Type));\t\n\tPy_DECREF(s);\n\n#define SETTYPE(name) \\\n Py_INCREF(&Py##name##ArrType_Type); \\\n PyDict_SetItemString(infodict, #name, \\\n (PyObject *)&Py##name##ArrType_Type);\n\n SETTYPE(Generic)\n SETTYPE(Number)\n SETTYPE(Integer)\n\tSETTYPE(Inexact)\n SETTYPE(SignedInteger)\n SETTYPE(UnsignedInteger)\n SETTYPE(Floating)\n SETTYPE(ComplexFloating)\n SETTYPE(Flexible)\n SETTYPE(Character)\n\n#undef SETTYPE \t\n\n\tPyDict_SetItemString(dict, \"typeinfo\", infodict);\n\tPy_DECREF(infodict);\n\treturn 0;\n}\n\n#undef _MAX_LETTER\n\n", + "source_code_before": "/* -*- c -*- */\n\n/**begin repeat\n#name=UnsignedLong,UnsignedLongLong,LongLong#\n#type=ulong,ulonglong,longlong#\n */\nstatic @type@\nMyPyLong_As@name@(PyObject *vv)\n{\n\t@type@ ret;\n\n\tif (!PyLong_Check(vv)) {\n\t\tPyObject *mylong;\n\t\tmylong = PyNumber_Long(vv);\n\t\tif (mylong == NULL) return (@type@) -1;\n\t\tvv = mylong;\n\t}\n\telse Py_INCREF(vv);\n\n\tret = PyLong_As@name@(vv);\n\tPy_DECREF(vv);\n\treturn ret;\n}\n/**end repeat**/\n\n\nstatic double \n_getNAN(void) {\n#ifdef NAN\n return NAN;\n#else\n static double nan=0;\n \n if (nan == 0) {\n\t\tdouble mul = 1e100;\n\t\tdouble tmp = 0.0;\n\t\tdouble pinf=0;\n pinf = mul;\n for (;;) {\n pinf *= mul;\n if (pinf == tmp) break;\n tmp = pinf;\n }\n nan = pinf / pinf;\n }\n return nan;\n#endif\n}\n\nstatic double\nMyPyFloat_AsDouble(PyObject *obj)\n{\n if (obj == Py_None) return _getNAN();\n return PyFloat_AsDouble(obj); \n}\n\n\n/****************** getitem and setitem **********************/\n\n/**begin repeat\n\n#TYP=BOOL,BYTE,UBYTE,SHORT,USHORT,INT,LONG,UINT,ULONG,LONGLONG,ULONGLONG,FLOAT,DOUBLE#\n#func1=PyBool_FromLong, PyInt_FromLong*6, PyLong_FromUnsignedLong*2, PyLong_FromLongLong, PyLong_FromUnsignedLongLong, PyFloat_FromDouble*2#\n#func2=PyObject_IsTrue, PyInt_AsLong*6, MyPyLong_AsUnsignedLong*2, MyPyLong_AsLongLong, MyPyLong_AsUnsignedLongLong, MyPyFloat_AsDouble*2#\n#typ=Bool, byte, ubyte, short, ushort, int, long, uint, ulong, longlong, ulonglong, float, double#\n#typ1=long*7, ulong*2, longlong, ulonglong, float, double#\n#kind=Bool, Byte, UByte, Short, UShort, Int, Long, UInt, ULong, LongLong, ULongLong, Float, Double#\n*/\n\nstatic PyObject * \n@TYP@_getitem(char *ip, PyArrayObject *ap) {\n @typ@ t1;\n\n\tif ((ap==NULL) || PyArray_ISBEHAVED_RO(ap)) {\n t1 = *((@typ@ *)ip);\n return @func1@((@typ1@)t1);\n\t}\n\telse {\n ap->descr->f->copyswap(&t1, ip, !PyArray_ISNOTSWAPPED(ap),\n\t\t\t\t ap->descr->elsize);\n return @func1@((@typ1@)t1);\n\t}\n}\n\nstatic int \n@TYP@_setitem(PyObject *op, char *ov, PyArrayObject *ap) {\n @typ@ temp; /* ensures alignment */\n\n if (PyArray_IsScalar(op, @kind@)) {\n temp = ((Py@kind@ScalarObject *)op)->obval;\n }\n else {\n temp = (@typ@)@func2@(op);\n }\n if (PyErr_Occurred()) return -1;\n if (ap == NULL || PyArray_ISBEHAVED(ap)) \n *((@typ@ *)ov)=temp;\n else {\n ap->descr->f->copyswap(ov, &temp, !PyArray_ISNOTSWAPPED(ap), \n\t\t\t\t ap->descr->elsize);\n }\n \n return 0;\n}\n\n/**end repeat**/\n\n\n/**begin repeat \n\n#TYP=CFLOAT,CDOUBLE#\n#typ=float, double#\n*/\n\nstatic PyObject * \n@TYP@_getitem(char *ip, PyArrayObject *ap) {\n @typ@ t1, t2;\n\n if ((ap==NULL) || PyArray_ISBEHAVED_RO(ap)) { \n return PyComplex_FromDoubles((double)((@typ@ *)ip)[0], \n (double)((@typ@ *)ip)[1]);\n }\n else {\n\t\tint size = sizeof(@typ@);\n\t\tBool swap = !PyArray_ISNOTSWAPPED(ap);\n copy_and_swap(&t1, ip, size, 1, 0, swap);\n copy_and_swap(&t2, ip+size, size, 1, 0, swap);\n return PyComplex_FromDoubles((double)t1, (double)t2);\n }\n}\n/**end repeat**/\n\n/**begin repeat \n\n#TYP=CFLOAT, CDOUBLE, CLONGDOUBLE#\n#typ=float, double, longdouble#\n#kind=CFloat, CDouble, CLongDouble#\n*/\nstatic int \n@TYP@_setitem(PyObject *op, char *ov, PyArrayObject *ap) \n{\n Py_complex oop;\n PyObject *op2;\n c@typ@ temp;\n\tint rsize;\n \n if (!(PyArray_IsScalar(op, @kind@))) {\n if (PyArray_Check(op) && (PyArray_NDIM(op)==0)) {\n op2 = ((PyArrayObject *)op)->descr->f->getitem \\\n (((PyArrayObject *)op)->data, \n (PyArrayObject *)op);\n\t\t}\n\t\telse { \n op2 = op; Py_INCREF(op);\n }\n if (op2 == Py_None) {\n oop.real = oop.imag = _getNAN();\n }\n else {\n oop = PyComplex_AsCComplex (op2);\n }\n Py_DECREF(op2);\n if (PyErr_Occurred()) return -1;\n temp.real = (@typ@) oop.real;\n temp.imag = (@typ@) oop.imag; \n }\n\telse {\n temp = ((Py@kind@ScalarObject *)op)->obval;\n }\n\t\n memcpy(ov, &temp, ap->descr->elsize);\n if (!PyArray_ISNOTSWAPPED(ap))\n byte_swap_vector(ov, 2, sizeof(@typ@));\n\t\n\trsize = sizeof(@typ@);\n\tcopy_and_swap(ov, &temp, rsize, 2, rsize, !PyArray_ISNOTSWAPPED(ap));\n return 0;\n}\n/**end repeat**/\n\nstatic PyObject * \nLONGDOUBLE_getitem(char *ip, PyArrayObject *ap) \n{\n return PyArray_Scalar(ip, ap->descr, NULL);\n}\n\nstatic int \nLONGDOUBLE_setitem(PyObject *op, char *ov, PyArrayObject *ap) {\n longdouble temp; /* ensures alignment */\n\n if (PyArray_IsScalar(op, LongDouble)) {\n temp = ((PyLongDoubleScalarObject *)op)->obval;\n }\n else {\n if (op == Py_None) temp = (longdouble)_getNAN();\n else temp = (longdouble)PyFloat_AsDouble(op);\n }\n if (PyErr_Occurred()) return -1;\n if (ap == NULL || PyArray_ISBEHAVED(ap)) \n *((longdouble *)ov)=temp;\n else {\n copy_and_swap(ov, &temp, ap->descr->elsize, 1, 0,\n !PyArray_ISNOTSWAPPED(ap));\n }\n \n return 0;\n}\n\nstatic PyObject * \nCLONGDOUBLE_getitem(char *ip, PyArrayObject *ap) \n{\n return PyArray_Scalar(ip, ap->descr, NULL);\n}\n\n\n/* UNICODE */\nstatic PyObject * \nUNICODE_getitem(char *ip, PyArrayObject *ap) \n{\n\tPyObject *obj;\n\tint mysize;\n\tPyArray_UCS4 *dptr;\n\n\tmysize = ap->descr->elsize >> 2;\n\tdptr = (PyArray_UCS4 *)ip + mysize-1;\n\twhile(mysize > 0 && *dptr-- == 0) mysize--;\n\tif (!PyArray_ISNOTSWAPPED(ap) && (obj != NULL)) {\n\t\tbyte_swap_vector(PyArray_BYTES(ap), mysize, 4);\n\t}\n#ifdef Py_UNICODE_WIDE\n\tobj = PyUnicode_FromUnicode((const PyArray_UCS4 *)ip, mysize);\n#else\n\t/* create new empty unicode object of length mysize*2 */\n\tobj = MyPyUnicode_New(mysize*2);\n\tif (obj == NULL) return obj;\n\tmysize = PyUCS2Buffer_FromUCS4(((PyUnicodeObject *)obj)->str, \n\t\t\t\t (PyArray_UCS4 *)ip, mysize);\n\t/* reset length of unicode object to ucs2size */\n\tif (MyPyUnicode_Resize((PyUnicodeObject *)obj, mysize) < 0) {\n\t\tPy_DECREF(obj);\n\t\treturn NULL;\n\t}\n#endif\n\n\treturn obj;\n}\n\nstatic int \nUNICODE_setitem(PyObject *op, char *ov, PyArrayObject *ap) \n{\n PyObject *temp;\n\tPy_UNICODE *ptr;\n\tint datalen;\n\n\tif ((temp=PyObject_Unicode(op)) == NULL) return -1;\n\tptr = PyUnicode_AS_UNICODE(temp);\n\tif ((ptr == NULL) || (PyErr_Occurred())) {\n\t\tPy_DECREF(temp);\n\t\treturn -1;\n\t}\n\tdatalen = PyUnicode_GET_DATA_SIZE(temp);\n\n#ifdef Py_UNICODE_WIDE\n\tmemcpy(ov, ptr, MIN(ap->descr->elsize, datalen));\n#else\n datalen = PyUCS2Buffer_AsUCS4(ptr, (PyArray_UCS4 *)ov, datalen >> 1,\n\t\t\t\t ap->descr->elsize >> 2);\n\tdatalen <<= 2;\n#endif\n\t/* Fill in the rest of the space with 0 */\n\tif (ap->descr->elsize > datalen) {\n\t\tmemset(ov + datalen, 0, (ap->descr->elsize - datalen));\n\t}\n\t\n\tif (!PyArray_ISNOTSWAPPED(ap)) \n\t\tbyte_swap_vector(ov, ap->descr->elsize >> 2, 4);\n\tPy_DECREF(temp);\n\treturn 0;\n}\n\n/* STRING -- can handle both NULL-terminated and not NULL-terminated cases */\nstatic PyObject * \nSTRING_getitem(char *ip, PyArrayObject *ap) \n{\n\tif (ip[ap->descr->elsize-1])\n\t\treturn PyString_FromStringAndSize(ip,ap->descr->elsize);\n\telse\n\t\treturn PyString_FromString(ip);\n}\n\nstatic int \nSTRING_setitem(PyObject *op, char *ov, PyArrayObject *ap) \n{\n\tchar *ptr;\n\tint len;\n\tPyObject *temp=PyObject_Str(op);\n\t\n\tif (temp == NULL) return -1;\n\t\n\tif (PyString_AsStringAndSize(temp, &ptr, &len) == -1) {\n\t\tPy_DECREF(temp);\n\t\treturn -1;\n\t}\n\tmemcpy(ov, ptr, MIN(ap->descr->elsize,len));\n\tif (ap->descr->elsize > len) {\n\t\tmemset(ov + len, 0, (ap->descr->elsize - len));\n\t}\n\tPy_DECREF(temp);\n\treturn 0;\n}\n\n/* OBJECT */\n\nstatic PyObject * \nOBJECT_getitem(char *ip, PyArrayObject *ap) \n{\n\tPy_INCREF(*(PyObject **)ip);\n\treturn *(PyObject **)ip;\n}\n\nstatic int \nOBJECT_setitem(PyObject *op, char *ov, PyArrayObject *ap) \n{\n\tPy_XDECREF(*(PyObject **)ov);\n\tPy_INCREF(op);\n\t*(PyObject **)ov = op;\n\treturn PyErr_Occurred() ? -1:0;\n}\n\n/* VOID */\n\nstatic PyObject *\nVOID_getitem(char *ip, PyArrayObject *ap)\n{\n PyObject *u=NULL;\n\tPyArray_Descr* descr;\n int itemsize;\n\n\tdescr = ap->descr;\n\tif (descr->fields && descr->fields != Py_None) {\n\t\tPyObject *key;\n\t\tPyObject *names;\n\t\tint i, n;\n\t\tPyObject *ret;\n\t\tPyObject *tup, *title;\n\t\tPyArray_Descr *new;\n\t\tint offset;\n\t\tint savedflags;\n\n\t\t/* get the names from the fields dictionary*/\n\t\tkey = PyInt_FromLong(-1);\n\t\tnames = PyDict_GetItem(descr->fields, key);\n\t\tPy_DECREF(key);\n\t\tif (!names) goto finish;\n\t\tn = PyList_GET_SIZE(names);\n\t\tret = PyTuple_New(n);\n\t\tsavedflags = ap->flags;\n\t\tfor (i=0; ifields, key);\n\t\t\tif (!PyArg_ParseTuple(tup, \"Oi|O\", &new, &offset, \n\t\t\t\t\t &title)) {\n\t\t\t\tPy_DECREF(ret); \n\t\t\t\tap->descr = descr;\n\t\t\t\treturn NULL;\n\t\t\t}\n\t\t\tap->descr = new;\n\t\t\t/* update alignment based on offset */\n\t\t\tif ((new->alignment > 1) &&\t\t\t\\\n\t\t\t ((((intp)(ip+offset)) % new->alignment) != 0))\n\t\t\t\tap->flags &= ~ALIGNED;\n\t\t\telse\n\t\t\t\tap->flags |= ALIGNED;\n\n\t\t\tPyTuple_SET_ITEM(ret, i,\t\t\t\\\n\t\t\t\t\t new->f->getitem(ip+offset, ap));\n\t\t\tap->flags = savedflags;\n\t\t}\n\t\tap->descr = descr;\n\t\treturn ret;\n\t}\n\n\tif (descr->subarray) {\n\t\t/* return an array of the basic type */\n\t\tPyArray_Dims shape={NULL,-1};\n\t\tPyObject *ret;\n\t\tif (!(PyArray_IntpConverter(descr->subarray->shape, \n\t\t\t\t\t &shape))) {\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\treturn NULL;\n\t\t}\n Py_INCREF(descr->subarray->base);\n\t\tret = PyArray_NewFromDescr(&PyArray_Type,\n\t\t\t\t\t descr->subarray->base,\n\t\t\t\t\t shape.len, shape.ptr,\n\t\t\t\t\t NULL, ip, ap->flags, NULL);\n\t\tPyDimMem_FREE(shape.ptr);\n\t\tif (!ret) return NULL;\n\t\tPyArray_BASE(ret) = (PyObject *)ap;\n\t\tPy_INCREF(ap);\n\t\tPyArray_UpdateFlags((PyArrayObject *)ret, UPDATE_ALL_FLAGS);\n\t\treturn ret;\n\t}\n\n finish:\n\titemsize=ap->descr->elsize;\n\tif (PyArray_ISWRITEABLE(ap))\n\t\tu = PyBuffer_FromReadWriteMemory(ip, itemsize);\n\telse\n\t\tu = PyBuffer_FromMemory(ip, itemsize);\n\tif (u==NULL) goto fail;\n\n\t/* default is to return buffer object pointing to current item */\n\t/* a view of it */\n\treturn u; \n\t\n fail:\n return NULL;\n}\n\n\n\nstatic int PyArray_CopyObject(PyArrayObject *, PyObject *);\n\nstatic int\nVOID_setitem(PyObject *op, char *ip, PyArrayObject *ap)\n{\n\tPyArray_Descr* descr;\n int itemsize=ap->descr->elsize;\n\tint res;\n\n\tdescr = ap->descr;\n\tif (descr->fields && (descr->fields != Py_None) && \\\n\t PyTuple_Check(op)) {\n\t\tPyObject *key;\n\t\tPyObject *names;\n\t\tint i, n;\n\t\tPyObject *tup, *title;\n\t\tPyArray_Descr *new;\n\t\tint offset;\n\t\tint savedflags;\n\t\tres = -1;\n\t\t/* get the names from the fields dictionary*/\n\t\tkey = PyInt_FromLong(-1);\n\t\tnames = PyDict_GetItem(descr->fields, key);\n\t\tPy_DECREF(key);\n\t\tif (!names) goto finish;\n\t\tn = PyList_GET_SIZE(names);\n\t\tif (PyTuple_GET_SIZE(op) != n) {\n\t\t\tPyErr_SetString(PyExc_ValueError, \n\t\t\t\t\t\"size of tuple must match\"\\\n\t\t\t\t\t\"number of fields.\");\n\t\t\treturn -1;\n\t\t}\n\t\tsavedflags = ap->flags;\n\t\tfor (i=0; ifields, key);\n\t\t\tif (!PyArg_ParseTuple(tup, \"Oi|O\", &new, &offset, \n\t\t\t\t\t &title)) {\n\t\t\t\tap->descr = descr;\n\t\t\t\treturn -1;\n\t\t\t}\n\t\t\tap->descr = new;\n\t\t\t/* remember to update alignment flags */\n\t\t\tif ((new->alignment > 1) &&\t\t\t\\\n\t\t\t ((((intp)(ip+offset)) % new->alignment) != 0))\n\t\t\t\tap->flags &= ~ALIGNED;\n\t\t\telse\n\t\t\t\tap->flags |= ALIGNED;\n\n\t\t\tres = new->f->setitem(PyTuple_GET_ITEM(op, i),\n\t\t\t\t\t ip+offset, ap);\n\t\t\tap->flags = savedflags;\n\t\t\tif (res < 0) break;\n\t\t}\n\t\tap->descr = descr;\n\t\treturn res;\n\t}\n\n\tif (descr->subarray) {\n\t\t/* copy into an array of the same basic type */\n\t\tPyArray_Dims shape={NULL,-1};\n\t\tPyObject *ret;\n\t\tif (!(PyArray_IntpConverter(descr->subarray->shape, \n\t\t\t\t\t &shape))) {\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\treturn -1;\n\t\t}\n Py_INCREF(descr->subarray->base);\n\t\tret = PyArray_NewFromDescr(&PyArray_Type,\n\t\t\t\t\t descr->subarray->base,\n\t\t\t\t\t shape.len, shape.ptr,\n\t\t\t\t\t NULL, ip, ap->flags, NULL);\n\t\tPyDimMem_FREE(shape.ptr);\n\t\tif (!ret) return -1;\n\t\tPyArray_BASE(ret) = (PyObject *)ap;\n\t\tPy_INCREF(ap);\n\t\tPyArray_UpdateFlags((PyArrayObject *)ret, UPDATE_ALL_FLAGS);\n\t\tres = PyArray_CopyObject((PyArrayObject *)ret, op);\n\t\tPy_DECREF(ret);\n\t\treturn res;\n\t}\n\n finish:\n\t/* Default is to use buffer interface to set item */\n\t{\n\t\tconst void *buffer;\n\t\tint buflen;\n\t\tres = PyObject_AsReadBuffer(op, &buffer, &buflen);\n\t\tif (res == -1) goto fail;\n\t\tmemcpy(ip, buffer, MIN(buflen, itemsize));\n }\n\treturn 0;\n\n fail:\n return -1; \n}\n\n\n/****************** XXX_to_YYY *******************************/ \n\n/* Assumes contiguous, and aligned, from and to */\n\n\n/**begin repeat\n#to=(BYTE,UBYTE,SHORT,USHORT,INT,UINT,LONG,ULONG,LONGLONG,ULONGLONG,FLOAT,DOUBLE,LONGDOUBLE)*16#\n#from=BYTE*13,UBYTE*13,SHORT*13,USHORT*13,INT*13,UINT*13,LONG*13,ULONG*13,LONGLONG*13,ULONGLONG*13,FLOAT*13,DOUBLE*13,LONGDOUBLE*13,CFLOAT*13,CDOUBLE*13,CLONGDOUBLE*13#\n#totyp=(byte, ubyte, short, ushort, int, uint, long, ulong, longlong, ulonglong, float, double, longdouble)*16#\n#fromtyp=byte*13, ubyte*13, short*13, ushort*13, int*13, uint*13, long*13, ulong*13, longlong*13, ulonglong*13, float*13, double*13, longdouble*13, float*13, double*13, longdouble*13#\n#incr= ip++*169,ip+=2*39#\n*/\nstatic void \n@from@_to_@to@(@fromtyp@ *ip, @totyp@ *op, intp n, PyArrayObject *aip, \n\t PyArrayObject *aop) {\n\tregister intp i; \n\tfor(i=0;idescr->elsize*3, 1#\n*/\nstatic void \n@from@_to_OBJECT(@fromtyp@ *ip, PyObject **op, intp n, PyArrayObject *aip,\n\t\t PyArrayObject *aop)\n{\n\tregister intp i; \n\tint skip=@skip@;\n\tfor(i=0;idescr->elsize*3#\n*/\nstatic void \nOBJECT_to_@to@(PyObject **ip, @totyp@ *op, intp n, PyArrayObject *aip,\n\t\t PyArrayObject *aop)\n{\n\tregister intp i; \n\tint skip=@skip@;\n\tfor(i=0;idescr->elsize*3)*3#\n#convert=1*17,0*3,1*17,0*3,0*20#\n#convstr=(Int*9,Long*2,Float*3,Complex*3,Tuple*3)*3#\n*/\nstatic void\n@from@_to_@to@(@fromtyp@ *ip, @totyp@ *op, intp n, PyArrayObject *aip, \n\t PyArrayObject *aop)\n{\n\tregister intp i;\n\tPyObject *temp=NULL;\n\tint skip=aip->descr->elsize;\n\tint oskip=@oskip@;\n\tfor(i=0; idescr->elsize;\n\tfor(i=0; i= 0x02040000) || defined(PyOS_ascii_strtod)\nstatic int\n@fname@_fromstr(char *str, @type@ *ip, char **endptr, void *ignore)\n{\n\tdouble result;\n\n\tresult = PyOS_ascii_strtod(str, endptr);\n\t*ip = (@type@) result;\n\treturn 0;\n}\n#else\n#define @fname@_fromstr NULL\n#endif\n/**end repeat**/\n\n\n\n/**begin repeat\n#fname=BOOL,CFLOAT,CDOUBLE,CLONGDOUBLE,OBJECT,STRING,UNICODE,VOID#\n*/\n#define @fname@_fromstr NULL\n/**end repeat**/\n\n\n/****************** copyswapn *************************************/\n\n/**begin repeat\n\n#fname=SHORT,USHORT,INT,UINT,LONG,ULONG,LONGLONG,ULONGLONG,FLOAT,DOUBLE,LONGDOUBLE#\n#fsize=SHORT,SHORT,INT,INT,LONG,LONG,LONGLONG,LONGLONG,FLOAT,DOUBLE,LONGDOUBLE#\n#type=short,ushort,int,uint,long,ulong,longlong,ulonglong,float,double,longdouble#\n*/\nstatic void\n@fname@_copyswapn (void *dst, void *src, intp n, int swap, int itemsize)\n{\n\tif (src != NULL) /* copy first if needed */\n\t\tmemcpy(dst, src, n*sizeof(@type@));\n\n\tif (swap) {\n\t\tregister char *a, *b, c;\n\t\tfor (a = (char *)dst; n>0; n--) {\n#if SIZEOF_@fsize@ == 2\n\t\t\tb = a + 1;\n\t\t\tc = *a; *a++ = *b; *b = c;\n\t\t\ta += 1;\n#elif SIZEOF_@fsize@ == 4\n\t\t\tb = a + 3;\n c = *a; *a++ = *b; *b-- = c;\n c = *a; *a++ = *b; *b = c;\n\t\t\ta += 2;\n#elif SIZEOF_@fsize@ == 8\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\t\t\ta += 4;\n#elif SIZEOF_@fsize@ == 10\n b = a + 9;\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 c = *a; *a++ = *b; *b = c;\n\t\t\ta += 5;\n#elif SIZEOF_@fsize@ == 12\n b = a + 11;\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 c = *a; *a++ = *b; *b-- = c;\n c = *a; *a++ = *b; *b = c;\n\t\t\ta += 6;\n#elif SIZEOF_@fsize@ == 16\n b = a + 15;\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 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\t\t\ta += 8;\n#else\n\t\t\tregister int i, nn;\n b = a + (SIZEOF_@fsize@-1);\n\t\t\tnn = SIZEOF_@fsize@ / 2;\n for (i=0; i0; nn--) {\n#if SIZEOF_@fsize@ == 4\n\t\t\tb = a + 3;\n c = *a; *a++ = *b; *b-- = c;\n c = *a; *a++ = *b; *b = c;\n\t\t\ta += 2;\n#elif SIZEOF_@fsize@ == 8\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\t\t\ta += 4;\n#elif SIZEOF_@fsize@ == 10\n b = a + 9;\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 c = *a; *a++ = *b; *b = c;\n\t\t\ta += 5;\n#elif SIZEOF_@fsize@ == 12\n b = a + 11;\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 c = *a; *a++ = *b; *b-- = c;\n c = *a; *a++ = *b; *b = c;\n\t\t\ta += 6;\n#elif SIZEOF_@fsize@ == 16\n b = a + 15;\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 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\t\t\ta += 8;\n#else\n\t\t\tregister int i, kn;\n\n b = a + (SIZEOF_@fsize@-1);\n\t\t\tkn = SIZEOF_@fsize@ / 2;\n for (i=0; i0; n--) {\n\t\t\tb = a + 3;\n\t\t\tc=*a; *a++ = *b; *b-- = c;\n\t\t\tc=*a; *a++ = *b; *b-- = c;\n\t\t\ta += 1;\n\t\t}\n\t}\n}\n\n\nstatic void\nOBJECT_copyswap (PyObject **dst, PyObject **src, int swap, int itemsize)\n{\n OBJECT_copyswapn(dst, src, 1, swap, itemsize);\n}\n\nstatic void\nSTRING_copyswap (char *dst, char *src, int swap, int itemsize)\n{\n\tif (src != NULL) \n\t\tmemcpy(dst, src, itemsize);\n\t\n}\n\n/* ignore swap */\nstatic void\nVOID_copyswap (char *dst, char *src, int swap, int itemsize)\n{\n\tif (src != NULL) \n\t\tmemcpy(dst, src, itemsize);\t\n\treturn;\n}\n\nstatic void\nUNICODE_copyswap (char *dst, char *src, int swap, int itemsize)\n{\n\n\tif (src != NULL) \n\t\tmemcpy(dst, src, itemsize);\n\t\n\tif (swap) {\n\t\tregister char *a, *b, c;\n a = (char *)dst;\n b = a + 3;\n\t\tc=*a; *a++ = *b; *b-- = c;\n\t\tc=*a; *a++ = *b; *b-- = c;\n\t}\n}\n\n\n/****************** nonzero **********************************/\n\n/**begin repeat\n#fname=BOOL,BYTE,UBYTE,SHORT,USHORT,INT,UINT,LONG,ULONG,LONGLONG,ULONGLONG,FLOAT,DOUBLE,LONGDOUBLE#\n#type=Bool, byte, ubyte, short, ushort, int, uint, long, ulong, longlong, ulonglong, float, double, longdouble#\n*/\nstatic Bool \n@fname@_nonzero (@type@ *ip, PyArrayObject *ap)\n{\n\t@type@ t1;\n\tif (ap==NULL || PyArray_ISBEHAVED_RO(ap))\n\t\treturn (Bool) (*ip != 0);\n\telse {\n\t\t/* don't worry about swap, since we are just testing\n\t\t whether or not equal to 0 */\n\t\tmemcpy(&t1, ip, sizeof(@type@));\n\t\treturn (Bool) (t1 != 0);\n\t}\n}\n/**end repeat**/\n\n/**begin repeat\n#fname=CFLOAT,CDOUBLE,CLONGDOUBLE#\n#type=cfloat, cdouble, clongdouble#\n*/\nstatic Bool \n@fname@_nonzero (@type@ *ip, PyArrayObject *ap)\n{\n\t@type@ t1;\n\tif (ap==NULL || PyArray_ISBEHAVED_RO(ap))\n\t\treturn (Bool) ((ip->real != 0) || (ip->imag != 0));\n\telse {\n\t\t/* don't worry about swap, since we are just testing\n\t\t whether or not equal to 0 */\n\t\tmemcpy(&t1, ip, sizeof(@type@));\n\t\treturn (Bool) ((t1.real != 0) || (t1.imag != 0));\n\t}\n}\n/**end repeat**/\n\n\n\n#define WHITESPACE \" \\t\\n\\r\\v\\f\"\n#define WHITELEN 6\n\nstatic Bool\nPy_STRING_ISSPACE(char ch) \n{\n\tchar white[] = WHITESPACE;\n\tint j;\n\tBool space=FALSE;\n\tfor (j=0; jdescr->elsize;\n\tint i;\n\tBool nonz = FALSE;\n\n\tfor (i=0; idescr->elsize >> 2;\n\tint i;\n\tBool nonz = FALSE;\n\tchar *buffer=NULL;\t\n\n\tif ((!PyArray_ISNOTSWAPPED(ap)) || \\\n\t (!PyArray_ISALIGNED(ap))) {\n\t\tbuffer = _pya_malloc(ap->descr->elsize);\n\t\tif (buffer == NULL) {\n\t\t\treturn nonz;\n\t\t}\n\t\tmemcpy(buffer, ip, ap->descr->elsize);\n\t\tif (!PyArray_ISNOTSWAPPED(ap)) {\n\t\t\tbyte_swap_vector(buffer, len, 4);\n\t\t}\n\t\tip = (PyArray_UCS4 *)buffer;\n\t}\n\n\tfor (i=0; idescr->elsize;\n\tBool nonz = FALSE;\n\t\n\tfor (i=0; idescr->elsize);\n}\n\n/* taken from Python */\nstatic int \nUNICODE_compare(register PyArray_UCS4 *ip1, register PyArray_UCS4 *ip2, \n\t\tPyArrayObject *ap)\n{\n register int itemsize=ap->descr->elsize;\n\tregister PyArray_UCS4 c1, c2;\n\n\tif (itemsize < 0) return 0;\n\t\n\twhile(itemsize-- > 0) {\n\t\tc1 = *ip1++;\n\t\tc2 = *ip2++;\n\t\t\n\t\tif (c1 != c2) \n\t\t\treturn (c1 < c2) ? -1 : 1;\n\t}\n\treturn 0;\n}\n\n/* possibly redefine compare in terms of fields and subarrays if any */\n\n/* as it is, it compares raw-bytes as it they were strings */\n#define VOID_compare STRING_compare\n\n/****************** argfunc **********************************/\n\n/**begin repeat\n\n#fname= BOOL,BYTE, UBYTE, SHORT, USHORT, INT, UINT, LONG, ULONG, LONGLONG, ULONGLONG, FLOAT, DOUBLE, LONGDOUBLE, CFLOAT, CDOUBLE, CLONGDOUBLE#\n#type= Bool, byte, ubyte, short, ushort, int, uint, long, ulong, longlong, ulonglong, float, double, longdouble, float, double, longdouble#\n#incr= ip++*14, ip+=2*3#\n*/\n\nstatic int\n@fname@_argmax(@type@ *ip, intp n, intp *max_ind, PyArrayObject *aip)\n{\n\tregister intp i;\n\t@type@ mp=*ip;\n\t*max_ind=0;\n\tfor (i=1; i mp) {\n\t\t\tmp = *ip;\n\t\t\t*max_ind = i;\n\t\t}\n\t}\n\treturn 0;\n}\n\n/**end repeat**/\n\nstatic int \nOBJECT_argmax(PyObject **ip, intp n, intp *max_ind, PyArrayObject *aip) \n{\n\tregister intp i; \n\tPyObject *mp=ip[0]; *max_ind=0;\n\tfor(i=1; i 0) { \n\t\t\tmp = *ip; \n\t\t\t*max_ind=i;\n\t\t} \n\t} \n\treturn 0;\n}\n\n/**begin repeat\n\n#fname= STRING, UNICODE#\n#type= char, PyArray_UCS4#\n\n*/\nstatic int \n@fname@_argmax(@type@ *ip, intp n, intp *max_ind, PyArrayObject *aip) \n{\n\tregister intp i; \n\tint elsize = aip->descr->elsize;\n\t@type@ *mp = (@type@ *)_pya_malloc(elsize);\n\t\n\tif (mp==NULL) return 0;\n\tmemcpy(mp, ip, elsize);\n\t*max_ind = 0;\n\tfor(i=1; i 0) { \n\t\t\tmemcpy(mp, ip, elsize);\n\t\t\t*max_ind=i;\n\t\t} \n\t} \n\t_pya_free(mp);\n\treturn 0;\n}\n\n/**end repeat**/\n\n#define VOID_argmax NULL\n\nstatic void\nBOOL_dot(char *ip1, intp is1, char *ip2, intp is2, char *op, intp n, \n void *ignore)\n{\n\tregister Bool tmp=FALSE;\n\tregister intp i;\n\tfor(i=0;ireal;\n\tstart.imag = buffer->imag;\n\tdelta.real = buffer[1].real;\n\tdelta.imag = buffer[1].imag;\n\tdelta.real -= start.real;\n\tdelta.imag -= start.imag;\n\tbuffer += 2;\n\tfor (i=2; ireal = start.real + i*delta.real;\n\t\tbuffer->imag = start.imag + i*delta.imag;\n\t}\n}\n/**end repeat**/\n\n\n#define _ALIGN(type) offsetof(struct {char c; type v;},v)\n\n/**begin repeat\n\n#from= VOID, STRING, UNICODE#\n#align= char, char, PyArray_UCS4#\n#NAME= Void, String, Unicode#\n#endian= |, |, =#\n*/\n\nstatic PyArray_ArrFuncs _Py@NAME@_ArrFuncs = {\n\t{\n\t\t(PyArray_VectorUnaryFunc*)@from@_to_BOOL, \n\t\t(PyArray_VectorUnaryFunc*)@from@_to_BYTE, \n\t\t(PyArray_VectorUnaryFunc*)@from@_to_UBYTE, \n\t\t(PyArray_VectorUnaryFunc*)@from@_to_SHORT, \n\t\t(PyArray_VectorUnaryFunc*)@from@_to_USHORT, \n\t\t(PyArray_VectorUnaryFunc*)@from@_to_INT, \n\t\t(PyArray_VectorUnaryFunc*)@from@_to_UINT, \n\t\t(PyArray_VectorUnaryFunc*)@from@_to_LONG,\n\t\t(PyArray_VectorUnaryFunc*)@from@_to_ULONG, \n\t\t(PyArray_VectorUnaryFunc*)@from@_to_LONGLONG, \n\t\t(PyArray_VectorUnaryFunc*)@from@_to_ULONGLONG, \n\t\t(PyArray_VectorUnaryFunc*)@from@_to_FLOAT, \n\t\t(PyArray_VectorUnaryFunc*)@from@_to_DOUBLE, \n\t\t(PyArray_VectorUnaryFunc*)@from@_to_LONGDOUBLE, \n\t\t(PyArray_VectorUnaryFunc*)@from@_to_CFLOAT, \n\t\t(PyArray_VectorUnaryFunc*)@from@_to_CDOUBLE, \n\t\t(PyArray_VectorUnaryFunc*)@from@_to_CLONGDOUBLE, \n\t\t(PyArray_VectorUnaryFunc*)@from@_to_OBJECT, \n\t\t(PyArray_VectorUnaryFunc*)@from@_to_STRING, \n\t\t(PyArray_VectorUnaryFunc*)@from@_to_UNICODE, \n\t\t(PyArray_VectorUnaryFunc*)@from@_to_VOID\n\t},\n\t(PyArray_GetItemFunc*)@from@_getitem, \n\t(PyArray_SetItemFunc*)@from@_setitem,\n\t(PyArray_CopySwapNFunc*)@from@_copyswapn,\n\t(PyArray_CopySwapFunc*)@from@_copyswap,\n\t(PyArray_CompareFunc*)@from@_compare, \n\t(PyArray_ArgFunc*)@from@_argmax,\n\t(PyArray_DotFunc*)NULL, \n\t(PyArray_ScanFunc*)@from@_scan,\n\t(PyArray_FromStrFunc*)@from@_fromstr,\n\t(PyArray_NonzeroFunc*)@from@_nonzero,\n\t(PyArray_FillFunc*)NULL,\n\t{\n\t\tNULL, NULL, NULL, NULL\n\t},\n\t{\n\t\tNULL, NULL, NULL, NULL\n\t}\n};\n\nstatic PyArray_Descr @from@_Descr = { \n\tPyObject_HEAD_INIT(&PyArrayDescr_Type)\n\t&Py@NAME@ArrType_Type,\n\tPyArray_@from@LTR,\n\tPyArray_@from@LTR,\n\t'@endian@', 0,\n\tPyArray_@from@, 0,\n\t_ALIGN(@align@),\n\tNULL,\n\tNULL,\n\t&_Py@NAME@_ArrFuncs,\n};\n\n/**end repeat**/\n\n\n/**begin repeat\n\n#from= BOOL,BYTE,UBYTE,SHORT,USHORT,INT,UINT,LONG,ULONG,LONGLONG,ULONGLONG,FLOAT,DOUBLE,LONGDOUBLE,CFLOAT,CDOUBLE,CLONGDOUBLE,OBJECT#\n#num= 1*14,2*3,1#\n#fromtyp= Bool, byte, ubyte, short, ushort, int, uint, long, ulong, longlong, ulonglong, float, double, longdouble, float, double, longdouble, PyObject *#\n#NAME= Bool, Byte, UByte, Short, UShort, Int, UInt, Long, ULong, LongLong, ULongLong, Float, Double, LongDouble, CFloat, CDouble, CLongDouble, Object#\n#kind= GENBOOL, SIGNED, UNSIGNED, SIGNED, UNSIGNED, SIGNED, UNSIGNED, SIGNED, UNSIGNED, SIGNED, UNSIGNED, FLOATING, FLOATING, FLOATING, COMPLEX, COMPLEX, COMPLEX, OBJECT#\n#endian= |*3, =*14, |#\n#isobject= 0*17,1#\n*/\n\nstatic PyArray_ArrFuncs _Py@NAME@_ArrFuncs = {\n\t{\n\t\t(PyArray_VectorUnaryFunc*)@from@_to_BOOL, \n\t\t(PyArray_VectorUnaryFunc*)@from@_to_BYTE,\n\t\t(PyArray_VectorUnaryFunc*)@from@_to_UBYTE, \n\t\t(PyArray_VectorUnaryFunc*)@from@_to_SHORT, \n\t\t(PyArray_VectorUnaryFunc*)@from@_to_USHORT, \n\t\t(PyArray_VectorUnaryFunc*)@from@_to_INT, \n\t\t(PyArray_VectorUnaryFunc*)@from@_to_UINT, \n\t\t(PyArray_VectorUnaryFunc*)@from@_to_LONG,\n\t\t(PyArray_VectorUnaryFunc*)@from@_to_ULONG, \n\t\t(PyArray_VectorUnaryFunc*)@from@_to_LONGLONG, \n\t\t(PyArray_VectorUnaryFunc*)@from@_to_ULONGLONG, \n\t\t(PyArray_VectorUnaryFunc*)@from@_to_FLOAT, \n\t\t(PyArray_VectorUnaryFunc*)@from@_to_DOUBLE, \n\t\t(PyArray_VectorUnaryFunc*)@from@_to_LONGDOUBLE, \n\t\t(PyArray_VectorUnaryFunc*)@from@_to_CFLOAT, \n\t\t(PyArray_VectorUnaryFunc*)@from@_to_CDOUBLE, \n\t\t(PyArray_VectorUnaryFunc*)@from@_to_CLONGDOUBLE, \n\t\t(PyArray_VectorUnaryFunc*)@from@_to_OBJECT, \n\t\t(PyArray_VectorUnaryFunc*)@from@_to_STRING, \n\t\t(PyArray_VectorUnaryFunc*)@from@_to_UNICODE, \n\t\t(PyArray_VectorUnaryFunc*)@from@_to_VOID\n\t},\n\t(PyArray_GetItemFunc*)@from@_getitem, \n\t(PyArray_SetItemFunc*)@from@_setitem,\n\t(PyArray_CopySwapNFunc*)@from@_copyswapn,\n\t(PyArray_CopySwapFunc*)@from@_copyswap,\n\t(PyArray_CompareFunc*)@from@_compare, \n\t(PyArray_ArgFunc*)@from@_argmax,\n\t(PyArray_DotFunc*)@from@_dot, \n\t(PyArray_ScanFunc*)@from@_scan,\n\t(PyArray_FromStrFunc*)@from@_fromstr,\n\t(PyArray_NonzeroFunc*)@from@_nonzero,\n\t(PyArray_FillFunc*)@from@_fill,\n\t{\n\t\tNULL, NULL, NULL, NULL\n\t},\n\t{\n\t\tNULL, NULL, NULL, NULL\n\t}\n};\n\nstatic PyArray_Descr @from@_Descr = { \n\tPyObject_HEAD_INIT(&PyArrayDescr_Type)\n\t&Py@NAME@ArrType_Type,\n\tPyArray_@kind@LTR,\n\tPyArray_@from@LTR,\n\t'@endian@', @isobject@,\n\tPyArray_@from@, \n\t@num@*sizeof(@fromtyp@), \n\t_ALIGN(@fromtyp@),\n\tNULL,\n\tNULL,\n\t&_Py@NAME@_ArrFuncs,\n};\n\n/**end repeat**/\n\n#define _MAX_LETTER 128\nstatic char _letter_to_num[_MAX_LETTER];\n\nstatic PyArray_Descr *_builtin_descrs[] = {\n\t&BOOL_Descr,\n\t&BYTE_Descr,\n\t&UBYTE_Descr,\n\t&SHORT_Descr, \n\t&USHORT_Descr, \n\t&INT_Descr, \n\t&UINT_Descr, \n\t&LONG_Descr, \n\t&ULONG_Descr,\n\t&LONGLONG_Descr,\n\t&ULONGLONG_Descr,\n\t&FLOAT_Descr, \n\t&DOUBLE_Descr,\n\t&LONGDOUBLE_Descr,\n\t&CFLOAT_Descr, \n\t&CDOUBLE_Descr, \n\t&CLONGDOUBLE_Descr,\n\t&OBJECT_Descr, \n\t&STRING_Descr, \n\t&UNICODE_Descr,\n\t&VOID_Descr,\n};\n\n/*OBJECT_API\n Get the PyArray_Descr structure for a type.\n*/\nstatic PyArray_Descr *\nPyArray_DescrFromType(int type)\n{\n\tPyArray_Descr *ret=NULL;\n\n\tif (type < PyArray_NTYPES) {\n\t\tret = _builtin_descrs[type];\n\t}\n\telse if (type == PyArray_NOTYPE) {\n\t\t/* This needs to not raise an error so\n\t\t that PyArray_DescrFromType(PyArray_NOTYPE)\n\t\t works for backwards-compatible C-API \n\t\t*/\t\t\n\t\treturn NULL;\n\t}\n\telse if PyTypeNum_ISUSERDEF(type) {\n\t\tret = userdescrs[type-PyArray_USERDEF];\n\t} \n\telse {\n\t\tint num=PyArray_NTYPES;\n\t\tif (type < _MAX_LETTER) \n\t\t\tnum = (int) _letter_to_num[type];\n\t\tif (num >= PyArray_NTYPES)\n\t\t\tret = NULL;\n\t\telse\n\t\t\tret = _builtin_descrs[num];\n\t}\n\tif (ret==NULL) {\n\t\tPyErr_SetString(PyExc_ValueError, \n\t\t\t\t\"Invalid data-type for array\"); \n\t}\n\telse Py_INCREF(ret);\n\treturn ret;\n}\n\n\nstatic int\nset_typeinfo(PyObject *dict)\n{\n\tPyObject *infodict, *s;\n\tint i;\n\n\tfor (i=0; i<_MAX_LETTER; i++) {\n\t\t_letter_to_num[i] = PyArray_NTYPES;\n\t}\n\n/**begin repeat\n#name=BOOL,BYTE,UBYTE,SHORT,USHORT,INT,UINT,INTP,UINTP,LONG,ULONG,LONGLONG,ULONGLONG,FLOAT,DOUBLE,LONGDOUBLE,CFLOAT,CDOUBLE,CLONGDOUBLE,OBJECT,STRING,UNICODE,VOID#\n*/\n\t_letter_to_num[PyArray_@name@LTR] = PyArray_@name@;\n/**end repeat**/\n\t_letter_to_num[PyArray_STRINGLTR2] = PyArray_STRING;\n\n/**begin repeat\n#name=BOOL,BYTE,UBYTE,SHORT,USHORT,INT,UINT,LONG,ULONG,LONGLONG,ULONGLONG,FLOAT,DOUBLE,LONGDOUBLE,CFLOAT,CDOUBLE,CLONGDOUBLE,OBJECT,STRING,UNICODE,VOID#\n*/\n\t@name@_Descr.fields = Py_None;\n/**end repeat**/\n\t\n\t/* Set a dictionary with type information */\n\tinfodict = PyDict_New();\n\tif (infodict == NULL) return -1;\n\n#define BITSOF_INTP CHAR_BIT*SIZEOF_PY_INTPTR_T\n#define BITSOF_BYTE CHAR_BIT\n\n/**begin repeat \n\n#name=BOOL,BYTE,UBYTE,SHORT,USHORT,INT,UINT,INTP,UINTP,LONG,ULONG,LONGLONG,ULONGLONG#\n#uname=BOOL,BYTE*2,SHORT*2,INT*2,INTP*2,LONG*2,LONGLONG*2#\n#Name=Bool,Byte,UByte,Short,UShort,Int,UInt,Intp,UIntp,Long,ULong,LongLong,ULongLong#\n#type=Bool,byte,ubyte,short,ushort,int,uint,intp,uintp,long,ulong,longlong,ulonglong#\n#max=1,MAX_BYTE,MAX_UBYTE,MAX_SHORT,MAX_USHORT,MAX_INT,PyLong_FromUnsignedLong(MAX_UINT),PyLong_FromLongLong((longlong) MAX_INTP),PyLong_FromUnsignedLongLong((ulonglong) MAX_UINTP),MAX_LONG,PyLong_FromUnsignedLong((unsigned long) MAX_ULONG),PyLong_FromLongLong((longlong) MAX_LONGLONG), PyLong_FromUnsignedLongLong((ulonglong) MAX_ULONGLONG)#\n#min=0,MIN_BYTE,0,MIN_SHORT,0,MIN_INT,0,PyLong_FromLongLong((longlong) MIN_INTP),0,MIN_LONG,0,PyLong_FromLongLong((longlong) MIN_LONGLONG),0#\n#cx=i*6,N,N,N,l,N,N,N#\n#cn=i*7,N,i,l,i,N,i#\n*/\n \tPyDict_SetItemString(infodict, \"@name@\", \n\t\t\t s=Py_BuildValue(\"ciii@cx@@cn@O\", \n\t\t\t\t\t PyArray_@name@LTR, \n\t\t\t\t\t PyArray_@name@,\n\t\t\t\t\t BITSOF_@uname@,\n\t\t\t\t\t _ALIGN(@type@),\n\t\t\t\t\t @max@, @min@,\n\t\t\t\t (PyObject *)&Py@Name@ArrType_Type));\n\tPy_DECREF(s); \n/**end repeat**/\n\n#define BITSOF_CFLOAT 2*BITSOF_FLOAT\n#define BITSOF_CDOUBLE 2*BITSOF_DOUBLE\n#define BITSOF_CLONGDOUBLE 2*BITSOF_LONGDOUBLE\n\n/**begin repeat\n\n#type=float,double,longdouble,cfloat,cdouble,clongdouble#\n#name=FLOAT, DOUBLE, LONGDOUBLE, CFLOAT, CDOUBLE, CLONGDOUBLE#\n#Name=Float,Double,LongDouble,CFloat,CDouble,CLongDouble#\n*/\n \tPyDict_SetItemString(infodict, \"@name@\", \n\t\t\t s=Py_BuildValue(\"ciiiO\", PyArray_@name@LTR, \n\t\t\t\t\t PyArray_@name@, BITSOF_@name@,\n\t\t\t\t\t _ALIGN(@type@),\n (PyObject *)\\\n &Py@Name@ArrType_Type));\n\tPy_DECREF(s);\n/**end repeat**/\n\t\n\tPyDict_SetItemString(infodict, \"OBJECT\", \n\t\t\t s=Py_BuildValue(\"ciiiO\", PyArray_OBJECTLTR, \n\t\t\t\t\t PyArray_OBJECT, \n\t\t\t\t\t sizeof(PyObject *)*CHAR_BIT,\n\t\t\t\t\t _ALIGN(PyObject *),\n (PyObject *)\\\n &PyObjectArrType_Type));\n\tPy_DECREF(s);\n\tPyDict_SetItemString(infodict, \"STRING\", \n\t\t\t s=Py_BuildValue(\"ciiiO\", PyArray_STRINGLTR, \n\t\t\t\t\t PyArray_STRING, 0,\n\t\t\t\t\t _ALIGN(char),\n (PyObject *)\\\n &PyStringArrType_Type));\n\tPy_DECREF(s);\n\tPyDict_SetItemString(infodict, \"UNICODE\", \n\t\t\t s=Py_BuildValue(\"ciiiO\", PyArray_UNICODELTR, \n\t\t\t\t\t PyArray_UNICODE, 0,\n\t\t\t\t\t _ALIGN(PyArray_UCS4),\n (PyObject *)\\\n &PyUnicodeArrType_Type));\t\n\tPy_DECREF(s);\n\tPyDict_SetItemString(infodict, \"VOID\", \n\t\t\t s=Py_BuildValue(\"ciiiO\", PyArray_VOIDLTR, \n\t\t\t\t\t PyArray_VOID, 0,\n\t\t\t\t\t _ALIGN(char),\n (PyObject *)\\\n &PyVoidArrType_Type));\t\n\tPy_DECREF(s);\n\n#define SETTYPE(name) \\\n Py_INCREF(&Py##name##ArrType_Type); \\\n PyDict_SetItemString(infodict, #name, \\\n (PyObject *)&Py##name##ArrType_Type);\n\n SETTYPE(Generic)\n SETTYPE(Number)\n SETTYPE(Integer)\n\tSETTYPE(Inexact)\n SETTYPE(SignedInteger)\n SETTYPE(UnsignedInteger)\n SETTYPE(Floating)\n SETTYPE(ComplexFloating)\n SETTYPE(Flexible)\n SETTYPE(Character)\n\n#undef SETTYPE \t\n\n\tPyDict_SetItemString(dict, \"typeinfo\", infodict);\n\tPy_DECREF(infodict);\n\treturn 0;\n}\n\n#undef _MAX_LETTER\n\n", + "methods": [], + "methods_before": [], + "changed_methods": [], + "nloc": null, + "complexity": null, + "token_count": null, + "diff_parsed": { + "added": [ + "\tchar *buffer;", + "\tint alloc=0;", + "\tif (!PyArray_ISBEHAVED(ap)) {", + "\t\tbuffer = _pya_malloc(mysize << 2);", + "\t\tif (buffer == NULL)", + "\t\t\treturn PyErr_NoMemory();", + "\t\talloc = 1;", + "\t\tmemcpy(buffer, ip, mysize << 2);", + "\t\tif (!PyArray_ISNOTSWAPPED(ap)) {", + "\t\t\tbyte_swap_vector(buffer, mysize, 4);", + "\t\t}", + "\telse buffer = ip;", + "\tobj = PyUnicode_FromUnicode((const PyArray_UCS4 *)buffer, mysize);", + "\t\t\t\t (PyArray_UCS4 *)buffer, mysize);", + "\t\tif (alloc) _pya_free(buffer);", + "\tif (alloc) _pya_free(buffer);", + "", + "#ifndef Py_UNICODE_WIDE", + "\tchar *buffer;", + "#endif", + "\tif (!PyArray_ISALIGNED(ap)) {", + "\t\tbuffer = _pya_malloc(ap->descr->elsize);", + "\t\tif (buffer == NULL) {", + "\t\t\tPy_DECREF(temp);", + "\t\t\tPyErr_NoMemory();", + "\t\t\treturn -1;", + "\t\t}", + "\t}", + "\telse buffer = ov;", + " datalen = PyUCS2Buffer_AsUCS4(ptr, (PyArray_UCS4 *)buffer,", + "\t\t\t\t datalen >> 1,", + "\tif (!PyArray_ISALIGNED(ap)) {", + "\t\tmemcpy(ov, buffer, datalen);", + "\t\t_pya_free(buffer);", + "\t}" + ], + "deleted": [ + "\tif (!PyArray_ISNOTSWAPPED(ap) && (obj != NULL)) {", + "\t\tbyte_swap_vector(PyArray_BYTES(ap), mysize, 4);", + "\tobj = PyUnicode_FromUnicode((const PyArray_UCS4 *)ip, mysize);", + "\t\t\t\t (PyArray_UCS4 *)ip, mysize);", + "", + " datalen = PyUCS2Buffer_AsUCS4(ptr, (PyArray_UCS4 *)ov, datalen >> 1," + ] + } + } + ] + }, + { + "hash": "7d4d958724a9ea5259680e84a46837b86b1aefa8", + "msg": "Fixed minrelpath tests for platforms where os.path.sep<>'/'.", + "author": { + "name": "Pearu Peterson", + "email": "pearu.peterson@gmail.com" + }, + "committer": { + "name": "Pearu Peterson", + "email": "pearu.peterson@gmail.com" + }, + "author_date": "2006-02-11T15:18:36+00:00", + "author_timezone": 0, + "committer_date": "2006-02-11T15:18:36+00:00", + "committer_timezone": 0, + "branches": [ + "main" + ], + "in_main_branch": true, + "merge": false, + "parents": [ + "8ee6df7668b3ae0568573620153e71e36c9c399a" + ], + "project_name": "repo_copy", + "project_path": "/tmp/tmpdjwupkfu/repo_copy", + "deletions": 9, + "insertions": 9, + "lines": 18, + "files": 2, + "dmm_unit_size": 1.0, + "dmm_unit_complexity": 1.0, + "dmm_unit_interfacing": null, + "modified_files": [ + { + "old_path": "numpy/distutils/misc_util.py", + "new_path": "numpy/distutils/misc_util.py", + "filename": "misc_util.py", + "extension": "py", + "change_type": "MODIFY", + "diff": "@@ -93,8 +93,6 @@ def minrelpath(path):\n return path\n if '..' not in path:\n return path\n- if os.sep != '/':\n- path.replace('/',os.sep)\n l = path.split(os.sep)\n j = 1\n while l:\n", + "added_lines": 0, + "deleted_lines": 2, + "source_code": "import os\nimport re\nimport sys\nimport imp\nimport copy\nimport glob\n\n__all__ = ['Configuration', 'get_numpy_include_dirs', 'default_config_dict',\n 'dict_append', 'appendpath', 'generate_config_py',\n 'get_cmd', 'allpath', 'get_mathlibs',\n 'terminal_has_colors', 'red_text', 'green_text', 'yellow_text',\n 'blue_text', 'cyan_text', 'cyg2win32', 'all_strings',\n 'has_f_sources', 'has_cxx_sources', 'filter_sources',\n 'get_dependencies', 'is_local_src_dir', 'get_ext_source_files',\n 'get_script_files', 'get_lib_source_files', 'get_data_files',\n 'dot_join', 'get_frame', 'minrelpath','njoin',\n 'is_sequence', 'is_string', 'as_list']\n\ndef allpath(name):\n \"Convert a /-separated pathname to one using the OS's path separator.\"\n splitted = name.split('/')\n return os.path.join(*splitted)\n\ndef get_path(mod_name, parent_path=None):\n \"\"\" Return path of the module.\n\n Returned path is relative to parent_path when given,\n otherwise it is absolute path.\n \"\"\"\n if mod_name == '__builtin__':\n #builtin if/then added by Pearu for use in core.run_setup.\n d = os.path.dirname(os.path.abspath(sys.argv[0]))\n else:\n __import__(mod_name)\n mod = sys.modules[mod_name]\n if hasattr(mod,'__file__'):\n filename = mod.__file__\n d = os.path.dirname(os.path.abspath(mod.__file__))\n else:\n # we're probably running setup.py as execfile(\"setup.py\")\n # (likely we're building an egg) \n d = os.path.abspath('.')\n # hmm, should we use sys.argv[0] like in __builtin__ case?\n\n if parent_path is not None:\n pd = os.path.abspath(parent_path)\n if pd == d[:len(pd)]:\n d = d[len(pd)+1:]\n return d or '.'\n\ndef njoin(*path):\n \"\"\" Join two or more pathname components +\n - convert a /-separated pathname to one using the OS's path separator.\n - resolve `..` from path.\n\n Either passing n arguments as in njoin('a','b'), or a sequence\n of n names as in njoin(['a','b']) is handled.\n \"\"\"\n if not path:\n # njoin()\n joined = ''\n elif is_sequence(path[0]) and len(path) == 1:\n # njoin(['a', 'b'])\n joined = os.path.join(*path[0])\n else:\n # njoin('a', 'b')\n joined = os.path.join(*path)\n if os.path.sep != '/':\n joined = joined.replace('/',os.path.sep)\n return minrelpath(joined)\n\ndef get_mathlibs(path=None):\n \"\"\" Return the MATHLIB line from config.h\n \"\"\"\n if path is None:\n path = get_numpy_include_dirs()[0]\n config_file = os.path.join(path,'config.h')\n fid = open(config_file)\n mathlibs = []\n s = '#define MATHLIB'\n for line in fid.readlines():\n if line.startswith(s):\n value = line[len(s):].strip()\n if value:\n mathlibs.extend(value.split(','))\n fid.close()\n return mathlibs\n \ndef minrelpath(path):\n \"\"\" Resolve `..` from path.\n \"\"\"\n if not is_string(path):\n return path\n if '..' not in path:\n return path\n l = path.split(os.sep)\n j = 1\n while l:\n try:\n i = l.index('..',j)\n except ValueError:\n break\n if l[i-1]=='..':\n j += 1\n else:\n del l[i],l[i-1]\n j = 1\n if not l:\n return ''\n return os.path.join(*l)\n\n# Hooks for colored terminal output.\n# See also http://www.livinglogic.de/Python/ansistyle\ndef terminal_has_colors():\n if sys.platform=='cygwin' and not os.environ.has_key('USE_COLOR'):\n # Avoid importing curses that causes illegal operation\n # with a message:\n # PYTHON2 caused an invalid page fault in\n # module CYGNURSES7.DLL as 015f:18bbfc28\n # Details: Python 2.3.3 [GCC 3.3.1 (cygming special)]\n # ssh to Win32 machine from debian\n # curses.version is 2.2\n # CYGWIN_98-4.10, release 1.5.7(0.109/3/2))\n return 0\n if hasattr(sys.stdout,'isatty') and sys.stdout.isatty():\n try:\n import curses\n curses.setupterm()\n if (curses.tigetnum(\"colors\") >= 0\n and curses.tigetnum(\"pairs\") >= 0\n and ((curses.tigetstr(\"setf\") is not None\n and curses.tigetstr(\"setb\") is not None)\n or (curses.tigetstr(\"setaf\") is not None\n and curses.tigetstr(\"setab\") is not None)\n or curses.tigetstr(\"scp\") is not None)):\n return 1\n except Exception,msg:\n pass\n return 0\n\nif terminal_has_colors():\n def red_text(s): return '\\x1b[31m%s\\x1b[0m'%s\n def green_text(s): return '\\x1b[32m%s\\x1b[0m'%s\n def yellow_text(s): return '\\x1b[33m%s\\x1b[0m'%s\n def blue_text(s): return '\\x1b[34m%s\\x1b[0m'%s\n def cyan_text(s): return '\\x1b[35m%s\\x1b[0m'%s\nelse:\n def red_text(s): return s\n def green_text(s): return s\n def yellow_text(s): return s\n def cyan_text(s): return s\n def blue_text(s): return s\n\n#########################\n\ndef cyg2win32(path):\n if sys.platform=='cygwin' and path.startswith('/cygdrive'):\n path = path[10] + ':' + os.path.normcase(path[11:])\n return path\n\n#########################\n\n#XXX need support for .C that is also C++\ncxx_ext_match = re.compile(r'.*[.](cpp|cxx|cc)\\Z',re.I).match\nfortran_ext_match = re.compile(r'.*[.](f90|f95|f77|for|ftn|f)\\Z',re.I).match\nf90_ext_match = re.compile(r'.*[.](f90|f95)\\Z',re.I).match\nf90_module_name_match = re.compile(r'\\s*module\\s*(?P[\\w_]+)',re.I).match\ndef _get_f90_modules(source):\n \"\"\" Return a list of Fortran f90 module names that\n given source file defines.\n \"\"\"\n if not f90_ext_match(source):\n return []\n modules = []\n f = open(source,'r')\n f_readlines = getattr(f,'xreadlines',f.readlines)\n for line in f_readlines():\n m = f90_module_name_match(line)\n if m:\n name = m.group('name')\n modules.append(name)\n # break # XXX can we assume that there is one module per file?\n f.close()\n return modules\n\ndef is_string(s):\n return isinstance(s, str)\n\ndef all_strings(lst):\n \"\"\" Return True if all items in lst are string objects. \"\"\"\n for item in lst:\n if not is_string(item):\n return False\n return True\n\ndef is_sequence(seq):\n if is_string(seq):\n return False\n try:\n len(seq)\n except:\n return False\n return True\n\ndef as_list(seq):\n if is_sequence(seq):\n return list(seq)\n else:\n return [seq]\n\ndef has_f_sources(sources):\n \"\"\" Return True if sources contains Fortran files \"\"\"\n for source in sources:\n if fortran_ext_match(source):\n return True\n return False\n\ndef has_cxx_sources(sources):\n \"\"\" Return True if sources contains C++ files \"\"\"\n for source in sources:\n if cxx_ext_match(source):\n return True\n return False\n\ndef filter_sources(sources):\n \"\"\" Return four lists of filenames containing\n C, C++, Fortran, and Fortran 90 module sources,\n respectively.\n \"\"\"\n c_sources = []\n cxx_sources = []\n f_sources = []\n fmodule_sources = []\n for source in sources:\n if fortran_ext_match(source):\n modules = _get_f90_modules(source)\n if modules:\n fmodule_sources.append(source)\n else:\n f_sources.append(source)\n elif cxx_ext_match(source):\n cxx_sources.append(source)\n else:\n c_sources.append(source)\n return c_sources, cxx_sources, f_sources, fmodule_sources\n\n\ndef _get_headers(directory_list):\n # get *.h files from list of directories\n headers = []\n for d in directory_list:\n head = glob.glob(os.path.join(d,\"*.h\")) #XXX: *.hpp files??\n headers.extend(head)\n return headers\n\ndef _get_directories(list_of_sources):\n # get unique directories from list of sources.\n direcs = []\n for f in list_of_sources:\n d = os.path.split(f)\n if d[0] != '' and not d[0] in direcs:\n direcs.append(d[0])\n return direcs\n\ndef get_dependencies(sources):\n #XXX scan sources for include statements\n return _get_headers(_get_directories(sources))\n\ndef is_local_src_dir(directory):\n \"\"\" Return true if directory is local directory.\n \"\"\"\n if not is_string(directory):\n return False\n abs_dir = os.path.abspath(directory)\n c = os.path.commonprefix([os.getcwd(),abs_dir])\n new_dir = abs_dir[len(c):].split(os.sep)\n if new_dir and not new_dir[0]:\n new_dir = new_dir[1:]\n if new_dir and new_dir[0]=='build':\n return False\n new_dir = os.sep.join(new_dir)\n return os.path.isdir(new_dir)\n\ndef general_source_files(top_path):\n pruned_directories = {'CVS':1, '.svn':1, 'build':1}\n prune_file_pat = re.compile(r'(?:[~#]|\\.py[co]|\\.o)$')\n for dirpath, dirnames, filenames in os.walk(top_path, topdown=True):\n pruned = [ d for d in dirnames if d not in pruned_directories ]\n dirnames[:] = pruned\n for f in filenames:\n if not prune_file_pat.search(f):\n yield os.path.join(dirpath, f)\n\ndef get_ext_source_files(ext):\n # Get sources and any include files in the same directory.\n filenames = []\n sources = filter(is_string, ext.sources)\n filenames.extend(sources)\n filenames.extend(get_dependencies(sources))\n for d in ext.depends:\n if is_local_src_dir(d):\n filenames.extend(list(general_source_files(d)))\n elif os.path.isfile(d):\n filenames.append(d)\n return filenames\n\ndef get_script_files(scripts):\n scripts = filter(is_string, scripts)\n return scripts\n\ndef get_lib_source_files(lib):\n filenames = []\n sources = lib[1].get('sources',[])\n sources = filter(is_string, sources)\n filenames.extend(sources)\n filenames.extend(get_dependencies(sources))\n depends = lib[1].get('depends',[])\n for d in depends:\n if is_local_src_dir(d):\n filenames.extend(list(general_source_files(d)))\n elif os.path.isfile(d):\n filenames.append(d)\n return filenames\n\ndef get_data_files(data):\n if is_string(data):\n return [data]\n sources = data[1]\n filenames = []\n for s in sources:\n if callable(s):\n continue\n if is_local_src_dir(s):\n filenames.extend(list(general_source_files(s)))\n elif is_string(s):\n if os.path.isfile(s):\n filenames.append(s)\n else:\n print 'Not existing data file:',s\n else:\n raise TypeError,repr(s)\n return filenames\n\ndef dot_join(*args):\n return '.'.join([a for a in args if a])\n\ndef get_frame(level=0):\n try:\n return sys._getframe(level+1)\n except AttributeError:\n frame = sys.exc_info()[2].tb_frame\n for _ in range(level+1):\n frame = frame.f_back\n return frame\n\n######################\n\nclass Configuration(object):\n\n _list_keys = ['packages', 'ext_modules', 'data_files', 'include_dirs',\n 'libraries', 'headers', 'scripts', 'py_modules']\n _dict_keys = ['package_dir']\n\n numpy_include_dirs = []\n\n def __init__(self,\n package_name=None,\n parent_name=None,\n top_path=None,\n package_path=None,\n **attrs):\n \"\"\" Construct configuration instance of a package.\n\n package_name -- name of the package\n Ex.: 'distutils'\n parent_name -- name of the parent package\n Ex.: 'numpy'\n top_path -- directory of the toplevel package\n Ex.: the directory where the numpy package source sits\n package_path -- directory of package. Will be computed by magic from the\n directory of the caller module if not specified\n Ex.: the directory where numpy.distutils is\n \"\"\"\n self.name = dot_join(parent_name, package_name)\n\n caller_frame = get_frame(1)\n caller_name = eval('__name__',caller_frame.f_globals,caller_frame.f_locals)\n\n self.local_path = get_path(caller_name, top_path)\n if top_path is None:\n top_path = self.local_path\n if package_path is None:\n package_path = self.local_path\n elif os.path.isdir(njoin(self.local_path,package_path)):\n package_path = njoin(self.local_path,package_path)\n if not os.path.isdir(package_path):\n raise ValueError(\"%r is not a directory\" % (package_path,))\n self.top_path = top_path\n self.package_path = package_path\n # this is the relative path in the installed package\n self.path_in_package = os.path.join(*self.name.split('.'))\n\n self.list_keys = self._list_keys[:]\n self.dict_keys = self._dict_keys[:]\n\n for n in self.list_keys:\n v = copy.copy(attrs.get(n, []))\n setattr(self, n, as_list(v))\n\n for n in self.dict_keys:\n v = copy.copy(attrs.get(n, {}))\n setattr(self, n, v)\n\n known_keys = self.list_keys + self.dict_keys\n self.extra_keys = []\n for n in attrs.keys():\n if n in known_keys:\n continue\n a = attrs[n]\n setattr(self,n,a)\n if isinstance(a, list):\n self.list_keys.append(n)\n elif isinstance(a, dict):\n self.dict_keys.append(n)\n else:\n self.extra_keys.append(n)\n\n if os.path.exists(njoin(package_path,'__init__.py')):\n self.packages.append(self.name)\n self.package_dir[self.name] = package_path\n\n self.options = dict(\n ignore_setup_xxx_py = False,\n assume_default_configuration = False,\n delegate_options_to_subpackages = False,\n quiet = False,\n )\n\n for i in range(1,3):\n f = get_frame(i)\n try:\n caller_instance = eval('self',f.f_globals,f.f_locals)\n break\n except NameError:\n caller_instance = None\n if isinstance(caller_instance, self.__class__):\n if caller_instance.options['delegate_options_to_subpackages']:\n self.set_options(**caller_instance.options)\n\n def todict(self):\n \"\"\" Return configuration distionary suitable for passing\n to distutils.core.setup() function.\n \"\"\"\n d = {}\n for n in self.list_keys + self.dict_keys + self.extra_keys:\n a = getattr(self,n)\n if a:\n d[n] = a\n if self.name:\n d['name'] = self.name\n return d\n\n def info(self, message):\n if not self.options['quiet']:\n print message\n\n def warn(self, message):\n print>>sys.stderr, 'Warning:',message\n\n\n def set_options(self, **options):\n \"\"\" Configure Configuration instance.\n\n The following options are available:\n - ignore_setup_xxx_py\n - assume_default_configuration\n - delegate_options_to_subpackages\n - quiet\n \"\"\"\n for key, value in options.items():\n if self.options.has_key(key):\n self.options[key] = value\n else:\n raise ValueError,'Unknown option: '+key\n\n def get_distribution(self):\n import distutils.core\n dist = distutils.core._setup_distribution\n return dist\n\n def _wildcard_get_subpackage(self, subpackage_name):\n l = subpackage_name.split('.')\n subpackage_path = njoin([self.local_path]+l)\n dirs = filter(os.path.isdir,glob.glob(subpackage_path))\n config_list = []\n for d in dirs:\n if not os.path.isfile(njoin(d,'__init__.py')):\n continue\n if 'build' in d.split(os.sep):\n continue\n n = '.'.join(d.split(os.sep)[-len(l):])\n c = self.get_subpackage(n)\n config_list.extend(c)\n return config_list\n\n def _get_configuration_from_setup_py(self, setup_py,\n subpackage_name, subpackage_path):\n # In case setup_py imports local modules:\n sys.path.insert(0,os.path.dirname(setup_py))\n try:\n fo_setup_py = open(setup_py, 'U')\n setup_name = os.path.splitext(os.path.basename(setup_py))[0]\n n = dot_join(self.name,setup_name)\n setup_module = imp.load_module('_'.join(n.split('.')),\n fo_setup_py,\n setup_py,\n ('.py', 'U', 1))\n if not hasattr(setup_module,'configuration'):\n if not self.options['assume_default_configuration']:\n self.warn('Assuming default configuration '\\\n '(%s does not define configuration())'\\\n % (setup_module))\n config = Configuration(subpackage_name, self.name,\n self.top_path, subpackage_path)\n else:\n args = (self.name,)\n if setup_module.configuration.func_code.co_argcount > 1:\n args = args + (self.top_path,)\n config = setup_module.configuration(*args)\n finally:\n del sys.path[0]\n return config\n\n def get_subpackage(self,subpackage_name,subpackage_path=None):\n \"\"\" Return list of subpackage configurations.\n\n '*' in subpackage_name is handled as a wildcard.\n \"\"\"\n if subpackage_name is None:\n if subpackage_path is None:\n raise ValueError(\n \"either subpackage_name or subpackage_path must be specified\")\n subpackage_name = os.path.basename(subpackage_path)\n\n # handle wildcards\n l = subpackage_name.split('.')\n if subpackage_path is None and '*' in subpackage_name:\n return self._wildcard_get_subpackage(subpackage_name)\n\n if subpackage_path is None:\n subpackage_path = njoin([self.local_path] + l)\n else:\n subpackage_path = njoin([subpackage_path] + l[:-1])\n subpackage_path = self._fix_paths([subpackage_path])[0]\n\n setup_py = njoin(subpackage_path, 'setup.py')\n if not self.options['ignore_setup_xxx_py']:\n if not os.path.isfile(setup_py):\n setup_py = njoin(subpackage_path,\n 'setup_%s.py' % (subpackage_name))\n\n if not os.path.isfile(setup_py):\n if not self.options['assume_default_configuration']:\n self.warn('Assuming default configuration '\\\n '(%s/{setup_%s,setup}.py was not found)' \\\n % (os.path.dirname(setup_py), subpackage_name))\n config = Configuration(subpackage_name, self.name,\n self.top_path, subpackage_path)\n else:\n config = self._get_configuration_from_setup_py(setup_py,\n subpackage_name,\n subpackage_path)\n\n if config:\n return [config]\n else:\n return []\n\n def add_subpackage(self,subpackage_name,subpackage_path=None):\n \"\"\" Add subpackage to configuration.\n \"\"\"\n config_list = self.get_subpackage(subpackage_name,subpackage_path)\n if not config_list:\n self.warn('No configuration returned, assuming unavailable.')\n for config in config_list:\n try:\n d = config.todict()\n except AttributeError:\n d = config\n self.info('Appending %s configuration to %s' \\\n % (d.get('name'), self.name))\n self.dict_append(**d)\n\n dist = self.get_distribution()\n if dist is not None:\n self.warn('distutils distribution has been initialized,'\\\n ' it may be too late to add a subpackage '+ subpackage_name)\n return\n\n def add_data_dir(self,data_path):\n \"\"\" Recursively add files under data_path to data_files list.\n Argument can be either\n - 2-sequence (,)\n - path to data directory where python datadir suffix defaults\n to package dir.\n If path is not absolute then it's datadir suffix is\n package dir + subdirname of the path.\n \"\"\"\n if is_sequence(data_path):\n d, data_path = data_path\n else:\n d = None\n if not is_string(data_path):\n raise TypeError(\"not a string: %r\" % (data_path,))\n for path in self.paths(data_path):\n if not os.path.exists(path):\n continue\n filenames = list(general_source_files(path))\n if not os.path.isabs(path):\n npath = data_path\n if '*' in npath:\n npath = os.path.join(*(path.split(os.sep)[-len(npath.split(os.sep)):]))\n if d is None:\n d = self.path_in_package\n ds = os.path.join(d, npath)\n self.add_data_files((ds,filenames))\n else:\n if d is None:\n self.add_data_files(*filenames)\n else:\n self.add_data_files((d,filenames))\n return\n\n def add_data_files(self,*files):\n \"\"\" Add data files to configuration data_files.\n Argument(s) can be either\n - 2-sequence (,)\n - paths to data files where python datadir prefix defaults\n to package dir.\n If path is not absolute then it's datadir prefix is\n package dir + dirname of the path.\n \"\"\"\n data_dict = {}\n new_files = []\n for p in files:\n if not is_sequence(p):\n d = self.path_in_package\n if is_string(p) and not os.path.isabs(p):\n pd = os.path.dirname(p)\n if '*' in pd:\n pn = os.path.basename(p)\n n = len(pd.split(os.sep))\n for d1 in filter(os.path.isdir,self.paths(pd)):\n p = os.path.join(d1,pn)\n d1 = os.sep.join(d1.split(os.sep)[-n:])\n new_files.append((appendpath(d,d1),p))\n continue\n d = appendpath(d,pd)\n p = (d,p)\n new_files.append(p)\n\n files = []\n for prefix,filepattern in new_files:\n assert '*' not in prefix, repr((prefix,filepattern))\n if is_string(filepattern):\n file_list = self.paths(filepattern,include_non_existing=False)\n elif callable(filepattern):\n file_list = [filepattern]\n else:\n file_list = self.paths(*filepattern)\n\n nof_path_components = [len(f.split(os.sep))\n for f in file_list if is_string(f)]\n if nof_path_components:\n min_path_components = min(nof_path_components)-1\n else:\n min_path_components = 0\n\n for f in file_list:\n if is_string(f):\n extra_path_components = f.split(os.sep)[min_path_components:-1]\n p = njoin([prefix]+extra_path_components)\n else:\n p = prefix\n if not data_dict.has_key(p):\n data_dict[p] = [f]\n else:\n data_dict[p].append(f)\n\n dist = self.get_distribution()\n if dist is not None:\n dist.data_files.extend(data_dict.items())\n else:\n self.data_files.extend(data_dict.items())\n\n ### XXX Implement add_py_modules\n\n def add_include_dirs(self,*paths):\n \"\"\" Add paths to configuration include directories.\n \"\"\"\n include_dirs = self._fix_paths(paths)\n dist = self.get_distribution()\n if dist is not None:\n dist.include_dirs.extend(include_dirs)\n else:\n self.include_dirs.extend(include_dirs)\n return\n\n def add_headers(self,*files):\n \"\"\" Add installable headers to configuration.\n Argument(s) can be either\n - 2-sequence (,)\n - path(s) to header file(s) where python includedir suffix will default\n to package name.\n \"\"\"\n headers = []\n for path in files:\n if is_string(path):\n [headers.append((self.name,p)) for p in self.paths(path)]\n else:\n if not isinstance(path, (tuple, list)) or len(path) != 2:\n raise TypeError(repr(path))\n [headers.append((path[0],p)) for p in self.paths(path[1])]\n dist = self.get_distribution()\n if dist is not None:\n dist.headers.extend(headers)\n else:\n self.headers.extend(headers)\n return\n\n def _fix_paths(self,paths,include_non_existing=True):\n assert is_sequence(paths), repr(type(paths))\n new_paths = []\n for n in paths:\n if isinstance(n,str):\n if '*' in n or '?' in n:\n p = glob.glob(n)\n p2 = glob.glob(njoin(self.local_path,n))\n if p2:\n new_paths.extend(p2)\n elif p:\n new_paths.extend(p)\n else:\n if include_non_existing:\n new_paths.append(n)\n self.warn('could not resolve pattern in %s: %r' \\\n % (self.local_path,n))\n else:\n n2 = njoin(self.local_path,n)\n if os.path.exists(n2):\n new_paths.append(n2)\n else:\n if os.path.exists(n):\n new_paths.append(n)\n elif include_non_existing:\n new_paths.append(n)\n if not os.path.exists(n):\n self.warn('not existing path in %s: %s' \\\n % (self.local_path,n))\n else:\n new_paths.append(n)\n return map(minrelpath,new_paths)\n\n def paths(self,*paths,**kws):\n \"\"\" Apply glob to paths and prepend local_path if needed.\n \"\"\"\n include_non_existing = kws.get('include_non_existing',True)\n return self._fix_paths(paths,\n include_non_existing=include_non_existing)\n\n def _fix_paths_dict(self,kw):\n for k in kw.keys():\n v = kw[k]\n if k in ['sources','depends','include_dirs','library_dirs',\n 'module_dirs','extra_objects']:\n new_v = self._fix_paths(v)\n kw[k] = new_v\n return\n\n def add_extension(self,name,sources,**kw):\n \"\"\" Add extension to configuration.\n\n Keywords:\n include_dirs, define_macros, undef_macros,\n library_dirs, libraries, runtime_library_dirs,\n extra_objects, extra_compile_args, extra_link_args,\n export_symbols, swig_opts, depends, language,\n f2py_options, module_dirs\n extra_info - dict or list of dict of keywords to be\n appended to keywords.\n \"\"\"\n ext_args = copy.copy(kw)\n ext_args['name'] = dot_join(self.name,name)\n ext_args['sources'] = sources\n\n if ext_args.has_key('extra_info'):\n extra_info = ext_args['extra_info']\n del ext_args['extra_info']\n if isinstance(extra_info, dict):\n extra_info = [extra_info]\n for info in extra_info:\n assert isinstance(info, dict), repr(info)\n dict_append(ext_args,**info)\n\n self._fix_paths_dict(ext_args)\n\n # Resolve out-of-tree dependencies\n libraries = ext_args.get('libraries',[])\n libnames = []\n ext_args['libraries'] = []\n for libname in libraries:\n if isinstance(libname,tuple):\n self._fix_paths_dict(libname[1])\n\n # Handle library names of the form libname@relative/path/to/library\n if '@' in libname:\n lname,lpath = libname.split('@',1)\n lpath = os.path.abspath(njoin(self.local_path,lpath))\n if os.path.isdir(lpath):\n c = self.get_subpackage(None,lpath)\n if isinstance(c,Configuration):\n c = c.todict()\n for l in [l[0] for l in c.get('libraries',[])]:\n llname = l.split('__OF__',1)[0]\n if llname == lname:\n c.pop('name',None)\n dict_append(ext_args,**c)\n break\n continue\n libnames.append(libname)\n\n ext_args['libraries'] = libnames + ext_args['libraries']\n\n from numpy.distutils.core import Extension\n ext = Extension(**ext_args)\n self.ext_modules.append(ext)\n\n dist = self.get_distribution()\n if dist is not None:\n self.warn('distutils distribution has been initialized,'\\\n ' it may be too late to add an extension '+name)\n return ext\n\n def add_library(self,name,sources,**build_info):\n \"\"\" Add library to configuration.\n\n Valid keywords for build_info:\n depends\n macros\n include_dirs\n extra_compiler_args\n f2py_options\n \"\"\"\n build_info = copy.copy(build_info)\n name = name #+ '__OF__' + self.name\n build_info['sources'] = sources\n\n self._fix_paths_dict(build_info)\n \n self.libraries.append((name,build_info))\n\n dist = self.get_distribution()\n if dist is not None:\n self.warn('distutils distribution has been initialized,'\\\n ' it may be too late to add a library '+ name)\n return\n\n def add_scripts(self,*files):\n \"\"\" Add scripts to configuration.\n \"\"\"\n scripts = self._fix_paths(files)\n dist = self.get_distribution()\n if dist is not None:\n dist.scripts.extend(scripts)\n else:\n self.scripts.extend(scripts)\n return\n\n def dict_append(self,**dict):\n for key in self.list_keys:\n a = getattr(self,key)\n a.extend(dict.get(key,[]))\n for key in self.dict_keys:\n a = getattr(self,key)\n a.update(dict.get(key,{}))\n known_keys = self.list_keys + self.dict_keys + self.extra_keys\n for key in dict.keys():\n if key not in known_keys and not hasattr(self,key):\n if key not in ['version']:\n self.warn('Inheriting attribute %r from %r' \\\n % (key,dict.get('name','?')))\n setattr(self,key,dict[key])\n self.extra_keys.append(key)\n return\n\n def __str__(self):\n known_keys = self.list_keys + self.dict_keys + self.extra_keys\n s = '<'+5*'-' + '\\n'\n s += 'Configuration of '+self.name+':\\n'\n for k in known_keys:\n a = getattr(self,k,None)\n if a:\n s += '%s = %r\\n' % (k,a)\n s += 5*'-' + '>'\n return s\n\n def get_config_cmd(self):\n cmd = get_cmd('config')\n cmd.ensure_finalized()\n cmd.dump_source = 0\n cmd.noisy = 0\n old_path = os.environ.get('PATH')\n if old_path:\n path = os.pathsep.join(['.',old_path])\n os.environ['PATH'] = path\n return cmd\n\n def get_build_temp_dir(self):\n cmd = get_cmd('build')\n cmd.ensure_finalized()\n return cmd.build_temp\n\n def have_f77c(self):\n \"\"\" Check for availability of Fortran 77 compiler.\n Use it inside source generating function to ensure that\n setup distribution instance has been initialized.\n \"\"\"\n simple_fortran_subroutine = '''\n subroutine simple\n end\n '''\n config_cmd = self.get_config_cmd()\n flag = config_cmd.try_compile(simple_fortran_subroutine,lang='f77')\n return flag\n\n def have_f90c(self):\n \"\"\" Check for availability of Fortran 90 compiler.\n Use it inside source generating function to ensure that\n setup distribution instance has been initialized.\n \"\"\"\n simple_fortran_subroutine = '''\n subroutine simple\n end\n '''\n config_cmd = self.get_config_cmd()\n flag = config_cmd.try_compile(simple_fortran_subroutine,lang='f90')\n return flag\n\n def append_to(self, extlib):\n \"\"\" Append libraries, include_dirs to extension or library item.\n \"\"\"\n if is_sequence(extlib):\n lib_name, build_info = extlib\n dict_append(build_info,\n libraries=self.libraries,\n include_dirs=self.include_dirs)\n else:\n from numpy.distutils.core import Extension\n assert isinstance(extlib,Extension), repr(extlib)\n extlib.libraries.extend(self.libraries)\n extlib.include_dirs.extend(self.include_dirs)\n return\n\n def _get_svn_revision(self,path):\n \"\"\" Return path's SVN revision number.\n \"\"\"\n entries = njoin(path,'.svn','entries')\n revision = None\n if os.path.isfile(entries):\n f = open(entries)\n m = re.search(r'revision=\"(?P\\d+)\"',f.read())\n f.close()\n if m:\n revision = int(m.group('revision'))\n return revision\n\n def get_version(self):\n \"\"\" Try to get version string of a package.\n \"\"\"\n version = getattr(self,'version',None)\n if version is not None:\n return version\n\n # Get version from version file.\n files = ['__version__.py',\n self.name.split('.')[-1]+'_version.py',\n 'version.py',\n '__svn_version__.py']\n version_vars = ['version',\n '__version__',\n self.name.split('.')[-1]+'_version']\n for f in files:\n fn = njoin(self.local_path,f)\n if os.path.isfile(fn):\n info = (open(fn),fn,('.py','U',1))\n name = os.path.splitext(os.path.basename(fn))[0]\n n = dot_join(self.name,name)\n try:\n version_module = imp.load_module('_'.join(n.split('.')),*info)\n except ImportError,msg:\n self.warn(str(msg))\n version_module = None\n if version_module is None:\n continue\n\n for a in version_vars:\n version = getattr(version_module,a,None)\n if version is not None:\n break\n if version is not None:\n break\n\n if version is not None:\n self.version = version\n return version\n\n # Get version as SVN revision number\n revision = self._get_svn_revision(self.local_path)\n if revision is not None:\n version = str(revision)\n self.version = version\n\n return version\n\n def make_svn_version_py(self):\n \"\"\" Generate package __svn_version__.py file from SVN revision number,\n it will be removed after python exits but will be available\n when sdist, etc commands are executed.\n\n If __svn_version__.py existed before, nothing is done.\n \"\"\"\n target = njoin(self.local_path,'__svn_version__.py')\n if os.path.isfile(target):\n return\n def generate_svn_version_py():\n if not os.path.isfile(target):\n revision = self._get_svn_revision(self.local_path)\n assert revision is not None,'hmm, why I am not inside SVN tree???'\n version = str(revision)\n self.info('Creating %s (version=%r)' % (target,version))\n f = open(target,'w')\n f.write('version = %r\\n' % (version))\n f.close()\n\n import atexit\n def rm_file(f=target,p=self.info):\n try: os.remove(f); p('removed '+f)\n except OSError: pass\n try: os.remove(f+'c'); p('removed '+f+'c')\n except OSError: pass\n atexit.register(rm_file)\n\n return target\n\n self.add_data_files((self.path_in_package, generate_svn_version_py()))\n\n def make_config_py(self,name='__config__'):\n \"\"\" Generate package __config__.py file containing system_info\n information used during building the package.\n \"\"\"\n self.py_modules.append((self.name,name,generate_config_py))\n return\n\n def get_info(self,*names):\n \"\"\" Get resources information.\n \"\"\"\n from system_info import get_info, dict_append\n info_dict = {}\n for a in names:\n dict_append(info_dict,**get_info(a))\n return info_dict\n\nclass BadConfiguration(Configuration):\n \"\"\"\n When the command line is not ok, use this as the configuration class.\n \"\"\"\n def _do_nothing(self, *args, **kw):\n pass\n add_subpackage = _do_nothing\n add_extension = _do_nothing\n add_library = _do_nothing\n add_data_dir = _do_nothing\n add_data_files = _do_nothing\n add_scripts = _do_nothing\n add_headers = _do_nothing\n add_include_dirs = _do_nothing\n make_config_py = _do_nothing\n\n def get_info(self, *args, **kw):\n return {}\n def have_f77c(self, *args, **kw):\n return False\n def have_f90c(self, *args, **kw):\n return False\n\ndef command_line_ok(_cache=[]):\n \"\"\" Return True if command line does not contain any\n help or display requests.\n \"\"\"\n if _cache:\n return _cache[0]\n ok = True\n from distutils.dist import Distribution\n display_opts = ['--'+n for n in Distribution.display_option_names]\n for o in Distribution.display_options:\n if o[1]:\n display_opts.append('-'+o[1])\n for arg in sys.argv:\n if arg.startswith('--help') or arg=='-h' or arg in display_opts:\n ok = False\n break\n _cache.append(ok)\n return ok\n\nif not command_line_ok():\n Configuration = BadConfiguration\n\ndef get_cmd(cmdname, _cache={}):\n if not _cache.has_key(cmdname):\n import distutils.core\n dist = distutils.core._setup_distribution\n if dist is None:\n from distutils.errors import DistutilsInternalError\n raise DistutilsInternalError(\n 'setup distribution instance not initialized')\n cmd = dist.get_command_obj(cmdname)\n _cache[cmdname] = cmd\n return _cache[cmdname]\n\ndef get_numpy_include_dirs():\n # numpy_include_dirs are set by numpy/core/setup.py, otherwise []\n include_dirs = Configuration.numpy_include_dirs[:]\n if not include_dirs:\n import numpy\n if numpy.show_config is None:\n # running from numpy_core source directory\n include_dirs.append(njoin(os.path.dirname(numpy.__file__),\n 'core', 'include'))\n else:\n # using installed numpy core headers\n import numpy.core as core\n include_dirs.append(njoin(os.path.dirname(core.__file__), 'include'))\n # else running numpy/core/setup.py\n return include_dirs\n\n#########################\n\ndef default_config_dict(name = None, parent_name = None, local_path=None):\n \"\"\" Return a configuration dictionary for usage in\n configuration() function defined in file setup_.py.\n \"\"\"\n import warnings\n warnings.warn('Use Configuration(%r,%r,top_path=%r) instead of '\\\n 'deprecated default_config_dict(%r,%r,%r)'\n % (name, parent_name, local_path,\n name, parent_name, local_path,\n ))\n c = Configuration(name, parent_name, local_path)\n return c.todict()\n\n\ndef dict_append(d, **kws):\n for k, v in kws.items():\n if d.has_key(k):\n d[k].extend(v)\n else:\n d[k] = v\n\ndef appendpath(prefix, path):\n if os.path.sep != '/':\n prefix = prefix.replace('/', os.path.sep)\n path = path.replace('/', os.path.sep)\n drive = ''\n if os.path.isabs(path):\n drive = os.path.splitdrive(prefix)[0]\n absprefix = os.path.splitdrive(os.path.abspath(prefix))[1]\n pathdrive, path = os.path.splitdrive(path)\n d = os.path.commonprefix([absprefix, path])\n if os.path.join(absprefix[:len(d)], absprefix[len(d):]) != absprefix \\\n or os.path.join(path[:len(d)], path[len(d):]) != path:\n # Handle invalid paths\n d = os.path.dirname(d)\n subpath = path[len(d):]\n if os.path.isabs(subpath):\n subpath = subpath[1:]\n else:\n subpath = path\n return os.path.normpath(njoin(drive + prefix, subpath))\n\ndef generate_config_py(target):\n \"\"\" Generate config.py file containing system_info information\n used during building the package.\n\n Usage:\\\n config['py_modules'].append((packagename, '__config__',generate_config_py))\n \"\"\"\n from numpy.distutils.system_info import system_info\n from distutils.dir_util import mkpath\n mkpath(os.path.dirname(target))\n f = open(target, 'w')\n f.write('# This file is generated by %s\\n' % (os.path.abspath(sys.argv[0])))\n f.write('# It contains system_info results at the time of building this package.\\n')\n f.write('__all__ = [\"get_info\",\"show\"]\\n\\n')\n for k, i in system_info.saved_results.items():\n f.write('%s=%r\\n' % (k, i))\n f.write('\\ndef get_info(name): g=globals(); return g.get(name,g.get(name+\"_info\",{}))\\n')\n f.write('''\ndef show():\n for name,info_dict in globals().items():\n if name[0]==\"_\" or type(info_dict) is not type({}): continue\n print name+\":\"\n if not info_dict:\n print \" NOT AVAILABLE\"\n for k,v in info_dict.items():\n v = str(v)\n if k==\\'sources\\' and len(v)>200: v = v[:60]+\\' ...\\\\n... \\'+v[-60:]\n print \\' %s = %s\\'%(k,v)\n print\n return\n ''')\n\n f.close()\n return target\n", + "source_code_before": "import os\nimport re\nimport sys\nimport imp\nimport copy\nimport glob\n\n__all__ = ['Configuration', 'get_numpy_include_dirs', 'default_config_dict',\n 'dict_append', 'appendpath', 'generate_config_py',\n 'get_cmd', 'allpath', 'get_mathlibs',\n 'terminal_has_colors', 'red_text', 'green_text', 'yellow_text',\n 'blue_text', 'cyan_text', 'cyg2win32', 'all_strings',\n 'has_f_sources', 'has_cxx_sources', 'filter_sources',\n 'get_dependencies', 'is_local_src_dir', 'get_ext_source_files',\n 'get_script_files', 'get_lib_source_files', 'get_data_files',\n 'dot_join', 'get_frame', 'minrelpath','njoin',\n 'is_sequence', 'is_string', 'as_list']\n\ndef allpath(name):\n \"Convert a /-separated pathname to one using the OS's path separator.\"\n splitted = name.split('/')\n return os.path.join(*splitted)\n\ndef get_path(mod_name, parent_path=None):\n \"\"\" Return path of the module.\n\n Returned path is relative to parent_path when given,\n otherwise it is absolute path.\n \"\"\"\n if mod_name == '__builtin__':\n #builtin if/then added by Pearu for use in core.run_setup.\n d = os.path.dirname(os.path.abspath(sys.argv[0]))\n else:\n __import__(mod_name)\n mod = sys.modules[mod_name]\n if hasattr(mod,'__file__'):\n filename = mod.__file__\n d = os.path.dirname(os.path.abspath(mod.__file__))\n else:\n # we're probably running setup.py as execfile(\"setup.py\")\n # (likely we're building an egg) \n d = os.path.abspath('.')\n # hmm, should we use sys.argv[0] like in __builtin__ case?\n\n if parent_path is not None:\n pd = os.path.abspath(parent_path)\n if pd == d[:len(pd)]:\n d = d[len(pd)+1:]\n return d or '.'\n\ndef njoin(*path):\n \"\"\" Join two or more pathname components +\n - convert a /-separated pathname to one using the OS's path separator.\n - resolve `..` from path.\n\n Either passing n arguments as in njoin('a','b'), or a sequence\n of n names as in njoin(['a','b']) is handled.\n \"\"\"\n if not path:\n # njoin()\n joined = ''\n elif is_sequence(path[0]) and len(path) == 1:\n # njoin(['a', 'b'])\n joined = os.path.join(*path[0])\n else:\n # njoin('a', 'b')\n joined = os.path.join(*path)\n if os.path.sep != '/':\n joined = joined.replace('/',os.path.sep)\n return minrelpath(joined)\n\ndef get_mathlibs(path=None):\n \"\"\" Return the MATHLIB line from config.h\n \"\"\"\n if path is None:\n path = get_numpy_include_dirs()[0]\n config_file = os.path.join(path,'config.h')\n fid = open(config_file)\n mathlibs = []\n s = '#define MATHLIB'\n for line in fid.readlines():\n if line.startswith(s):\n value = line[len(s):].strip()\n if value:\n mathlibs.extend(value.split(','))\n fid.close()\n return mathlibs\n \ndef minrelpath(path):\n \"\"\" Resolve `..` from path.\n \"\"\"\n if not is_string(path):\n return path\n if '..' not in path:\n return path\n if os.sep != '/':\n path.replace('/',os.sep)\n l = path.split(os.sep)\n j = 1\n while l:\n try:\n i = l.index('..',j)\n except ValueError:\n break\n if l[i-1]=='..':\n j += 1\n else:\n del l[i],l[i-1]\n j = 1\n if not l:\n return ''\n return os.path.join(*l)\n\n# Hooks for colored terminal output.\n# See also http://www.livinglogic.de/Python/ansistyle\ndef terminal_has_colors():\n if sys.platform=='cygwin' and not os.environ.has_key('USE_COLOR'):\n # Avoid importing curses that causes illegal operation\n # with a message:\n # PYTHON2 caused an invalid page fault in\n # module CYGNURSES7.DLL as 015f:18bbfc28\n # Details: Python 2.3.3 [GCC 3.3.1 (cygming special)]\n # ssh to Win32 machine from debian\n # curses.version is 2.2\n # CYGWIN_98-4.10, release 1.5.7(0.109/3/2))\n return 0\n if hasattr(sys.stdout,'isatty') and sys.stdout.isatty():\n try:\n import curses\n curses.setupterm()\n if (curses.tigetnum(\"colors\") >= 0\n and curses.tigetnum(\"pairs\") >= 0\n and ((curses.tigetstr(\"setf\") is not None\n and curses.tigetstr(\"setb\") is not None)\n or (curses.tigetstr(\"setaf\") is not None\n and curses.tigetstr(\"setab\") is not None)\n or curses.tigetstr(\"scp\") is not None)):\n return 1\n except Exception,msg:\n pass\n return 0\n\nif terminal_has_colors():\n def red_text(s): return '\\x1b[31m%s\\x1b[0m'%s\n def green_text(s): return '\\x1b[32m%s\\x1b[0m'%s\n def yellow_text(s): return '\\x1b[33m%s\\x1b[0m'%s\n def blue_text(s): return '\\x1b[34m%s\\x1b[0m'%s\n def cyan_text(s): return '\\x1b[35m%s\\x1b[0m'%s\nelse:\n def red_text(s): return s\n def green_text(s): return s\n def yellow_text(s): return s\n def cyan_text(s): return s\n def blue_text(s): return s\n\n#########################\n\ndef cyg2win32(path):\n if sys.platform=='cygwin' and path.startswith('/cygdrive'):\n path = path[10] + ':' + os.path.normcase(path[11:])\n return path\n\n#########################\n\n#XXX need support for .C that is also C++\ncxx_ext_match = re.compile(r'.*[.](cpp|cxx|cc)\\Z',re.I).match\nfortran_ext_match = re.compile(r'.*[.](f90|f95|f77|for|ftn|f)\\Z',re.I).match\nf90_ext_match = re.compile(r'.*[.](f90|f95)\\Z',re.I).match\nf90_module_name_match = re.compile(r'\\s*module\\s*(?P[\\w_]+)',re.I).match\ndef _get_f90_modules(source):\n \"\"\" Return a list of Fortran f90 module names that\n given source file defines.\n \"\"\"\n if not f90_ext_match(source):\n return []\n modules = []\n f = open(source,'r')\n f_readlines = getattr(f,'xreadlines',f.readlines)\n for line in f_readlines():\n m = f90_module_name_match(line)\n if m:\n name = m.group('name')\n modules.append(name)\n # break # XXX can we assume that there is one module per file?\n f.close()\n return modules\n\ndef is_string(s):\n return isinstance(s, str)\n\ndef all_strings(lst):\n \"\"\" Return True if all items in lst are string objects. \"\"\"\n for item in lst:\n if not is_string(item):\n return False\n return True\n\ndef is_sequence(seq):\n if is_string(seq):\n return False\n try:\n len(seq)\n except:\n return False\n return True\n\ndef as_list(seq):\n if is_sequence(seq):\n return list(seq)\n else:\n return [seq]\n\ndef has_f_sources(sources):\n \"\"\" Return True if sources contains Fortran files \"\"\"\n for source in sources:\n if fortran_ext_match(source):\n return True\n return False\n\ndef has_cxx_sources(sources):\n \"\"\" Return True if sources contains C++ files \"\"\"\n for source in sources:\n if cxx_ext_match(source):\n return True\n return False\n\ndef filter_sources(sources):\n \"\"\" Return four lists of filenames containing\n C, C++, Fortran, and Fortran 90 module sources,\n respectively.\n \"\"\"\n c_sources = []\n cxx_sources = []\n f_sources = []\n fmodule_sources = []\n for source in sources:\n if fortran_ext_match(source):\n modules = _get_f90_modules(source)\n if modules:\n fmodule_sources.append(source)\n else:\n f_sources.append(source)\n elif cxx_ext_match(source):\n cxx_sources.append(source)\n else:\n c_sources.append(source)\n return c_sources, cxx_sources, f_sources, fmodule_sources\n\n\ndef _get_headers(directory_list):\n # get *.h files from list of directories\n headers = []\n for d in directory_list:\n head = glob.glob(os.path.join(d,\"*.h\")) #XXX: *.hpp files??\n headers.extend(head)\n return headers\n\ndef _get_directories(list_of_sources):\n # get unique directories from list of sources.\n direcs = []\n for f in list_of_sources:\n d = os.path.split(f)\n if d[0] != '' and not d[0] in direcs:\n direcs.append(d[0])\n return direcs\n\ndef get_dependencies(sources):\n #XXX scan sources for include statements\n return _get_headers(_get_directories(sources))\n\ndef is_local_src_dir(directory):\n \"\"\" Return true if directory is local directory.\n \"\"\"\n if not is_string(directory):\n return False\n abs_dir = os.path.abspath(directory)\n c = os.path.commonprefix([os.getcwd(),abs_dir])\n new_dir = abs_dir[len(c):].split(os.sep)\n if new_dir and not new_dir[0]:\n new_dir = new_dir[1:]\n if new_dir and new_dir[0]=='build':\n return False\n new_dir = os.sep.join(new_dir)\n return os.path.isdir(new_dir)\n\ndef general_source_files(top_path):\n pruned_directories = {'CVS':1, '.svn':1, 'build':1}\n prune_file_pat = re.compile(r'(?:[~#]|\\.py[co]|\\.o)$')\n for dirpath, dirnames, filenames in os.walk(top_path, topdown=True):\n pruned = [ d for d in dirnames if d not in pruned_directories ]\n dirnames[:] = pruned\n for f in filenames:\n if not prune_file_pat.search(f):\n yield os.path.join(dirpath, f)\n\ndef get_ext_source_files(ext):\n # Get sources and any include files in the same directory.\n filenames = []\n sources = filter(is_string, ext.sources)\n filenames.extend(sources)\n filenames.extend(get_dependencies(sources))\n for d in ext.depends:\n if is_local_src_dir(d):\n filenames.extend(list(general_source_files(d)))\n elif os.path.isfile(d):\n filenames.append(d)\n return filenames\n\ndef get_script_files(scripts):\n scripts = filter(is_string, scripts)\n return scripts\n\ndef get_lib_source_files(lib):\n filenames = []\n sources = lib[1].get('sources',[])\n sources = filter(is_string, sources)\n filenames.extend(sources)\n filenames.extend(get_dependencies(sources))\n depends = lib[1].get('depends',[])\n for d in depends:\n if is_local_src_dir(d):\n filenames.extend(list(general_source_files(d)))\n elif os.path.isfile(d):\n filenames.append(d)\n return filenames\n\ndef get_data_files(data):\n if is_string(data):\n return [data]\n sources = data[1]\n filenames = []\n for s in sources:\n if callable(s):\n continue\n if is_local_src_dir(s):\n filenames.extend(list(general_source_files(s)))\n elif is_string(s):\n if os.path.isfile(s):\n filenames.append(s)\n else:\n print 'Not existing data file:',s\n else:\n raise TypeError,repr(s)\n return filenames\n\ndef dot_join(*args):\n return '.'.join([a for a in args if a])\n\ndef get_frame(level=0):\n try:\n return sys._getframe(level+1)\n except AttributeError:\n frame = sys.exc_info()[2].tb_frame\n for _ in range(level+1):\n frame = frame.f_back\n return frame\n\n######################\n\nclass Configuration(object):\n\n _list_keys = ['packages', 'ext_modules', 'data_files', 'include_dirs',\n 'libraries', 'headers', 'scripts', 'py_modules']\n _dict_keys = ['package_dir']\n\n numpy_include_dirs = []\n\n def __init__(self,\n package_name=None,\n parent_name=None,\n top_path=None,\n package_path=None,\n **attrs):\n \"\"\" Construct configuration instance of a package.\n\n package_name -- name of the package\n Ex.: 'distutils'\n parent_name -- name of the parent package\n Ex.: 'numpy'\n top_path -- directory of the toplevel package\n Ex.: the directory where the numpy package source sits\n package_path -- directory of package. Will be computed by magic from the\n directory of the caller module if not specified\n Ex.: the directory where numpy.distutils is\n \"\"\"\n self.name = dot_join(parent_name, package_name)\n\n caller_frame = get_frame(1)\n caller_name = eval('__name__',caller_frame.f_globals,caller_frame.f_locals)\n\n self.local_path = get_path(caller_name, top_path)\n if top_path is None:\n top_path = self.local_path\n if package_path is None:\n package_path = self.local_path\n elif os.path.isdir(njoin(self.local_path,package_path)):\n package_path = njoin(self.local_path,package_path)\n if not os.path.isdir(package_path):\n raise ValueError(\"%r is not a directory\" % (package_path,))\n self.top_path = top_path\n self.package_path = package_path\n # this is the relative path in the installed package\n self.path_in_package = os.path.join(*self.name.split('.'))\n\n self.list_keys = self._list_keys[:]\n self.dict_keys = self._dict_keys[:]\n\n for n in self.list_keys:\n v = copy.copy(attrs.get(n, []))\n setattr(self, n, as_list(v))\n\n for n in self.dict_keys:\n v = copy.copy(attrs.get(n, {}))\n setattr(self, n, v)\n\n known_keys = self.list_keys + self.dict_keys\n self.extra_keys = []\n for n in attrs.keys():\n if n in known_keys:\n continue\n a = attrs[n]\n setattr(self,n,a)\n if isinstance(a, list):\n self.list_keys.append(n)\n elif isinstance(a, dict):\n self.dict_keys.append(n)\n else:\n self.extra_keys.append(n)\n\n if os.path.exists(njoin(package_path,'__init__.py')):\n self.packages.append(self.name)\n self.package_dir[self.name] = package_path\n\n self.options = dict(\n ignore_setup_xxx_py = False,\n assume_default_configuration = False,\n delegate_options_to_subpackages = False,\n quiet = False,\n )\n\n for i in range(1,3):\n f = get_frame(i)\n try:\n caller_instance = eval('self',f.f_globals,f.f_locals)\n break\n except NameError:\n caller_instance = None\n if isinstance(caller_instance, self.__class__):\n if caller_instance.options['delegate_options_to_subpackages']:\n self.set_options(**caller_instance.options)\n\n def todict(self):\n \"\"\" Return configuration distionary suitable for passing\n to distutils.core.setup() function.\n \"\"\"\n d = {}\n for n in self.list_keys + self.dict_keys + self.extra_keys:\n a = getattr(self,n)\n if a:\n d[n] = a\n if self.name:\n d['name'] = self.name\n return d\n\n def info(self, message):\n if not self.options['quiet']:\n print message\n\n def warn(self, message):\n print>>sys.stderr, 'Warning:',message\n\n\n def set_options(self, **options):\n \"\"\" Configure Configuration instance.\n\n The following options are available:\n - ignore_setup_xxx_py\n - assume_default_configuration\n - delegate_options_to_subpackages\n - quiet\n \"\"\"\n for key, value in options.items():\n if self.options.has_key(key):\n self.options[key] = value\n else:\n raise ValueError,'Unknown option: '+key\n\n def get_distribution(self):\n import distutils.core\n dist = distutils.core._setup_distribution\n return dist\n\n def _wildcard_get_subpackage(self, subpackage_name):\n l = subpackage_name.split('.')\n subpackage_path = njoin([self.local_path]+l)\n dirs = filter(os.path.isdir,glob.glob(subpackage_path))\n config_list = []\n for d in dirs:\n if not os.path.isfile(njoin(d,'__init__.py')):\n continue\n if 'build' in d.split(os.sep):\n continue\n n = '.'.join(d.split(os.sep)[-len(l):])\n c = self.get_subpackage(n)\n config_list.extend(c)\n return config_list\n\n def _get_configuration_from_setup_py(self, setup_py,\n subpackage_name, subpackage_path):\n # In case setup_py imports local modules:\n sys.path.insert(0,os.path.dirname(setup_py))\n try:\n fo_setup_py = open(setup_py, 'U')\n setup_name = os.path.splitext(os.path.basename(setup_py))[0]\n n = dot_join(self.name,setup_name)\n setup_module = imp.load_module('_'.join(n.split('.')),\n fo_setup_py,\n setup_py,\n ('.py', 'U', 1))\n if not hasattr(setup_module,'configuration'):\n if not self.options['assume_default_configuration']:\n self.warn('Assuming default configuration '\\\n '(%s does not define configuration())'\\\n % (setup_module))\n config = Configuration(subpackage_name, self.name,\n self.top_path, subpackage_path)\n else:\n args = (self.name,)\n if setup_module.configuration.func_code.co_argcount > 1:\n args = args + (self.top_path,)\n config = setup_module.configuration(*args)\n finally:\n del sys.path[0]\n return config\n\n def get_subpackage(self,subpackage_name,subpackage_path=None):\n \"\"\" Return list of subpackage configurations.\n\n '*' in subpackage_name is handled as a wildcard.\n \"\"\"\n if subpackage_name is None:\n if subpackage_path is None:\n raise ValueError(\n \"either subpackage_name or subpackage_path must be specified\")\n subpackage_name = os.path.basename(subpackage_path)\n\n # handle wildcards\n l = subpackage_name.split('.')\n if subpackage_path is None and '*' in subpackage_name:\n return self._wildcard_get_subpackage(subpackage_name)\n\n if subpackage_path is None:\n subpackage_path = njoin([self.local_path] + l)\n else:\n subpackage_path = njoin([subpackage_path] + l[:-1])\n subpackage_path = self._fix_paths([subpackage_path])[0]\n\n setup_py = njoin(subpackage_path, 'setup.py')\n if not self.options['ignore_setup_xxx_py']:\n if not os.path.isfile(setup_py):\n setup_py = njoin(subpackage_path,\n 'setup_%s.py' % (subpackage_name))\n\n if not os.path.isfile(setup_py):\n if not self.options['assume_default_configuration']:\n self.warn('Assuming default configuration '\\\n '(%s/{setup_%s,setup}.py was not found)' \\\n % (os.path.dirname(setup_py), subpackage_name))\n config = Configuration(subpackage_name, self.name,\n self.top_path, subpackage_path)\n else:\n config = self._get_configuration_from_setup_py(setup_py,\n subpackage_name,\n subpackage_path)\n\n if config:\n return [config]\n else:\n return []\n\n def add_subpackage(self,subpackage_name,subpackage_path=None):\n \"\"\" Add subpackage to configuration.\n \"\"\"\n config_list = self.get_subpackage(subpackage_name,subpackage_path)\n if not config_list:\n self.warn('No configuration returned, assuming unavailable.')\n for config in config_list:\n try:\n d = config.todict()\n except AttributeError:\n d = config\n self.info('Appending %s configuration to %s' \\\n % (d.get('name'), self.name))\n self.dict_append(**d)\n\n dist = self.get_distribution()\n if dist is not None:\n self.warn('distutils distribution has been initialized,'\\\n ' it may be too late to add a subpackage '+ subpackage_name)\n return\n\n def add_data_dir(self,data_path):\n \"\"\" Recursively add files under data_path to data_files list.\n Argument can be either\n - 2-sequence (,)\n - path to data directory where python datadir suffix defaults\n to package dir.\n If path is not absolute then it's datadir suffix is\n package dir + subdirname of the path.\n \"\"\"\n if is_sequence(data_path):\n d, data_path = data_path\n else:\n d = None\n if not is_string(data_path):\n raise TypeError(\"not a string: %r\" % (data_path,))\n for path in self.paths(data_path):\n if not os.path.exists(path):\n continue\n filenames = list(general_source_files(path))\n if not os.path.isabs(path):\n npath = data_path\n if '*' in npath:\n npath = os.path.join(*(path.split(os.sep)[-len(npath.split(os.sep)):]))\n if d is None:\n d = self.path_in_package\n ds = os.path.join(d, npath)\n self.add_data_files((ds,filenames))\n else:\n if d is None:\n self.add_data_files(*filenames)\n else:\n self.add_data_files((d,filenames))\n return\n\n def add_data_files(self,*files):\n \"\"\" Add data files to configuration data_files.\n Argument(s) can be either\n - 2-sequence (,)\n - paths to data files where python datadir prefix defaults\n to package dir.\n If path is not absolute then it's datadir prefix is\n package dir + dirname of the path.\n \"\"\"\n data_dict = {}\n new_files = []\n for p in files:\n if not is_sequence(p):\n d = self.path_in_package\n if is_string(p) and not os.path.isabs(p):\n pd = os.path.dirname(p)\n if '*' in pd:\n pn = os.path.basename(p)\n n = len(pd.split(os.sep))\n for d1 in filter(os.path.isdir,self.paths(pd)):\n p = os.path.join(d1,pn)\n d1 = os.sep.join(d1.split(os.sep)[-n:])\n new_files.append((appendpath(d,d1),p))\n continue\n d = appendpath(d,pd)\n p = (d,p)\n new_files.append(p)\n\n files = []\n for prefix,filepattern in new_files:\n assert '*' not in prefix, repr((prefix,filepattern))\n if is_string(filepattern):\n file_list = self.paths(filepattern,include_non_existing=False)\n elif callable(filepattern):\n file_list = [filepattern]\n else:\n file_list = self.paths(*filepattern)\n\n nof_path_components = [len(f.split(os.sep))\n for f in file_list if is_string(f)]\n if nof_path_components:\n min_path_components = min(nof_path_components)-1\n else:\n min_path_components = 0\n\n for f in file_list:\n if is_string(f):\n extra_path_components = f.split(os.sep)[min_path_components:-1]\n p = njoin([prefix]+extra_path_components)\n else:\n p = prefix\n if not data_dict.has_key(p):\n data_dict[p] = [f]\n else:\n data_dict[p].append(f)\n\n dist = self.get_distribution()\n if dist is not None:\n dist.data_files.extend(data_dict.items())\n else:\n self.data_files.extend(data_dict.items())\n\n ### XXX Implement add_py_modules\n\n def add_include_dirs(self,*paths):\n \"\"\" Add paths to configuration include directories.\n \"\"\"\n include_dirs = self._fix_paths(paths)\n dist = self.get_distribution()\n if dist is not None:\n dist.include_dirs.extend(include_dirs)\n else:\n self.include_dirs.extend(include_dirs)\n return\n\n def add_headers(self,*files):\n \"\"\" Add installable headers to configuration.\n Argument(s) can be either\n - 2-sequence (,)\n - path(s) to header file(s) where python includedir suffix will default\n to package name.\n \"\"\"\n headers = []\n for path in files:\n if is_string(path):\n [headers.append((self.name,p)) for p in self.paths(path)]\n else:\n if not isinstance(path, (tuple, list)) or len(path) != 2:\n raise TypeError(repr(path))\n [headers.append((path[0],p)) for p in self.paths(path[1])]\n dist = self.get_distribution()\n if dist is not None:\n dist.headers.extend(headers)\n else:\n self.headers.extend(headers)\n return\n\n def _fix_paths(self,paths,include_non_existing=True):\n assert is_sequence(paths), repr(type(paths))\n new_paths = []\n for n in paths:\n if isinstance(n,str):\n if '*' in n or '?' in n:\n p = glob.glob(n)\n p2 = glob.glob(njoin(self.local_path,n))\n if p2:\n new_paths.extend(p2)\n elif p:\n new_paths.extend(p)\n else:\n if include_non_existing:\n new_paths.append(n)\n self.warn('could not resolve pattern in %s: %r' \\\n % (self.local_path,n))\n else:\n n2 = njoin(self.local_path,n)\n if os.path.exists(n2):\n new_paths.append(n2)\n else:\n if os.path.exists(n):\n new_paths.append(n)\n elif include_non_existing:\n new_paths.append(n)\n if not os.path.exists(n):\n self.warn('not existing path in %s: %s' \\\n % (self.local_path,n))\n else:\n new_paths.append(n)\n return map(minrelpath,new_paths)\n\n def paths(self,*paths,**kws):\n \"\"\" Apply glob to paths and prepend local_path if needed.\n \"\"\"\n include_non_existing = kws.get('include_non_existing',True)\n return self._fix_paths(paths,\n include_non_existing=include_non_existing)\n\n def _fix_paths_dict(self,kw):\n for k in kw.keys():\n v = kw[k]\n if k in ['sources','depends','include_dirs','library_dirs',\n 'module_dirs','extra_objects']:\n new_v = self._fix_paths(v)\n kw[k] = new_v\n return\n\n def add_extension(self,name,sources,**kw):\n \"\"\" Add extension to configuration.\n\n Keywords:\n include_dirs, define_macros, undef_macros,\n library_dirs, libraries, runtime_library_dirs,\n extra_objects, extra_compile_args, extra_link_args,\n export_symbols, swig_opts, depends, language,\n f2py_options, module_dirs\n extra_info - dict or list of dict of keywords to be\n appended to keywords.\n \"\"\"\n ext_args = copy.copy(kw)\n ext_args['name'] = dot_join(self.name,name)\n ext_args['sources'] = sources\n\n if ext_args.has_key('extra_info'):\n extra_info = ext_args['extra_info']\n del ext_args['extra_info']\n if isinstance(extra_info, dict):\n extra_info = [extra_info]\n for info in extra_info:\n assert isinstance(info, dict), repr(info)\n dict_append(ext_args,**info)\n\n self._fix_paths_dict(ext_args)\n\n # Resolve out-of-tree dependencies\n libraries = ext_args.get('libraries',[])\n libnames = []\n ext_args['libraries'] = []\n for libname in libraries:\n if isinstance(libname,tuple):\n self._fix_paths_dict(libname[1])\n\n # Handle library names of the form libname@relative/path/to/library\n if '@' in libname:\n lname,lpath = libname.split('@',1)\n lpath = os.path.abspath(njoin(self.local_path,lpath))\n if os.path.isdir(lpath):\n c = self.get_subpackage(None,lpath)\n if isinstance(c,Configuration):\n c = c.todict()\n for l in [l[0] for l in c.get('libraries',[])]:\n llname = l.split('__OF__',1)[0]\n if llname == lname:\n c.pop('name',None)\n dict_append(ext_args,**c)\n break\n continue\n libnames.append(libname)\n\n ext_args['libraries'] = libnames + ext_args['libraries']\n\n from numpy.distutils.core import Extension\n ext = Extension(**ext_args)\n self.ext_modules.append(ext)\n\n dist = self.get_distribution()\n if dist is not None:\n self.warn('distutils distribution has been initialized,'\\\n ' it may be too late to add an extension '+name)\n return ext\n\n def add_library(self,name,sources,**build_info):\n \"\"\" Add library to configuration.\n\n Valid keywords for build_info:\n depends\n macros\n include_dirs\n extra_compiler_args\n f2py_options\n \"\"\"\n build_info = copy.copy(build_info)\n name = name #+ '__OF__' + self.name\n build_info['sources'] = sources\n\n self._fix_paths_dict(build_info)\n \n self.libraries.append((name,build_info))\n\n dist = self.get_distribution()\n if dist is not None:\n self.warn('distutils distribution has been initialized,'\\\n ' it may be too late to add a library '+ name)\n return\n\n def add_scripts(self,*files):\n \"\"\" Add scripts to configuration.\n \"\"\"\n scripts = self._fix_paths(files)\n dist = self.get_distribution()\n if dist is not None:\n dist.scripts.extend(scripts)\n else:\n self.scripts.extend(scripts)\n return\n\n def dict_append(self,**dict):\n for key in self.list_keys:\n a = getattr(self,key)\n a.extend(dict.get(key,[]))\n for key in self.dict_keys:\n a = getattr(self,key)\n a.update(dict.get(key,{}))\n known_keys = self.list_keys + self.dict_keys + self.extra_keys\n for key in dict.keys():\n if key not in known_keys and not hasattr(self,key):\n if key not in ['version']:\n self.warn('Inheriting attribute %r from %r' \\\n % (key,dict.get('name','?')))\n setattr(self,key,dict[key])\n self.extra_keys.append(key)\n return\n\n def __str__(self):\n known_keys = self.list_keys + self.dict_keys + self.extra_keys\n s = '<'+5*'-' + '\\n'\n s += 'Configuration of '+self.name+':\\n'\n for k in known_keys:\n a = getattr(self,k,None)\n if a:\n s += '%s = %r\\n' % (k,a)\n s += 5*'-' + '>'\n return s\n\n def get_config_cmd(self):\n cmd = get_cmd('config')\n cmd.ensure_finalized()\n cmd.dump_source = 0\n cmd.noisy = 0\n old_path = os.environ.get('PATH')\n if old_path:\n path = os.pathsep.join(['.',old_path])\n os.environ['PATH'] = path\n return cmd\n\n def get_build_temp_dir(self):\n cmd = get_cmd('build')\n cmd.ensure_finalized()\n return cmd.build_temp\n\n def have_f77c(self):\n \"\"\" Check for availability of Fortran 77 compiler.\n Use it inside source generating function to ensure that\n setup distribution instance has been initialized.\n \"\"\"\n simple_fortran_subroutine = '''\n subroutine simple\n end\n '''\n config_cmd = self.get_config_cmd()\n flag = config_cmd.try_compile(simple_fortran_subroutine,lang='f77')\n return flag\n\n def have_f90c(self):\n \"\"\" Check for availability of Fortran 90 compiler.\n Use it inside source generating function to ensure that\n setup distribution instance has been initialized.\n \"\"\"\n simple_fortran_subroutine = '''\n subroutine simple\n end\n '''\n config_cmd = self.get_config_cmd()\n flag = config_cmd.try_compile(simple_fortran_subroutine,lang='f90')\n return flag\n\n def append_to(self, extlib):\n \"\"\" Append libraries, include_dirs to extension or library item.\n \"\"\"\n if is_sequence(extlib):\n lib_name, build_info = extlib\n dict_append(build_info,\n libraries=self.libraries,\n include_dirs=self.include_dirs)\n else:\n from numpy.distutils.core import Extension\n assert isinstance(extlib,Extension), repr(extlib)\n extlib.libraries.extend(self.libraries)\n extlib.include_dirs.extend(self.include_dirs)\n return\n\n def _get_svn_revision(self,path):\n \"\"\" Return path's SVN revision number.\n \"\"\"\n entries = njoin(path,'.svn','entries')\n revision = None\n if os.path.isfile(entries):\n f = open(entries)\n m = re.search(r'revision=\"(?P\\d+)\"',f.read())\n f.close()\n if m:\n revision = int(m.group('revision'))\n return revision\n\n def get_version(self):\n \"\"\" Try to get version string of a package.\n \"\"\"\n version = getattr(self,'version',None)\n if version is not None:\n return version\n\n # Get version from version file.\n files = ['__version__.py',\n self.name.split('.')[-1]+'_version.py',\n 'version.py',\n '__svn_version__.py']\n version_vars = ['version',\n '__version__',\n self.name.split('.')[-1]+'_version']\n for f in files:\n fn = njoin(self.local_path,f)\n if os.path.isfile(fn):\n info = (open(fn),fn,('.py','U',1))\n name = os.path.splitext(os.path.basename(fn))[0]\n n = dot_join(self.name,name)\n try:\n version_module = imp.load_module('_'.join(n.split('.')),*info)\n except ImportError,msg:\n self.warn(str(msg))\n version_module = None\n if version_module is None:\n continue\n\n for a in version_vars:\n version = getattr(version_module,a,None)\n if version is not None:\n break\n if version is not None:\n break\n\n if version is not None:\n self.version = version\n return version\n\n # Get version as SVN revision number\n revision = self._get_svn_revision(self.local_path)\n if revision is not None:\n version = str(revision)\n self.version = version\n\n return version\n\n def make_svn_version_py(self):\n \"\"\" Generate package __svn_version__.py file from SVN revision number,\n it will be removed after python exits but will be available\n when sdist, etc commands are executed.\n\n If __svn_version__.py existed before, nothing is done.\n \"\"\"\n target = njoin(self.local_path,'__svn_version__.py')\n if os.path.isfile(target):\n return\n def generate_svn_version_py():\n if not os.path.isfile(target):\n revision = self._get_svn_revision(self.local_path)\n assert revision is not None,'hmm, why I am not inside SVN tree???'\n version = str(revision)\n self.info('Creating %s (version=%r)' % (target,version))\n f = open(target,'w')\n f.write('version = %r\\n' % (version))\n f.close()\n\n import atexit\n def rm_file(f=target,p=self.info):\n try: os.remove(f); p('removed '+f)\n except OSError: pass\n try: os.remove(f+'c'); p('removed '+f+'c')\n except OSError: pass\n atexit.register(rm_file)\n\n return target\n\n self.add_data_files((self.path_in_package, generate_svn_version_py()))\n\n def make_config_py(self,name='__config__'):\n \"\"\" Generate package __config__.py file containing system_info\n information used during building the package.\n \"\"\"\n self.py_modules.append((self.name,name,generate_config_py))\n return\n\n def get_info(self,*names):\n \"\"\" Get resources information.\n \"\"\"\n from system_info import get_info, dict_append\n info_dict = {}\n for a in names:\n dict_append(info_dict,**get_info(a))\n return info_dict\n\nclass BadConfiguration(Configuration):\n \"\"\"\n When the command line is not ok, use this as the configuration class.\n \"\"\"\n def _do_nothing(self, *args, **kw):\n pass\n add_subpackage = _do_nothing\n add_extension = _do_nothing\n add_library = _do_nothing\n add_data_dir = _do_nothing\n add_data_files = _do_nothing\n add_scripts = _do_nothing\n add_headers = _do_nothing\n add_include_dirs = _do_nothing\n make_config_py = _do_nothing\n\n def get_info(self, *args, **kw):\n return {}\n def have_f77c(self, *args, **kw):\n return False\n def have_f90c(self, *args, **kw):\n return False\n\ndef command_line_ok(_cache=[]):\n \"\"\" Return True if command line does not contain any\n help or display requests.\n \"\"\"\n if _cache:\n return _cache[0]\n ok = True\n from distutils.dist import Distribution\n display_opts = ['--'+n for n in Distribution.display_option_names]\n for o in Distribution.display_options:\n if o[1]:\n display_opts.append('-'+o[1])\n for arg in sys.argv:\n if arg.startswith('--help') or arg=='-h' or arg in display_opts:\n ok = False\n break\n _cache.append(ok)\n return ok\n\nif not command_line_ok():\n Configuration = BadConfiguration\n\ndef get_cmd(cmdname, _cache={}):\n if not _cache.has_key(cmdname):\n import distutils.core\n dist = distutils.core._setup_distribution\n if dist is None:\n from distutils.errors import DistutilsInternalError\n raise DistutilsInternalError(\n 'setup distribution instance not initialized')\n cmd = dist.get_command_obj(cmdname)\n _cache[cmdname] = cmd\n return _cache[cmdname]\n\ndef get_numpy_include_dirs():\n # numpy_include_dirs are set by numpy/core/setup.py, otherwise []\n include_dirs = Configuration.numpy_include_dirs[:]\n if not include_dirs:\n import numpy\n if numpy.show_config is None:\n # running from numpy_core source directory\n include_dirs.append(njoin(os.path.dirname(numpy.__file__),\n 'core', 'include'))\n else:\n # using installed numpy core headers\n import numpy.core as core\n include_dirs.append(njoin(os.path.dirname(core.__file__), 'include'))\n # else running numpy/core/setup.py\n return include_dirs\n\n#########################\n\ndef default_config_dict(name = None, parent_name = None, local_path=None):\n \"\"\" Return a configuration dictionary for usage in\n configuration() function defined in file setup_.py.\n \"\"\"\n import warnings\n warnings.warn('Use Configuration(%r,%r,top_path=%r) instead of '\\\n 'deprecated default_config_dict(%r,%r,%r)'\n % (name, parent_name, local_path,\n name, parent_name, local_path,\n ))\n c = Configuration(name, parent_name, local_path)\n return c.todict()\n\n\ndef dict_append(d, **kws):\n for k, v in kws.items():\n if d.has_key(k):\n d[k].extend(v)\n else:\n d[k] = v\n\ndef appendpath(prefix, path):\n if os.path.sep != '/':\n prefix = prefix.replace('/', os.path.sep)\n path = path.replace('/', os.path.sep)\n drive = ''\n if os.path.isabs(path):\n drive = os.path.splitdrive(prefix)[0]\n absprefix = os.path.splitdrive(os.path.abspath(prefix))[1]\n pathdrive, path = os.path.splitdrive(path)\n d = os.path.commonprefix([absprefix, path])\n if os.path.join(absprefix[:len(d)], absprefix[len(d):]) != absprefix \\\n or os.path.join(path[:len(d)], path[len(d):]) != path:\n # Handle invalid paths\n d = os.path.dirname(d)\n subpath = path[len(d):]\n if os.path.isabs(subpath):\n subpath = subpath[1:]\n else:\n subpath = path\n return os.path.normpath(njoin(drive + prefix, subpath))\n\ndef generate_config_py(target):\n \"\"\" Generate config.py file containing system_info information\n used during building the package.\n\n Usage:\\\n config['py_modules'].append((packagename, '__config__',generate_config_py))\n \"\"\"\n from numpy.distutils.system_info import system_info\n from distutils.dir_util import mkpath\n mkpath(os.path.dirname(target))\n f = open(target, 'w')\n f.write('# This file is generated by %s\\n' % (os.path.abspath(sys.argv[0])))\n f.write('# It contains system_info results at the time of building this package.\\n')\n f.write('__all__ = [\"get_info\",\"show\"]\\n\\n')\n for k, i in system_info.saved_results.items():\n f.write('%s=%r\\n' % (k, i))\n f.write('\\ndef get_info(name): g=globals(); return g.get(name,g.get(name+\"_info\",{}))\\n')\n f.write('''\ndef show():\n for name,info_dict in globals().items():\n if name[0]==\"_\" or type(info_dict) is not type({}): continue\n print name+\":\"\n if not info_dict:\n print \" NOT AVAILABLE\"\n for k,v in info_dict.items():\n v = str(v)\n if k==\\'sources\\' and len(v)>200: v = v[:60]+\\' ...\\\\n... \\'+v[-60:]\n print \\' %s = %s\\'%(k,v)\n print\n return\n ''')\n\n f.close()\n return target\n", + "methods": [ + { + "name": "allpath", + "long_name": "allpath( name )", + "filename": "misc_util.py", + "nloc": 4, + "complexity": 1, + "token_count": 24, + "parameters": [ + "name" + ], + "start_line": 19, + "end_line": 22, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 0 + }, + { + "name": "get_path", + "long_name": "get_path( mod_name , parent_path = None )", + "filename": "misc_util.py", + "nloc": 16, + "complexity": 6, + "token_count": 139, + "parameters": [ + "mod_name", + "parent_path" + ], + "start_line": 24, + "end_line": 49, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 26, + "top_nesting_level": 0 + }, + { + "name": "njoin", + "long_name": "njoin( * path )", + "filename": "misc_util.py", + "nloc": 10, + "complexity": 5, + "token_count": 85, + "parameters": [ + "path" + ], + "start_line": 51, + "end_line": 70, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 20, + "top_nesting_level": 0 + }, + { + "name": "get_mathlibs", + "long_name": "get_mathlibs( path = None )", + "filename": "misc_util.py", + "nloc": 14, + "complexity": 5, + "token_count": 98, + "parameters": [ + "path" + ], + "start_line": 72, + "end_line": 87, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 16, + "top_nesting_level": 0 + }, + { + "name": "minrelpath", + "long_name": "minrelpath( path )", + "filename": "misc_util.py", + "nloc": 20, + "complexity": 7, + "token_count": 101, + "parameters": [ + "path" + ], + "start_line": 89, + "end_line": 110, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 22, + "top_nesting_level": 0 + }, + { + "name": "terminal_has_colors", + "long_name": "terminal_has_colors( )", + "filename": "misc_util.py", + "nloc": 18, + "complexity": 13, + "token_count": 137, + "parameters": [], + "start_line": 114, + "end_line": 139, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 26, + "top_nesting_level": 0 + }, + { + "name": "cyg2win32", + "long_name": "cyg2win32( path )", + "filename": "misc_util.py", + "nloc": 4, + "complexity": 3, + "token_count": 42, + "parameters": [ + "path" + ], + "start_line": 156, + "end_line": 159, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 0 + }, + { + "name": "_get_f90_modules", + "long_name": "_get_f90_modules( source )", + "filename": "misc_util.py", + "nloc": 13, + "complexity": 4, + "token_count": 77, + "parameters": [ + "source" + ], + "start_line": 168, + "end_line": 184, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 17, + "top_nesting_level": 0 + }, + { + "name": "is_string", + "long_name": "is_string( s )", + "filename": "misc_util.py", + "nloc": 2, + "complexity": 1, + "token_count": 12, + "parameters": [ + "s" + ], + "start_line": 186, + "end_line": 187, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 0 + }, + { + "name": "all_strings", + "long_name": "all_strings( lst )", + "filename": "misc_util.py", + "nloc": 5, + "complexity": 3, + "token_count": 22, + "parameters": [ + "lst" + ], + "start_line": 189, + "end_line": 194, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 6, + "top_nesting_level": 0 + }, + { + "name": "is_sequence", + "long_name": "is_sequence( seq )", + "filename": "misc_util.py", + "nloc": 8, + "complexity": 3, + "token_count": 25, + "parameters": [ + "seq" + ], + "start_line": 196, + "end_line": 203, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 8, + "top_nesting_level": 0 + }, + { + "name": "as_list", + "long_name": "as_list( seq )", + "filename": "misc_util.py", + "nloc": 5, + "complexity": 2, + "token_count": 22, + "parameters": [ + "seq" + ], + "start_line": 205, + "end_line": 209, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 5, + "top_nesting_level": 0 + }, + { + "name": "has_f_sources", + "long_name": "has_f_sources( sources )", + "filename": "misc_util.py", + "nloc": 5, + "complexity": 3, + "token_count": 21, + "parameters": [ + "sources" + ], + "start_line": 211, + "end_line": 216, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 6, + "top_nesting_level": 0 + }, + { + "name": "has_cxx_sources", + "long_name": "has_cxx_sources( sources )", + "filename": "misc_util.py", + "nloc": 5, + "complexity": 3, + "token_count": 21, + "parameters": [ + "sources" + ], + "start_line": 218, + "end_line": 223, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 6, + "top_nesting_level": 0 + }, + { + "name": "filter_sources", + "long_name": "filter_sources( sources )", + "filename": "misc_util.py", + "nloc": 17, + "complexity": 5, + "token_count": 84, + "parameters": [ + "sources" + ], + "start_line": 225, + "end_line": 245, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 21, + "top_nesting_level": 0 + }, + { + "name": "_get_headers", + "long_name": "_get_headers( directory_list )", + "filename": "misc_util.py", + "nloc": 6, + "complexity": 2, + "token_count": 39, + "parameters": [ + "directory_list" + ], + "start_line": 248, + "end_line": 254, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 7, + "top_nesting_level": 0 + }, + { + "name": "_get_directories", + "long_name": "_get_directories( list_of_sources )", + "filename": "misc_util.py", + "nloc": 7, + "complexity": 4, + "token_count": 51, + "parameters": [ + "list_of_sources" + ], + "start_line": 256, + "end_line": 263, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 8, + "top_nesting_level": 0 + }, + { + "name": "get_dependencies", + "long_name": "get_dependencies( sources )", + "filename": "misc_util.py", + "nloc": 2, + "complexity": 1, + "token_count": 13, + "parameters": [ + "sources" + ], + "start_line": 265, + "end_line": 267, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 0 + }, + { + "name": "is_local_src_dir", + "long_name": "is_local_src_dir( directory )", + "filename": "misc_util.py", + "nloc": 12, + "complexity": 6, + "token_count": 107, + "parameters": [ + "directory" + ], + "start_line": 269, + "end_line": 282, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 14, + "top_nesting_level": 0 + }, + { + "name": "general_source_files", + "long_name": "general_source_files( top_path )", + "filename": "misc_util.py", + "nloc": 9, + "complexity": 6, + "token_count": 92, + "parameters": [ + "top_path" + ], + "start_line": 284, + "end_line": 292, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 9, + "top_nesting_level": 0 + }, + { + "name": "get_ext_source_files", + "long_name": "get_ext_source_files( ext )", + "filename": "misc_util.py", + "nloc": 11, + "complexity": 4, + "token_count": 77, + "parameters": [ + "ext" + ], + "start_line": 294, + "end_line": 305, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 12, + "top_nesting_level": 0 + }, + { + "name": "get_script_files", + "long_name": "get_script_files( scripts )", + "filename": "misc_util.py", + "nloc": 3, + "complexity": 1, + "token_count": 15, + "parameters": [ + "scripts" + ], + "start_line": 307, + "end_line": 309, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 0 + }, + { + "name": "get_lib_source_files", + "long_name": "get_lib_source_files( lib )", + "filename": "misc_util.py", + "nloc": 13, + "complexity": 4, + "token_count": 101, + "parameters": [ + "lib" + ], + "start_line": 311, + "end_line": 323, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 13, + "top_nesting_level": 0 + }, + { + "name": "get_data_files", + "long_name": "get_data_files( data )", + "filename": "misc_util.py", + "nloc": 18, + "complexity": 7, + "token_count": 94, + "parameters": [ + "data" + ], + "start_line": 325, + "end_line": 342, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 18, + "top_nesting_level": 0 + }, + { + "name": "dot_join", + "long_name": "dot_join( * args )", + "filename": "misc_util.py", + "nloc": 2, + "complexity": 3, + "token_count": 21, + "parameters": [ + "args" + ], + "start_line": 344, + "end_line": 345, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 0 + }, + { + "name": "get_frame", + "long_name": "get_frame( level = 0 )", + "filename": "misc_util.py", + "nloc": 8, + "complexity": 3, + "token_count": 50, + "parameters": [ + "level" + ], + "start_line": 347, + "end_line": 354, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 8, + "top_nesting_level": 0 + }, + { + "name": "__init__", + "long_name": "__init__( self , package_name = None , parent_name = None , top_path = None , package_path = None , ** attrs )", + "filename": "misc_util.py", + "nloc": 61, + "complexity": 16, + "token_count": 458, + "parameters": [ + "self", + "package_name", + "parent_name", + "top_path", + "package_path", + "attrs" + ], + "start_line": 366, + "end_line": 448, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 83, + "top_nesting_level": 1 + }, + { + "name": "todict", + "long_name": "todict( self )", + "filename": "misc_util.py", + "nloc": 9, + "complexity": 4, + "token_count": 57, + "parameters": [ + "self" + ], + "start_line": 450, + "end_line": 461, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 12, + "top_nesting_level": 1 + }, + { + "name": "info", + "long_name": "info( self , message )", + "filename": "misc_util.py", + "nloc": 3, + "complexity": 2, + "token_count": 18, + "parameters": [ + "self", + "message" + ], + "start_line": 463, + "end_line": 465, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "warn", + "long_name": "warn( self , message )", + "filename": "misc_util.py", + "nloc": 2, + "complexity": 1, + "token_count": 17, + "parameters": [ + "self", + "message" + ], + "start_line": 467, + "end_line": 468, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 1 + }, + { + "name": "set_options", + "long_name": "set_options( self , ** options )", + "filename": "misc_util.py", + "nloc": 6, + "complexity": 3, + "token_count": 46, + "parameters": [ + "self", + "options" + ], + "start_line": 471, + "end_line": 484, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 14, + "top_nesting_level": 1 + }, + { + "name": "get_distribution", + "long_name": "get_distribution( self )", + "filename": "misc_util.py", + "nloc": 4, + "complexity": 1, + "token_count": 18, + "parameters": [ + "self" + ], + "start_line": 486, + "end_line": 489, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 1 + }, + { + "name": "_wildcard_get_subpackage", + "long_name": "_wildcard_get_subpackage( self , subpackage_name )", + "filename": "misc_util.py", + "nloc": 14, + "complexity": 4, + "token_count": 122, + "parameters": [ + "self", + "subpackage_name" + ], + "start_line": 491, + "end_line": 504, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 14, + "top_nesting_level": 1 + }, + { + "name": "_get_configuration_from_setup_py", + "long_name": "_get_configuration_from_setup_py( self , setup_py , subpackage_name , subpackage_path )", + "filename": "misc_util.py", + "nloc": 26, + "complexity": 5, + "token_count": 196, + "parameters": [ + "self", + "setup_py", + "subpackage_name", + "subpackage_path" + ], + "start_line": 506, + "end_line": 532, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 27, + "top_nesting_level": 1 + }, + { + "name": "get_subpackage", + "long_name": "get_subpackage( self , subpackage_name , subpackage_path = None )", + "filename": "misc_util.py", + "nloc": 34, + "complexity": 11, + "token_count": 232, + "parameters": [ + "self", + "subpackage_name", + "subpackage_path" + ], + "start_line": 534, + "end_line": 577, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 44, + "top_nesting_level": 1 + }, + { + "name": "add_subpackage", + "long_name": "add_subpackage( self , subpackage_name , subpackage_path = None )", + "filename": "misc_util.py", + "nloc": 17, + "complexity": 5, + "token_count": 103, + "parameters": [ + "self", + "subpackage_name", + "subpackage_path" + ], + "start_line": 579, + "end_line": 598, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 20, + "top_nesting_level": 1 + }, + { + "name": "add_data_dir", + "long_name": "add_data_dir( self , data_path )", + "filename": "misc_util.py", + "nloc": 25, + "complexity": 9, + "token_count": 185, + "parameters": [ + "self", + "data_path" + ], + "start_line": 600, + "end_line": 632, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 33, + "top_nesting_level": 1 + }, + { + "name": "add_data_files", + "long_name": "add_data_files( self , * files )", + "filename": "misc_util.py", + "nloc": 49, + "complexity": 17, + "token_count": 392, + "parameters": [ + "self", + "files" + ], + "start_line": 634, + "end_line": 694, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 61, + "top_nesting_level": 1 + }, + { + "name": "add_include_dirs", + "long_name": "add_include_dirs( self , * paths )", + "filename": "misc_util.py", + "nloc": 8, + "complexity": 2, + "token_count": 49, + "parameters": [ + "self", + "paths" + ], + "start_line": 698, + "end_line": 707, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 10, + "top_nesting_level": 1 + }, + { + "name": "add_headers", + "long_name": "add_headers( self , * files )", + "filename": "misc_util.py", + "nloc": 15, + "complexity": 8, + "token_count": 136, + "parameters": [ + "self", + "files" + ], + "start_line": 709, + "end_line": 729, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 21, + "top_nesting_level": 1 + }, + { + "name": "_fix_paths", + "long_name": "_fix_paths( self , paths , include_non_existing = True )", + "filename": "misc_util.py", + "nloc": 32, + "complexity": 12, + "token_count": 213, + "parameters": [ + "self", + "paths", + "include_non_existing" + ], + "start_line": 731, + "end_line": 762, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 32, + "top_nesting_level": 1 + }, + { + "name": "paths", + "long_name": "paths( self , * paths , ** kws )", + "filename": "misc_util.py", + "nloc": 4, + "complexity": 1, + "token_count": 33, + "parameters": [ + "self", + "paths", + "kws" + ], + "start_line": 764, + "end_line": 769, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 6, + "top_nesting_level": 1 + }, + { + "name": "_fix_paths_dict", + "long_name": "_fix_paths_dict( self , kw )", + "filename": "misc_util.py", + "nloc": 8, + "complexity": 3, + "token_count": 54, + "parameters": [ + "self", + "kw" + ], + "start_line": 771, + "end_line": 778, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 8, + "top_nesting_level": 1 + }, + { + "name": "add_extension", + "long_name": "add_extension( self , name , sources , ** kw )", + "filename": "misc_util.py", + "nloc": 43, + "complexity": 13, + "token_count": 337, + "parameters": [ + "self", + "name", + "sources", + "kw" + ], + "start_line": 780, + "end_line": 842, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 63, + "top_nesting_level": 1 + }, + { + "name": "add_library", + "long_name": "add_library( self , name , sources , ** build_info )", + "filename": "misc_util.py", + "nloc": 11, + "complexity": 2, + "token_count": 72, + "parameters": [ + "self", + "name", + "sources", + "build_info" + ], + "start_line": 844, + "end_line": 866, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 23, + "top_nesting_level": 1 + }, + { + "name": "add_scripts", + "long_name": "add_scripts( self , * files )", + "filename": "misc_util.py", + "nloc": 8, + "complexity": 2, + "token_count": 49, + "parameters": [ + "self", + "files" + ], + "start_line": 868, + "end_line": 877, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 10, + "top_nesting_level": 1 + }, + { + "name": "dict_append", + "long_name": "dict_append( self , ** dict )", + "filename": "misc_util.py", + "nloc": 16, + "complexity": 7, + "token_count": 150, + "parameters": [ + "self", + "dict" + ], + "start_line": 879, + "end_line": 894, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 16, + "top_nesting_level": 1 + }, + { + "name": "__str__", + "long_name": "__str__( self )", + "filename": "misc_util.py", + "nloc": 10, + "complexity": 3, + "token_count": 72, + "parameters": [ + "self" + ], + "start_line": 896, + "end_line": 905, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 10, + "top_nesting_level": 1 + }, + { + "name": "get_config_cmd", + "long_name": "get_config_cmd( self )", + "filename": "misc_util.py", + "nloc": 10, + "complexity": 2, + "token_count": 63, + "parameters": [ + "self" + ], + "start_line": 907, + "end_line": 916, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 10, + "top_nesting_level": 1 + }, + { + "name": "get_build_temp_dir", + "long_name": "get_build_temp_dir( self )", + "filename": "misc_util.py", + "nloc": 4, + "complexity": 1, + "token_count": 20, + "parameters": [ + "self" + ], + "start_line": 918, + "end_line": 921, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 1 + }, + { + "name": "have_f77c", + "long_name": "have_f77c( self )", + "filename": "misc_util.py", + "nloc": 8, + "complexity": 1, + "token_count": 30, + "parameters": [ + "self" + ], + "start_line": 923, + "end_line": 934, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 12, + "top_nesting_level": 1 + }, + { + "name": "have_f90c", + "long_name": "have_f90c( self )", + "filename": "misc_util.py", + "nloc": 8, + "complexity": 1, + "token_count": 30, + "parameters": [ + "self" + ], + "start_line": 936, + "end_line": 947, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 12, + "top_nesting_level": 1 + }, + { + "name": "append_to", + "long_name": "append_to( self , extlib )", + "filename": "misc_util.py", + "nloc": 12, + "complexity": 2, + "token_count": 78, + "parameters": [ + "self", + "extlib" + ], + "start_line": 949, + "end_line": 962, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 14, + "top_nesting_level": 1 + }, + { + "name": "_get_svn_revision", + "long_name": "_get_svn_revision( self , path )", + "filename": "misc_util.py", + "nloc": 10, + "complexity": 3, + "token_count": 73, + "parameters": [ + "self", + "path" + ], + "start_line": 964, + "end_line": 975, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 12, + "top_nesting_level": 1 + }, + { + "name": "get_version", + "long_name": "get_version( self )", + "filename": "misc_util.py", + "nloc": 38, + "complexity": 11, + "token_count": 260, + "parameters": [ + "self" + ], + "start_line": 977, + "end_line": 1023, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 47, + "top_nesting_level": 1 + }, + { + "name": "make_svn_version_py.make_svn_version_py.generate_svn_version_py.rm_file", + "long_name": "make_svn_version_py.make_svn_version_py.generate_svn_version_py.rm_file( f = target , p = self . info )", + "filename": "misc_util.py", + "nloc": 5, + "complexity": 3, + "token_count": 55, + "parameters": [ + "f", + "p" + ], + "start_line": 1046, + "end_line": 1050, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 5, + "top_nesting_level": 3 + }, + { + "name": "make_svn_version_py.generate_svn_version_py", + "long_name": "make_svn_version_py.generate_svn_version_py( )", + "filename": "misc_util.py", + "nloc": 13, + "complexity": 2, + "token_count": 85, + "parameters": [], + "start_line": 1035, + "end_line": 1053, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 19, + "top_nesting_level": 2 + }, + { + "name": "make_svn_version_py", + "long_name": "make_svn_version_py( self )", + "filename": "misc_util.py", + "nloc": 6, + "complexity": 2, + "token_count": 43, + "parameters": [ + "self" + ], + "start_line": 1025, + "end_line": 1055, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 31, + "top_nesting_level": 1 + }, + { + "name": "make_config_py", + "long_name": "make_config_py( self , name = '__config__' )", + "filename": "misc_util.py", + "nloc": 3, + "complexity": 1, + "token_count": 27, + "parameters": [ + "self", + "name" + ], + "start_line": 1057, + "end_line": 1062, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 6, + "top_nesting_level": 1 + }, + { + "name": "get_info", + "long_name": "get_info( self , * names )", + "filename": "misc_util.py", + "nloc": 6, + "complexity": 2, + "token_count": 36, + "parameters": [ + "self", + "names" + ], + "start_line": 1064, + "end_line": 1071, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 8, + "top_nesting_level": 1 + }, + { + "name": "_do_nothing", + "long_name": "_do_nothing( self , * args , ** kw )", + "filename": "misc_util.py", + "nloc": 2, + "complexity": 1, + "token_count": 12, + "parameters": [ + "self", + "args", + "kw" + ], + "start_line": 1077, + "end_line": 1078, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 1 + }, + { + "name": "get_info", + "long_name": "get_info( self , * args , ** kw )", + "filename": "misc_util.py", + "nloc": 2, + "complexity": 1, + "token_count": 14, + "parameters": [ + "self", + "args", + "kw" + ], + "start_line": 1089, + "end_line": 1090, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 1 + }, + { + "name": "have_f77c", + "long_name": "have_f77c( self , * args , ** kw )", + "filename": "misc_util.py", + "nloc": 2, + "complexity": 1, + "token_count": 13, + "parameters": [ + "self", + "args", + "kw" + ], + "start_line": 1091, + "end_line": 1092, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 1 + }, + { + "name": "have_f90c", + "long_name": "have_f90c( self , * args , ** kw )", + "filename": "misc_util.py", + "nloc": 2, + "complexity": 1, + "token_count": 13, + "parameters": [ + "self", + "args", + "kw" + ], + "start_line": 1093, + "end_line": 1094, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 1 + }, + { + "name": "command_line_ok", + "long_name": "command_line_ok( _cache = [ ] )", + "filename": "misc_util.py", + "nloc": 15, + "complexity": 9, + "token_count": 98, + "parameters": [ + "_cache" + ], + "start_line": 1096, + "end_line": 1113, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 18, + "top_nesting_level": 0 + }, + { + "name": "get_cmd", + "long_name": "get_cmd( cmdname , _cache = { } )", + "filename": "misc_util.py", + "nloc": 11, + "complexity": 3, + "token_count": 65, + "parameters": [ + "cmdname", + "_cache" + ], + "start_line": 1118, + "end_line": 1128, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 11, + "top_nesting_level": 0 + }, + { + "name": "get_numpy_include_dirs", + "long_name": "get_numpy_include_dirs( )", + "filename": "misc_util.py", + "nloc": 11, + "complexity": 3, + "token_count": 77, + "parameters": [], + "start_line": 1130, + "end_line": 1144, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 15, + "top_nesting_level": 0 + }, + { + "name": "default_config_dict", + "long_name": "default_config_dict( name = None , parent_name = None , local_path = None )", + "filename": "misc_util.py", + "nloc": 9, + "complexity": 1, + "token_count": 57, + "parameters": [ + "name", + "parent_name", + "local_path" + ], + "start_line": 1148, + "end_line": 1159, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 12, + "top_nesting_level": 0 + }, + { + "name": "dict_append", + "long_name": "dict_append( d , ** kws )", + "filename": "misc_util.py", + "nloc": 6, + "complexity": 3, + "token_count": 44, + "parameters": [ + "d", + "kws" + ], + "start_line": 1162, + "end_line": 1167, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 6, + "top_nesting_level": 0 + }, + { + "name": "appendpath", + "long_name": "appendpath( prefix , path )", + "filename": "misc_util.py", + "nloc": 19, + "complexity": 6, + "token_count": 230, + "parameters": [ + "prefix", + "path" + ], + "start_line": 1169, + "end_line": 1188, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 20, + "top_nesting_level": 0 + }, + { + "name": "generate_config_py", + "long_name": "generate_config_py( target )", + "filename": "misc_util.py", + "nloc": 27, + "complexity": 2, + "token_count": 117, + "parameters": [ + "target" + ], + "start_line": 1190, + "end_line": 1223, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 34, + "top_nesting_level": 0 + } + ], + "methods_before": [ + { + "name": "allpath", + "long_name": "allpath( name )", + "filename": "misc_util.py", + "nloc": 4, + "complexity": 1, + "token_count": 24, + "parameters": [ + "name" + ], + "start_line": 19, + "end_line": 22, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 0 + }, + { + "name": "get_path", + "long_name": "get_path( mod_name , parent_path = None )", + "filename": "misc_util.py", + "nloc": 16, + "complexity": 6, + "token_count": 139, + "parameters": [ + "mod_name", + "parent_path" + ], + "start_line": 24, + "end_line": 49, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 26, + "top_nesting_level": 0 + }, + { + "name": "njoin", + "long_name": "njoin( * path )", + "filename": "misc_util.py", + "nloc": 10, + "complexity": 5, + "token_count": 85, + "parameters": [ + "path" + ], + "start_line": 51, + "end_line": 70, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 20, + "top_nesting_level": 0 + }, + { + "name": "get_mathlibs", + "long_name": "get_mathlibs( path = None )", + "filename": "misc_util.py", + "nloc": 14, + "complexity": 5, + "token_count": 98, + "parameters": [ + "path" + ], + "start_line": 72, + "end_line": 87, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 16, + "top_nesting_level": 0 + }, + { + "name": "minrelpath", + "long_name": "minrelpath( path )", + "filename": "misc_util.py", + "nloc": 22, + "complexity": 8, + "token_count": 118, + "parameters": [ + "path" + ], + "start_line": 89, + "end_line": 112, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 24, + "top_nesting_level": 0 + }, + { + "name": "terminal_has_colors", + "long_name": "terminal_has_colors( )", + "filename": "misc_util.py", + "nloc": 18, + "complexity": 13, + "token_count": 137, + "parameters": [], + "start_line": 116, + "end_line": 141, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 26, + "top_nesting_level": 0 + }, + { + "name": "cyg2win32", + "long_name": "cyg2win32( path )", + "filename": "misc_util.py", + "nloc": 4, + "complexity": 3, + "token_count": 42, + "parameters": [ + "path" + ], + "start_line": 158, + "end_line": 161, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 0 + }, + { + "name": "_get_f90_modules", + "long_name": "_get_f90_modules( source )", + "filename": "misc_util.py", + "nloc": 13, + "complexity": 4, + "token_count": 77, + "parameters": [ + "source" + ], + "start_line": 170, + "end_line": 186, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 17, + "top_nesting_level": 0 + }, + { + "name": "is_string", + "long_name": "is_string( s )", + "filename": "misc_util.py", + "nloc": 2, + "complexity": 1, + "token_count": 12, + "parameters": [ + "s" + ], + "start_line": 188, + "end_line": 189, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 0 + }, + { + "name": "all_strings", + "long_name": "all_strings( lst )", + "filename": "misc_util.py", + "nloc": 5, + "complexity": 3, + "token_count": 22, + "parameters": [ + "lst" + ], + "start_line": 191, + "end_line": 196, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 6, + "top_nesting_level": 0 + }, + { + "name": "is_sequence", + "long_name": "is_sequence( seq )", + "filename": "misc_util.py", + "nloc": 8, + "complexity": 3, + "token_count": 25, + "parameters": [ + "seq" + ], + "start_line": 198, + "end_line": 205, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 8, + "top_nesting_level": 0 + }, + { + "name": "as_list", + "long_name": "as_list( seq )", + "filename": "misc_util.py", + "nloc": 5, + "complexity": 2, + "token_count": 22, + "parameters": [ + "seq" + ], + "start_line": 207, + "end_line": 211, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 5, + "top_nesting_level": 0 + }, + { + "name": "has_f_sources", + "long_name": "has_f_sources( sources )", + "filename": "misc_util.py", + "nloc": 5, + "complexity": 3, + "token_count": 21, + "parameters": [ + "sources" + ], + "start_line": 213, + "end_line": 218, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 6, + "top_nesting_level": 0 + }, + { + "name": "has_cxx_sources", + "long_name": "has_cxx_sources( sources )", + "filename": "misc_util.py", + "nloc": 5, + "complexity": 3, + "token_count": 21, + "parameters": [ + "sources" + ], + "start_line": 220, + "end_line": 225, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 6, + "top_nesting_level": 0 + }, + { + "name": "filter_sources", + "long_name": "filter_sources( sources )", + "filename": "misc_util.py", + "nloc": 17, + "complexity": 5, + "token_count": 84, + "parameters": [ + "sources" + ], + "start_line": 227, + "end_line": 247, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 21, + "top_nesting_level": 0 + }, + { + "name": "_get_headers", + "long_name": "_get_headers( directory_list )", + "filename": "misc_util.py", + "nloc": 6, + "complexity": 2, + "token_count": 39, + "parameters": [ + "directory_list" + ], + "start_line": 250, + "end_line": 256, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 7, + "top_nesting_level": 0 + }, + { + "name": "_get_directories", + "long_name": "_get_directories( list_of_sources )", + "filename": "misc_util.py", + "nloc": 7, + "complexity": 4, + "token_count": 51, + "parameters": [ + "list_of_sources" + ], + "start_line": 258, + "end_line": 265, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 8, + "top_nesting_level": 0 + }, + { + "name": "get_dependencies", + "long_name": "get_dependencies( sources )", + "filename": "misc_util.py", + "nloc": 2, + "complexity": 1, + "token_count": 13, + "parameters": [ + "sources" + ], + "start_line": 267, + "end_line": 269, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 0 + }, + { + "name": "is_local_src_dir", + "long_name": "is_local_src_dir( directory )", + "filename": "misc_util.py", + "nloc": 12, + "complexity": 6, + "token_count": 107, + "parameters": [ + "directory" + ], + "start_line": 271, + "end_line": 284, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 14, + "top_nesting_level": 0 + }, + { + "name": "general_source_files", + "long_name": "general_source_files( top_path )", + "filename": "misc_util.py", + "nloc": 9, + "complexity": 6, + "token_count": 92, + "parameters": [ + "top_path" + ], + "start_line": 286, + "end_line": 294, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 9, + "top_nesting_level": 0 + }, + { + "name": "get_ext_source_files", + "long_name": "get_ext_source_files( ext )", + "filename": "misc_util.py", + "nloc": 11, + "complexity": 4, + "token_count": 77, + "parameters": [ + "ext" + ], + "start_line": 296, + "end_line": 307, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 12, + "top_nesting_level": 0 + }, + { + "name": "get_script_files", + "long_name": "get_script_files( scripts )", + "filename": "misc_util.py", + "nloc": 3, + "complexity": 1, + "token_count": 15, + "parameters": [ + "scripts" + ], + "start_line": 309, + "end_line": 311, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 0 + }, + { + "name": "get_lib_source_files", + "long_name": "get_lib_source_files( lib )", + "filename": "misc_util.py", + "nloc": 13, + "complexity": 4, + "token_count": 101, + "parameters": [ + "lib" + ], + "start_line": 313, + "end_line": 325, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 13, + "top_nesting_level": 0 + }, + { + "name": "get_data_files", + "long_name": "get_data_files( data )", + "filename": "misc_util.py", + "nloc": 18, + "complexity": 7, + "token_count": 94, + "parameters": [ + "data" + ], + "start_line": 327, + "end_line": 344, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 18, + "top_nesting_level": 0 + }, + { + "name": "dot_join", + "long_name": "dot_join( * args )", + "filename": "misc_util.py", + "nloc": 2, + "complexity": 3, + "token_count": 21, + "parameters": [ + "args" + ], + "start_line": 346, + "end_line": 347, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 0 + }, + { + "name": "get_frame", + "long_name": "get_frame( level = 0 )", + "filename": "misc_util.py", + "nloc": 8, + "complexity": 3, + "token_count": 50, + "parameters": [ + "level" + ], + "start_line": 349, + "end_line": 356, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 8, + "top_nesting_level": 0 + }, + { + "name": "__init__", + "long_name": "__init__( self , package_name = None , parent_name = None , top_path = None , package_path = None , ** attrs )", + "filename": "misc_util.py", + "nloc": 61, + "complexity": 16, + "token_count": 458, + "parameters": [ + "self", + "package_name", + "parent_name", + "top_path", + "package_path", + "attrs" + ], + "start_line": 368, + "end_line": 450, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 83, + "top_nesting_level": 1 + }, + { + "name": "todict", + "long_name": "todict( self )", + "filename": "misc_util.py", + "nloc": 9, + "complexity": 4, + "token_count": 57, + "parameters": [ + "self" + ], + "start_line": 452, + "end_line": 463, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 12, + "top_nesting_level": 1 + }, + { + "name": "info", + "long_name": "info( self , message )", + "filename": "misc_util.py", + "nloc": 3, + "complexity": 2, + "token_count": 18, + "parameters": [ + "self", + "message" + ], + "start_line": 465, + "end_line": 467, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "warn", + "long_name": "warn( self , message )", + "filename": "misc_util.py", + "nloc": 2, + "complexity": 1, + "token_count": 17, + "parameters": [ + "self", + "message" + ], + "start_line": 469, + "end_line": 470, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 1 + }, + { + "name": "set_options", + "long_name": "set_options( self , ** options )", + "filename": "misc_util.py", + "nloc": 6, + "complexity": 3, + "token_count": 46, + "parameters": [ + "self", + "options" + ], + "start_line": 473, + "end_line": 486, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 14, + "top_nesting_level": 1 + }, + { + "name": "get_distribution", + "long_name": "get_distribution( self )", + "filename": "misc_util.py", + "nloc": 4, + "complexity": 1, + "token_count": 18, + "parameters": [ + "self" + ], + "start_line": 488, + "end_line": 491, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 1 + }, + { + "name": "_wildcard_get_subpackage", + "long_name": "_wildcard_get_subpackage( self , subpackage_name )", + "filename": "misc_util.py", + "nloc": 14, + "complexity": 4, + "token_count": 122, + "parameters": [ + "self", + "subpackage_name" + ], + "start_line": 493, + "end_line": 506, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 14, + "top_nesting_level": 1 + }, + { + "name": "_get_configuration_from_setup_py", + "long_name": "_get_configuration_from_setup_py( self , setup_py , subpackage_name , subpackage_path )", + "filename": "misc_util.py", + "nloc": 26, + "complexity": 5, + "token_count": 196, + "parameters": [ + "self", + "setup_py", + "subpackage_name", + "subpackage_path" + ], + "start_line": 508, + "end_line": 534, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 27, + "top_nesting_level": 1 + }, + { + "name": "get_subpackage", + "long_name": "get_subpackage( self , subpackage_name , subpackage_path = None )", + "filename": "misc_util.py", + "nloc": 34, + "complexity": 11, + "token_count": 232, + "parameters": [ + "self", + "subpackage_name", + "subpackage_path" + ], + "start_line": 536, + "end_line": 579, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 44, + "top_nesting_level": 1 + }, + { + "name": "add_subpackage", + "long_name": "add_subpackage( self , subpackage_name , subpackage_path = None )", + "filename": "misc_util.py", + "nloc": 17, + "complexity": 5, + "token_count": 103, + "parameters": [ + "self", + "subpackage_name", + "subpackage_path" + ], + "start_line": 581, + "end_line": 600, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 20, + "top_nesting_level": 1 + }, + { + "name": "add_data_dir", + "long_name": "add_data_dir( self , data_path )", + "filename": "misc_util.py", + "nloc": 25, + "complexity": 9, + "token_count": 185, + "parameters": [ + "self", + "data_path" + ], + "start_line": 602, + "end_line": 634, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 33, + "top_nesting_level": 1 + }, + { + "name": "add_data_files", + "long_name": "add_data_files( self , * files )", + "filename": "misc_util.py", + "nloc": 49, + "complexity": 17, + "token_count": 392, + "parameters": [ + "self", + "files" + ], + "start_line": 636, + "end_line": 696, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 61, + "top_nesting_level": 1 + }, + { + "name": "add_include_dirs", + "long_name": "add_include_dirs( self , * paths )", + "filename": "misc_util.py", + "nloc": 8, + "complexity": 2, + "token_count": 49, + "parameters": [ + "self", + "paths" + ], + "start_line": 700, + "end_line": 709, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 10, + "top_nesting_level": 1 + }, + { + "name": "add_headers", + "long_name": "add_headers( self , * files )", + "filename": "misc_util.py", + "nloc": 15, + "complexity": 8, + "token_count": 136, + "parameters": [ + "self", + "files" + ], + "start_line": 711, + "end_line": 731, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 21, + "top_nesting_level": 1 + }, + { + "name": "_fix_paths", + "long_name": "_fix_paths( self , paths , include_non_existing = True )", + "filename": "misc_util.py", + "nloc": 32, + "complexity": 12, + "token_count": 213, + "parameters": [ + "self", + "paths", + "include_non_existing" + ], + "start_line": 733, + "end_line": 764, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 32, + "top_nesting_level": 1 + }, + { + "name": "paths", + "long_name": "paths( self , * paths , ** kws )", + "filename": "misc_util.py", + "nloc": 4, + "complexity": 1, + "token_count": 33, + "parameters": [ + "self", + "paths", + "kws" + ], + "start_line": 766, + "end_line": 771, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 6, + "top_nesting_level": 1 + }, + { + "name": "_fix_paths_dict", + "long_name": "_fix_paths_dict( self , kw )", + "filename": "misc_util.py", + "nloc": 8, + "complexity": 3, + "token_count": 54, + "parameters": [ + "self", + "kw" + ], + "start_line": 773, + "end_line": 780, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 8, + "top_nesting_level": 1 + }, + { + "name": "add_extension", + "long_name": "add_extension( self , name , sources , ** kw )", + "filename": "misc_util.py", + "nloc": 43, + "complexity": 13, + "token_count": 337, + "parameters": [ + "self", + "name", + "sources", + "kw" + ], + "start_line": 782, + "end_line": 844, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 63, + "top_nesting_level": 1 + }, + { + "name": "add_library", + "long_name": "add_library( self , name , sources , ** build_info )", + "filename": "misc_util.py", + "nloc": 11, + "complexity": 2, + "token_count": 72, + "parameters": [ + "self", + "name", + "sources", + "build_info" + ], + "start_line": 846, + "end_line": 868, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 23, + "top_nesting_level": 1 + }, + { + "name": "add_scripts", + "long_name": "add_scripts( self , * files )", + "filename": "misc_util.py", + "nloc": 8, + "complexity": 2, + "token_count": 49, + "parameters": [ + "self", + "files" + ], + "start_line": 870, + "end_line": 879, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 10, + "top_nesting_level": 1 + }, + { + "name": "dict_append", + "long_name": "dict_append( self , ** dict )", + "filename": "misc_util.py", + "nloc": 16, + "complexity": 7, + "token_count": 150, + "parameters": [ + "self", + "dict" + ], + "start_line": 881, + "end_line": 896, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 16, + "top_nesting_level": 1 + }, + { + "name": "__str__", + "long_name": "__str__( self )", + "filename": "misc_util.py", + "nloc": 10, + "complexity": 3, + "token_count": 72, + "parameters": [ + "self" + ], + "start_line": 898, + "end_line": 907, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 10, + "top_nesting_level": 1 + }, + { + "name": "get_config_cmd", + "long_name": "get_config_cmd( self )", + "filename": "misc_util.py", + "nloc": 10, + "complexity": 2, + "token_count": 63, + "parameters": [ + "self" + ], + "start_line": 909, + "end_line": 918, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 10, + "top_nesting_level": 1 + }, + { + "name": "get_build_temp_dir", + "long_name": "get_build_temp_dir( self )", + "filename": "misc_util.py", + "nloc": 4, + "complexity": 1, + "token_count": 20, + "parameters": [ + "self" + ], + "start_line": 920, + "end_line": 923, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 1 + }, + { + "name": "have_f77c", + "long_name": "have_f77c( self )", + "filename": "misc_util.py", + "nloc": 8, + "complexity": 1, + "token_count": 30, + "parameters": [ + "self" + ], + "start_line": 925, + "end_line": 936, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 12, + "top_nesting_level": 1 + }, + { + "name": "have_f90c", + "long_name": "have_f90c( self )", + "filename": "misc_util.py", + "nloc": 8, + "complexity": 1, + "token_count": 30, + "parameters": [ + "self" + ], + "start_line": 938, + "end_line": 949, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 12, + "top_nesting_level": 1 + }, + { + "name": "append_to", + "long_name": "append_to( self , extlib )", + "filename": "misc_util.py", + "nloc": 12, + "complexity": 2, + "token_count": 78, + "parameters": [ + "self", + "extlib" + ], + "start_line": 951, + "end_line": 964, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 14, + "top_nesting_level": 1 + }, + { + "name": "_get_svn_revision", + "long_name": "_get_svn_revision( self , path )", + "filename": "misc_util.py", + "nloc": 10, + "complexity": 3, + "token_count": 73, + "parameters": [ + "self", + "path" + ], + "start_line": 966, + "end_line": 977, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 12, + "top_nesting_level": 1 + }, + { + "name": "get_version", + "long_name": "get_version( self )", + "filename": "misc_util.py", + "nloc": 38, + "complexity": 11, + "token_count": 260, + "parameters": [ + "self" + ], + "start_line": 979, + "end_line": 1025, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 47, + "top_nesting_level": 1 + }, + { + "name": "make_svn_version_py.make_svn_version_py.generate_svn_version_py.rm_file", + "long_name": "make_svn_version_py.make_svn_version_py.generate_svn_version_py.rm_file( f = target , p = self . info )", + "filename": "misc_util.py", + "nloc": 5, + "complexity": 3, + "token_count": 55, + "parameters": [ + "f", + "p" + ], + "start_line": 1048, + "end_line": 1052, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 5, + "top_nesting_level": 3 + }, + { + "name": "make_svn_version_py.generate_svn_version_py", + "long_name": "make_svn_version_py.generate_svn_version_py( )", + "filename": "misc_util.py", + "nloc": 13, + "complexity": 2, + "token_count": 85, + "parameters": [], + "start_line": 1037, + "end_line": 1055, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 19, + "top_nesting_level": 2 + }, + { + "name": "make_svn_version_py", + "long_name": "make_svn_version_py( self )", + "filename": "misc_util.py", + "nloc": 6, + "complexity": 2, + "token_count": 43, + "parameters": [ + "self" + ], + "start_line": 1027, + "end_line": 1057, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 31, + "top_nesting_level": 1 + }, + { + "name": "make_config_py", + "long_name": "make_config_py( self , name = '__config__' )", + "filename": "misc_util.py", + "nloc": 3, + "complexity": 1, + "token_count": 27, + "parameters": [ + "self", + "name" + ], + "start_line": 1059, + "end_line": 1064, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 6, + "top_nesting_level": 1 + }, + { + "name": "get_info", + "long_name": "get_info( self , * names )", + "filename": "misc_util.py", + "nloc": 6, + "complexity": 2, + "token_count": 36, + "parameters": [ + "self", + "names" + ], + "start_line": 1066, + "end_line": 1073, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 8, + "top_nesting_level": 1 + }, + { + "name": "_do_nothing", + "long_name": "_do_nothing( self , * args , ** kw )", + "filename": "misc_util.py", + "nloc": 2, + "complexity": 1, + "token_count": 12, + "parameters": [ + "self", + "args", + "kw" + ], + "start_line": 1079, + "end_line": 1080, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 1 + }, + { + "name": "get_info", + "long_name": "get_info( self , * args , ** kw )", + "filename": "misc_util.py", + "nloc": 2, + "complexity": 1, + "token_count": 14, + "parameters": [ + "self", + "args", + "kw" + ], + "start_line": 1091, + "end_line": 1092, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 1 + }, + { + "name": "have_f77c", + "long_name": "have_f77c( self , * args , ** kw )", + "filename": "misc_util.py", + "nloc": 2, + "complexity": 1, + "token_count": 13, + "parameters": [ + "self", + "args", + "kw" + ], + "start_line": 1093, + "end_line": 1094, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 1 + }, + { + "name": "have_f90c", + "long_name": "have_f90c( self , * args , ** kw )", + "filename": "misc_util.py", + "nloc": 2, + "complexity": 1, + "token_count": 13, + "parameters": [ + "self", + "args", + "kw" + ], + "start_line": 1095, + "end_line": 1096, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 1 + }, + { + "name": "command_line_ok", + "long_name": "command_line_ok( _cache = [ ] )", + "filename": "misc_util.py", + "nloc": 15, + "complexity": 9, + "token_count": 98, + "parameters": [ + "_cache" + ], + "start_line": 1098, + "end_line": 1115, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 18, + "top_nesting_level": 0 + }, + { + "name": "get_cmd", + "long_name": "get_cmd( cmdname , _cache = { } )", + "filename": "misc_util.py", + "nloc": 11, + "complexity": 3, + "token_count": 65, + "parameters": [ + "cmdname", + "_cache" + ], + "start_line": 1120, + "end_line": 1130, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 11, + "top_nesting_level": 0 + }, + { + "name": "get_numpy_include_dirs", + "long_name": "get_numpy_include_dirs( )", + "filename": "misc_util.py", + "nloc": 11, + "complexity": 3, + "token_count": 77, + "parameters": [], + "start_line": 1132, + "end_line": 1146, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 15, + "top_nesting_level": 0 + }, + { + "name": "default_config_dict", + "long_name": "default_config_dict( name = None , parent_name = None , local_path = None )", + "filename": "misc_util.py", + "nloc": 9, + "complexity": 1, + "token_count": 57, + "parameters": [ + "name", + "parent_name", + "local_path" + ], + "start_line": 1150, + "end_line": 1161, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 12, + "top_nesting_level": 0 + }, + { + "name": "dict_append", + "long_name": "dict_append( d , ** kws )", + "filename": "misc_util.py", + "nloc": 6, + "complexity": 3, + "token_count": 44, + "parameters": [ + "d", + "kws" + ], + "start_line": 1164, + "end_line": 1169, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 6, + "top_nesting_level": 0 + }, + { + "name": "appendpath", + "long_name": "appendpath( prefix , path )", + "filename": "misc_util.py", + "nloc": 19, + "complexity": 6, + "token_count": 230, + "parameters": [ + "prefix", + "path" + ], + "start_line": 1171, + "end_line": 1190, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 20, + "top_nesting_level": 0 + }, + { + "name": "generate_config_py", + "long_name": "generate_config_py( target )", + "filename": "misc_util.py", + "nloc": 27, + "complexity": 2, + "token_count": 117, + "parameters": [ + "target" + ], + "start_line": 1192, + "end_line": 1225, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 34, + "top_nesting_level": 0 + } + ], + "changed_methods": [ + { + "name": "minrelpath", + "long_name": "minrelpath( path )", + "filename": "misc_util.py", + "nloc": 22, + "complexity": 8, + "token_count": 118, + "parameters": [ + "path" + ], + "start_line": 89, + "end_line": 112, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 24, + "top_nesting_level": 0 + } + ], + "nloc": 921, + "complexity": 298, + "token_count": 6501, + "diff_parsed": { + "added": [], + "deleted": [ + " if os.sep != '/':", + " path.replace('/',os.sep)" + ] + } + }, + { + "old_path": "numpy/distutils/tests/test_misc_util.py", + "new_path": "numpy/distutils/tests/test_misc_util.py", + "filename": "test_misc_util.py", + "extension": "py", + "change_type": "MODIFY", + "diff": "@@ -32,13 +32,15 @@ def check_3(self):\n class test_minrelpath(ScipyTestCase):\n \n def check_1(self):\n- assert_equal(minrelpath(join('aa/bb')),'aa/bb')\n- assert_equal(minrelpath(join('..')),'..')\n- assert_equal(minrelpath(join('aa/..')),'')\n- assert_equal(minrelpath(join('aa/../bb')),'bb')\n- assert_equal(minrelpath(join('aa/bb/..')),'aa')\n- assert_equal(minrelpath(join('aa/bb/../..')),'')\n- assert_equal(minrelpath(join('aa/bb/../cc/../dd')),'aa/dd')\n+ import os\n+ n = lambda path: path.replace('/',os.path.sep)\n+ assert_equal(minrelpath(n('aa/bb')),n('aa/bb'))\n+ assert_equal(minrelpath('..'),'..')\n+ assert_equal(minrelpath(n('aa/..')),'')\n+ assert_equal(minrelpath(n('aa/../bb')),'bb')\n+ assert_equal(minrelpath(n('aa/bb/..')),'aa')\n+ assert_equal(minrelpath(n('aa/bb/../..')),'')\n+ assert_equal(minrelpath(n('aa/bb/../cc/../dd')),n('aa/dd'))\n \n if __name__ == \"__main__\":\n ScipyTest().run()\n", + "added_lines": 9, + "deleted_lines": 7, + "source_code": "import sys\nfrom numpy.testing import *\nfrom numpy.distutils.misc_util import appendpath, minrelpath\nfrom os.path import join, sep\n\najoin = lambda *paths: join(*((sep,)+paths))\n\nclass test_appendpath(ScipyTestCase):\n\n def check_1(self):\n assert_equal(appendpath('prefix','name'),join('prefix','name'))\n assert_equal(appendpath('/prefix','name'),ajoin('prefix','name'))\n assert_equal(appendpath('/prefix','/name'),ajoin('prefix','name'))\n assert_equal(appendpath('prefix','/name'),join('prefix','name'))\n\n def check_2(self):\n assert_equal(appendpath('prefix/sub','name'),\n join('prefix','sub','name'))\n assert_equal(appendpath('prefix/sub','sup/name'),\n join('prefix','sub','sup','name'))\n assert_equal(appendpath('/prefix/sub','/prefix/name'),\n ajoin('prefix','sub','name'))\n\n def check_3(self):\n assert_equal(appendpath('/prefix/sub','/prefix/sup/name'),\n ajoin('prefix','sub','sup','name'))\n assert_equal(appendpath('/prefix/sub/sub2','/prefix/sup/sup2/name'),\n ajoin('prefix','sub','sub2','sup','sup2','name'))\n assert_equal(appendpath('/prefix/sub/sub2','/prefix/sub/sup/name'),\n ajoin('prefix','sub','sub2','sup','name'))\n\nclass test_minrelpath(ScipyTestCase):\n\n def check_1(self):\n import os\n n = lambda path: path.replace('/',os.path.sep)\n assert_equal(minrelpath(n('aa/bb')),n('aa/bb'))\n assert_equal(minrelpath('..'),'..')\n assert_equal(minrelpath(n('aa/..')),'')\n assert_equal(minrelpath(n('aa/../bb')),'bb')\n assert_equal(minrelpath(n('aa/bb/..')),'aa')\n assert_equal(minrelpath(n('aa/bb/../..')),'')\n assert_equal(minrelpath(n('aa/bb/../cc/../dd')),n('aa/dd'))\n\nif __name__ == \"__main__\":\n ScipyTest().run()\n", + "source_code_before": "import sys\nfrom numpy.testing import *\nfrom numpy.distutils.misc_util import appendpath, minrelpath\nfrom os.path import join, sep\n\najoin = lambda *paths: join(*((sep,)+paths))\n\nclass test_appendpath(ScipyTestCase):\n\n def check_1(self):\n assert_equal(appendpath('prefix','name'),join('prefix','name'))\n assert_equal(appendpath('/prefix','name'),ajoin('prefix','name'))\n assert_equal(appendpath('/prefix','/name'),ajoin('prefix','name'))\n assert_equal(appendpath('prefix','/name'),join('prefix','name'))\n\n def check_2(self):\n assert_equal(appendpath('prefix/sub','name'),\n join('prefix','sub','name'))\n assert_equal(appendpath('prefix/sub','sup/name'),\n join('prefix','sub','sup','name'))\n assert_equal(appendpath('/prefix/sub','/prefix/name'),\n ajoin('prefix','sub','name'))\n\n def check_3(self):\n assert_equal(appendpath('/prefix/sub','/prefix/sup/name'),\n ajoin('prefix','sub','sup','name'))\n assert_equal(appendpath('/prefix/sub/sub2','/prefix/sup/sup2/name'),\n ajoin('prefix','sub','sub2','sup','sup2','name'))\n assert_equal(appendpath('/prefix/sub/sub2','/prefix/sub/sup/name'),\n ajoin('prefix','sub','sub2','sup','name'))\n\nclass test_minrelpath(ScipyTestCase):\n\n def check_1(self):\n assert_equal(minrelpath(join('aa/bb')),'aa/bb')\n assert_equal(minrelpath(join('..')),'..')\n assert_equal(minrelpath(join('aa/..')),'')\n assert_equal(minrelpath(join('aa/../bb')),'bb')\n assert_equal(minrelpath(join('aa/bb/..')),'aa')\n assert_equal(minrelpath(join('aa/bb/../..')),'')\n assert_equal(minrelpath(join('aa/bb/../cc/../dd')),'aa/dd')\n\nif __name__ == \"__main__\":\n ScipyTest().run()\n", + "methods": [ + { + "name": "check_1", + "long_name": "check_1( self )", + "filename": "test_misc_util.py", + "nloc": 5, + "complexity": 1, + "token_count": 69, + "parameters": [ + "self" + ], + "start_line": 10, + "end_line": 14, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 5, + "top_nesting_level": 1 + }, + { + "name": "check_2", + "long_name": "check_2( self )", + "filename": "test_misc_util.py", + "nloc": 7, + "complexity": 1, + "token_count": 61, + "parameters": [ + "self" + ], + "start_line": 16, + "end_line": 22, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 7, + "top_nesting_level": 1 + }, + { + "name": "check_3", + "long_name": "check_3( self )", + "filename": "test_misc_util.py", + "nloc": 7, + "complexity": 1, + "token_count": 71, + "parameters": [ + "self" + ], + "start_line": 24, + "end_line": 30, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 7, + "top_nesting_level": 1 + }, + { + "name": "check_1", + "long_name": "check_1( self )", + "filename": "test_misc_util.py", + "nloc": 10, + "complexity": 1, + "token_count": 111, + "parameters": [ + "self" + ], + "start_line": 34, + "end_line": 43, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 10, + "top_nesting_level": 1 + } + ], + "methods_before": [ + { + "name": "check_1", + "long_name": "check_1( self )", + "filename": "test_misc_util.py", + "nloc": 5, + "complexity": 1, + "token_count": 69, + "parameters": [ + "self" + ], + "start_line": 10, + "end_line": 14, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 5, + "top_nesting_level": 1 + }, + { + "name": "check_2", + "long_name": "check_2( self )", + "filename": "test_misc_util.py", + "nloc": 7, + "complexity": 1, + "token_count": 61, + "parameters": [ + "self" + ], + "start_line": 16, + "end_line": 22, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 7, + "top_nesting_level": 1 + }, + { + "name": "check_3", + "long_name": "check_3( self )", + "filename": "test_misc_util.py", + "nloc": 7, + "complexity": 1, + "token_count": 71, + "parameters": [ + "self" + ], + "start_line": 24, + "end_line": 30, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 7, + "top_nesting_level": 1 + }, + { + "name": "check_1", + "long_name": "check_1( self )", + "filename": "test_misc_util.py", + "nloc": 8, + "complexity": 1, + "token_count": 89, + "parameters": [ + "self" + ], + "start_line": 34, + "end_line": 41, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 8, + "top_nesting_level": 1 + } + ], + "changed_methods": [ + { + "name": "check_1", + "long_name": "check_1( self )", + "filename": "test_misc_util.py", + "nloc": 10, + "complexity": 1, + "token_count": 111, + "parameters": [ + "self" + ], + "start_line": 34, + "end_line": 43, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 10, + "top_nesting_level": 1 + } + ], + "nloc": 38, + "complexity": 4, + "token_count": 384, + "diff_parsed": { + "added": [ + " import os", + " n = lambda path: path.replace('/',os.path.sep)", + " assert_equal(minrelpath(n('aa/bb')),n('aa/bb'))", + " assert_equal(minrelpath('..'),'..')", + " assert_equal(minrelpath(n('aa/..')),'')", + " assert_equal(minrelpath(n('aa/../bb')),'bb')", + " assert_equal(minrelpath(n('aa/bb/..')),'aa')", + " assert_equal(minrelpath(n('aa/bb/../..')),'')", + " assert_equal(minrelpath(n('aa/bb/../cc/../dd')),n('aa/dd'))" + ], + "deleted": [ + " assert_equal(minrelpath(join('aa/bb')),'aa/bb')", + " assert_equal(minrelpath(join('..')),'..')", + " assert_equal(minrelpath(join('aa/..')),'')", + " assert_equal(minrelpath(join('aa/../bb')),'bb')", + " assert_equal(minrelpath(join('aa/bb/..')),'aa')", + " assert_equal(minrelpath(join('aa/bb/../..')),'')", + " assert_equal(minrelpath(join('aa/bb/../cc/../dd')),'aa/dd')" + ] + } + } + ] + }, + { + "hash": "9175b192fe26d84a9c9b8a06c130baa3405721fe", + "msg": "Add check to make sure title dictionary insert is not over-writing something already there.", + "author": { + "name": "Travis Oliphant", + "email": "oliphant@enthought.com" + }, + "committer": { + "name": "Travis Oliphant", + "email": "oliphant@enthought.com" + }, + "author_date": "2006-02-11T22:24:21+00:00", + "author_timezone": 0, + "committer_date": "2006-02-11T22:24:21+00:00", + "committer_timezone": 0, + "branches": [ + "main" + ], + "in_main_branch": true, + "merge": false, + "parents": [ + "7d4d958724a9ea5259680e84a46837b86b1aefa8" + ], + "project_name": "repo_copy", + "project_path": "/tmp/tmpdjwupkfu/repo_copy", + "deletions": 1, + "insertions": 10, + "lines": 11, + "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": "@@ -3729,7 +3729,16 @@ _convert_from_dict(PyObject *obj, int align)\n \t\t}\n \t\tPyDict_SetItem(fields, name, tup);\n \t\tPy_DECREF(name);\n-\t\tif (len == 3) PyDict_SetItem(fields, item, tup);\n+\t\tif (len == 3) {\n+\t\t\tif (PyDict_GetItem(fields, item) != NULL) {\n+\t\t\t\tPyErr_SetString(PyExc_ValueError, \n+\t\t\t\t\t\t\"titles cannot be the same as names\");\n+\t\t\t\tret=PY_FAIL;\n+\t\t\t}\n+\t\t\telse {\n+\t\t\t\tPyDict_SetItem(fields, item, tup);\n+\t\t\t}\n+\t\t}\n \t\tPy_DECREF(tup);\n \t\tif ((ret == PY_FAIL) || (newdescr->elsize == 0)) goto fail;\n if (!hasobject && newdescr->hasobject)\n", + "added_lines": 10, + "deleted_lines": 1, + "source_code": "\n/*\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 extensively for numpy 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, \"dtype\");\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, \"dtype\",\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)) == 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\tif (mps[i]->ob_type != subtype) {\n\t\t\tprior2 = PyArray_GetPriority((PyObject *)(mps[i]), 0.0);\n\t\t\tif (prior2 > prior1) {\n\t\t\t\tprior1 = prior2;\n\t\t\t\tsubtype = mps[i]->ob_type;\n\t\t\t\tret = mps[i];\n\t\t\t}\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, NULL);\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 Make a new empty array, of the passed size, of a type that takes the\n priority of ap1 and ap2 into account.\n */\nstatic PyArrayObject *\nnew_array_for_sum(PyArrayObject *ap1, PyArrayObject *ap2,\n\t\t int nd, intp dimensions[], int typenum)\n{\n\tPyArrayObject *ret;\n\tPyTypeObject *subtype;\n\tdouble prior1, prior2;\n\t/* Need to choose an output array that can hold a sum \n\t -- use priority to determine which subtype.\n\t */\n\tif (ap2->ob_type != ap1->ob_type) {\n\t\tprior2 = PyArray_GetPriority((PyObject *)ap2, 0.0);\n\t\tprior1 = PyArray_GetPriority((PyObject *)ap1, 0.0);\n\n\t\tsubtype = (prior2 > prior1 ? ap2->ob_type : ap1->ob_type);\n\t} else {\n\t\tprior1 = prior2 = 0.0;\n\t\tsubtype = ap1->ob_type;\n\t}\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\treturn ret;\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\tPyArrayIterObject *it1, *it2;\n\tintp i, j, l;\n\tint typenum, nd;\n\tintp is1, is2, os;\n\tchar *op;\n\tintp dimensions[MAX_DIMS];\n\tPyArray_DotFunc *dot;\n\tPyArray_Descr *typec;\n\t\n\ttypenum = PyArray_ObjectType(op1, 0); \n\ttypenum = PyArray_ObjectType(op2, typenum);\n\n\ttypec = PyArray_DescrFromType(typenum);\n\tPy_INCREF(typec);\n\tap1 = (PyArrayObject *)PyArray_FromAny(op1, typec, 0, 0, \n\t\t\t\t\t BEHAVED_FLAGS, NULL);\n\tif (ap1 == NULL) {Py_DECREF(typec); return NULL;}\n\tap2 = (PyArrayObject *)PyArray_FromAny(op2, typec, 0, 0,\n\t\t\t\t\t BEHAVED_FLAGS, NULL);\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\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\tret = new_array_for_sum(ap1, ap2, nd, dimensions, typenum);\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\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\tit1 = (PyArrayIterObject *)\\\n\t\tPyArray_IterAllButAxis((PyObject *)ap1, ap1->nd-1);\n\tit2 = (PyArrayIterObject *)\\\n\t\tPyArray_IterAllButAxis((PyObject *)ap2, ap2->nd-1);\n\n\twhile(1) {\n\t\twhile(it2->index < it2->size) {\n\t\t\tdot(it1->dataptr, is1, it2->dataptr, is2, op, l, ret);\n\t\t\top += os;\n\t\t\tPyArray_ITER_NEXT(it2);\n\t\t}\n\t\tPyArray_ITER_NEXT(it1);\n\t\tif (it1->index >= it1->size) break;\n\t\tPyArray_ITER_RESET(it2);\n\t}\n\tPy_DECREF(it1);\n\tPy_DECREF(it2);\n\n\tif (PyErr_Occurred()) goto fail;\n\t\t\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/* just like inner product but does the swapaxes stuff on the fly */\n/*MULTIARRAY_API\n Numeric.matrixproduct(a,v)\n*/\nstatic PyObject *\nPyArray_MatrixProduct(PyObject *op1, PyObject *op2) \n{\n\tPyArrayObject *ap1, *ap2, *ret=NULL;\n\tPyArrayIterObject *it1, *it2;\n\tintp i, j, l;\n\tint typenum, nd;\n\tintp is1, is2, os;\n\tchar *op;\n\tintp dimensions[MAX_DIMS];\n\tPyArray_DotFunc *dot;\n\tintp matchDim;\n\tPyArray_Descr *typec;\n\n\ttypenum = PyArray_ObjectType(op1, 0); \n\ttypenum = PyArray_ObjectType(op2, typenum);\t\n\t\n\ttypec = PyArray_DescrFromType(typenum);\n\tPy_INCREF(typec);\n\tap1 = (PyArrayObject *)PyArray_FromAny(op1, typec, 0, 0, \n\t\t\t\t\t BEHAVED_FLAGS, NULL);\n\tif (ap1 == NULL) {Py_DECREF(typec); return NULL;}\n\tap2 = (PyArrayObject *)PyArray_FromAny(op2, typec, 0, 0,\n\t\t\t\t\t BEHAVED_FLAGS, NULL);\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\tif (ap2->nd > 1) {\n\t\tmatchDim = ap2->nd - 2;\n\t}\n\telse {\n\t\tmatchDim = 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\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; istrides[ap1->nd-1]; is2 = ap2->strides[matchDim];\n\n /* Choose which subtype to return */\n\tret = new_array_for_sum(ap1, ap2, nd, dimensions, typenum);\n\tif (ret == NULL) goto fail;\n\n\t/* Ensure that multiarray.dot([],[]) -> 0 */\n\tmemset(PyArray_DATA(ret), 0, PyArray_ITEMSIZE(ret));\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\top = ret->data; os = ret->descr->elsize;\n\n\tit1 = (PyArrayIterObject *)\\\n\t\tPyArray_IterAllButAxis((PyObject *)ap1, ap1->nd-1);\n\tit2 = (PyArrayIterObject *)\\\n\t\tPyArray_IterAllButAxis((PyObject *)ap2, matchDim);\n\n\twhile(1) {\n\t\twhile(it2->index < it2->size) {\n\t\t\tdot(it1->dataptr, is1, it2->dataptr, is2, op, l, ret);\n\t\t\top += os;\n\t\t\tPyArray_ITER_NEXT(it2);\n\t\t}\n\t\tPyArray_ITER_NEXT(it1);\n\t\tif (it1->index >= it1->size) break;\n\t\tPyArray_ITER_RESET(it2);\n\t}\n\tPy_DECREF(it1);\n\tPy_DECREF(it2);\n\tif (PyErr_Occurred()) goto fail; /* only for OBJECT arrays */\n\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/*MULTIARRAY_API\n Fast Copy and Transpose\n*/\nstatic PyObject *\nPyArray_CopyAndTranspose(PyObject *op) \n{\n\tPyObject *ret, *arr;\n\tint nd;\n\tintp dims[2];\n\tintp i,j;\n\tint elsize, str2;\n\tchar *iptr;\n\tchar *optr;\n\n\t/* make sure it is well-behaved */\n\tarr = PyArray_FromAny(op, NULL, 0, 0, CARRAY_FLAGS, NULL);\n\tnd = PyArray_NDIM(arr);\n\tif (nd == 1) { /* we will give in to old behavior */\n\t\tret = PyArray_Copy((PyArrayObject *)arr);\n\t\tPy_DECREF(arr);\n\t\treturn ret;\t\t\n\t}\n\telse if (nd != 2) {\n\t\tPy_DECREF(arr);\n\t\tPyErr_SetString(PyExc_ValueError, \n\t\t\t\t\"only 2-d arrays are allowed\");\n\t\treturn NULL;\n\t}\n\n\t/* Now construct output array */\n\tdims[0] = PyArray_DIM(arr,1);\n\tdims[1] = PyArray_DIM(arr,0);\n\telsize = PyArray_ITEMSIZE(arr);\n\t\n\tPy_INCREF(PyArray_DESCR(arr));\n\tret = PyArray_NewFromDescr(arr->ob_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\tret = new_array_for_sum(ap1, ap2, 1, &length, typenum);\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, NULL);\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\tif (type->type_num == PyArray_UNICODE)\n\t\t\ttype->elsize = itemsize << 2; \n\t\telse\n\t\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\tif (type->hasobject) newdescr->hasobject = 1;\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 int hasobject=0;\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; ihasobject)\n hasobject = 1;\n\t\ttup = PyTuple_New(2);\n\t\tPyTuple_SET_ITEM(tup, 0, (PyObject *)conv);\n\t\tPyTuple_SET_ITEM(tup, 1, PyInt_FromLong((long) totalsize));\n\t\ttotalsize += conv->elsize;\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 new->hasobject=hasobject;\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 int hasobject=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; ihasobject)\n\t\t\thasobject=1;\t\t\t\n\t\tPyTuple_SET_ITEM(tup, 0, (PyObject *)conv);\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\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\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 new->hasobject=hasobject;\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 int hasobject=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\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\tPyTuple_SET_ITEM(tup, 1, PyInt_FromLong(totalsize));\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\tif (PyDict_GetItem(fields, name) != NULL) {\n\t\t\tPyErr_SetString(PyExc_ValueError,\n\t\t\t\t\t\"two fields with the same name\");\n\t\t\tret = PY_FAIL;\n\t\t}\n\t\tPyDict_SetItem(fields, name, tup);\n\t\tPy_DECREF(name);\n\t\tif (len == 3) {\n\t\t\tif (PyDict_GetItem(fields, item) != NULL) {\n\t\t\t\tPyErr_SetString(PyExc_ValueError, \n\t\t\t\t\t\t\"titles cannot be the same as names\");\n\t\t\t\tret=PY_FAIL;\n\t\t\t}\n\t\t\telse {\n\t\t\t\tPyDict_SetItem(fields, item, tup);\n\t\t\t}\n\t\t}\n\t\tPy_DECREF(tup);\n\t\tif ((ret == PY_FAIL) || (newdescr->elsize == 0)) goto fail;\n if (!hasobject && newdescr->hasobject)\n hasobject = 1;\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 new->hasobject=hasobject;\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 == '|' || (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\tint i;\n\t\t\telsize = atoi(type+1);\n\t\t\t/* check for commas present */\n\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\nstatic PyObject *\n_prepend_ones(PyArrayObject *arr, int nd, int ndmin)\n{\n\tintp newdims[MAX_DIMS];\n\tintp newstrides[MAX_DIMS];\n\tint i,k,num;\n\tPyObject *ret;\n\n\tnum = ndmin-nd;\n\tfor (i=0; idescr->elsize;\n\t}\n\tfor (i=num;idimensions[k];\n\t\tnewstrides[i] = arr->strides[k];\n\t}\n\tPy_INCREF(arr->descr);\n\tret = PyArray_NewFromDescr(arr->ob_type, arr->descr, ndmin,\n\t\t\t\t newdims, newstrides, arr->data, arr->flags,\n\t\t\t\t (PyObject *)arr);\n\t/* steals a reference to arr --- so don't increment\n\t here */\n\tPyArray_BASE(ret) = (PyObject *)arr;\n\treturn ret;\n}\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,ndmin=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\"\\\n\t\"The ndmin argument specifies how many dimensions the returned\\n\"\\\n\t\"array should have as a minimum. 1's will be pre-pended to the\\n\"\\\n\t\"shape as needed to meet this requirement.\";\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\t\t\t \"ndmin\", NULL};\n Bool subok=FALSE;\n\tBool copy=TRUE;\n\tint ndmin=0, nd;\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&i\", 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\t\t\t\t&ndmin)) \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\tret = op;\n\t\t\t\tgoto finish;\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\tgoto finish;\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\tret = op;\n\t\t\t\tgoto finish;\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\tgoto finish;\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_CheckFromAny(op, type, 0, 0, flags, NULL)) == NULL) \n\t\treturn NULL;\n\n finish:\n\n\tif ((nd=PyArray_NDIM(ret)) >= ndmin) return ret;\n\t/* create a new array from the same data with ones in the shape */\n\t/* steals a reference to ret */\n\treturn _prepend_ones((PyArrayObject *)ret, nd, ndmin);\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(dtype,obj) will return a new scalar array of the given type initialized with obj. Mainly for pickle support. The dtype must be a valid data-type descriptor. If dtype 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[] = {\"dtype\",\"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}; /* XXX ? */\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\nstatic int\n_skip_sep(char **ptr, char *sep)\n{\n\tchar *a;\n\tint n;\n\tn = strlen(sep);\n\ta = *ptr;\n\twhile(*a != '\\0' && (strncmp(a, sep, n) != 0))\n\t\ta++;\n\tif (*a == '\\0') return -1;\n\t*ptr = a+strlen(sep);\n\treturn 0;\n}\n\n/* steals a reference to dtype -- accepts NULL */\n/*OBJECT_API*/\nstatic PyObject *\nPyArray_FromString(char *data, intp slen, PyArray_Descr *dtype, \n\t\t intp n, char *sep)\n{\n\tint itemsize;\n\tPyArrayObject *ret;\n\tBool binary;\n\n\tif (dtype == NULL)\n\t\tdtype=PyArray_DescrFromType(PyArray_LONG);\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\n\tbinary = ((sep == NULL) || (strlen(sep) == 0));\t\n\n\tif (binary) {\n\t\tif (dtype == &OBJECT_Descr) {\n\t\t\tPyErr_SetString(PyExc_ValueError, \n\t\t\t\t\t\"Cannot create an object array from\"\\\n\t\t\t\t\t\" a binary string\");\n\t\t\tPy_DECREF(dtype);\n\t\t\treturn NULL;\n\t\t}\t\t\n\t\tif (n < 0 ) {\n\t\t\tif (slen % itemsize != 0) {\n\t\t\t\tPyErr_SetString(PyExc_ValueError, \n\t\t\t\t\t\t\"string size must be a \"\\\n\t\t\t\t\t\t\"multiple of element size\");\n\t\t\t\tPy_DECREF(dtype);\n\t\t\t\treturn NULL;\n\t\t\t}\n\t\t\tn = slen/itemsize;\n\t\t} else {\n\t\t\tif (slen < n*itemsize) {\n\t\t\t\tPyErr_SetString(PyExc_ValueError, \n\t\t\t\t\t\t\"string is smaller than \" \\\n\t\t\t\t\t\t\"requested size\");\n\t\t\t\tPy_DECREF(dtype);\n\t\t\t\treturn NULL;\n\t\t\t}\n\t\t}\n\t\n\t\tif ((ret = (PyArrayObject *)\\\n\t\t PyArray_NewFromDescr(&PyArray_Type, dtype,\n\t\t\t\t\t 1, &n, NULL, NULL,\n\t\t\t\t\t 0, NULL)) == NULL)\n\t\t\treturn NULL;\t\t\n\t\tmemcpy(ret->data, data, n*dtype->elsize);\n\t\treturn (PyObject *)ret;\n\t}\n\telse { /* read from character-based string */\n\t\tchar *ptr;\t\t\n\t\tPyArray_FromStrFunc *fromstr;\n\t\tchar *dptr;\n\t\tintp nread=0;\n\t\tintp index;\n\n\t\tfromstr = dtype->f->fromstr;\n\t\tif (fromstr == 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 strings for given \"\t\\\n\t\t\t\t\t\"array type\");\n\t\t\tPy_DECREF(dtype);\n\t\t\treturn NULL;\n\t\t}\n\n\t\tif (n!=-1) {\n\t\t\tret = (PyArrayObject *) \\\n\t\t\t\tPyArray_NewFromDescr(&PyArray_Type,\n\t\t\t\t\t\t dtype, 1, &n, NULL,\n\t\t\t\t\t\t NULL, 0, NULL);\n\t\t\tif (ret == NULL) return NULL;\n\t\t\tptr = data;\n\t\t\tdptr = ret->data;\n\t\t\tfor (index=0; index < n; index++) {\n\t\t\t\tif (fromstr(ptr, dptr, &ptr, ret) < 0)\n\t\t\t\t\tbreak;\n\t\t\t\tnread += 1;\n\t\t\t\tdptr += dtype->elsize;\n\t\t\t\tif (_skip_sep(&ptr, sep) < 0) \n\t\t\t\t\tbreak;\n\t\t\t}\n\t\t\tif (nread < n) {\n\t\t\t\tfprintf(stderr, \"%ld items requested but \"\\\n\t\t\t\t\t\"only %ld read\\n\", \n\t\t\t\t\t(long) n, (long) nread);\n\t\t\t\tret->data = \\\n\t\t\t\t\tPyDataMem_RENEW(ret->data, \n\t\t\t\t\t\t\tnread *\t\t\\\n\t\t\t\t\t\t\tret->descr->elsize);\n\t\t\t\tPyArray_DIM(ret,0) = nread;\n\t\t\t}\n\t\t}\n\t\telse {\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\t\t\tchar *end;\n\t\t\tint val;\n\n\t\t\tret = (PyArrayObject *)\\\n\t\t\t\tPyArray_NewFromDescr(&PyArray_Type, \n\t\t\t\t\t\t dtype,\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 (ret==NULL) return NULL;\n\t\t\ttotalbytes = bytes = size * dtype->elsize;\n\t\t\tdptr = ret->data;\n\t\t\tptr = data;\n\t\t\tend = data+slen;\n\t\t\twhile (ptr < end) {\n\t\t\t\tval = fromstr(ptr, dptr, &ptr, ret);\n\t\t\t\tif (val < 0) break;\n\t\t\t\tnread += 1;\n\t\t\t\tval = _skip_sep(&ptr, sep);\n\t\t\t\tif (val < 0) break;\n\t\t\t\tthisbuf += 1;\n\t\t\t\tdptr += dtype->elsize;\n\t\t\t\tif (thisbuf == size) {\n\t\t\t\t\ttotalbytes += bytes;\n\t\t\t\t\tret->data = PyDataMem_RENEW(ret->data, \n\t\t\t\t\t\t\t\t totalbytes);\n\t\t\t\t\tdptr = ret->data + \\\n\t\t\t\t\t\t(totalbytes - bytes);\n\t\t\t\t\tthisbuf = 0;\n\t\t\t\t}\n\t\t\t}\n\t\t\tret->data = PyDataMem_RENEW(ret->data, \n\t\t\t\t\t\t nread*ret->descr->elsize);\n\t\t\tPyArray_DIM(ret,0) = nread;\n#undef _FILEBUFNUM\n\t\t}\n\t}\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\tchar *sep=NULL;\n\tint s;\n\tstatic char *kwlist[] = {\"string\", \"dtype\", \"count\", \"sep\", NULL};\n\tPyArray_Descr *descr=NULL;\n\n\tif (!PyArg_ParseTupleAndKeywords(args, keywds, \"s#|O&Ls\", 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, &sep)) {\n\t\treturn NULL;\n\t}\n\n\treturn PyArray_FromString(data, (intp)s, descr, (intp)nin, sep);\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\tPy_DECREF(typecode);\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\tPy_DECREF(typecode);\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\tPy_DECREF(typecode);\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 platform-independent method of persistence. But it can be \\n\"\\\n\t\" useful to 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_BYTES(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_BYTES(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[] = \n\"arange([start,] stop[, step,], dtype=None)\\n\\n\"\n\"For integer arguments, just like range() except it returns an array whose type can\\n\"\n\"be specified by the keyword argument dtype.\\n\\n\"\n\"If dtype is not specified, the type of the result is deduced from the type of the\\n\"\n\"arguments.\\n\\n\"\n\"For floating point arguments, the length of the result is ceil((stop - start)/step).\\n\"\n\"This rule may result in the last element of the result be greater than stop.\";\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_DescrConverter2,\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/*MULTIARRAY_API\n GetNDArrayCVersion\n*/\nstatic unsigned int\nPyArray_GetNDArrayCVersion(void)\n{\n\treturn (unsigned int)NDARRAY_VERSION;\n}\n\nstatic char \ndoc__get_ndarray_c_version[] = \"_get_ndarray_c_version() gets the compile time NDARRAY_VERSION number\";\n\nstatic PyObject *\narray__get_ndarray_c_version(PyObject *dummy, PyObject *args, PyObject *kwds) \n{\n\tstatic char *kwlist[] = {NULL};\n\tif(!PyArg_ParseTupleAndKeywords(args, kwds, \"\", kwlist )) return NULL;\n\t\n\treturn PyInt_FromLong( (long) PyArray_GetNDArrayCVersion() );\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, NULL);\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{\"_get_ndarray_c_version\", (PyCFunction)array__get_ndarray_c_version, \n\t METH_VARARGS|METH_KEYWORDS, doc__get_ndarray_c_version},\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, \"dtype\", (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\tif (!PyErr_Occurred()) {\n\t\tPyErr_SetString(PyExc_RuntimeError, \n\t\t\t\t\"cannot load multiarray module.\");\n\t}\n\treturn;\n}\n\n", + "source_code_before": "\n/*\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 extensively for numpy 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, \"dtype\");\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, \"dtype\",\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)) == 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\tif (mps[i]->ob_type != subtype) {\n\t\t\tprior2 = PyArray_GetPriority((PyObject *)(mps[i]), 0.0);\n\t\t\tif (prior2 > prior1) {\n\t\t\t\tprior1 = prior2;\n\t\t\t\tsubtype = mps[i]->ob_type;\n\t\t\t\tret = mps[i];\n\t\t\t}\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, NULL);\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 Make a new empty array, of the passed size, of a type that takes the\n priority of ap1 and ap2 into account.\n */\nstatic PyArrayObject *\nnew_array_for_sum(PyArrayObject *ap1, PyArrayObject *ap2,\n\t\t int nd, intp dimensions[], int typenum)\n{\n\tPyArrayObject *ret;\n\tPyTypeObject *subtype;\n\tdouble prior1, prior2;\n\t/* Need to choose an output array that can hold a sum \n\t -- use priority to determine which subtype.\n\t */\n\tif (ap2->ob_type != ap1->ob_type) {\n\t\tprior2 = PyArray_GetPriority((PyObject *)ap2, 0.0);\n\t\tprior1 = PyArray_GetPriority((PyObject *)ap1, 0.0);\n\n\t\tsubtype = (prior2 > prior1 ? ap2->ob_type : ap1->ob_type);\n\t} else {\n\t\tprior1 = prior2 = 0.0;\n\t\tsubtype = ap1->ob_type;\n\t}\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\treturn ret;\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\tPyArrayIterObject *it1, *it2;\n\tintp i, j, l;\n\tint typenum, nd;\n\tintp is1, is2, os;\n\tchar *op;\n\tintp dimensions[MAX_DIMS];\n\tPyArray_DotFunc *dot;\n\tPyArray_Descr *typec;\n\t\n\ttypenum = PyArray_ObjectType(op1, 0); \n\ttypenum = PyArray_ObjectType(op2, typenum);\n\n\ttypec = PyArray_DescrFromType(typenum);\n\tPy_INCREF(typec);\n\tap1 = (PyArrayObject *)PyArray_FromAny(op1, typec, 0, 0, \n\t\t\t\t\t BEHAVED_FLAGS, NULL);\n\tif (ap1 == NULL) {Py_DECREF(typec); return NULL;}\n\tap2 = (PyArrayObject *)PyArray_FromAny(op2, typec, 0, 0,\n\t\t\t\t\t BEHAVED_FLAGS, NULL);\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\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\tret = new_array_for_sum(ap1, ap2, nd, dimensions, typenum);\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\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\tit1 = (PyArrayIterObject *)\\\n\t\tPyArray_IterAllButAxis((PyObject *)ap1, ap1->nd-1);\n\tit2 = (PyArrayIterObject *)\\\n\t\tPyArray_IterAllButAxis((PyObject *)ap2, ap2->nd-1);\n\n\twhile(1) {\n\t\twhile(it2->index < it2->size) {\n\t\t\tdot(it1->dataptr, is1, it2->dataptr, is2, op, l, ret);\n\t\t\top += os;\n\t\t\tPyArray_ITER_NEXT(it2);\n\t\t}\n\t\tPyArray_ITER_NEXT(it1);\n\t\tif (it1->index >= it1->size) break;\n\t\tPyArray_ITER_RESET(it2);\n\t}\n\tPy_DECREF(it1);\n\tPy_DECREF(it2);\n\n\tif (PyErr_Occurred()) goto fail;\n\t\t\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/* just like inner product but does the swapaxes stuff on the fly */\n/*MULTIARRAY_API\n Numeric.matrixproduct(a,v)\n*/\nstatic PyObject *\nPyArray_MatrixProduct(PyObject *op1, PyObject *op2) \n{\n\tPyArrayObject *ap1, *ap2, *ret=NULL;\n\tPyArrayIterObject *it1, *it2;\n\tintp i, j, l;\n\tint typenum, nd;\n\tintp is1, is2, os;\n\tchar *op;\n\tintp dimensions[MAX_DIMS];\n\tPyArray_DotFunc *dot;\n\tintp matchDim;\n\tPyArray_Descr *typec;\n\n\ttypenum = PyArray_ObjectType(op1, 0); \n\ttypenum = PyArray_ObjectType(op2, typenum);\t\n\t\n\ttypec = PyArray_DescrFromType(typenum);\n\tPy_INCREF(typec);\n\tap1 = (PyArrayObject *)PyArray_FromAny(op1, typec, 0, 0, \n\t\t\t\t\t BEHAVED_FLAGS, NULL);\n\tif (ap1 == NULL) {Py_DECREF(typec); return NULL;}\n\tap2 = (PyArrayObject *)PyArray_FromAny(op2, typec, 0, 0,\n\t\t\t\t\t BEHAVED_FLAGS, NULL);\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\tif (ap2->nd > 1) {\n\t\tmatchDim = ap2->nd - 2;\n\t}\n\telse {\n\t\tmatchDim = 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\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; istrides[ap1->nd-1]; is2 = ap2->strides[matchDim];\n\n /* Choose which subtype to return */\n\tret = new_array_for_sum(ap1, ap2, nd, dimensions, typenum);\n\tif (ret == NULL) goto fail;\n\n\t/* Ensure that multiarray.dot([],[]) -> 0 */\n\tmemset(PyArray_DATA(ret), 0, PyArray_ITEMSIZE(ret));\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\top = ret->data; os = ret->descr->elsize;\n\n\tit1 = (PyArrayIterObject *)\\\n\t\tPyArray_IterAllButAxis((PyObject *)ap1, ap1->nd-1);\n\tit2 = (PyArrayIterObject *)\\\n\t\tPyArray_IterAllButAxis((PyObject *)ap2, matchDim);\n\n\twhile(1) {\n\t\twhile(it2->index < it2->size) {\n\t\t\tdot(it1->dataptr, is1, it2->dataptr, is2, op, l, ret);\n\t\t\top += os;\n\t\t\tPyArray_ITER_NEXT(it2);\n\t\t}\n\t\tPyArray_ITER_NEXT(it1);\n\t\tif (it1->index >= it1->size) break;\n\t\tPyArray_ITER_RESET(it2);\n\t}\n\tPy_DECREF(it1);\n\tPy_DECREF(it2);\n\tif (PyErr_Occurred()) goto fail; /* only for OBJECT arrays */\n\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/*MULTIARRAY_API\n Fast Copy and Transpose\n*/\nstatic PyObject *\nPyArray_CopyAndTranspose(PyObject *op) \n{\n\tPyObject *ret, *arr;\n\tint nd;\n\tintp dims[2];\n\tintp i,j;\n\tint elsize, str2;\n\tchar *iptr;\n\tchar *optr;\n\n\t/* make sure it is well-behaved */\n\tarr = PyArray_FromAny(op, NULL, 0, 0, CARRAY_FLAGS, NULL);\n\tnd = PyArray_NDIM(arr);\n\tif (nd == 1) { /* we will give in to old behavior */\n\t\tret = PyArray_Copy((PyArrayObject *)arr);\n\t\tPy_DECREF(arr);\n\t\treturn ret;\t\t\n\t}\n\telse if (nd != 2) {\n\t\tPy_DECREF(arr);\n\t\tPyErr_SetString(PyExc_ValueError, \n\t\t\t\t\"only 2-d arrays are allowed\");\n\t\treturn NULL;\n\t}\n\n\t/* Now construct output array */\n\tdims[0] = PyArray_DIM(arr,1);\n\tdims[1] = PyArray_DIM(arr,0);\n\telsize = PyArray_ITEMSIZE(arr);\n\t\n\tPy_INCREF(PyArray_DESCR(arr));\n\tret = PyArray_NewFromDescr(arr->ob_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\tret = new_array_for_sum(ap1, ap2, 1, &length, typenum);\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, NULL);\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\tif (type->type_num == PyArray_UNICODE)\n\t\t\ttype->elsize = itemsize << 2; \n\t\telse\n\t\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\tif (type->hasobject) newdescr->hasobject = 1;\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 int hasobject=0;\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; ihasobject)\n hasobject = 1;\n\t\ttup = PyTuple_New(2);\n\t\tPyTuple_SET_ITEM(tup, 0, (PyObject *)conv);\n\t\tPyTuple_SET_ITEM(tup, 1, PyInt_FromLong((long) totalsize));\n\t\ttotalsize += conv->elsize;\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 new->hasobject=hasobject;\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 int hasobject=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; ihasobject)\n\t\t\thasobject=1;\t\t\t\n\t\tPyTuple_SET_ITEM(tup, 0, (PyObject *)conv);\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\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\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 new->hasobject=hasobject;\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 int hasobject=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\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\tPyTuple_SET_ITEM(tup, 1, PyInt_FromLong(totalsize));\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\tif (PyDict_GetItem(fields, name) != NULL) {\n\t\t\tPyErr_SetString(PyExc_ValueError,\n\t\t\t\t\t\"two fields with the same name\");\n\t\t\tret = PY_FAIL;\n\t\t}\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 if (!hasobject && newdescr->hasobject)\n hasobject = 1;\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 new->hasobject=hasobject;\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 == '|' || (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\tint i;\n\t\t\telsize = atoi(type+1);\n\t\t\t/* check for commas present */\n\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\nstatic PyObject *\n_prepend_ones(PyArrayObject *arr, int nd, int ndmin)\n{\n\tintp newdims[MAX_DIMS];\n\tintp newstrides[MAX_DIMS];\n\tint i,k,num;\n\tPyObject *ret;\n\n\tnum = ndmin-nd;\n\tfor (i=0; idescr->elsize;\n\t}\n\tfor (i=num;idimensions[k];\n\t\tnewstrides[i] = arr->strides[k];\n\t}\n\tPy_INCREF(arr->descr);\n\tret = PyArray_NewFromDescr(arr->ob_type, arr->descr, ndmin,\n\t\t\t\t newdims, newstrides, arr->data, arr->flags,\n\t\t\t\t (PyObject *)arr);\n\t/* steals a reference to arr --- so don't increment\n\t here */\n\tPyArray_BASE(ret) = (PyObject *)arr;\n\treturn ret;\n}\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,ndmin=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\"\\\n\t\"The ndmin argument specifies how many dimensions the returned\\n\"\\\n\t\"array should have as a minimum. 1's will be pre-pended to the\\n\"\\\n\t\"shape as needed to meet this requirement.\";\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\t\t\t \"ndmin\", NULL};\n Bool subok=FALSE;\n\tBool copy=TRUE;\n\tint ndmin=0, nd;\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&i\", 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\t\t\t\t&ndmin)) \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\tret = op;\n\t\t\t\tgoto finish;\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\tgoto finish;\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\tret = op;\n\t\t\t\tgoto finish;\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\tgoto finish;\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_CheckFromAny(op, type, 0, 0, flags, NULL)) == NULL) \n\t\treturn NULL;\n\n finish:\n\n\tif ((nd=PyArray_NDIM(ret)) >= ndmin) return ret;\n\t/* create a new array from the same data with ones in the shape */\n\t/* steals a reference to ret */\n\treturn _prepend_ones((PyArrayObject *)ret, nd, ndmin);\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(dtype,obj) will return a new scalar array of the given type initialized with obj. Mainly for pickle support. The dtype must be a valid data-type descriptor. If dtype 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[] = {\"dtype\",\"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}; /* XXX ? */\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\nstatic int\n_skip_sep(char **ptr, char *sep)\n{\n\tchar *a;\n\tint n;\n\tn = strlen(sep);\n\ta = *ptr;\n\twhile(*a != '\\0' && (strncmp(a, sep, n) != 0))\n\t\ta++;\n\tif (*a == '\\0') return -1;\n\t*ptr = a+strlen(sep);\n\treturn 0;\n}\n\n/* steals a reference to dtype -- accepts NULL */\n/*OBJECT_API*/\nstatic PyObject *\nPyArray_FromString(char *data, intp slen, PyArray_Descr *dtype, \n\t\t intp n, char *sep)\n{\n\tint itemsize;\n\tPyArrayObject *ret;\n\tBool binary;\n\n\tif (dtype == NULL)\n\t\tdtype=PyArray_DescrFromType(PyArray_LONG);\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\n\tbinary = ((sep == NULL) || (strlen(sep) == 0));\t\n\n\tif (binary) {\n\t\tif (dtype == &OBJECT_Descr) {\n\t\t\tPyErr_SetString(PyExc_ValueError, \n\t\t\t\t\t\"Cannot create an object array from\"\\\n\t\t\t\t\t\" a binary string\");\n\t\t\tPy_DECREF(dtype);\n\t\t\treturn NULL;\n\t\t}\t\t\n\t\tif (n < 0 ) {\n\t\t\tif (slen % itemsize != 0) {\n\t\t\t\tPyErr_SetString(PyExc_ValueError, \n\t\t\t\t\t\t\"string size must be a \"\\\n\t\t\t\t\t\t\"multiple of element size\");\n\t\t\t\tPy_DECREF(dtype);\n\t\t\t\treturn NULL;\n\t\t\t}\n\t\t\tn = slen/itemsize;\n\t\t} else {\n\t\t\tif (slen < n*itemsize) {\n\t\t\t\tPyErr_SetString(PyExc_ValueError, \n\t\t\t\t\t\t\"string is smaller than \" \\\n\t\t\t\t\t\t\"requested size\");\n\t\t\t\tPy_DECREF(dtype);\n\t\t\t\treturn NULL;\n\t\t\t}\n\t\t}\n\t\n\t\tif ((ret = (PyArrayObject *)\\\n\t\t PyArray_NewFromDescr(&PyArray_Type, dtype,\n\t\t\t\t\t 1, &n, NULL, NULL,\n\t\t\t\t\t 0, NULL)) == NULL)\n\t\t\treturn NULL;\t\t\n\t\tmemcpy(ret->data, data, n*dtype->elsize);\n\t\treturn (PyObject *)ret;\n\t}\n\telse { /* read from character-based string */\n\t\tchar *ptr;\t\t\n\t\tPyArray_FromStrFunc *fromstr;\n\t\tchar *dptr;\n\t\tintp nread=0;\n\t\tintp index;\n\n\t\tfromstr = dtype->f->fromstr;\n\t\tif (fromstr == 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 strings for given \"\t\\\n\t\t\t\t\t\"array type\");\n\t\t\tPy_DECREF(dtype);\n\t\t\treturn NULL;\n\t\t}\n\n\t\tif (n!=-1) {\n\t\t\tret = (PyArrayObject *) \\\n\t\t\t\tPyArray_NewFromDescr(&PyArray_Type,\n\t\t\t\t\t\t dtype, 1, &n, NULL,\n\t\t\t\t\t\t NULL, 0, NULL);\n\t\t\tif (ret == NULL) return NULL;\n\t\t\tptr = data;\n\t\t\tdptr = ret->data;\n\t\t\tfor (index=0; index < n; index++) {\n\t\t\t\tif (fromstr(ptr, dptr, &ptr, ret) < 0)\n\t\t\t\t\tbreak;\n\t\t\t\tnread += 1;\n\t\t\t\tdptr += dtype->elsize;\n\t\t\t\tif (_skip_sep(&ptr, sep) < 0) \n\t\t\t\t\tbreak;\n\t\t\t}\n\t\t\tif (nread < n) {\n\t\t\t\tfprintf(stderr, \"%ld items requested but \"\\\n\t\t\t\t\t\"only %ld read\\n\", \n\t\t\t\t\t(long) n, (long) nread);\n\t\t\t\tret->data = \\\n\t\t\t\t\tPyDataMem_RENEW(ret->data, \n\t\t\t\t\t\t\tnread *\t\t\\\n\t\t\t\t\t\t\tret->descr->elsize);\n\t\t\t\tPyArray_DIM(ret,0) = nread;\n\t\t\t}\n\t\t}\n\t\telse {\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\t\t\tchar *end;\n\t\t\tint val;\n\n\t\t\tret = (PyArrayObject *)\\\n\t\t\t\tPyArray_NewFromDescr(&PyArray_Type, \n\t\t\t\t\t\t dtype,\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 (ret==NULL) return NULL;\n\t\t\ttotalbytes = bytes = size * dtype->elsize;\n\t\t\tdptr = ret->data;\n\t\t\tptr = data;\n\t\t\tend = data+slen;\n\t\t\twhile (ptr < end) {\n\t\t\t\tval = fromstr(ptr, dptr, &ptr, ret);\n\t\t\t\tif (val < 0) break;\n\t\t\t\tnread += 1;\n\t\t\t\tval = _skip_sep(&ptr, sep);\n\t\t\t\tif (val < 0) break;\n\t\t\t\tthisbuf += 1;\n\t\t\t\tdptr += dtype->elsize;\n\t\t\t\tif (thisbuf == size) {\n\t\t\t\t\ttotalbytes += bytes;\n\t\t\t\t\tret->data = PyDataMem_RENEW(ret->data, \n\t\t\t\t\t\t\t\t totalbytes);\n\t\t\t\t\tdptr = ret->data + \\\n\t\t\t\t\t\t(totalbytes - bytes);\n\t\t\t\t\tthisbuf = 0;\n\t\t\t\t}\n\t\t\t}\n\t\t\tret->data = PyDataMem_RENEW(ret->data, \n\t\t\t\t\t\t nread*ret->descr->elsize);\n\t\t\tPyArray_DIM(ret,0) = nread;\n#undef _FILEBUFNUM\n\t\t}\n\t}\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\tchar *sep=NULL;\n\tint s;\n\tstatic char *kwlist[] = {\"string\", \"dtype\", \"count\", \"sep\", NULL};\n\tPyArray_Descr *descr=NULL;\n\n\tif (!PyArg_ParseTupleAndKeywords(args, keywds, \"s#|O&Ls\", 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, &sep)) {\n\t\treturn NULL;\n\t}\n\n\treturn PyArray_FromString(data, (intp)s, descr, (intp)nin, sep);\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\tPy_DECREF(typecode);\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\tPy_DECREF(typecode);\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\tPy_DECREF(typecode);\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 platform-independent method of persistence. But it can be \\n\"\\\n\t\" useful to 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_BYTES(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_BYTES(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[] = \n\"arange([start,] stop[, step,], dtype=None)\\n\\n\"\n\"For integer arguments, just like range() except it returns an array whose type can\\n\"\n\"be specified by the keyword argument dtype.\\n\\n\"\n\"If dtype is not specified, the type of the result is deduced from the type of the\\n\"\n\"arguments.\\n\\n\"\n\"For floating point arguments, the length of the result is ceil((stop - start)/step).\\n\"\n\"This rule may result in the last element of the result be greater than stop.\";\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_DescrConverter2,\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/*MULTIARRAY_API\n GetNDArrayCVersion\n*/\nstatic unsigned int\nPyArray_GetNDArrayCVersion(void)\n{\n\treturn (unsigned int)NDARRAY_VERSION;\n}\n\nstatic char \ndoc__get_ndarray_c_version[] = \"_get_ndarray_c_version() gets the compile time NDARRAY_VERSION number\";\n\nstatic PyObject *\narray__get_ndarray_c_version(PyObject *dummy, PyObject *args, PyObject *kwds) \n{\n\tstatic char *kwlist[] = {NULL};\n\tif(!PyArg_ParseTupleAndKeywords(args, kwds, \"\", kwlist )) return NULL;\n\t\n\treturn PyInt_FromLong( (long) PyArray_GetNDArrayCVersion() );\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, NULL);\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{\"_get_ndarray_c_version\", (PyCFunction)array__get_ndarray_c_version, \n\t METH_VARARGS|METH_KEYWORDS, doc__get_ndarray_c_version},\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, \"dtype\", (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\tif (!PyErr_Occurred()) {\n\t\tPyErr_SetString(PyExc_RuntimeError, \n\t\t\t\t\"cannot load multiarray module.\");\n\t}\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": 35, + "end_line": 50, + "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": 75, + "end_line": 80, + "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": 86, + "end_line": 91, + "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": 97, + "end_line": 105, + "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": 111, + "end_line": 123, + "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": 129, + "end_line": 136, + "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": 143, + "end_line": 173, + "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": 179, + "end_line": 196, + "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": 202, + "end_line": 237, + "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": 248, + "end_line": 257, + "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": 260, + "end_line": 286, + "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": 297, + "end_line": 384, + "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": 393, + "end_line": 428, + "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": 435, + "end_line": 456, + "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": 463, + "end_line": 522, + "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": 529, + "end_line": 539, + "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": 545, + "end_line": 555, + "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": 561, + "end_line": 571, + "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": 577, + "end_line": 588, + "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": 594, + "end_line": 605, + "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": 611, + "end_line": 622, + "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": 102, + "parameters": [ + "self", + "condition", + "axis" + ], + "start_line": 629, + "end_line": 649, + "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": 655, + "end_line": 714, + "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": 720, + "end_line": 750, + "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": 756, + "end_line": 792, + "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": 798, + "end_line": 808, + "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": 776, + "parameters": [ + "self", + "offset", + "axis1", + "axis2" + ], + "start_line": 814, + "end_line": 933, + "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": 402, + "parameters": [ + "op", + "ptr", + "dims", + "nd", + "typedescr" + ], + "start_line": 949, + "end_line": 1000, + "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": 1008, + "end_line": 1018, + "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": 1024, + "end_line": 1036, + "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": 1044, + "end_line": 1055, + "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": 1059, + "end_line": 1087, + "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": 94, + "complexity": 21, + "token_count": 630, + "parameters": [ + "op", + "axis" + ], + "start_line": 1099, + "end_line": 1205, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 107, + "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": 1211, + "end_line": 1252, + "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": 1258, + "end_line": 1311, + "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": 1317, + "end_line": 1412, + "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": 65, + "complexity": 13, + "token_count": 439, + "parameters": [ + "op", + "retn" + ], + "start_line": 1416, + "end_line": 1487, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 72, + "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": 1494, + "end_line": 1575, + "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": 1578, + "end_line": 1585, + "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": 1596, + "end_line": 1650, + "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": 1653, + "end_line": 1731, + "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": 1739, + "end_line": 1742, + "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": 355, + "parameters": [ + "op", + "axis", + "which" + ], + "start_line": 1797, + "end_line": 1863, + "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": 1869, + "end_line": 1877, + "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": 1883, + "end_line": 1963, + "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": 1975, + "end_line": 2119, + "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": 2123, + "end_line": 2158, + "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": 2164, + "end_line": 2209, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 46, + "top_nesting_level": 0 + }, + { + "name": "new_array_for_sum", + "long_name": "new_array_for_sum( PyArrayObject * ap1 , PyArrayObject * ap2 , int nd , intp dimensions [ ] , int typenum)", + "filename": "multiarraymodule.c", + "nloc": 20, + "complexity": 4, + "token_count": 147, + "parameters": [ + "ap1", + "ap2", + "nd", + "typenum" + ], + "start_line": 2216, + "end_line": 2240, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 25, + "top_nesting_level": 0 + }, + { + "name": "PyArray_InnerProduct", + "long_name": "PyArray_InnerProduct( PyObject * op1 , PyObject * op2)", + "filename": "multiarraymodule.c", + "nloc": 79, + "complexity": 15, + "token_count": 624, + "parameters": [ + "op1", + "op2" + ], + "start_line": 2249, + "end_line": 2347, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 99, + "top_nesting_level": 0 + }, + { + "name": "PyArray_MatrixProduct", + "long_name": "PyArray_MatrixProduct( PyObject * op1 , PyObject * op2)", + "filename": "multiarraymodule.c", + "nloc": 89, + "complexity": 17, + "token_count": 680, + "parameters": [ + "op1", + "op2" + ], + "start_line": 2355, + "end_line": 2466, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 112, + "top_nesting_level": 0 + }, + { + "name": "PyArray_CopyAndTranspose", + "long_name": "PyArray_CopyAndTranspose( PyObject * op)", + "filename": "multiarraymodule.c", + "nloc": 47, + "complexity": 6, + "token_count": 286, + "parameters": [ + "op" + ], + "start_line": 2472, + "end_line": 2526, + "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": 86, + "complexity": 13, + "token_count": 601, + "parameters": [ + "op1", + "op2", + "mode" + ], + "start_line": 2532, + "end_line": 2629, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 98, + "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": 2636, + "end_line": 2660, + "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": 2666, + "end_line": 2677, + "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": 2683, + "end_line": 2694, + "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": 2700, + "end_line": 2723, + "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": 2730, + "end_line": 2787, + "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": 2794, + "end_line": 2869, + "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": 2875, + "end_line": 2944, + "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": 2950, + "end_line": 3021, + "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": 68, + "parameters": [ + "object", + "address" + ], + "start_line": 3037, + "end_line": 3049, + "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": 3055, + "end_line": 3063, + "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": 3070, + "end_line": 3185, + "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": 3203, + "end_line": 3228, + "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": 3243, + "end_line": 3279, + "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": 3297, + "end_line": 3330, + "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": 65, + "complexity": 16, + "token_count": 399, + "parameters": [ + "obj" + ], + "start_line": 3333, + "end_line": 3410, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 78, + "top_nesting_level": 0 + }, + { + "name": "_convert_from_array_descr", + "long_name": "_convert_from_array_descr( PyObject * obj)", + "filename": "multiarraymodule.c", + "nloc": 69, + "complexity": 14, + "token_count": 442, + "parameters": [ + "obj" + ], + "start_line": 3418, + "end_line": 3489, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 72, + "top_nesting_level": 0 + }, + { + "name": "_convert_from_list", + "long_name": "_convert_from_list( PyObject * obj , int align , int try_descr)", + "filename": "multiarraymodule.c", + "nloc": 70, + "complexity": 13, + "token_count": 428, + "parameters": [ + "obj", + "align", + "try_descr" + ], + "start_line": 3500, + "end_line": 3571, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 72, + "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": 3584, + "end_line": 3600, + "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": 3637, + "end_line": 3642, + "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": 111, + "complexity": 29, + "token_count": 718, + "parameters": [ + "obj", + "align" + ], + "start_line": 3645, + "end_line": 3765, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 121, + "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": 3783, + "end_line": 3790, + "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": 141, + "complexity": 55, + "token_count": 886, + "parameters": [ + "obj", + "at" + ], + "start_line": 3807, + "end_line": 3987, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 181, + "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": 3993, + "end_line": 4025, + "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": 4031, + "end_line": 4057, + "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": 4066, + "end_line": 4085, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 20, + "top_nesting_level": 0 + }, + { + "name": "_prepend_ones", + "long_name": "_prepend_ones( PyArrayObject * arr , int nd , int ndmin)", + "filename": "multiarraymodule.c", + "nloc": 23, + "complexity": 3, + "token_count": 175, + "parameters": [ + "arr", + "nd", + "ndmin" + ], + "start_line": 4090, + "end_line": 4115, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 26, + "top_nesting_level": 0 + }, + { + "name": "_array_fromobject", + "long_name": "_array_fromobject( PyObject * ignored , PyObject * args , PyObject * kws)", + "filename": "multiarraymodule.c", + "nloc": 66, + "complexity": 16, + "token_count": 380, + "parameters": [ + "ignored", + "args", + "kws" + ], + "start_line": 4137, + "end_line": 4212, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 76, + "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": 4220, + "end_line": 4235, + "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": 4241, + "end_line": 4265, + "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": 4270, + "end_line": 4328, + "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": 4337, + "end_line": 4361, + "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": 4367, + "end_line": 4391, + "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": 4398, + "end_line": 4407, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 10, + "top_nesting_level": 0 + }, + { + "name": "_skip_sep", + "long_name": "_skip_sep( char ** ptr , char * sep)", + "filename": "multiarraymodule.c", + "nloc": 12, + "complexity": 4, + "token_count": 78, + "parameters": [ + "ptr", + "sep" + ], + "start_line": 4410, + "end_line": 4421, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 12, + "top_nesting_level": 0 + }, + { + "name": "PyArray_FromString", + "long_name": "PyArray_FromString( char * data , intp slen , PyArray_Descr * dtype , intp n , char * sep)", + "filename": "multiarraymodule.c", + "nloc": 133, + "complexity": 22, + "token_count": 711, + "parameters": [ + "data", + "slen", + "dtype", + "n", + "sep" + ], + "start_line": 4426, + "end_line": 4568, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 143, + "top_nesting_level": 0 + }, + { + "name": "array_fromString", + "long_name": "array_fromString( PyObject * ignored , PyObject * args , PyObject * keywds)", + "filename": "multiarraymodule.c", + "nloc": 16, + "complexity": 2, + "token_count": 116, + "parameters": [ + "ignored", + "args", + "keywds" + ], + "start_line": 4573, + "end_line": 4590, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 18, + "top_nesting_level": 0 + }, + { + "name": "PyArray_FromFile", + "long_name": "PyArray_FromFile( FILE * fp , PyArray_Descr * typecode , intp num , char * sep)", + "filename": "multiarraymodule.c", + "nloc": 114, + "complexity": 22, + "token_count": 664, + "parameters": [ + "fp", + "typecode", + "num", + "sep" + ], + "start_line": 4604, + "end_line": 4732, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 129, + "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": 4750, + "end_line": 4788, + "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": 4792, + "end_line": 4885, + "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": 4901, + "end_line": 4918, + "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": 4924, + "end_line": 4935, + "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": 4942, + "end_line": 4948, + "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": 4955, + "end_line": 4961, + "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": 4965, + "end_line": 4971, + "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": 4975, + "end_line": 4984, + "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": 4991, + "end_line": 5042, + "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": 5048, + "end_line": 5080, + "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": 5087, + "end_line": 5171, + "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": 5184, + "end_line": 5196, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 13, + "top_nesting_level": 0 + }, + { + "name": "PyArray_GetNDArrayCVersion", + "long_name": "PyArray_GetNDArrayCVersion()", + "filename": "multiarraymodule.c", + "nloc": 4, + "complexity": 1, + "token_count": 13, + "parameters": [], + "start_line": 5202, + "end_line": 5205, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 0 + }, + { + "name": "array__get_ndarray_c_version", + "long_name": "array__get_ndarray_c_version( PyObject * dummy , PyObject * args , PyObject * kwds)", + "filename": "multiarraymodule.c", + "nloc": 6, + "complexity": 2, + "token_count": 55, + "parameters": [ + "dummy", + "args", + "kwds" + ], + "start_line": 5211, + "end_line": 5217, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 7, + "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": 5223, + "end_line": 5239, + "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": 5245, + "end_line": 5262, + "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": 233, + "parameters": [ + "condition", + "x", + "y" + ], + "start_line": 5269, + "end_line": 5309, + "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": 5317, + "end_line": 5325, + "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": 5337, + "end_line": 5347, + "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": 5356, + "end_line": 5367, + "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": 5374, + "end_line": 5397, + "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": 5404, + "end_line": 5412, + "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": 5421, + "end_line": 5439, + "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": 5505, + "end_line": 5618, + "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": 5623, + "end_line": 5647, + "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": 64, + "complexity": 15, + "token_count": 435, + "parameters": [], + "start_line": 5652, + "end_line": 5744, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 93, + "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": 35, + "end_line": 50, + "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": 75, + "end_line": 80, + "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": 86, + "end_line": 91, + "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": 97, + "end_line": 105, + "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": 111, + "end_line": 123, + "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": 129, + "end_line": 136, + "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": 143, + "end_line": 173, + "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": 179, + "end_line": 196, + "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": 202, + "end_line": 237, + "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": 248, + "end_line": 257, + "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": 260, + "end_line": 286, + "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": 297, + "end_line": 384, + "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": 393, + "end_line": 428, + "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": 435, + "end_line": 456, + "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": 463, + "end_line": 522, + "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": 529, + "end_line": 539, + "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": 545, + "end_line": 555, + "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": 561, + "end_line": 571, + "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": 577, + "end_line": 588, + "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": 594, + "end_line": 605, + "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": 611, + "end_line": 622, + "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": 102, + "parameters": [ + "self", + "condition", + "axis" + ], + "start_line": 629, + "end_line": 649, + "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": 655, + "end_line": 714, + "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": 720, + "end_line": 750, + "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": 756, + "end_line": 792, + "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": 798, + "end_line": 808, + "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": 776, + "parameters": [ + "self", + "offset", + "axis1", + "axis2" + ], + "start_line": 814, + "end_line": 933, + "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": 402, + "parameters": [ + "op", + "ptr", + "dims", + "nd", + "typedescr" + ], + "start_line": 949, + "end_line": 1000, + "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": 1008, + "end_line": 1018, + "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": 1024, + "end_line": 1036, + "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": 1044, + "end_line": 1055, + "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": 1059, + "end_line": 1087, + "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": 94, + "complexity": 21, + "token_count": 630, + "parameters": [ + "op", + "axis" + ], + "start_line": 1099, + "end_line": 1205, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 107, + "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": 1211, + "end_line": 1252, + "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": 1258, + "end_line": 1311, + "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": 1317, + "end_line": 1412, + "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": 65, + "complexity": 13, + "token_count": 439, + "parameters": [ + "op", + "retn" + ], + "start_line": 1416, + "end_line": 1487, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 72, + "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": 1494, + "end_line": 1575, + "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": 1578, + "end_line": 1585, + "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": 1596, + "end_line": 1650, + "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": 1653, + "end_line": 1731, + "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": 1739, + "end_line": 1742, + "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": 355, + "parameters": [ + "op", + "axis", + "which" + ], + "start_line": 1797, + "end_line": 1863, + "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": 1869, + "end_line": 1877, + "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": 1883, + "end_line": 1963, + "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": 1975, + "end_line": 2119, + "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": 2123, + "end_line": 2158, + "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": 2164, + "end_line": 2209, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 46, + "top_nesting_level": 0 + }, + { + "name": "new_array_for_sum", + "long_name": "new_array_for_sum( PyArrayObject * ap1 , PyArrayObject * ap2 , int nd , intp dimensions [ ] , int typenum)", + "filename": "multiarraymodule.c", + "nloc": 20, + "complexity": 4, + "token_count": 147, + "parameters": [ + "ap1", + "ap2", + "nd", + "typenum" + ], + "start_line": 2216, + "end_line": 2240, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 25, + "top_nesting_level": 0 + }, + { + "name": "PyArray_InnerProduct", + "long_name": "PyArray_InnerProduct( PyObject * op1 , PyObject * op2)", + "filename": "multiarraymodule.c", + "nloc": 79, + "complexity": 15, + "token_count": 624, + "parameters": [ + "op1", + "op2" + ], + "start_line": 2249, + "end_line": 2347, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 99, + "top_nesting_level": 0 + }, + { + "name": "PyArray_MatrixProduct", + "long_name": "PyArray_MatrixProduct( PyObject * op1 , PyObject * op2)", + "filename": "multiarraymodule.c", + "nloc": 89, + "complexity": 17, + "token_count": 680, + "parameters": [ + "op1", + "op2" + ], + "start_line": 2355, + "end_line": 2466, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 112, + "top_nesting_level": 0 + }, + { + "name": "PyArray_CopyAndTranspose", + "long_name": "PyArray_CopyAndTranspose( PyObject * op)", + "filename": "multiarraymodule.c", + "nloc": 47, + "complexity": 6, + "token_count": 286, + "parameters": [ + "op" + ], + "start_line": 2472, + "end_line": 2526, + "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": 86, + "complexity": 13, + "token_count": 601, + "parameters": [ + "op1", + "op2", + "mode" + ], + "start_line": 2532, + "end_line": 2629, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 98, + "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": 2636, + "end_line": 2660, + "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": 2666, + "end_line": 2677, + "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": 2683, + "end_line": 2694, + "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": 2700, + "end_line": 2723, + "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": 2730, + "end_line": 2787, + "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": 2794, + "end_line": 2869, + "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": 2875, + "end_line": 2944, + "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": 2950, + "end_line": 3021, + "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": 68, + "parameters": [ + "object", + "address" + ], + "start_line": 3037, + "end_line": 3049, + "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": 3055, + "end_line": 3063, + "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": 3070, + "end_line": 3185, + "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": 3203, + "end_line": 3228, + "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": 3243, + "end_line": 3279, + "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": 3297, + "end_line": 3330, + "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": 65, + "complexity": 16, + "token_count": 399, + "parameters": [ + "obj" + ], + "start_line": 3333, + "end_line": 3410, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 78, + "top_nesting_level": 0 + }, + { + "name": "_convert_from_array_descr", + "long_name": "_convert_from_array_descr( PyObject * obj)", + "filename": "multiarraymodule.c", + "nloc": 69, + "complexity": 14, + "token_count": 442, + "parameters": [ + "obj" + ], + "start_line": 3418, + "end_line": 3489, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 72, + "top_nesting_level": 0 + }, + { + "name": "_convert_from_list", + "long_name": "_convert_from_list( PyObject * obj , int align , int try_descr)", + "filename": "multiarraymodule.c", + "nloc": 70, + "complexity": 13, + "token_count": 428, + "parameters": [ + "obj", + "align", + "try_descr" + ], + "start_line": 3500, + "end_line": 3571, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 72, + "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": 3584, + "end_line": 3600, + "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": 3637, + "end_line": 3642, + "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": 102, + "complexity": 28, + "token_count": 689, + "parameters": [ + "obj", + "align" + ], + "start_line": 3645, + "end_line": 3756, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 112, + "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": 3774, + "end_line": 3781, + "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": 141, + "complexity": 55, + "token_count": 886, + "parameters": [ + "obj", + "at" + ], + "start_line": 3798, + "end_line": 3978, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 181, + "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": 3984, + "end_line": 4016, + "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": 4022, + "end_line": 4048, + "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": 4057, + "end_line": 4076, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 20, + "top_nesting_level": 0 + }, + { + "name": "_prepend_ones", + "long_name": "_prepend_ones( PyArrayObject * arr , int nd , int ndmin)", + "filename": "multiarraymodule.c", + "nloc": 23, + "complexity": 3, + "token_count": 175, + "parameters": [ + "arr", + "nd", + "ndmin" + ], + "start_line": 4081, + "end_line": 4106, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 26, + "top_nesting_level": 0 + }, + { + "name": "_array_fromobject", + "long_name": "_array_fromobject( PyObject * ignored , PyObject * args , PyObject * kws)", + "filename": "multiarraymodule.c", + "nloc": 66, + "complexity": 16, + "token_count": 380, + "parameters": [ + "ignored", + "args", + "kws" + ], + "start_line": 4128, + "end_line": 4203, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 76, + "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": 4211, + "end_line": 4226, + "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": 4232, + "end_line": 4256, + "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": 4261, + "end_line": 4319, + "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": 4328, + "end_line": 4352, + "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": 4358, + "end_line": 4382, + "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": 4389, + "end_line": 4398, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 10, + "top_nesting_level": 0 + }, + { + "name": "_skip_sep", + "long_name": "_skip_sep( char ** ptr , char * sep)", + "filename": "multiarraymodule.c", + "nloc": 12, + "complexity": 4, + "token_count": 78, + "parameters": [ + "ptr", + "sep" + ], + "start_line": 4401, + "end_line": 4412, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 12, + "top_nesting_level": 0 + }, + { + "name": "PyArray_FromString", + "long_name": "PyArray_FromString( char * data , intp slen , PyArray_Descr * dtype , intp n , char * sep)", + "filename": "multiarraymodule.c", + "nloc": 133, + "complexity": 22, + "token_count": 711, + "parameters": [ + "data", + "slen", + "dtype", + "n", + "sep" + ], + "start_line": 4417, + "end_line": 4559, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 143, + "top_nesting_level": 0 + }, + { + "name": "array_fromString", + "long_name": "array_fromString( PyObject * ignored , PyObject * args , PyObject * keywds)", + "filename": "multiarraymodule.c", + "nloc": 16, + "complexity": 2, + "token_count": 116, + "parameters": [ + "ignored", + "args", + "keywds" + ], + "start_line": 4564, + "end_line": 4581, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 18, + "top_nesting_level": 0 + }, + { + "name": "PyArray_FromFile", + "long_name": "PyArray_FromFile( FILE * fp , PyArray_Descr * typecode , intp num , char * sep)", + "filename": "multiarraymodule.c", + "nloc": 114, + "complexity": 22, + "token_count": 664, + "parameters": [ + "fp", + "typecode", + "num", + "sep" + ], + "start_line": 4595, + "end_line": 4723, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 129, + "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": 4741, + "end_line": 4779, + "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": 4783, + "end_line": 4876, + "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": 4892, + "end_line": 4909, + "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": 4915, + "end_line": 4926, + "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": 4933, + "end_line": 4939, + "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": 4946, + "end_line": 4952, + "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": 4956, + "end_line": 4962, + "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": 4966, + "end_line": 4975, + "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": 4982, + "end_line": 5033, + "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": 5039, + "end_line": 5071, + "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": 5078, + "end_line": 5162, + "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": 5175, + "end_line": 5187, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 13, + "top_nesting_level": 0 + }, + { + "name": "PyArray_GetNDArrayCVersion", + "long_name": "PyArray_GetNDArrayCVersion()", + "filename": "multiarraymodule.c", + "nloc": 4, + "complexity": 1, + "token_count": 13, + "parameters": [], + "start_line": 5193, + "end_line": 5196, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 0 + }, + { + "name": "array__get_ndarray_c_version", + "long_name": "array__get_ndarray_c_version( PyObject * dummy , PyObject * args , PyObject * kwds)", + "filename": "multiarraymodule.c", + "nloc": 6, + "complexity": 2, + "token_count": 55, + "parameters": [ + "dummy", + "args", + "kwds" + ], + "start_line": 5202, + "end_line": 5208, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 7, + "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": 5214, + "end_line": 5230, + "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": 5236, + "end_line": 5253, + "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": 233, + "parameters": [ + "condition", + "x", + "y" + ], + "start_line": 5260, + "end_line": 5300, + "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": 5308, + "end_line": 5316, + "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": 5328, + "end_line": 5338, + "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": 5347, + "end_line": 5358, + "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": 5365, + "end_line": 5388, + "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": 5395, + "end_line": 5403, + "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": 5412, + "end_line": 5430, + "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": 5496, + "end_line": 5609, + "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": 5614, + "end_line": 5638, + "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": 64, + "complexity": 15, + "token_count": 435, + "parameters": [], + "start_line": 5643, + "end_line": 5735, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 93, + "top_nesting_level": 0 + } + ], + "changed_methods": [ + { + "name": "_convert_from_dict", + "long_name": "_convert_from_dict( PyObject * obj , int align)", + "filename": "multiarraymodule.c", + "nloc": 111, + "complexity": 29, + "token_count": 718, + "parameters": [ + "obj", + "align" + ], + "start_line": 3645, + "end_line": 3765, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 121, + "top_nesting_level": 0 + } + ], + "nloc": 4351, + "complexity": 944, + "token_count": 28231, + "diff_parsed": { + "added": [ + "\t\tif (len == 3) {", + "\t\t\tif (PyDict_GetItem(fields, item) != NULL) {", + "\t\t\t\tPyErr_SetString(PyExc_ValueError,", + "\t\t\t\t\t\t\"titles cannot be the same as names\");", + "\t\t\t\tret=PY_FAIL;", + "\t\t\t}", + "\t\t\telse {", + "\t\t\t\tPyDict_SetItem(fields, item, tup);", + "\t\t\t}", + "\t\t}" + ], + "deleted": [ + "\t\tif (len == 3) PyDict_SetItem(fields, item, tup);" + ] + } + } + ] + }, + { + "hash": "17049d1f489ce9fa46014cf2839715ca663ffd22", + "msg": "This is a test to see if I (tim_hochberg) can successfully commit.", + "author": { + "name": "Tim Hochberg", + "email": "tim_hochberg@local" + }, + "committer": { + "name": "Tim Hochberg", + "email": "tim_hochberg@local" + }, + "author_date": "2006-02-13T22:39:00+00:00", + "author_timezone": 0, + "committer_date": "2006-02-13T22:39:00+00:00", + "committer_timezone": 0, + "branches": [ + "main" + ], + "in_main_branch": true, + "merge": false, + "parents": [ + "9175b192fe26d84a9c9b8a06c130baa3405721fe" + ], + "project_name": "repo_copy", + "project_path": "/tmp/tmpdjwupkfu/repo_copy", + "deletions": 1, + "insertions": 2, + "lines": 3, + "files": 1, + "dmm_unit_size": null, + "dmm_unit_complexity": null, + "dmm_unit_interfacing": null, + "modified_files": [ + { + "old_path": "TEST_COMMIT", + "new_path": "TEST_COMMIT", + "filename": "TEST_COMMIT", + "extension": "TEST_COMMIT", + "change_type": "MODIFY", + "diff": "@@ -10,4 +10,5 @@ charris: no\n fonnesbeck: no\n afayolle: no\n dubois: no\n-sasha: yes\n+sasha: yes\r\n+tim_hochberg: yes\n", + "added_lines": 2, + "deleted_lines": 1, + "source_code": "oliphant: yes\nrkern: yes\npearu: yes\nfperez: yes\nchanley: yes - still\ncookedm: yes\nswalton: yes\neric: no\ncharris: no\nfonnesbeck: no\nafayolle: no\ndubois: no\nsasha: yes\r\ntim_hochberg: yes\n", + "source_code_before": "oliphant: yes\nrkern: yes\npearu: yes\nfperez: yes\nchanley: yes - still\ncookedm: yes\nswalton: yes\neric: no\ncharris: no\nfonnesbeck: no\nafayolle: no\ndubois: no\nsasha: yes\n", + "methods": [], + "methods_before": [], + "changed_methods": [], + "nloc": null, + "complexity": null, + "token_count": null, + "diff_parsed": { + "added": [ + "sasha: yes", + "tim_hochberg: yes" + ], + "deleted": [ + "sasha: yes" + ] + } + } + ] + }, + { + "hash": "b3746796dc5608645ff5a9f4e46b4ef697a51a77", + "msg": "Fixed allocation problem.", + "author": { + "name": "Travis Oliphant", + "email": "oliphant@enthought.com" + }, + "committer": { + "name": "Travis Oliphant", + "email": "oliphant@enthought.com" + }, + "author_date": "2006-02-14T00:39:30+00:00", + "author_timezone": 0, + "committer_date": "2006-02-14T00:39:30+00:00", + "committer_timezone": 0, + "branches": [ + "main" + ], + "in_main_branch": true, + "merge": false, + "parents": [ + "17049d1f489ce9fa46014cf2839715ca663ffd22" + ], + "project_name": "repo_copy", + "project_path": "/tmp/tmpdjwupkfu/repo_copy", + "deletions": 77, + "insertions": 85, + "lines": 162, + "files": 3, + "dmm_unit_size": 0.0, + "dmm_unit_complexity": 0.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": "@@ -870,7 +870,7 @@ PyArray_Scalar(void *data, PyArray_Descr *descr, PyObject *base)\n \t\t\tint length = itemsize >> 2;\n #ifndef Py_UNICODE_WIDE\n \t\t\tchar *buffer;\n-\t\t\tint alloc=1;\n+\t\t\tint alloc=0;\n \t\t\tlength *= 2;\n #endif\n \t\t\t/* Need an extra slot and need to use \n", + "added_lines": 1, + "deleted_lines": 1, + "source_code": "/*\n Provide multidimensional arrays as a basic object type in python. \n\nBased on Original Numeric implementation\nCopyright (c) 1995, 1996, 1997 Jim Hugunin, hugunin@mit.edu\n\nwith contributions from many Numeric Python developers 1995-2004 \n\nHeavily modified in 2005 with inspiration from Numarray \n\nby\n\nTravis Oliphant\nAssistant Professor at\nBrigham Young University \n\nmaintainer email: oliphant.travis@ieee.org\n\nNumarray design (which provided guidance) by \nSpace Science Telescope Institute \n (J. Todd Miller, Perry Greenfield, Rick White)\n*/\n\n/*OBJECT_API\n Get Priority from object\n*/\nstatic double\nPyArray_GetPriority(PyObject *obj, double default_) \n{\n PyObject *ret;\n double priority=PyArray_PRIORITY;\n\n\tif (PyArray_CheckExact(obj))\n\t\treturn priority;\n 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\n\n#ifndef Py_UNICODE_WIDE\n#include \"ucsnarrow.c\"\n#endif\n\n\nstatic PyArray_Descr **userdescrs=NULL;\n#define error_converting(x) (((x) == -1) && PyErr_Occurred())\n\n/* Computer-generated arraytype and scalartype code */\n#include \"scalartypes.inc\"\n#include \"arraytypes.inc\"\n\n\n/* Helper functions */\n\n/*OBJECT_API*/\nstatic intp\nPyArray_PyIntAsIntp(PyObject *o)\n{\n\tlonglong long_value = -1;\n\tPyObject *obj;\n\tstatic char *msg = \"an integer is required\";\n\tPyObject *arr;\n\tPyArray_Descr *descr;\n\tintp ret;\n\n\tif (!o) {\n\t\tPyErr_SetString(PyExc_TypeError, msg);\n\t\treturn -1;\n\t}\n\n\tif (PyInt_Check(o)) {\n\t\tlong_value = (longlong) PyInt_AS_LONG(o);\n\t\tgoto finish;\n\t} else if (PyLong_Check(o)) {\n\t\tlong_value = (longlong) PyLong_AsLongLong(o);\n\t\tgoto finish;\n\t}\n\n#if SIZEOF_INTP == SIZEOF_LONG \n\tdescr = &LONG_Descr;\n#elif SIZEOF_INTP == SIZEOF_INT\n\tdescr = &INT_Descr;\n#else\n\tdescr = &LONGLONG_DESCR;\n#endif\n\tarr = NULL;\n\n\tif (PyArray_Check(o)) {\n\t\tif (PyArray_SIZE(o)!=1 || !PyArray_ISINTEGER(o)) {\n\t\t\tPyErr_SetString(PyExc_TypeError, msg);\n\t\t\treturn -1;\n\t\t}\n\t\tPy_INCREF(descr);\n\t\tarr = PyArray_CastToType((PyArrayObject *)o, descr, 0);\n\t}\n\telse if (PyArray_IsScalar(o, Integer)) {\n\t\tPy_INCREF(descr);\n\t\tarr = PyArray_FromScalar(o, descr);\n\t}\n\tif (arr != NULL) {\n\t\tret = *((intp *)PyArray_DATA(arr));\n\t\tPy_DECREF(arr);\n\t\treturn ret;\n\t}\t\t\n\tif (o->ob_type->tp_as_number != NULL &&\t\t\t\\\n\t o->ob_type->tp_as_number->nb_long != NULL) {\n\t\tobj = o->ob_type->tp_as_number->nb_long(o);\n\t\tif (obj != NULL) {\n\t\t\tlong_value = (longlong) PyLong_AsLongLong(obj);\n\t\t\tPy_DECREF(obj);\n\t\t}\n\t}\n\telse if (o->ob_type->tp_as_number != NULL &&\t\t\\\n\t\t o->ob_type->tp_as_number->nb_int != NULL) {\n\t\tobj = o->ob_type->tp_as_number->nb_int(o);\n\t\tif (obj != NULL) {\n\t\t\tlong_value = (longlong) PyLong_AsLongLong(obj);\n\t\t\tPy_DECREF(obj);\n\t\t}\n\t}\n\telse {\n\t\tPyErr_SetString(PyExc_NotImplementedError,\"\");\n\t}\n\t\n finish:\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_INTP)\n\tif ((long_value < MIN_INTP) || (long_value > MAX_INTP)) {\n\t\tPyErr_SetString(PyExc_ValueError,\n\t\t\t\t\"integer won't fit into a C intp\");\n\t\treturn -1;\n\t}\n#endif\n\treturn (intp) long_value;\n}\n\n\nstatic PyObject *array_int(PyArrayObject *v);\n\n/*OBJECT_API*/\nstatic int\nPyArray_PyIntAsInt(PyObject *o)\n{\n\tlong long_value = -1;\n\tPyObject *obj;\n\tstatic char *msg = \"an integer is required\";\n\tPyObject *arr;\n\tPyArray_Descr *descr;\n\tint ret;\n\n\t\n\tif (!o) {\n\t\tPyErr_SetString(PyExc_TypeError, msg);\n\t\treturn -1;\n\t}\n\n\tif (PyInt_Check(o)) {\n\t\tlong_value = (long) PyInt_AS_LONG(o);\n\t\tgoto finish;\n\t} else if (PyLong_Check(o)) {\n\t\tlong_value = (long) PyLong_AsLong(o);\n\t\tgoto finish;\n\t}\n\n\tdescr = &INT_Descr;\n\tarr=NULL;\n\tif (PyArray_Check(o)) {\n\t\tif (PyArray_SIZE(o)!=1 || !PyArray_ISINTEGER(o)) {\n\t\t\tPyErr_SetString(PyExc_TypeError, msg);\n\t\t\treturn -1;\n\t\t}\n\t\tPy_INCREF(descr);\n\t\tarr = PyArray_CastToType((PyArrayObject *)o, descr, 0);\n\t}\n\tif (PyArray_IsScalar(o, Integer)) {\n\t\tPy_INCREF(descr);\n\t\tarr = PyArray_FromScalar(o, descr);\n\t}\n\tif (arr != NULL) {\n\t\tret = *((int *)PyArray_DATA(arr));\n\t\tPy_DECREF(arr);\n\t\treturn ret;\n\t}\t\t\n\tif (o->ob_type->tp_as_number != NULL &&\t\t\\\n\t o->ob_type->tp_as_number->nb_int != NULL) {\n\t\tobj = o->ob_type->tp_as_number->nb_int(o);\n\t\tif (obj == NULL) return -1;\n\t\tlong_value = (long) PyLong_AsLong(obj);\n\t\tPy_DECREF(obj);\n\t}\n\telse if (o->ob_type->tp_as_number != NULL &&\t\t\t\\\n\t\t o->ob_type->tp_as_number->nb_long != NULL) {\n\t\tobj = o->ob_type->tp_as_number->nb_long(o);\n\t\tif (obj == NULL) return -1;\n\t\tlong_value = (long) PyLong_AsLong(obj);\n\t\tPy_DECREF(obj);\n\t}\t\t\n\telse {\n\t\tPyErr_SetString(PyExc_NotImplementedError,\"\");\n\t}\n\n finish:\n\tif error_converting(long_value) {\n\t\tPyErr_SetString(PyExc_TypeError, msg);\n\t\treturn -1;\n\t}\n\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\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 dest->descr, 0,\n dest->nd, FORTRAN_IF(dest), NULL);\n if (src == NULL) return -1;\n\n ret = PyArray_CopyInto(dest, src);\n Py_DECREF(src);\n return ret;\n}\n\n\n/* These are also old calls (should use PyArray_New) */\n\n/* They all zero-out the memory as previously done */\n\n/* steals reference to descr -- and enforces native byteorder on it.*/\n/*OBJECT_API\n Like FromDimsAndData but uses the Descr structure instead of typecode\n as input.\n*/\nstatic PyObject *\nPyArray_FromDimsAndDataAndDescr(int nd, int *d, \n PyArray_Descr *descr,\n char *data)\n{\n\tPyObject *ret;\n#if SIZEOF_INTP != SIZEOF_INT\n\tint i;\n\tintp newd[MAX_DIMS];\n#endif\n\n\tif (!PyArray_ISNBO(descr->byteorder))\n\t\tdescr->byteorder = '=';\n\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\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_BOOL)\n\t\tPyArrayScalar_RETURN_BOOL_FROM_LONG(*(Bool*)data);\n\telse if (type_num == PyArray_OBJECT) {\n\t\tPy_INCREF(*((PyObject **)data));\n\t\treturn *((PyObject **)data);\n\t}\n\titemsize = descr->elsize;\n type = descr->typeobj;\n copyswap = descr->f->copyswap;\n\tswap = !PyArray_ISNBO(descr->byteorder);\n\tif (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 >> 2;\n#ifndef Py_UNICODE_WIDE\n\t\t\tchar *buffer;\n\t\t\tint alloc=0;\n\t\t\tlength *= 2;\n#endif\n\t\t\t/* Need an extra slot and need to use \n\t\t\t Python memory manager */\n\t\t\tuni->str = NULL;\n\t\t\tdestptr = PyMem_NEW(Py_UNICODE, length+1);\n\t\t\tif (destptr == NULL) {\n Py_DECREF(obj);\n\t\t\t\treturn PyErr_NoMemory();\n\t\t\t}\n\t\t\tuni->str = (Py_UNICODE *)destptr;\n\t\t\tuni->str[0] = 0;\n\t\t\tuni->str[length] = 0;\n\t\t\tuni->length = length;\n\t\t\tuni->hash = -1;\n\t\t\tuni->defenc = NULL;\n#ifndef Py_UNICODE_WIDE\n\t\t\t/* need aligned data buffer */\n\t\t\tif (!PyArray_ISBEHAVED(base)) {\n\t\t\t\tbuffer = _pya_malloc(itemsize);\n\t\t\t\tif (buffer == NULL)\n\t\t\t\t\treturn PyErr_NoMemory();\n\t\t\t\talloc = 1;\n\t\t\t\tmemcpy(buffer, data, itemsize);\n\t\t\t\tif (!PyArray_ISNOTSWAPPED(base)) {\n\t\t\t\t\tbyte_swap_vector(buffer, itemsize >> 2, 4);\n\t\t\t\t}\n\t\t\t}\n\t\t\telse buffer = data;\n\n /* Allocated enough for 2-characters per itemsize.\n\t\t\t Now convert from the data-buffer\n */\n\t\t\tlength = PyUCS2Buffer_FromUCS4(uni->str, (PyArray_UCS4 *)buffer,\n\t\t\t\t\t\t itemsize >> 2);\n\t\t\tif (alloc) _pya_free(buffer);\n\t\t\t/* Resize the unicode result */\n\t\t\tif (MyPyUnicode_Resize(uni, length) < 0) {\n\t\t\t\tPy_DECREF(obj);\n\t\t\t\treturn NULL;\n\t\t\t}\n\t\t\treturn obj;\n#endif\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_XDECREF(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, 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, NULL);\n\tif (arr == NULL) return -1;\n\n\tif ((mit->subspace != NULL) && (mit->consec)) {\n\t\tif (mit->iteraxes[0] > 0) { /* then we need to swap */\n\t\t\t_swap_axes(mit, (PyArrayObject **)&arr);\n\t\t}\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\n/* This checks the args for any fancy indexing objects */\n\n#define SOBJ_NOTFANCY 0 \n#define SOBJ_ISFANCY 1\n#define SOBJ_BADARRAY 2\n#define SOBJ_TOOMANY 3\n#define SOBJ_LISTTUP 4\n\nstatic int\nfancy_indexing_check(PyObject *args)\n{\n\tint i, n;\n\tPyObject *obj;\n\tint retval = SOBJ_NOTFANCY;\n\n\tif (PyTuple_Check(args)) {\n\t\tn = PyTuple_GET_SIZE(args);\n\t\tif (n >= MAX_DIMS) return SOBJ_TOOMANY;\n\t\tfor (i=0; i=MAX_DIMS) return SOBJ_ISFANCY;\n\t\tfor (i=0; i SOBJ_ISFANCY) return retval;\n\t\t}\n\t}\n\n\treturn retval;\n}\n\n/* Called when treating array object like a mapping -- called first from \n Python when using a[object] unless object is a standard slice object\n (not an extended one). \n\n*/\n\n/* There are two situations: \n\n 1 - the subscript is a standard view and a reference to the \n array can be returned\n\n 2 - the subscript uses Boolean masks or integer indexing and\n therefore a new array is created and returned. \n\n*/\n\n/* Always returns arrays */\n\nstatic PyObject *iter_subscript(PyArrayIterObject *, PyObject *); \n\n\nstatic PyObject *\narray_subscript(PyArrayObject *self, PyObject *op) \n{\n intp dimensions[MAX_DIMS], strides[MAX_DIMS];\n\tintp offset;\n int nd, oned, fancy;\n\tintp i;\n PyArrayObject *other;\n\tPyArrayMapIterObject *mit;\n\n\tif (PyString_Check(op) || PyUnicode_Check(op)) {\n\t\tif (self->descr->fields) {\n\t\t\tPyObject *obj;\n\t\t\tobj = PyDict_GetItem(self->descr->fields, op);\n\t\t\tif (obj != NULL) {\n\t\t\t\tPyArray_Descr *descr;\n\t\t\t\tint offset;\n\t\t\t\tPyObject *title;\n\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\tfancy = fancy_indexing_check(op);\n\n\tif (fancy != SOBJ_NOTFANCY) { \n\t\toned = ((self->nd == 1) && !(PyTuple_Check(op) &&\t\\\n\t\t\t\t\t PyTuple_GET_SIZE(op) > 1));\n\n\t\t/* wrap arguments into a mapiter object */\n\t\tmit = (PyArrayMapIterObject *)\\\n\t\t\tPyArray_MapIterNew(op, oned, fancy);\n\t\tif (mit == NULL) return NULL;\n\t\tif (oned) {\n\t\t\tPyArrayIterObject *it;\n\t\t\tPyObject *rval;\n\t\t\tit = (PyArrayIterObject *)PyArray_IterNew((PyObject *)self);\n\t\t\tif (it == NULL) {Py_DECREF(mit); return NULL;}\n\t\t\trval = iter_subscript(it, mit->indexobj);\n\t\t\tPy_DECREF(it);\n\t\t\tPy_DECREF(mit);\n\t\t\treturn rval;\n\t\t}\n PyArray_MapIterBind(mit, self);\n other = (PyArrayObject *)PyArray_GetMap(mit);\n Py_DECREF(mit);\n return (PyObject *)other;\n }\n\n\ti = PyArray_PyIntAsIntp(op);\n\tif (!error_converting(i)) {\n\t\tif (i < 0 && self->nd > 0) i = i+self->dimensions[0];\n\t\treturn array_big_item(self, i);\n\t}\n\tPyErr_Clear();\n\n\t/* Standard (view-based) Indexing */\n if ((nd = parse_index(self, op, dimensions, strides, &offset)) \n == -1) \n return NULL;\n\n\t/* This will only work if new array will be a view */\n\tPy_INCREF(self->descr);\n\tif ((other = (PyArrayObject *)\t\t\t\t\t\\\n\t PyArray_NewFromDescr(self->ob_type, self->descr,\n\t\t\t\t nd, dimensions,\n\t\t\t\t strides, self->data+offset, \n\t\t\t\t self->flags,\n\t\t\t\t (PyObject *)self)) == NULL) \n\t\treturn NULL;\n\n\n\tother->base = (PyObject *)self;\n\tPy_INCREF(self);\n\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, fancy;\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\tfancy = fancy_indexing_check(index);\n\n\tif (fancy != SOBJ_NOTFANCY) { \n\t\toned = ((self->nd == 1) && !(PyTuple_Check(index) && \\\n\t\t\t\t\t PyTuple_GET_SIZE(index) > 1));\n\n\t\tmit = (PyArrayMapIterObject *)\t\t\t\\\n\t\t\tPyArray_MapIterNew(index, oned, fancy);\n\t\tif (mit == NULL) return -1;\n\t\tif (oned) {\n\t\t\tPyArrayIterObject *it;\n\t\t\tint rval;\n\t\t\tit = (PyArrayIterObject *)PyArray_IterNew((PyObject *)self);\n\t\t\tif (it == NULL) {Py_DECREF(mit); return -1;}\n\t\t\trval = iter_ass_subscript(it, mit->indexobj, op);\n\t\t\tPy_DECREF(it);\n\t\t\tPy_DECREF(mit);\n\t\t\treturn rval;\n\t\t}\n PyArray_MapIterBind(mit, self);\n ret = PyArray_SetMap(mit, op);\n Py_DECREF(mit);\n return ret;\n }\n\t\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\t\t\tif (other == Py_None) {\n\t\t\t\tPy_INCREF(Py_False);\n\t\t\t\treturn Py_False;\n\t\t\t}\n /* Try to convert other to an array */\n\t\t\tif (!PyArray_Check(other)) {\n\t\t\t\tarray_other = PyArray_FromObject(other, \n\t\t\t\t\t\t\t\t self->descr->type_num, 0, 0);\n\t\t\t\t/* If not successful, then return the integer\n\t\t\t\t object 0. This fixes code that used to\n\t\t\t\t allow equality comparisons between arrays\n\t\t\t\t and other objects which would give a result\n\t\t\t\t of 0\n\t\t\t\t*/\n\t\t\t\tif ((array_other == NULL) ||\t\\\n\t\t\t\t (array_other == Py_None)) {\n\t\t\t\t\tPy_XDECREF(array_other);\n\t\t\t\t\tPyErr_Clear();\n\t\t\t\t\tPy_INCREF(Py_False);\n\t\t\t\t\treturn Py_False;\n\t\t\t\t}\n\t\t\t}\n\t\t\telse {\n\t\t\t\tPy_INCREF(other);\n\t\t\t\tarray_other = other;\n\t\t\t}\n result = PyArray_GenericBinaryFunction(self, \n\t\t\t\t\t\t\t array_other, \n\t\t\t\t\t\t\t n_ops.equal);\n /* If the comparison results in NULL, then the \n\t\t\t two array objects can not be compared together so \n\t\t\t return zero \n */\n Py_DECREF(array_other);\n if (result == NULL) {\n PyErr_Clear();\n Py_INCREF(Py_False);\n return Py_False;\n }\n return result;\n case Py_NE:\n\t\t\tif (other == Py_None) {\n\t\t\t\tPy_INCREF(Py_True);\n\t\t\t\treturn Py_True;\n\t\t\t}\n /* Try to convert other to an array */\n\t\t\tif (!PyArray_Check(other)) {\n\t\t\t\tarray_other = PyArray_FromObject(other, \n\t\t\t\t\t\t\t\t self->descr->type_num, 0, 0);\n\t\t\t\t/* If not successful, then objects cannot be \n\t\t\t\t compared and cannot be equal, therefore, \n\t\t\t\t return True;\n\t\t\t\t*/\n\t\t\t\tif ((array_other == NULL) ||\t\\\n\t\t\t\t (array_other == Py_None)) {\n\t\t\t\t\tPy_XDECREF(array_other);\n\t\t\t\t\tPyErr_Clear();\n\t\t\t\t\tPy_INCREF(Py_True);\n\t\t\t\t\treturn Py_True;\n\t\t\t\t}\n\t\t\t}\n\t\t\telse {\n\t\t\t\tPy_INCREF(other);\n\t\t\t\tarray_other = other;\n\t\t\t}\n\t\t\tresult = PyArray_GenericBinaryFunction(self, \n\t\t\t\t\t\t\t array_other, \n\t\t\t\t\t\t\t n_ops.not_equal);\n\t\t\tPy_DECREF(array_other);\n if (result == NULL) {\n PyErr_Clear();\n Py_INCREF(Py_True);\n return Py_True;\n }\n 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 = PyArray_NDIM(temp)-1;\n\t\treturn temp;\n\t}\n\telse {\n\t\tif (flags) {\n\t\t\ttemp = PyArray_CheckFromAny((PyObject *)arr, NULL, \n 0, 0, flags, NULL);\n\t\t\tif (temp == NULL) return NULL;\n\t\t}\n\t\telse {\n\t\t\tPy_INCREF(arr);\n\t\t\ttemp = (PyObject *)arr;\n\t\t}\n\t}\n\tif (*axis < 0) *axis += n;\n\tif ((*axis < 0) || (*axis >= n)) {\n\t\tPyErr_Format(PyExc_ValueError, \n\t\t\t \"axis(=%d) out of bounds\", *axis);\n\t\tPy_DECREF(temp);\n\t\treturn NULL;\n\t}\n\treturn temp;\n}\n\n#include \"arraymethods.c\"\n\n/* Lifted from numarray */\nstatic PyObject *\nPyArray_IntTupleFromIntp(int len, intp *vals)\n{\n\tint i;\n PyObject *intTuple = PyTuple_New(len);\n if (!intTuple) goto fail;\n for(i=0; i= SIZEOF_INTP\n\t\tif (!(op = PyNumber_Int(seq))) return -1;\n#else\n\t\tif (!(op = PyNumber_Long(seq))) return -1;\n#endif\n\t\tnd = 1;\n#if SIZEOF_LONG >= SIZEOF_INTP\n\t\tvals[0] = (intp ) PyInt_AsLong(op);\n#else\n\t\tvals[0] = (intp ) PyLong_AsLongLong(op);\n#endif\n\t\tPy_DECREF(op);\n\t} else {\n\t\tfor(i=0; i < MIN(nd,maxvals); i++) {\n\t\t\top = PySequence_GetItem(seq, i);\n\t\t\tif (op == NULL) return -1;\n#if SIZEOF_LONG >= SIZEOF_INTP\n\t\t\tvals[i]=(intp )PyInt_AsLong(op);\n#else\n\t\t\tvals[i]=(intp )PyLong_AsLongLong(op);\n#endif\n\t\t\tPy_DECREF(op);\n\t\t\tif(PyErr_Occurred()) return -1;\n\t\t}\n\t}\n\treturn nd;\n}\n\n\n/* Check whether the given array is stored contiguously (row-wise) in\n memory. */\nstatic int\n_IsContiguous(PyArrayObject *ap) \n{\n\tregister intp sd;\n\tregister intp dim;\n\tregister int i;\n \n\n\tif (ap->nd == 0) return 1;\n\tsd = ap->descr->elsize;\n\tif (ap->nd == 1) return (ap->dimensions[0] == 1 || \\\n\t\t\t\t sd == ap->strides[0]);\n\tfor (i = ap->nd-1; i >= 0; --i) {\n\t\tdim = ap->dimensions[i];\n\t\t/* contiguous by definition */\n\t\tif (dim == 0) return 1;\n\t\tif (ap->strides[i] != sd) return 0;\n\t\tsd *= dim;\n\t}\n\treturn 1;\n}\n\n\nstatic int \n_IsFortranContiguous(PyArrayObject *ap) \n{\n\tregister intp sd;\n\tregister intp dim;\n\tregister int i;\n\t\n\tif (ap->nd == 0) return 1;\n\tsd = ap->descr->elsize;\n\tif (ap->nd == 1) return (ap->dimensions[0] == 1 || \\\n\t\t\t\t sd == ap->strides[0]);\n\tfor (i=0; i< ap->nd; ++i) {\n\t\tdim = ap->dimensions[i];\n\t\t/* contiguous by definition */\n\t\tif (dim == 0) return 1; \n\t\tif (ap->strides[i] != sd) return 0;\n\t\tsd *= dim;\n\t}\n\treturn 1;\n}\n\nstatic int\n_IsAligned(PyArrayObject *ap) \n{\n\tint i, alignment, aligned=1;\n\tintp ptr;\n\tint type = ap->descr->type_num;\n\n\tif ((type == PyArray_STRING) || (type == PyArray_VOID))\n\t\treturn 1;\n\n\talignment = ap->descr->alignment;\n\tif (alignment == 1) return 1;\n\n\tptr = (intp) ap->data;\n aligned = (ptr % alignment) == 0;\n for (i=0; i nd; i++)\n aligned &= ((ap->strides[i] % alignment) == 0);\n return aligned != 0;\n}\n\nstatic Bool\n_IsWriteable(PyArrayObject *ap)\n{\n\tPyObject *base=ap->base;\n\tvoid *dummy;\n\tint n;\n\n\t/* If we own our own data, then no-problem */\n\tif ((base == NULL) || (ap->flags & OWN_DATA)) return TRUE;\n\n\t/* Get to the final base object \n\t If it is a writeable array, then return TRUE\n\t If we can find an array object \n\t or a writeable buffer object as the final base object\n\t or a string object (for pickling support memory savings).\n\t - this last could be removed if a proper pickleable \n\t buffer was added to Python.\n\t*/\n\n\twhile(PyArray_Check(base)) {\n\t\tif (PyArray_CHKFLAGS(base, OWN_DATA)) \n\t\t\treturn (Bool) (PyArray_ISWRITEABLE(base));\n\t\tbase = PyArray_BASE(base);\n\t}\n\n\t/* here so pickle support works seamlessly \n\t and unpickled array can be set and reset writeable \n\t -- could be abused -- */\n\tif PyString_Check(base) return TRUE;\n\n\tif (PyObject_AsWriteBuffer(base, &dummy, &n) < 0)\n\t\treturn FALSE;\n\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 For axes with a positive stride this function checks for a walk\n beyond the right end of the buffer, for axes with a negative stride,\n it checks for a walk beyond the left end of the buffer. Zero strides\n are disallowed.\n*/\n/*OBJECT_API*/\nstatic Bool\nPyArray_CheckStrides(int elsize, int nd, intp numbytes, intp offset,\n\t\t intp *dims, intp *newstrides)\n{\n\tint i;\n\t\n\tif (numbytes == 0) \n\t\tnumbytes = PyArray_MultiplyList(dims, nd) * elsize;\n\t\n\tfor (i=0; i 0) {\n\t\t\t/* The last stride does not need to be fully inside\n\t\t\t the buffer, only its first elsize bytes */\n\t\t\tif (offset + stride*(dims[i]-1)+elsize > numbytes) {\n\t\t\t\treturn FALSE;\n\t\t\t}\n\t\t}\n\t\telse if (stride < 0) {\n\t\t\tif (offset + stride*dims[i] < 0) {\n\t\t\t\treturn FALSE;\n\t\t\t}\n\t\t} else {\n\t\t\t/* XXX: Zero strides may be useful, but currently \n\t\t\t XXX: allowing them would lead to strange results,\n\t\t\t XXX: for example :\n\t\t\t XXX: >>> x = arange(5)\n\t\t\t XXX: >>> x.strides = 0\n\t\t\t XXX: >>> x += 1\n\t\t\t XXX: >>> x\n\t\t\t XXX: array([5, 5, 5, 5, 5]) */\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 /* which could also be sub-fields of a VOID array */\n\t\tif (descr->hasobject) {\n if (descr != &OBJECT_Descr) {\n PyErr_SetString(PyExc_TypeError,\n \"fields with object members \" \\\n \"not yet supported.\");\n goto fail;\n }\n\t\t\tmemset(data, 0, sd);\n\t\t}\n\t}\n\telse {\n self->flags &= ~OWN_DATA; /* If data is passed in, \n\t\t\t\t\t this object won't own it \n\t\t\t\t\t by default.\n\t\t\t\t\t Caller must arrange for \n\t\t\t\t\t this to be reset if truly\n\t\t\t\t\t desired */\n }\n self->data = data;\n\n /* call the __array_finalize__\n\t method if a subtype 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, NULL);\n\tif (newarr == NULL) return -1;\n\tfromptr = PyArray_DATA(newarr);\n\tsize=PyArray_SIZE(arr);\n\tswap=!PyArray_ISNOTSWAPPED(arr);\n\tcopyswap = arr->descr->f->copyswap;\n\tif (PyArray_ISONESEGMENT(arr)) {\n\t\tchar *toptr=PyArray_DATA(arr);\n\t\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\", /* XXX ? */\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 strides.ptr, NULL, fortran, NULL);\n if (ret == NULL) {descr=NULL;goto fail;}\n if (type_num == PyArray_OBJECT) { /* place Py_None */\n PyArray_FillObjectArray(ret, Py_None);\n }\n }\n else { /* buffer given -- use it */\n if (dims.len == 1 && dims.ptr[0] == -1) {\n dims.ptr[offset] = 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, offset,\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 offset + (char *)buffer.ptr, \n\t\t\t\t\t buffer.flags, NULL); \n if (ret == NULL) {descr=NULL; goto fail;}\n PyArray_UpdateFlags(ret, UPDATE_ALL_FLAGS);\n ret->base = buffer.base;\n Py_INCREF(buffer.base); \n }\n\n PyDimMem_FREE(dims.ptr);\n if (strides.ptr) PyDimMem_FREE(strides.ptr);\n return (PyObject *)ret;\n \n fail:\n\tPy_XDECREF(descr);\n if (dims.ptr) PyDimMem_FREE(dims.ptr);\n if (strides.ptr) PyDimMem_FREE(strides.ptr);\n return NULL;\n}\n\n\nstatic PyObject *\narray_iter(PyArrayObject *arr)\n{\n\tif (arr->nd == 0) {\n\t\tPyErr_SetString(PyExc_TypeError,\n\t\t\t\t\"iteration over a scalar (0-dim array)\");\n\t\treturn NULL;\n\t}\n\treturn PySeqIter_New((PyObject *)arr);\n}\n\n\n/******************* array attribute get and set routines ******************/\n\nstatic PyObject *\narray_ndim_get(PyArrayObject *self)\n{\n\treturn PyInt_FromLong(self->nd);\n}\n\nstatic PyObject *\narray_flags_get(PyArrayObject *self)\n{\n return 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->data - new->data,\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 *arraydescr_protocol_typestr_get(PyArray_Descr *);\n\nstatic PyObject *\narray_typestr_get(PyArrayObject *self)\n{\n\treturn arraydescr_protocol_typestr_get(self->descr);\n}\n\nstatic PyObject *\narray_descr_get(PyArrayObject *self) \n{\n\tPy_INCREF(self->descr);\n\treturn (PyObject *)self->descr;\n}\n\n\n/* If the type is changed. \n Also needing change: strides, itemsize\n\n Either itemsize is exactly the same\n or the array is single-segment (contiguous or fortran) with\n compatibile dimensions\n\n The shape and strides will be adjusted in that case as well.\n*/\n\nstatic int\narray_descr_set(PyArrayObject *self, PyObject *arg)\n{\n PyArray_Descr *newtype=NULL;\n intp newdim;\n int index;\n char *msg = \"new type not compatible with array.\";\n\n if (!(PyArray_DescrConverter(arg, &newtype)) ||\n newtype == NULL) {\n PyErr_SetString(PyExc_TypeError, \"invalid data-type for array\");\n\t\treturn -1;\n }\n\tif (newtype->type_num == PyArray_OBJECT || \\\n\t self->descr->type_num == PyArray_OBJECT) {\n\t\tPyErr_SetString(PyExc_TypeError, \\\n\t\t\t\t\"Cannot change descriptor for object\"\\\n\t\t\t\t\"array.\");\n\t\tPy_DECREF(newtype);\n\t\treturn -1;\n\t}\n\n\tif ((newtype->elsize != self->descr->elsize) &&\t\t\\\n\t (self->nd == 0 || !PyArray_ISONESEGMENT(self) || \\\n\t newtype->subarray)) goto fail;\n\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\t/* We would decref newtype here --- temp will \n\t\t steal a reference to it */\n\t\ttemp = (PyArrayObject *)\t\t\t\t\\\n\t\t\tPyArray_NewFromDescr(&PyArray_Type, newtype, self->nd,\n\t\t\t\t\t self->dimensions, self->strides,\n\t\t\t\t\t self->data, self->flags, NULL);\n\t\tPyDimMem_FREE(self->dimensions);\n\t\tself->dimensions = temp->dimensions;\n\t\tself->nd = temp->nd;\n\t\tself->strides = temp->strides;\n\t\tnewtype = temp->descr;\n\t\t/* Fool deallocator not to delete these*/\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, \"descr\");\n\tif (res) return res;\n\tPyErr_Clear();\n\n\t/* get default */\n\tdobj = PyTuple_New(2);\n\tif (dobj == NULL) return NULL;\n\tPyTuple_SET_ITEM(dobj, 0, PyString_FromString(\"\"));\n\tPyTuple_SET_ITEM(dobj, 1, array_typestr_get(self));\n\tres = PyList_New(1);\n\tif (res == NULL) {Py_DECREF(dobj); return NULL;}\n\tPyList_SET_ITEM(res, 0, dobj);\n\treturn res;\n}\n\nstatic PyObject *\narray_struct_get(PyArrayObject *self)\n{\n PyArrayInterface *inter;\n \n inter = (PyArrayInterface *)_pya_malloc(sizeof(PyArrayInterface));\n inter->version = 2;\n inter->nd = self->nd;\n inter->typekind = self->descr->kind;\n inter->itemsize = self->descr->elsize;\n inter->flags = self->flags;\n /* reset unused flags */\n\tinter->flags &= ~(UPDATEIFCOPY | OWNDATA); \n\tif (PyArray_ISNOTSWAPPED(self)) inter->flags |= NOTSWAPPED;\n inter->strides = self->strides;\n inter->shape = self->dimensions;\n inter->data = self->data;\n\tPy_INCREF(self);\n return PyCObject_FromVoidPtrAndDesc(inter, self, gentype_struct_free);\n}\n\nstatic PyObject *\narray_base_get(PyArrayObject *self)\n{\n\tif (self->base == NULL) {\n\t\tPy_INCREF(Py_None);\n\t\treturn Py_None;\n\t}\n\telse {\n\t\tPy_INCREF(self->base);\n\t\treturn self->base;\n\t}\n}\n\n\nstatic PyObject *\narray_real_get(PyArrayObject *self)\n{\n\tPyArrayObject *ret;\n\n\tif (PyArray_ISCOMPLEX(self)) {\n\t\tret = (PyArrayObject *)PyArray_New(self->ob_type,\n\t\t\t\t\t\t self->nd,\n\t\t\t\t\t\t self->dimensions,\n\t\t\t\t\t\t self->descr->type_num - \\\n\t\t\t\t\t\t PyArray_NUM_FLOATTYPE,\n\t\t\t\t\t\t self->strides,\n\t\t\t\t\t\t self->data,\n\t\t\t\t\t\t 0,\n\t\t\t\t\t\t self->flags, (PyObject *)self);\n\t\tif (ret == NULL) return NULL;\n\t\tret->flags &= ~CONTIGUOUS;\n\t\tret->flags &= ~FORTRAN;\n\t\tPy_INCREF(self);\n\t\tret->base = (PyObject *)self;\n\t\treturn (PyObject *)ret;\n\t}\n\telse {\n\t\tPy_INCREF(self);\n\t\treturn (PyObject *)self;\n\t}\n}\n\n\nstatic int\narray_real_set(PyArrayObject *self, PyObject *val)\n{\n\tPyArrayObject *ret;\n\tPyArrayObject *new;\n\tint rint;\n\n\tnew = (PyArrayObject *)PyArray_FromAny(val, NULL, 0, 0, 0, NULL);\n\tif (new == NULL) return -1;\n\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, NULL); \n\t\tif (new == NULL) return -1;\n\t\tret = (PyArrayObject *)PyArray_New(self->ob_type,\n\t\t\t\t\t\t self->nd,\n\t\t\t\t\t\t self->dimensions,\n\t\t\t\t\t\t self->descr->type_num - \\\n\t\t\t\t\t\t PyArray_NUM_FLOATTYPE,\n\t\t\t\t\t\t self->strides,\n \t\t\t\t\t\t self->data +\t\t\\\n\t\t\t\t\t\t (self->descr->elsize >> 1),\n\t\t\t\t\t\t 0,\n\t\t\t\t\t\t self->flags, (PyObject *)self);\n\t\tif (ret == NULL) {\n\t\t\tPy_DECREF(new); \n\t\t\treturn -1;\n\t\t}\n\t\tret->flags &= ~CONTIGUOUS;\n\t\tret->flags &= ~FORTRAN;\n\t\tPy_INCREF(self);\n\t\tret->base = (PyObject *)self;\n\t\trint = PyArray_CopyInto(ret, new);\n\t\tPy_DECREF(ret);\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), NULL);\n\tif (arr == NULL) return -1;\n\tarrit = (PyArrayIterObject *)PyArray_IterNew(arr);\n\tif (arrit == NULL) goto exit;\n\tselfit = (PyArrayIterObject *)PyArray_IterNew((PyObject *)self);\n\tif (selfit == NULL) goto exit;\n\n swap = PyArray_ISNOTSWAPPED(self) != PyArray_ISNOTSWAPPED(arr);\n copyswap = self->descr->f->copyswap;\n if (PyArray_ISOBJECT(self)) {\n while(selfit->index < selfit->size) {\n Py_XDECREF(*((PyObject **)selfit->dataptr));\n Py_INCREF(*((PyObject **)arrit->dataptr)); \n memmove(selfit->dataptr, arrit->dataptr, \n sizeof(PyObject *));\n PyArray_ITER_NEXT(selfit);\n PyArray_ITER_NEXT(arrit);\n if (arrit->index == arrit->size) \n PyArray_ITER_RESET(arrit);\n }\n retval = 0; \n goto exit;\n }\n\n\twhile(selfit->index < selfit->size) {\n\t\tmemmove(selfit->dataptr, arrit->dataptr, self->descr->elsize);\n copyswap(selfit->dataptr, NULL, swap, self->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\t{\"dtype\",\n\t (getter)array_descr_get,\n\t (setter)array_descr_set,\n\t \"get(set) data-type-descriptor for array\"},\n {\"real\", \n\t (getter)array_real_get, \n\t (setter)array_real_set, \n\t \"real part of array\"},\n {\"imag\", \n\t (getter)array_imag_get, \n\t (setter)array_imag_set, \n\t \"imaginary part of array\"},\n\t{\"flat\", \n\t (getter)array_flat_get, \n\t (setter)array_flat_set, \n\t \"a 1-d view of a contiguous array\"}, \n\t{\"__array_data__\", \n\t (getter)array_dataptr_get,\n\t NULL,\n\t \"Array protocol: data\"},\n\t{\"__array_typestr__\",\n\t (getter)array_typestr_get,\n\t NULL,\n\t \"Array protocol: typestr\"},\n\t{\"__array_descr__\",\n\t (getter)array_protocol_descr_get,\n\t NULL,\n\t \"Array protocol: descr\"},\n\t{\"__array_shape__\", \n\t (getter)array_shape_get,\n\t NULL,\n\t \"Array protocol: shape\"},\n\t{\"__array_strides__\",\n\t (getter)array_protocol_strides_get,\n\t NULL,\n\t \"Array protocol: strides\"},\n {\"__array_struct__\",\n (getter)array_struct_get,\n NULL,\n \"Array protocol: struct\"},\n\t{\"__array_priority__\",\n\t (getter)array_priority_get,\n\t NULL,\n\t \"Array priority\"},\n \t{NULL, NULL, NULL, NULL}, /* Sentinel */\n};\n\n/****************** end of attribute get and set routines *******************/\n\n\nstatic PyObject *\narray_alloc(PyTypeObject *type, int nitems)\n{\n PyObject *obj;\n /* nitems will always be 0 */ \n obj = (PyObject *)_pya_malloc(sizeof(PyArrayObject));\n PyObject_Init(obj, type);\n return obj;\n}\n\n\nstatic char Arraytype__doc__[] = \n \"A array object represents a multidimensional, homogeneous array\\n\"\n\t\" of fixed-size items. An associated data-type-descriptor object\\n\"\n\t\" details the data-type in an array (including byteorder and any\\n\"\n\t\" fields). An array can be constructed using the numpy.array\\n\"\n\t\" command. Arrays are sequence, mapping and numeric objects.\\n\"\n\t\" More information is available in the numpy module and by looking\\n\"\n\t\" at the methods and attributes of an array.\\n\\n\"\n\t\" ndarray.__new__(subtype, shape=, dtype=int_, buffer=None, \\n\"\n\t\" offset=0, strides=None, fortran=False)\\n\\n\"\n\t\" There are two modes of creating an array using __new__:\\n\"\n\t\" 1) If buffer is None, then only shape, dtype, and fortran \\n\"\n\t\" are used\\n\"\n\t\" 2) If buffer is an object exporting the buffer interface, then\\n\"\n\t\" all keywords are interpreted.\\n\"\n\t\" The dtype parameter can be any object that can be interpreted \\n\"\n\t\" as a numpy.dtype object.\\n\\n\"\n\t\" No __init__ method is needed because the array is fully \\n\"\n\t\" initialized after the __new__ method.\";\n\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, 4*n);\n\t\telse\n\t\t\t*itemsize = MAX(*itemsize, n);\n\t\treturn 0;\n\t}\n\tfor (i=0; i n_lower) n_lower = d[1];\n }\n d[1] = n_lower;\n\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, 4*minsize);\n\t\t}\n\t\telse {\n\t\t\ttestsize = MAX(chksize, minsize);\n\t\t}\n\t\tif (testsize != outtype->elsize) {\n\t\t\tPyArray_DESCR_REPLACE(outtype);\n\t\t\touttype->elsize = testsize;\n\t\t\tPy_XDECREF(outtype->fields);\n\t\t\touttype->fields = NULL;\n\t\t}\n\t}\n\treturn outtype;\n}\n\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#ifndef Py_UNICODE_WIDE\n\t\tchktype->elsize <<= 1;\n#endif\t\t\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\t} else if (PyLong_Check(op)) {\n\t\t/* if integer can fit into a longlong then return that\n\t\t*/\n\t\tif ((PyLong_AsLongLong(op) == -1) && PyErr_Occurred()) {\n\t\t\tPyErr_Clear();\n\t\t\tgoto deflt;\n\t\t}\n\t\tchktype = PyArray_DescrFromType(PyArray_LONGLONG);\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 *= 4;\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\tif (ret->nd > 0) {\n\t\tPyErr_SetString(PyExc_ValueError,\n\t\t\t\t\"shape-mismatch on array construction\");\n\t\tPy_DECREF(ret);\n\t\treturn NULL;\n\t}\n\n ret->descr->f->setitem(op, ret->data, ret);\n\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 */\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\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\t\tgoto fail;\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\t\tgoto fail;\n }\n\t\n\tif(discover_dimensions(s,nd,d, !stop_at_string) == -1) goto fail;\n\n\tif (itemsize == 0 && PyTypeNum_ISEXTENDED(type)) {\n\t\tif (discover_itemsize(s, nd, &itemsize) == -1) goto fail;\n\t\tif (type == PyArray_UNICODE) itemsize*=4;\n\t}\n\n\tif (itemsize != typecode->elsize) {\n\t\tPyArray_DESCR_REPLACE(typecode);\n\t\ttypecode->elsize = itemsize;\n\t}\n\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) return NULL;\n if(Assign_Array(r,s) == -1) {\n\t\tPy_DECREF(r);\n\t\treturn NULL;\n\t}\n return (PyObject*)r;\n\n fail:\n\tPy_DECREF(typecode);\n\treturn NULL;\n}\n\n\n/*OBJECT_API\n Is the typenum valid?\n*/\nstatic int \nPyArray_ValidType(int type) \n{\n\tPyArray_Descr *descr;\n\tint res=TRUE;\n\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 << 2;\n\t\tif (mpd->type_num == PyArray_UNICODE &&\n\t\t at->type_num == PyArray_STRING) \n\t\t\tat->elsize = mpd->elsize >> 2;\n\t\tif (at->type_num == PyArray_VOID)\n\t\t\tat->elsize = mpd->elsize;\n\t}\n\n\tout = PyArray_NewFromDescr(mp->ob_type, at,\n\t\t\t\t mp->nd, \n\t\t\t\t mp->dimensions, \n\t\t\t\t NULL, NULL, \n\t\t\t\t fortran,\n\t\t\t\t (PyObject *)mp);\n\n\tif (out == NULL) return NULL;\n\tret = PyArray_CastTo((PyArrayObject *)out, mp);\n\tif (ret != -1) return out;\n\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 */\n/*OBJECT_API*/\nstatic PyObject *\nPyArray_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 break;\n\tcase PyArray_STRINGLTR:\n\t\ttype_num = PyArray_STRING;\n\t\tbreak;\n\tcase PyArray_UNICODELTR:\n\t\ttype_num = PyArray_UNICODE;\n\t\tsize <<= 2;\n\t\tbreak;\n\tcase 'V':\n\t\ttype_num = PyArray_VOID;\n\t\tbreak;\n\tdefault:\n\t\t_MY_FAIL\n\t}\n\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/* OBJECT_API */\nstatic PyObject *\nPyArray_FromStructInterface(PyObject *input)\n{\n\tPyArray_Descr *thetype;\n\tchar buf[40];\n\tPyArrayInterface *inter;\n\tPyObject *attr, *r;\n\tchar endian = PyArray_NATBYTE;\n \n attr = PyObject_GetAttrString(input, \"__array_struct__\");\n if (attr == NULL) {\n\t\tPyErr_Clear();\n\t\treturn Py_NotImplemented;\n\t}\n if (!PyCObject_Check(attr) || \\\n ((inter=((PyArrayInterface *)\\\n\t\t PyCObject_AsVoidPtr(attr)))->version != 2)) {\n PyErr_SetString(PyExc_ValueError, \"invalid __array_struct__\");\n\t\tPy_DECREF(attr);\n return NULL;\n }\n\tif ((inter->flags & NOTSWAPPED) != NOTSWAPPED) {\n\t\tendian = PyArray_OPPBYTE;\n\t\tinter->flags &= ~NOTSWAPPED;\n\t}\n\n snprintf(buf, 40, \"%c%c%d\", endian, inter->typekind, inter->itemsize);\n if (!(thetype=_array_typedescr_fromstr(buf))) {\n\t\tPy_DECREF(attr);\n return NULL;\n }\n\n r = PyArray_NewFromDescr(&PyArray_Type, thetype,\n\t\t\t\t inter->nd, inter->shape,\n\t\t\t\t inter->strides, inter->data,\n\t\t\t\t inter->flags, NULL);\n\tPy_INCREF(input);\n\tPyArray_BASE(r) = input;\n Py_DECREF(attr);\n PyArray_UpdateFlags((PyArrayObject *)r, UPDATE_ALL_FLAGS);\n return r;\n}\n\n/*OBJECT_API*/\nstatic PyObject *\nPyArray_FromInterface(PyObject *input)\n{\n\tPyObject *attr=NULL, *item=NULL;\n PyObject *tstr=NULL, *shape=NULL; \n PyArrayObject *ret;\n\tPyArray_Descr *type=NULL;\n\tchar *data;\n\tint buffer_len;\n\tint res, i, n;\n\tintp dims[MAX_DIMS], strides[MAX_DIMS];\n\tint dataflags = BEHAVED_FLAGS;\n\n\t/* Get the memory from __array_data__ and __array_offset__ */\n\t/* Get the shape */\n\t/* Get the typestring -- ignore array_descr */\n\t/* Get the strides */\n\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\treturn NULL;\n\t\t}\n\t\tif (n != PyTuple_GET_SIZE(attr)) {\n\t\t\tPyErr_SetString(PyExc_ValueError, \n\t\t\t\t\t\"mismatch in length of \"\\\n\t\t\t\t\t\"__array_strides__ and \"\\\n\t\t\t\t\t\"__array_shape__\");\n\t\t\tPy_DECREF(attr);\n\t\t\tPy_DECREF(ret);\n\t\t\treturn NULL;\n\t\t}\n\t\tfor (i=0; istrides, strides, n*sizeof(intp));\n\t}\n\telse PyErr_Clear();\n\tPyArray_UpdateFlags(ret, UPDATE_ALL_FLAGS);\n\treturn (PyObject *)ret;\n\n fail:\n\tPy_XDECREF(attr);\n\tPy_XDECREF(shape);\n\tPy_XDECREF(tstr);\n\treturn NULL;\n}\n\n/* OBJECT_API*/\nstatic PyObject *\nPyArray_FromArrayAttr(PyObject *op, PyArray_Descr *typecode, PyObject *context) \n{\n PyObject *new;\n PyObject *array_meth;\n\n array_meth = PyObject_GetAttrString(op, \"__array__\");\n if (array_meth == NULL) {PyErr_Clear(); return Py_NotImplemented;}\n if (context == NULL) {\n if (typecode == NULL) new = PyObject_CallFunction(array_meth, NULL);\n else new = PyObject_CallFunction(array_meth, \"O\", typecode);\n }\n else {\n if (typecode == NULL) {\n new = PyObject_CallFunction(array_meth, \"OO\", Py_None, context);\n if (new == NULL && PyErr_ExceptionMatches(PyExc_TypeError)) {\n PyErr_Clear();\n new = PyObject_CallFunction(array_meth, \"\");\n }\n }\n else {\n new = PyObject_CallFunction(array_meth, \"OO\", typecode, context);\n if (new == NULL && PyErr_ExceptionMatches(PyExc_TypeError)) {\n PyErr_Clear();\n new = PyObject_CallFunction(array_meth, \"O\", typecode);\n }\n }\n }\n Py_DECREF(array_meth);\n if (new == NULL) return NULL;\n if (!PyArray_Check(new)) {\n PyErr_SetString(PyExc_ValueError, \n \"object __array__ method not \" \\\n \"producing an array\");\n Py_DECREF(new);\n return NULL;\n }\n return new;\n} \n\n/* Does not check for ENSURECOPY and NOTSWAPPED in flags */\n/* Steals a reference to newtype --- which can be NULL */\n/*OBJECT_API*/\nstatic PyObject *\nPyArray_FromAny(PyObject *op, PyArray_Descr *newtype, int min_depth, \n int max_depth, int flags, PyObject *context) \n{\n /* This is the main code to make a NumPy array from a Python\n Object. It is called from lot's of different places which\n is why there are so many checks. The comments try to\n explain some of the checks. */\n\n PyObject *r=NULL;\n int seq = FALSE;\n \n\t/* Is input object already an array? */\n\t/* This is where the flags are used */\n if (PyArray_Check(op)) \n\t\tr = PyArray_FromArray((PyArrayObject *)op, newtype, flags);\n\telse if (PyArray_IsScalar(op, Generic)) {\n\t\tr = PyArray_FromScalar(op, newtype);\n\t}\n else if (((r = PyArray_FromStructInterface(op))!=Py_NotImplemented)|| \\\n ((r = PyArray_FromInterface(op)) != Py_NotImplemented) || \\\n ((r = PyArray_FromArrayAttr(op, newtype, context)) \\\n != Py_NotImplemented)) {\n PyObject *new;\n if (r == NULL) return NULL;\n if (newtype != NULL || flags != 0) {\n new = PyArray_FromArray((PyArrayObject *)r, newtype, flags);\n Py_DECREF(r);\n r = new;\n }\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\n\t\t\tPy_INCREF(newtype);\n\t\t\tr = Array_FromSequence(op, newtype, flags & FORTRAN,\n\t\t\t\t\t min_depth, max_depth);\n\t\t\tif (PyErr_Occurred() && r == NULL) {\n /* It wasn't really a sequence after all.\n * Try interpreting it as a scalar */\n\t\t\t\tPyErr_Clear();\n\t\t\t}\n else {\n\t\t\t\tseq = TRUE;\n\t\t\t\tPy_DECREF(newtype);\n\t\t\t}\n }\n if (!seq)\n\t\t\tr = Array_FromScalar(op, newtype);\n\t}\n\n /* If we didn't succeed return NULL */\n if (r == NULL) return NULL;\n\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: PyArray_FromAny \"\\\n\t\t\t\t\"not producing an array\");\n\t\tPy_DECREF(r);\n return NULL;\n }\n\n if (min_depth != 0 && ((PyArrayObject *)r)->nd < min_depth) {\n PyErr_SetString(PyExc_ValueError, \n \"object of too small depth for desired array\");\n Py_DECREF(r);\n return NULL;\n }\n if (max_depth != 0 && ((PyArrayObject *)r)->nd > max_depth) {\n PyErr_SetString(PyExc_ValueError, \n \"object too deep for desired array\");\n Py_DECREF(r);\n return NULL;\n }\n return r;\n}\n\n/* new reference -- accepts NULL for mintype*/\n/*OBJECT_API*/\nstatic PyArray_Descr *\nPyArray_DescrFromObject(PyObject *op, PyArray_Descr *mintype)\n{\n\treturn _array_find_type(op, mintype, MAX_DIMS);\n}\n\n/*OBJECT_API\n Return the typecode of the array a Python object would be converted\n to\n*/\nstatic int \nPyArray_ObjectType(PyObject *op, int minimum_type) \n{\n\tPyArray_Descr *intype;\n\tPyArray_Descr *outtype;\n\tint ret;\n\n\tintype = PyArray_DescrFromType(minimum_type);\n\tif (intype == NULL) PyErr_Clear();\n\touttype = _array_find_type(op, intype, MAX_DIMS);\n\tret = outtype->type_num;\n\tPy_DECREF(outtype);\n\tPy_DECREF(intype);\n\treturn ret;\n}\n\n\n/* flags is any of \n CONTIGUOUS, \n FORTRAN,\n ALIGNED, \n WRITEABLE, \n NOTSWAPPED,\n ENSURECOPY, \n UPDATEIFCOPY,\n FORCECAST,\n ENSUREARRAY\n\n or'd (|) together\n\n Any of these flags present means that the returned array should \n guarantee that aspect of the array. Otherwise the returned array\n won't guarantee it -- it will depend on the object as to whether or \n not it has such features. \n\n Note that ENSURECOPY is enough\n to guarantee CONTIGUOUS, ALIGNED and WRITEABLE\n and therefore it is redundant to include those as well. \n\n BEHAVED_FLAGS == ALIGNED | WRITEABLE\n CARRAY_FLAGS = CONTIGUOUS | BEHAVED_FLAGS\n FARRAY_FLAGS = FORTRAN | BEHAVED_FLAGS\n \n FORTRAN can be set in the FLAGS to request a FORTRAN array. \n Fortran arrays are always behaved (aligned, \n notswapped, and writeable) and not (C) CONTIGUOUS (if > 1d). \n\n UPDATEIFCOPY flag sets this flag in the returned array if a copy is\n made and the base argument points to the (possibly) misbehaved array.\n When the new array is deallocated, the original array held in base\n is updated with the contents of the new array. \n\n FORCECAST will cause a cast to occur regardless of whether or not\n it is safe. \n*/\n\n\n/* steals a reference to descr -- accepts NULL */\n/*OBJECT_API*/\nstatic PyObject *\nPyArray_CheckFromAny(PyObject *op, PyArray_Descr *descr, int min_depth, \n int max_depth, int requires, PyObject *context) \n{\n\tif (requires & NOTSWAPPED) {\n\t\tif (!descr && PyArray_Check(op) && \\\n\t\t !PyArray_ISNBO(PyArray_DESCR(op)->byteorder)) {\n\t\t\tdescr = PyArray_DescrNew(PyArray_DESCR(op));\n\t\t}\n\t\telse if ((descr && !PyArray_ISNBO(descr->byteorder))) {\n\t\t\tPyArray_DESCR_REPLACE(descr);\n\t\t}\n\t\tdescr->byteorder = PyArray_NATIVE;\n\t}\n\n\treturn PyArray_FromAny(op, descr, min_depth, max_depth,\n requires, context);\n}\n\n/* This is a quick wrapper around PyArray_FromAny(op, NULL, 0, 0, \n ENSUREARRAY) */\n/* that special cases Arrays and PyArray_Scalars up front */\n/* It *steals a reference* to the object */\n/* It also guarantees that the result is PyArray_Type 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_FromAny(op, NULL, 0, 0, ENSUREARRAY, NULL);\n Py_DECREF(op);\n return new;\n}\n\n/*OBJECT_API\n Check the type coercion rules.\n*/\nstatic int \nPyArray_CanCastSafely(int fromtype, int totype) \n{\n\tPyArray_Descr *from, *to;\n\tregister int felsize, telsize;\n\n if (fromtype == totype) return 1;\n if (fromtype == PyArray_BOOL) return 1;\n\tif (totype == PyArray_BOOL) return 0;\n if (totype == PyArray_OBJECT || totype == PyArray_VOID) return 1;\n\tif (fromtype == PyArray_OBJECT || fromtype == PyArray_VOID) return 0;\n\n\tfrom = PyArray_DescrFromType(fromtype);\n\tto = PyArray_DescrFromType(totype);\n\ttelsize = to->elsize;\n\tfelsize = from->elsize;\n\tPy_DECREF(from);\n\tPy_DECREF(to);\n\n switch(fromtype) {\n case PyArray_BYTE:\n\tcase PyArray_SHORT:\n case PyArray_INT:\n case PyArray_LONG:\n\tcase PyArray_LONGLONG:\n\t\tif (PyTypeNum_ISINTEGER(totype)) {\n\t\t\tif (PyTypeNum_ISUNSIGNED(totype)) {\n\t\t\t\treturn (telsize > felsize);\n\t\t\t}\n\t\t\telse {\n\t\t\t\treturn (telsize >= felsize);\n\t\t\t}\n\t\t}\n\t\telse if (PyTypeNum_ISFLOAT(totype)) {\n if (felsize < 8)\n return (telsize > felsize);\n else\n return (telsize >= felsize);\n\t\t}\n\t\telse if (PyTypeNum_ISCOMPLEX(totype)) {\n if (felsize < 8)\n return ((telsize >> 1) > felsize);\n else\n return ((telsize >> 1) >= felsize);\n\t\t}\n\t\telse return totype > fromtype;\n case PyArray_UBYTE:\n case PyArray_USHORT:\n case PyArray_UINT:\n\tcase PyArray_ULONG:\n\tcase PyArray_ULONGLONG:\n\t\tif (PyTypeNum_ISINTEGER(totype)) {\n\t\t\tif (PyTypeNum_ISSIGNED(totype)) {\n\t\t\t\treturn (telsize > felsize);\n\t\t\t}\n\t\t\telse {\n\t\t\t\treturn (telsize >= felsize);\n\t\t\t}\n\t\t}\n\t\telse if (PyTypeNum_ISFLOAT(totype)) {\n if (felsize < 8)\n return (telsize > felsize);\n else\n return (telsize >= felsize);\n\t\t}\n\t\telse if (PyTypeNum_ISCOMPLEX(totype)) {\n if (felsize < 8)\n return ((telsize >> 1) > felsize);\n else\n return ((telsize >> 1) >= felsize);\n\t\t}\n\t\telse return totype > fromtype;\n case PyArray_FLOAT:\n case PyArray_DOUBLE:\n\tcase PyArray_LONGDOUBLE:\n\t\tif (PyTypeNum_ISCOMPLEX(totype)) \n\t\t\treturn ((telsize >> 1) >= felsize);\n\t\telse\n\t\t\treturn (totype > fromtype);\n case PyArray_CFLOAT:\n case PyArray_CDOUBLE:\n\tcase PyArray_CLONGDOUBLE:\n\t\treturn (totype > fromtype);\n\tcase PyArray_STRING:\n\tcase PyArray_UNICODE:\n\t\treturn (totype > fromtype);\n default:\n return 0;\n }\n}\n\n/* leaves reference count alone --- cannot be NULL*/\n/*OBJECT_API*/\nstatic Bool\nPyArray_CanCastTo(PyArray_Descr *from, PyArray_Descr *to)\n{\n\tint fromtype=from->type_num;\n\tint totype=to->type_num;\n\tBool ret;\n\n\tret = (Bool) PyArray_CanCastSafely(fromtype, totype);\n\tif (ret) { /* Check String and Unicode more closely */\n\t\tif (fromtype == PyArray_STRING) {\n\t\t\tif (totype == PyArray_STRING) {\n\t\t\t\tret = (from->elsize <= to->elsize);\n\t\t\t}\n\t\t\telse if (totype == PyArray_UNICODE) {\n\t\t\t\tret = (from->elsize << 2 \\\n\t\t\t\t <= to->elsize);\n\t\t\t}\n\t\t}\n\t\telse if (fromtype == PyArray_UNICODE) {\n\t\t\tif (totype == PyArray_UNICODE) {\n\t\t\t\tret = (from->elsize <= to->elsize);\n\t\t\t}\n\t\t}\n\t\t/* TODO: If totype is STRING or unicode \n\t\t see if the length is long enough to hold the\n\t\t stringified value of the object.\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, NULL);\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 FORCECAST | ALIGNED, NULL);\n\t\t\tif (new==NULL) goto fail;\n Py_DECREF(obj);\n\t\t\tobj = new;\n\t\t\tr = iter_subscript_int(self, (PyArrayObject *)obj);\n\t\t}\n\t\telse {\n\t\t\tgoto fail;\n\t\t}\n\t\tPy_DECREF(obj);\n\t\treturn r;\n\t}\n\telse Py_DECREF(indtype);\n\n\n fail:\n\tif (!PyErr_Occurred())\n\t\tPyErr_SetString(PyExc_IndexError, \"unsupported iterator index\");\n\tPy_XDECREF(indtype);\n\tPy_XDECREF(obj);\n\treturn NULL;\n\n}\n\n\nstatic int\niter_ass_sub_Bool(PyArrayIterObject *self, PyArrayObject *ind,\n\t\t PyArrayIterObject *val, int swap)\n{\n\tint index, strides, itemsize;\n\tchar *dptr;\n PyArray_CopySwapFunc *copyswap;\n\n\tif (ind->nd != 1) {\n\t\tPyErr_SetString(PyExc_ValueError, \n\t\t\t\t\"boolean index array should have 1 dimension\");\n\t\treturn -1;\n\t}\n\titemsize = self->ao->descr->elsize;\n\tindex = ind->dimensions[0];\n\tstrides = ind->strides[0];\n\tdptr = ind->data;\n\tPyArray_ITER_RESET(self);\n\t/* Loop over Boolean array */\n copyswap = self->ao->descr->f->copyswap;\n\twhile(index--) {\n\t\tif (*((Bool *)dptr) != 0) {\n copyswap(self->dataptr, val->dataptr, swap,\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, NULL);\n\tif (arrval==NULL) return -1;\n\tval_it = (PyArrayIterObject *)PyArray_IterNew(arrval);\n\tif (val_it==NULL) goto finish;\n\n\t/* Check for Boolean -- this is first becasue\n\t Bool is a subclass of Int */\n\n copyswap = PyArray_DESCR(arrval)->f->copyswap;\n\tswap = (PyArray_ISNOTSWAPPED(self->ao)!=PyArray_ISNOTSWAPPED(arrval));\n\tif (PyBool_Check(ind)) {\n\t\tif (PyObject_IsTrue(ind)) {\n copyswap(self->dataptr, PyArray_DATA(arrval), \n swap, 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, NULL);\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_CheckFromAny(obj, indtype, 0, 0, \n FORCECAST | BEHAVED_NS_FLAGS, NULL);\n\t\t\tPy_DECREF(obj);\n\t\t\tobj = new;\n\t\t\tif (new==NULL) goto finish;\n\t\t\tif (iter_ass_sub_int(self, (PyArrayObject *)obj,\n\t\t\t\t\t val_it, swap) < 0)\n\t\t\t\tgoto finish;\n\t\t\tretval=0;\n\t\t}\n\t}\n\n finish:\n\tif (!PyErr_Occurred() && retval < 0)\n\t\tPyErr_SetString(PyExc_IndexError, \n\t\t\t\t\"unsupported iterator index\");\n\tPy_XDECREF(indtype);\n\tPy_XDECREF(obj);\n\tPy_XDECREF(val_it);\n\tPy_XDECREF(arrval);\n\treturn retval;\n\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 {\"index\", T_INT, offsetof(PyArrayIterObject, index), RO, NULL},\n\t{NULL},\n};\n\nstatic PyObject *\niter_coords_get(PyArrayIterObject *self)\n{\n int nd;\n nd = self->ao->nd;\n if (self->contiguous) { /* coordinates not kept track of --- need to generate\n from index */\n intp val;\n int i;\n val = self->index;\n for (i=0;icoordinates[i] = val / self->factors[i];\n val = val % self->factors[i];\n }\n }\n return PyArray_IntTupleFromIntp(nd, self->coordinates);\n}\n\nstatic PyGetSetDef iter_getsets[] = {\n\t{\"coords\", \n\t (getter)iter_coords_get,\n\t NULL,\n\t \"An N-d tuple of current coordinates.\"},\n\t{NULL, NULL, NULL, NULL},\n};\n\nstatic PyTypeObject PyArrayIter_Type = {\n PyObject_HEAD_INIT(NULL)\n 0,\t\t\t\t\t /* ob_size */\n \"numpy.flatiter\",\t\t /* tp_name */\n sizeof(PyArrayIterObject), /* tp_basicsize */\n 0,\t\t\t\t\t /* tp_itemsize */\n /* methods */\n (destructor)arrayiter_dealloc,\t\t/* tp_dealloc */\n 0,\t\t\t\t\t/* tp_print */\n 0,\t\t\t\t\t/* tp_getattr */\n 0,\t\t\t\t\t/* tp_setattr */\n 0,\t\t\t\t\t/* tp_compare */\n 0,\t\t\t\t\t/* tp_repr */\n 0,\t\t\t\t\t/* tp_as_number */\n 0, \t\t\t /* tp_as_sequence */\n &iter_as_mapping, \t /* tp_as_mapping */\n 0,\t\t\t\t\t/* tp_hash */\n 0,\t\t\t\t\t/* tp_call */\n 0,\t\t\t\t\t/* tp_str */\n 0,\t \t/* tp_getattro */\n 0,\t\t\t\t\t/* tp_setattro */\n 0,\t\t\t\t\t/* tp_as_buffer */\n Py_TPFLAGS_DEFAULT, /* tp_flags */\n 0,\t\t\t\t\t/* tp_doc */\n 0, \t /* tp_traverse */\n 0,\t\t\t\t\t/* tp_clear */\n 0,\t\t\t\t\t/* tp_richcompare */\n 0,\t\t\t\t\t/* tp_weaklistoffset */\n 0, \t /* tp_iter */\n (iternextfunc)arrayiter_next,\t\t/* tp_iternext */\n iter_methods,\t\t\t\t/* tp_methods */\n iter_members,\t \t /* tp_members */\n iter_getsets, /* tp_getset */\n\n};\n\n/** END of Array Iterator **/\n\n\n\n/*********************** Subscript Array Iterator *************************\n * *\n * This object handles subscript behavior for array objects. *\n * It is an iterator object with a next method *\n * It abstracts the n-dimensional mapping behavior to make the looping *\n * code more understandable (maybe) *\n * and so that indexing can be set up ahead of time *\n */ \n\n/* convert an indexing object to an INTP indexing array iterator\n if possible -- otherwise, it is a Slice or Ellipsis object\n and has to be interpreted on bind to a particular \n array so leave it NULL for now.\n */\nstatic int\n_convert_obj(PyObject *obj, PyArrayIterObject **iter)\n{\n\tPyArray_Descr *indtype;\n\tPyObject *arr;\n\n\tif (PySlice_Check(obj) || (obj == Py_Ellipsis))\n\t\t*iter = NULL;\n\telse {\n\t\tindtype = PyArray_DescrFromType(PyArray_INTP);\n\t\tarr = PyArray_FromAny(obj, indtype, 0, 0, FORCECAST, NULL);\n\t\tif (arr == NULL) return -1;\n\t\t*iter = (PyArrayIterObject *)PyArray_IterNew(arr);\n\t\tPy_DECREF(arr);\n\t\tif (*iter == NULL) return -1;\n\t}\n\treturn 0;\n}\n\n/* Adjust dimensionality and strides for index object iterators \n --- i.e. broadcast\n */\n/*OBJECT_API*/\nstatic int\nPyArray_Broadcast(PyArrayMultiIterObject *mit)\n{\n\tint i, nd, k, j;\n\tintp tmp;\n\tPyArrayIterObject *it;\n\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\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, NULL);\n\tif (ba == NULL) return -1;\n\tnd = ba->nd;\n\tfor (j=0; jdata;\n\tcount = 0;\n\n\t/* pre-determine how many nonzero entries there are */\n\tfor (i=0; iao->data;\n\t\tcoords[j] = 0;\n\t\tdims_m1[j] = ba->dimensions[j]-1;\n\t}\n\n\tptr = (Bool *)ba->data;\n\n\tif (count == 0) goto finish;\n\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->index = 0;\n \tmit->ait = NULL;\n \tmit->subspace = NULL;\n\tmit->numiter = 0;\n\tmit->consec = 1;\n\tPy_INCREF(indexobj);\n\tmit->indexobj = indexobj;\n\n\tif (fancy == SOBJ_LISTTUP) {\n\t\tPyObject *newobj;\n\t\tnewobj = PySequence_Tuple(indexobj);\n\t\tif (newobj == NULL) goto fail;\n\t\tPy_DECREF(indexobj);\n\t\tindexobj = newobj;\n\t\tmit->indexobj = indexobj;\n\t}\n\n#undef SOBJ_NOTFANCY \n#undef SOBJ_ISFANCY \n#undef SOBJ_BADARRAY \n#undef SOBJ_TOOMANY \n#undef SOBJ_LISTTUP \n \n\tif (oned) return (PyObject *)mit;\n\n\t/* Must have some kind of fancy indexing if we are here */\n\t/* indexobj is either a list, an arrayobject, or a tuple \n\t (with at least 1 list or arrayobject or Bool object), */\n\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, NULL);\n\t\tif (arr == NULL) goto fail;\n\t\tmit->iters[0] = (PyArrayIterObject *)PyArray_IterNew(arr);\n\t\tif (mit->iters[0] == NULL) {Py_DECREF(arr); goto fail;}\n\t\tmit->nd = PyArray_NDIM(arr);\n\t\tmemcpy(mit->dimensions,PyArray_DIMS(arr),mit->nd*sizeof(intp));\n\t\tmit->size = PyArray_SIZE(arr);\n\t\tPy_DECREF(arr);\n\t\tPy_DECREF(mit->indexobj);\n\t\tmit->indexobj = Py_BuildValue(\"(N)\", PyInt_FromLong(0));\n\t}\n\telse { /* must be a tuple */\n\t\tPyObject *obj;\n\t\tPyArrayIterObject *iter;\n\t\tPyObject *new;\n\t\t/* Make a copy of the tuple -- we will be replacing \n\t\t index objects with 0's */\n\t\tn = PyTuple_GET_SIZE(indexobj);\n\t\tnew = PyTuple_New(n);\n\t\tif (new == NULL) goto fail;\n\t\tstarted = 0;\n\t\tnonindex = 0;\n\t\tfor (i=0; iconsec = 0;\n\t\t\t\tmit->iters[(mit->numiter)++] = iter;\n\t\t\t\tPyTuple_SET_ITEM(new,i,\n\t\t\t\t\t\t PyInt_FromLong(0));\n\t\t\t}\n\t\t\telse {\n\t\t\t\tif (started) nonindex = 1;\n\t\t\t\tPy_INCREF(obj);\n\t\t\t\tPyTuple_SET_ITEM(new,i,obj);\n\t\t\t}\n\t\t}\n\t\tPy_DECREF(mit->indexobj);\n\t\tmit->indexobj = new;\n\t\t/* Store the number of iterators actually converted */\n\t\t/* These will be mapped to actual axes at bind time */\n\t\tif (PyArray_Broadcast((PyArrayMultiIterObject *)mit) < 0)\n\t\t\tgoto fail;\n\t}\n\n return (PyObject *)mit;\n \n fail:\n Py_DECREF(mit);\n\treturn NULL;\n}\n\n\nstatic void\narraymapiter_dealloc(PyArrayMapIterObject *mit)\n{\n\tint i;\n\tPy_XDECREF(mit->indexobj);\n Py_XDECREF(mit->ait);\n\tPy_XDECREF(mit->subspace);\n\tfor (i=0; inumiter; i++)\n\t\tPy_XDECREF(mit->iters[i]);\n _pya_free(mit);\n}\n\n/* The mapiter object must be created new each time. It does not work\n to bind to a new array, and continue.\n\n This was the orginal intention, but currently that does not work. \n Do not expose the MapIter_Type to Python.\n\n It's not very useful anyway, since mapiter(indexobj); mapiter.bind(a); \n mapiter is equivalent to a[indexobj].flat but the latter gets to use \n slice syntax.\n*/\n\nstatic PyTypeObject PyArrayMapIter_Type = {\n PyObject_HEAD_INIT(NULL)\n 0,\t\t\t\t\t /* ob_size */\n \"numpy.mapiter\",\t\t \t/* tp_name */\n sizeof(PyArrayIterObject), /* tp_basicsize */\n 0,\t\t\t\t\t /* tp_itemsize */\n /* methods */\n (destructor)arraymapiter_dealloc,\t/* tp_dealloc */\n 0,\t\t\t\t\t/* tp_print */\n 0,\t\t\t\t\t/* tp_getattr */\n 0,\t\t\t\t\t/* tp_setattr */\n 0,\t\t\t\t\t/* tp_compare */\n 0,\t\t\t\t\t/* tp_repr */\n 0,\t\t\t\t\t/* tp_as_number */\n 0,\t\t\t\t\t/* tp_as_sequence */\n 0,\t\t\t\t\t/* tp_as_mapping */\n 0,\t\t\t\t\t/* tp_hash */\n 0,\t\t\t\t\t/* tp_call */\n 0,\t\t\t\t\t/* tp_str */\n 0, \t\t/* tp_getattro */\n 0,\t\t\t\t\t/* tp_setattro */\n 0,\t\t\t\t\t/* tp_as_buffer */\n Py_TPFLAGS_DEFAULT, /* tp_flags */\n 0,\t\t\t\t\t/* tp_doc */\n (traverseproc)0, \t /* tp_traverse */\n 0,\t\t\t\t\t/* tp_clear */\n 0,\t\t\t\t\t/* tp_richcompare */\n 0,\t\t\t\t\t/* tp_weaklistoffset */\n 0,\t\t \t /* tp_iter */\n (iternextfunc)0, \t /* tp_iternext */\n 0, \t /* tp_methods */\n 0,\t\t\t\t\t /* tp_members */\n 0,\t\t\t /* tp_getset */\n 0,\t\t\t\t\t /* tp_base */\n 0,\t\t\t\t\t /* tp_dict */\n 0,\t\t\t\t\t /* tp_descr_get */\n 0,\t\t\t\t\t /* tp_descr_set */\n 0,\t\t\t\t\t /* tp_dictoffset */\n (initproc)0,\t \t /* tp_init */\n 0, \t /* tp_alloc */\n 0,\t /* tp_new */\n 0,\t /* tp_free */\n 0,\t\t\t\t\t /* tp_is_gc */\n 0,\t\t\t\t\t /* tp_bases */\n 0,\t\t\t\t\t /* tp_mro */\n 0,\t\t\t\t\t /* tp_cache */\n 0,\t\t\t\t\t /* tp_subclasses */\n 0\t\t\t\t\t /* tp_weaklist */\n\n};\n\n/** END of Subscript Iterator **/\n\n\n/*OBJECT_API\n Get MultiIterator,\n*/\nstatic PyObject *\nPyArray_MultiIterNew(int n, ...)\n{\n va_list va;\n\tPyArrayMultiIterObject *multi;\n\tPyObject *current;\n\tPyObject *arr;\n\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 dtype objects can be set. \n*/\nstatic PyMemberDef arraydescr_members[] = {\n\t{\"type\", T_OBJECT, offsetof(PyArray_Descr, typeobj), RO, NULL},\n\t{\"kind\", T_CHAR, offsetof(PyArray_Descr, kind), RO, NULL},\n\t{\"char\", T_CHAR, offsetof(PyArray_Descr, type), RO, NULL},\n\t{\"num\", T_INT, offsetof(PyArray_Descr, type_num), RO, NULL},\n\t{\"byteorder\", T_CHAR, offsetof(PyArray_Descr, byteorder), RO, NULL},\n\t{\"itemsize\", T_INT, offsetof(PyArray_Descr, elsize), RO, NULL},\n\t{\"alignment\", T_INT, offsetof(PyArray_Descr, alignment), RO, NULL},\n {\"hasobject\", T_UBYTE, offsetof(PyArray_Descr, hasobject), RO, NULL},\n\t{NULL}, \n};\n\nstatic PyObject *\narraydescr_subdescr_get(PyArray_Descr *self)\n{\n\tif (self->subarray == NULL) {\n\t\tPy_INCREF(Py_None);\n\t\treturn Py_None;\n\t}\n\treturn Py_BuildValue(\"OO\", (PyObject *)self->subarray->base, \n\t\t\t self->subarray->shape);\n}\n\nstatic PyObject *\narraydescr_protocol_typestr_get(PyArray_Descr *self)\n{\n char basic_=self->kind;\n char endian = self->byteorder;\n\tint size=self->elsize;\n\n if (endian == '=') {\n endian = '<';\n if (!PyArray_IsNativeByteOrder(endian)) endian = '>';\n }\n \n\tif (self->type_num == PyArray_UNICODE) {\n\t\tsize >>= 2;\n\t}\n return PyString_FromFormat(\"%c%c%d\", endian, basic_, size);\n}\n\nstatic PyObject *\narraydescr_typename_get(PyArray_Descr *self)\n{\n int len;\n PyTypeObject *typeobj = self->typeobj;\n\tPyObject *res;\n\tstatic int suffix_len=0;\n\n\tif (PyTypeNum_ISUSERDEF(self->type_num)) {\n\t\tres = PyString_FromString(typeobj->tp_name);\n\t}\n\telse {\n\t\tif (suffix_len == 0) \n\t\t\tsuffix_len = strlen(\"scalar\");\n\t\tlen = strlen(typeobj->tp_name) - suffix_len;\n\t\tres = PyString_FromStringAndSize(typeobj->tp_name, len);\n\t}\n\tif (PyTypeNum_ISEXTENDED(self->type_num) && self->elsize != 0) {\n\t\tPyObject *p;\n\t\tp = PyString_FromFormat(\"%d\", self->elsize * 8);\n\t\tPyString_ConcatAndDel(&res, p);\n\t}\n\treturn res;\t\t\t\t\t\t \n}\n\nstatic PyObject *\narraydescr_base_get(PyArray_Descr *self)\n{\n\tif (self->subarray == NULL) {\n\t\tPy_INCREF(self);\n return (PyObject *)self;\n\t}\n Py_INCREF(self->subarray->base);\n return (PyObject *)(self->subarray->base);\n}\n\nstatic PyObject *\narraydescr_shape_get(PyArray_Descr *self)\n{\n\tif (self->subarray == NULL) {\n return Py_BuildValue(\"(N)\", PyInt_FromLong(1));\n\t}\n Py_INCREF(self->subarray->shape);\n return (PyObject *)(self->subarray->shape);\n}\n\nstatic PyObject *\narraydescr_protocol_descr_get(PyArray_Descr *self)\n{\n\tPyObject *dobj, *res;\n\n\tif (self->fields == NULL || self->fields == Py_None) {\n\t\t/* get default */\n\t\tdobj = PyTuple_New(2);\n\t\tif (dobj == NULL) return NULL;\n\t\tPyTuple_SET_ITEM(dobj, 0, PyString_FromString(\"\"));\n\t\tPyTuple_SET_ITEM(dobj, 1, \\\n\t\t\t\t arraydescr_protocol_typestr_get(self));\n\t\tres = PyList_New(1);\n\t\tif (res == NULL) {Py_DECREF(dobj); return NULL;}\n\t\tPyList_SET_ITEM(res, 0, dobj);\n\t\treturn res;\n\t}\n\n return PyObject_CallMethod(_numpy_internal, \"_array_descr\", \n\t\t\t\t \"O\", self);\n}\n\n/* returns 1 for a builtin type\n and 2 for a user-defined data-type descriptor\n return 0 if neither (i.e. it's a copy of one)\n*/\nstatic PyObject *\narraydescr_isbuiltin_get(PyArray_Descr *self) \n{\n\tlong val;\n\tval = 0;\n\tif (self->fields == Py_None) val = 1;\n\tif (PyTypeNum_ISUSERDEF(self->type_num)) val = 2;\n\treturn PyInt_FromLong(val);\n}\n\nstatic PyObject *\narraydescr_isnative_get(PyArray_Descr *self)\n{\n\tPyObject *ret;\n\n\tret = (PyArray_ISNBO(self->byteorder) ? Py_True : Py_False);\n\tPy_INCREF(ret);\n\treturn ret;\n}\n\nstatic PyObject *\narraydescr_fields_get(PyArray_Descr *self)\n{\n\tif (self->fields == NULL || self->fields == Py_None) {\n\t\tPy_INCREF(Py_None);\n\t\treturn Py_None;\n\t}\n\treturn PyDictProxy_New(self->fields);\n}\n\nstatic PyGetSetDef arraydescr_getsets[] = {\n\t{\"subdtype\", \n\t (getter)arraydescr_subdescr_get,\n\t NULL,\n\t \"A tuple of (descr, shape) or None.\"},\n\t{\"descr\",\n\t (getter)arraydescr_protocol_descr_get,\n\t NULL,\n\t \"The array_protocol type descriptor.\"},\n\t{\"str\",\n\t (getter)arraydescr_protocol_typestr_get,\n\t NULL,\n\t \"The array_protocol typestring.\"},\n {\"name\",\n (getter)arraydescr_typename_get,\n NULL,\n \"The name of the true data-type\"},\n\t{\"base\",\n\t (getter)arraydescr_base_get,\n\t NULL,\n\t \"The base data-type or self if no subdtype\"},\n {\"shape\",\n (getter)arraydescr_shape_get,\n NULL,\n \"The shape of the subdtype or (1,)\"},\n \t{\"isbuiltin\",\n\t (getter)arraydescr_isbuiltin_get,\n\t NULL,\n\t \"Is this a buillt-in data-type descriptor?\"},\n\t{\"isnative\",\n\t (getter)arraydescr_isnative_get,\n\t NULL,\n\t \"Is the byte-order of this descriptor native?\"},\n\t{\"fields\",\n\t (getter)arraydescr_fields_get,\n\t NULL,\n\t NULL},\n\t{NULL, NULL, NULL, NULL},\n};\n\nstatic PyArray_Descr *_convert_from_list(PyObject *obj, int align, int try_descr);\nstatic PyArray_Descr *_convert_from_dict(PyObject *obj, int align);\nstatic PyArray_Descr *_convert_from_commastring(PyObject *obj, int align);\nstatic PyArray_Descr *_convert_from_array_descr(PyObject *obj);\n\nstatic PyObject *\narraydescr_new(PyTypeObject *subtype, PyObject *args, PyObject *kwds)\n{\n\tPyObject *odescr;\n\tPyArray_Descr *descr, *conv;\n\tint align=0;\n\tBool copy=FALSE;\n\tstatic char *kwlist[] = {\"dtype\", \"align\", \"copy\", NULL};\n\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, \"dtype\");\n\tPy_DECREF(mod);\n\tif (obj == NULL) {Py_DECREF(ret); return NULL;}\n\tPyTuple_SET_ITEM(ret, 0, obj);\n\tif (PyTypeNum_ISUSERDEF(self->type_num) ||\t\t\\\n\t ((self->type_num == PyArray_VOID &&\t\t\t\\\n\t self->typeobj != &PyVoidArrType_Type))) {\n\t\tobj = (PyObject *)self->typeobj;\n\t\tPy_INCREF(obj);\n\t}\n\telse {\n\t\telsize = self->elsize;\n\t\tif (self->type_num == PyArray_UNICODE) {\n\t\t\telsize >>= 2;\n\t\t}\n\t\tobj = PyString_FromFormat(\"%c%d\",self->kind, elsize);\n\t}\n\tPyTuple_SET_ITEM(ret, 1, Py_BuildValue(\"(Nii)\", obj, 0, 1));\n\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 dtype object\\n\"\n\t\" with altered byteorders. If is not given all byteorders\\n\"\n\t\" are swapped. Otherwise endian can be '>', '<', or '=' to force\\n\"\n\t\" a byteorder. Descriptors in all fields are also updated in the\\n\"\n\t\" new dtype object.\";\n\nstatic PyObject *\narraydescr_newbyteorder(PyArray_Descr *self, PyObject *args) \n{\n\tchar endian=PyArray_SWAP;\n\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);\n\t\tif (self->type_num != PyArray_VOID) {\n\t\t\tPyObject *p;\n\t\t\tPyObject *t=PyString_FromString(\"'\");\n\t\t\tp = arraydescr_protocol_typestr_get(self);\n\t\t\tPyString_Concat(&p, t);\n\t\t\tPyString_ConcatAndDel(&t, p);\n\t\t\tp = PyString_FromString(\"(\");\n\t\t\tPyString_ConcatAndDel(&p, t);\n\t\t\tPyString_ConcatAndDel(&p, PyString_FromString(\", \"));\n\t\t\tPyString_ConcatAndDel(&p, sub);\n\t\t\tPyString_ConcatAndDel(&p, PyString_FromString(\")\"));\n\t\t\tsub = p;\n\t\t}\n\t}\n\telse if (self->subarray) {\n\t\tPyObject *p;\n\t\tPyObject *t = PyString_FromString(\"(\");\n\t\tp = arraydescr_str(self->subarray->base);\n\t\tPyString_ConcatAndDel(&t, p);\n\t\tPyString_ConcatAndDel(&t, PyString_FromString(\",\"));\n\t\tPyString_ConcatAndDel(&t, PyObject_Str(self->subarray->shape));\n\t\tPyString_ConcatAndDel(&t, PyString_FromString(\")\"));\n\t\tsub = t;\n\t}\n\telse {\n\t\tPyObject *t=PyString_FromString(\"'\");\n\t\tsub = arraydescr_protocol_typestr_get(self);\n\t\tPyString_Concat(&sub, t);\n\t\tPyString_ConcatAndDel(&t, sub);\n\t\tsub = t;\n\t}\n\treturn sub;\n}\n\nstatic PyObject *\narraydescr_repr(PyArray_Descr *self)\n{\n\tPyObject *sub, *s;\n\ts = PyString_FromString(\"dtype(\");\n sub = arraydescr_str(self);\n\tPyString_ConcatAndDel(&s, sub);\n\tsub = PyString_FromString(\")\");\n\tPyString_ConcatAndDel(&s, sub);\n\treturn s;\n}\n\nstatic int\narraydescr_compare(PyArray_Descr *self, PyObject *other)\n{\n \tif (!PyArray_DescrCheck(other)) {\n\t\tPyErr_SetString(PyExc_TypeError,\n\t\t\t\t\"not a dtype object.\");\n\t\treturn -1;\n\t}\n\tif (PyArray_EquivTypes(self, (PyArray_Descr *)other)) return 0;\n\tif (PyArray_CanCastTo(self, (PyArray_Descr *)other)) return -1;\n\treturn 1;\n}\n\n/*************************************************************************\n **************** Implement Mapping Protocol ***************************\n *************************************************************************/\n\nstatic int \ndescr_length(PyArray_Descr *self) \n{\n\n\tif (self->fields && self->fields != Py_None)\n\t\t/* Remove the last entry (root) */\n\t\treturn PyDict_Size(self->fields) - 1;\n\telse return 0;\n}\n\nstatic PyObject *\ndescr_subscript(PyArray_Descr *self, PyObject *op) \n{\n\n\tif (self->fields) {\n\t\tif (PyString_Check(op) || PyUnicode_Check(op)) {\n\t\t\tPyObject *obj;\n\t\t\tobj = PyDict_GetItem(self->fields, op);\n\t\t\tif (obj != NULL) {\n\t\t\t\tPyObject *descr;\n\t\t\t\tdescr = PyTuple_GET_ITEM(obj, 0);\n\t\t\t\tPy_INCREF(descr);\n\t\t\t\treturn descr;\n\t\t\t}\n\t\t\telse {\n\t\t\t\tPyErr_Format(PyExc_KeyError, \n\t\t\t\t\t \"field named \\'%s\\' not found.\",\n\t\t\t\t\t PyString_AsString(op));\n\t\t\t}\n\t\t}\n\t\telse {\n\t\t PyErr_SetString(PyExc_ValueError, \n\t\t\t\t \"only strings or unicode values allowed \" \\\n\t\t\t\t \"for getting fields.\");\n\t\t}\n\t}\n\telse {\n\t\tPyErr_Format(PyExc_KeyError, \n\t\t\t \"there are no fields in dtype %s.\",\n\t\t\t PyString_AsString(arraydescr_str(self)));\n\t}\n\n\treturn NULL;\n}\n\nstatic PyMappingMethods descr_as_mapping = {\n (inquiry)descr_length,\t\t /*mp_length*/\n (binaryfunc)descr_subscript,\t /*mp_subscript*/\n (objobjargproc)NULL,\t /*mp_ass_subscript*/\n};\n\n/****************** End of Mapping Protocol ******************************/\n\n\nstatic PyTypeObject PyArrayDescr_Type = {\n PyObject_HEAD_INIT(NULL)\n 0,\t\t\t\t\t /* ob_size */\n \"numpy.dtype\",\t\t \t /* tp_name */\n sizeof(PyArray_Descr), /* tp_basicsize */\n 0,\t\t\t\t\t /* tp_itemsize */\n /* methods */\n (destructor)arraydescr_dealloc,\t\t/* tp_dealloc */\n 0,\t\t\t\t\t/* tp_print */\n 0,\t\t\t\t\t/* tp_getattr */\n 0,\t\t\t\t\t/* tp_setattr */\n\t(cmpfunc)arraydescr_compare,\t\t/* tp_compare */\n (reprfunc)arraydescr_repr,\t /* tp_repr */\n 0,\t\t\t\t\t/* tp_as_number */\n 0, \t\t\t /* tp_as_sequence */\n &descr_as_mapping, \t /* tp_as_mapping */\n 0,\t\t\t\t\t/* tp_hash */\n 0,\t\t\t\t\t/* tp_call */\n (reprfunc)arraydescr_str, /* tp_str */\n 0,\t \t/* tp_getattro */\n 0,\t\t\t\t\t/* tp_setattro */\n 0,\t\t\t\t\t/* tp_as_buffer */\n Py_TPFLAGS_DEFAULT, /* tp_flags */\n 0,\t\t\t\t\t/* tp_doc */\n 0, \t /* tp_traverse */\n 0,\t\t\t\t\t/* tp_clear */\n 0,\t\t\t\t\t/* tp_richcompare */\n 0,\t\t\t\t\t/* tp_weaklistoffset */\n 0, \t /* tp_iter */\n 0,\t \t/* tp_iternext */\n arraydescr_methods,\t \t /* tp_methods */\n arraydescr_members,\t /* tp_members */\n arraydescr_getsets, /* tp_getset */\n 0,\t\t\t\t\t /* tp_base */\n 0,\t\t\t\t\t /* tp_dict */\n 0,\t\t\t\t\t /* tp_descr_get */\n 0,\t\t\t\t\t /* tp_descr_set */\n 0,\t\t\t\t\t /* tp_dictoffset */\n 0, \t \t /* tp_init */\n 0, \t /* tp_alloc */\n arraydescr_new,\t /* tp_new */\n 0,\t /* tp_free */\n 0,\t\t\t\t\t /* tp_is_gc */\n 0,\t\t\t\t\t /* tp_bases */\n 0,\t\t\t\t\t /* tp_mro */\n 0,\t\t\t\t\t /* tp_cache */\n 0,\t\t\t\t\t /* tp_subclasses */\n 0\t\t\t\t\t /* tp_weaklist */\n};\n", + "source_code_before": "/*\n Provide multidimensional arrays as a basic object type in python. \n\nBased on Original Numeric implementation\nCopyright (c) 1995, 1996, 1997 Jim Hugunin, hugunin@mit.edu\n\nwith contributions from many Numeric Python developers 1995-2004 \n\nHeavily modified in 2005 with inspiration from Numarray \n\nby\n\nTravis Oliphant\nAssistant Professor at\nBrigham Young University \n\nmaintainer email: oliphant.travis@ieee.org\n\nNumarray design (which provided guidance) by \nSpace Science Telescope Institute \n (J. Todd Miller, Perry Greenfield, Rick White)\n*/\n\n/*OBJECT_API\n Get Priority from object\n*/\nstatic double\nPyArray_GetPriority(PyObject *obj, double default_) \n{\n PyObject *ret;\n double priority=PyArray_PRIORITY;\n\n\tif (PyArray_CheckExact(obj))\n\t\treturn priority;\n 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\n\n#ifndef Py_UNICODE_WIDE\n#include \"ucsnarrow.c\"\n#endif\n\n\nstatic PyArray_Descr **userdescrs=NULL;\n#define error_converting(x) (((x) == -1) && PyErr_Occurred())\n\n/* Computer-generated arraytype and scalartype code */\n#include \"scalartypes.inc\"\n#include \"arraytypes.inc\"\n\n\n/* Helper functions */\n\n/*OBJECT_API*/\nstatic intp\nPyArray_PyIntAsIntp(PyObject *o)\n{\n\tlonglong long_value = -1;\n\tPyObject *obj;\n\tstatic char *msg = \"an integer is required\";\n\tPyObject *arr;\n\tPyArray_Descr *descr;\n\tintp ret;\n\n\tif (!o) {\n\t\tPyErr_SetString(PyExc_TypeError, msg);\n\t\treturn -1;\n\t}\n\n\tif (PyInt_Check(o)) {\n\t\tlong_value = (longlong) PyInt_AS_LONG(o);\n\t\tgoto finish;\n\t} else if (PyLong_Check(o)) {\n\t\tlong_value = (longlong) PyLong_AsLongLong(o);\n\t\tgoto finish;\n\t}\n\n#if SIZEOF_INTP == SIZEOF_LONG \n\tdescr = &LONG_Descr;\n#elif SIZEOF_INTP == SIZEOF_INT\n\tdescr = &INT_Descr;\n#else\n\tdescr = &LONGLONG_DESCR;\n#endif\n\tarr = NULL;\n\n\tif (PyArray_Check(o)) {\n\t\tif (PyArray_SIZE(o)!=1 || !PyArray_ISINTEGER(o)) {\n\t\t\tPyErr_SetString(PyExc_TypeError, msg);\n\t\t\treturn -1;\n\t\t}\n\t\tPy_INCREF(descr);\n\t\tarr = PyArray_CastToType((PyArrayObject *)o, descr, 0);\n\t}\n\telse if (PyArray_IsScalar(o, Integer)) {\n\t\tPy_INCREF(descr);\n\t\tarr = PyArray_FromScalar(o, descr);\n\t}\n\tif (arr != NULL) {\n\t\tret = *((intp *)PyArray_DATA(arr));\n\t\tPy_DECREF(arr);\n\t\treturn ret;\n\t}\t\t\n\tif (o->ob_type->tp_as_number != NULL &&\t\t\t\\\n\t o->ob_type->tp_as_number->nb_long != NULL) {\n\t\tobj = o->ob_type->tp_as_number->nb_long(o);\n\t\tif (obj != NULL) {\n\t\t\tlong_value = (longlong) PyLong_AsLongLong(obj);\n\t\t\tPy_DECREF(obj);\n\t\t}\n\t}\n\telse if (o->ob_type->tp_as_number != NULL &&\t\t\\\n\t\t o->ob_type->tp_as_number->nb_int != NULL) {\n\t\tobj = o->ob_type->tp_as_number->nb_int(o);\n\t\tif (obj != NULL) {\n\t\t\tlong_value = (longlong) PyLong_AsLongLong(obj);\n\t\t\tPy_DECREF(obj);\n\t\t}\n\t}\n\telse {\n\t\tPyErr_SetString(PyExc_NotImplementedError,\"\");\n\t}\n\t\n finish:\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_INTP)\n\tif ((long_value < MIN_INTP) || (long_value > MAX_INTP)) {\n\t\tPyErr_SetString(PyExc_ValueError,\n\t\t\t\t\"integer won't fit into a C intp\");\n\t\treturn -1;\n\t}\n#endif\n\treturn (intp) long_value;\n}\n\n\nstatic PyObject *array_int(PyArrayObject *v);\n\n/*OBJECT_API*/\nstatic int\nPyArray_PyIntAsInt(PyObject *o)\n{\n\tlong long_value = -1;\n\tPyObject *obj;\n\tstatic char *msg = \"an integer is required\";\n\tPyObject *arr;\n\tPyArray_Descr *descr;\n\tint ret;\n\n\t\n\tif (!o) {\n\t\tPyErr_SetString(PyExc_TypeError, msg);\n\t\treturn -1;\n\t}\n\n\tif (PyInt_Check(o)) {\n\t\tlong_value = (long) PyInt_AS_LONG(o);\n\t\tgoto finish;\n\t} else if (PyLong_Check(o)) {\n\t\tlong_value = (long) PyLong_AsLong(o);\n\t\tgoto finish;\n\t}\n\n\tdescr = &INT_Descr;\n\tarr=NULL;\n\tif (PyArray_Check(o)) {\n\t\tif (PyArray_SIZE(o)!=1 || !PyArray_ISINTEGER(o)) {\n\t\t\tPyErr_SetString(PyExc_TypeError, msg);\n\t\t\treturn -1;\n\t\t}\n\t\tPy_INCREF(descr);\n\t\tarr = PyArray_CastToType((PyArrayObject *)o, descr, 0);\n\t}\n\tif (PyArray_IsScalar(o, Integer)) {\n\t\tPy_INCREF(descr);\n\t\tarr = PyArray_FromScalar(o, descr);\n\t}\n\tif (arr != NULL) {\n\t\tret = *((int *)PyArray_DATA(arr));\n\t\tPy_DECREF(arr);\n\t\treturn ret;\n\t}\t\t\n\tif (o->ob_type->tp_as_number != NULL &&\t\t\\\n\t o->ob_type->tp_as_number->nb_int != NULL) {\n\t\tobj = o->ob_type->tp_as_number->nb_int(o);\n\t\tif (obj == NULL) return -1;\n\t\tlong_value = (long) PyLong_AsLong(obj);\n\t\tPy_DECREF(obj);\n\t}\n\telse if (o->ob_type->tp_as_number != NULL &&\t\t\t\\\n\t\t o->ob_type->tp_as_number->nb_long != NULL) {\n\t\tobj = o->ob_type->tp_as_number->nb_long(o);\n\t\tif (obj == NULL) return -1;\n\t\tlong_value = (long) PyLong_AsLong(obj);\n\t\tPy_DECREF(obj);\n\t}\t\t\n\telse {\n\t\tPyErr_SetString(PyExc_NotImplementedError,\"\");\n\t}\n\n finish:\n\tif error_converting(long_value) {\n\t\tPyErr_SetString(PyExc_TypeError, msg);\n\t\treturn -1;\n\t}\n\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\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 dest->descr, 0,\n dest->nd, FORTRAN_IF(dest), NULL);\n if (src == NULL) return -1;\n\n ret = PyArray_CopyInto(dest, src);\n Py_DECREF(src);\n return ret;\n}\n\n\n/* These are also old calls (should use PyArray_New) */\n\n/* They all zero-out the memory as previously done */\n\n/* steals reference to descr -- and enforces native byteorder on it.*/\n/*OBJECT_API\n Like FromDimsAndData but uses the Descr structure instead of typecode\n as input.\n*/\nstatic PyObject *\nPyArray_FromDimsAndDataAndDescr(int nd, int *d, \n PyArray_Descr *descr,\n char *data)\n{\n\tPyObject *ret;\n#if SIZEOF_INTP != SIZEOF_INT\n\tint i;\n\tintp newd[MAX_DIMS];\n#endif\n\n\tif (!PyArray_ISNBO(descr->byteorder))\n\t\tdescr->byteorder = '=';\n\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\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_BOOL)\n\t\tPyArrayScalar_RETURN_BOOL_FROM_LONG(*(Bool*)data);\n\telse if (type_num == PyArray_OBJECT) {\n\t\tPy_INCREF(*((PyObject **)data));\n\t\treturn *((PyObject **)data);\n\t}\n\titemsize = descr->elsize;\n type = descr->typeobj;\n copyswap = descr->f->copyswap;\n\tswap = !PyArray_ISNBO(descr->byteorder);\n\tif (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 >> 2;\n#ifndef Py_UNICODE_WIDE\n\t\t\tchar *buffer;\n\t\t\tint alloc=1;\n\t\t\tlength *= 2;\n#endif\n\t\t\t/* Need an extra slot and need to use \n\t\t\t Python memory manager */\n\t\t\tuni->str = NULL;\n\t\t\tdestptr = PyMem_NEW(Py_UNICODE, length+1);\n\t\t\tif (destptr == NULL) {\n Py_DECREF(obj);\n\t\t\t\treturn PyErr_NoMemory();\n\t\t\t}\n\t\t\tuni->str = (Py_UNICODE *)destptr;\n\t\t\tuni->str[0] = 0;\n\t\t\tuni->str[length] = 0;\n\t\t\tuni->length = length;\n\t\t\tuni->hash = -1;\n\t\t\tuni->defenc = NULL;\n#ifndef Py_UNICODE_WIDE\n\t\t\t/* need aligned data buffer */\n\t\t\tif (!PyArray_ISBEHAVED(base)) {\n\t\t\t\tbuffer = _pya_malloc(itemsize);\n\t\t\t\tif (buffer == NULL)\n\t\t\t\t\treturn PyErr_NoMemory();\n\t\t\t\talloc = 1;\n\t\t\t\tmemcpy(buffer, data, itemsize);\n\t\t\t\tif (!PyArray_ISNOTSWAPPED(base)) {\n\t\t\t\t\tbyte_swap_vector(buffer, itemsize >> 2, 4);\n\t\t\t\t}\n\t\t\t}\n\t\t\telse buffer = data;\n\n /* Allocated enough for 2-characters per itemsize.\n\t\t\t Now convert from the data-buffer\n */\n\t\t\tlength = PyUCS2Buffer_FromUCS4(uni->str, (PyArray_UCS4 *)buffer,\n\t\t\t\t\t\t itemsize >> 2);\n\t\t\tif (alloc) _pya_free(buffer);\n\t\t\t/* Resize the unicode result */\n\t\t\tif (MyPyUnicode_Resize(uni, length) < 0) {\n\t\t\t\tPy_DECREF(obj);\n\t\t\t\treturn NULL;\n\t\t\t}\n\t\t\treturn obj;\n#endif\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_XDECREF(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, 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, NULL);\n\tif (arr == NULL) return -1;\n\n\tif ((mit->subspace != NULL) && (mit->consec)) {\n\t\tif (mit->iteraxes[0] > 0) { /* then we need to swap */\n\t\t\t_swap_axes(mit, (PyArrayObject **)&arr);\n\t\t}\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\n/* This checks the args for any fancy indexing objects */\n\n#define SOBJ_NOTFANCY 0 \n#define SOBJ_ISFANCY 1\n#define SOBJ_BADARRAY 2\n#define SOBJ_TOOMANY 3\n#define SOBJ_LISTTUP 4\n\nstatic int\nfancy_indexing_check(PyObject *args)\n{\n\tint i, n;\n\tPyObject *obj;\n\tint retval = SOBJ_NOTFANCY;\n\n\tif (PyTuple_Check(args)) {\n\t\tn = PyTuple_GET_SIZE(args);\n\t\tif (n >= MAX_DIMS) return SOBJ_TOOMANY;\n\t\tfor (i=0; i=MAX_DIMS) return SOBJ_ISFANCY;\n\t\tfor (i=0; i SOBJ_ISFANCY) return retval;\n\t\t}\n\t}\n\n\treturn retval;\n}\n\n/* Called when treating array object like a mapping -- called first from \n Python when using a[object] unless object is a standard slice object\n (not an extended one). \n\n*/\n\n/* There are two situations: \n\n 1 - the subscript is a standard view and a reference to the \n array can be returned\n\n 2 - the subscript uses Boolean masks or integer indexing and\n therefore a new array is created and returned. \n\n*/\n\n/* Always returns arrays */\n\nstatic PyObject *iter_subscript(PyArrayIterObject *, PyObject *); \n\n\nstatic PyObject *\narray_subscript(PyArrayObject *self, PyObject *op) \n{\n intp dimensions[MAX_DIMS], strides[MAX_DIMS];\n\tintp offset;\n int nd, oned, fancy;\n\tintp i;\n PyArrayObject *other;\n\tPyArrayMapIterObject *mit;\n\n\tif (PyString_Check(op) || PyUnicode_Check(op)) {\n\t\tif (self->descr->fields) {\n\t\t\tPyObject *obj;\n\t\t\tobj = PyDict_GetItem(self->descr->fields, op);\n\t\t\tif (obj != NULL) {\n\t\t\t\tPyArray_Descr *descr;\n\t\t\t\tint offset;\n\t\t\t\tPyObject *title;\n\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\tfancy = fancy_indexing_check(op);\n\n\tif (fancy != SOBJ_NOTFANCY) { \n\t\toned = ((self->nd == 1) && !(PyTuple_Check(op) &&\t\\\n\t\t\t\t\t PyTuple_GET_SIZE(op) > 1));\n\n\t\t/* wrap arguments into a mapiter object */\n\t\tmit = (PyArrayMapIterObject *)\\\n\t\t\tPyArray_MapIterNew(op, oned, fancy);\n\t\tif (mit == NULL) return NULL;\n\t\tif (oned) {\n\t\t\tPyArrayIterObject *it;\n\t\t\tPyObject *rval;\n\t\t\tit = (PyArrayIterObject *)PyArray_IterNew((PyObject *)self);\n\t\t\tif (it == NULL) {Py_DECREF(mit); return NULL;}\n\t\t\trval = iter_subscript(it, mit->indexobj);\n\t\t\tPy_DECREF(it);\n\t\t\tPy_DECREF(mit);\n\t\t\treturn rval;\n\t\t}\n PyArray_MapIterBind(mit, self);\n other = (PyArrayObject *)PyArray_GetMap(mit);\n Py_DECREF(mit);\n return (PyObject *)other;\n }\n\n\ti = PyArray_PyIntAsIntp(op);\n\tif (!error_converting(i)) {\n\t\tif (i < 0 && self->nd > 0) i = i+self->dimensions[0];\n\t\treturn array_big_item(self, i);\n\t}\n\tPyErr_Clear();\n\n\t/* Standard (view-based) Indexing */\n if ((nd = parse_index(self, op, dimensions, strides, &offset)) \n == -1) \n return NULL;\n\n\t/* This will only work if new array will be a view */\n\tPy_INCREF(self->descr);\n\tif ((other = (PyArrayObject *)\t\t\t\t\t\\\n\t PyArray_NewFromDescr(self->ob_type, self->descr,\n\t\t\t\t nd, dimensions,\n\t\t\t\t strides, self->data+offset, \n\t\t\t\t self->flags,\n\t\t\t\t (PyObject *)self)) == NULL) \n\t\treturn NULL;\n\n\n\tother->base = (PyObject *)self;\n\tPy_INCREF(self);\n\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, fancy;\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\tfancy = fancy_indexing_check(index);\n\n\tif (fancy != SOBJ_NOTFANCY) { \n\t\toned = ((self->nd == 1) && !(PyTuple_Check(index) && \\\n\t\t\t\t\t PyTuple_GET_SIZE(index) > 1));\n\n\t\tmit = (PyArrayMapIterObject *)\t\t\t\\\n\t\t\tPyArray_MapIterNew(index, oned, fancy);\n\t\tif (mit == NULL) return -1;\n\t\tif (oned) {\n\t\t\tPyArrayIterObject *it;\n\t\t\tint rval;\n\t\t\tit = (PyArrayIterObject *)PyArray_IterNew((PyObject *)self);\n\t\t\tif (it == NULL) {Py_DECREF(mit); return -1;}\n\t\t\trval = iter_ass_subscript(it, mit->indexobj, op);\n\t\t\tPy_DECREF(it);\n\t\t\tPy_DECREF(mit);\n\t\t\treturn rval;\n\t\t}\n PyArray_MapIterBind(mit, self);\n ret = PyArray_SetMap(mit, op);\n Py_DECREF(mit);\n return ret;\n }\n\t\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\t\t\tif (other == Py_None) {\n\t\t\t\tPy_INCREF(Py_False);\n\t\t\t\treturn Py_False;\n\t\t\t}\n /* Try to convert other to an array */\n\t\t\tif (!PyArray_Check(other)) {\n\t\t\t\tarray_other = PyArray_FromObject(other, \n\t\t\t\t\t\t\t\t self->descr->type_num, 0, 0);\n\t\t\t\t/* If not successful, then return the integer\n\t\t\t\t object 0. This fixes code that used to\n\t\t\t\t allow equality comparisons between arrays\n\t\t\t\t and other objects which would give a result\n\t\t\t\t of 0\n\t\t\t\t*/\n\t\t\t\tif ((array_other == NULL) ||\t\\\n\t\t\t\t (array_other == Py_None)) {\n\t\t\t\t\tPy_XDECREF(array_other);\n\t\t\t\t\tPyErr_Clear();\n\t\t\t\t\tPy_INCREF(Py_False);\n\t\t\t\t\treturn Py_False;\n\t\t\t\t}\n\t\t\t}\n\t\t\telse {\n\t\t\t\tPy_INCREF(other);\n\t\t\t\tarray_other = other;\n\t\t\t}\n result = PyArray_GenericBinaryFunction(self, \n\t\t\t\t\t\t\t array_other, \n\t\t\t\t\t\t\t n_ops.equal);\n /* If the comparison results in NULL, then the \n\t\t\t two array objects can not be compared together so \n\t\t\t return zero \n */\n Py_DECREF(array_other);\n if (result == NULL) {\n PyErr_Clear();\n Py_INCREF(Py_False);\n return Py_False;\n }\n return result;\n case Py_NE:\n\t\t\tif (other == Py_None) {\n\t\t\t\tPy_INCREF(Py_True);\n\t\t\t\treturn Py_True;\n\t\t\t}\n /* Try to convert other to an array */\n\t\t\tif (!PyArray_Check(other)) {\n\t\t\t\tarray_other = PyArray_FromObject(other, \n\t\t\t\t\t\t\t\t self->descr->type_num, 0, 0);\n\t\t\t\t/* If not successful, then objects cannot be \n\t\t\t\t compared and cannot be equal, therefore, \n\t\t\t\t return True;\n\t\t\t\t*/\n\t\t\t\tif ((array_other == NULL) ||\t\\\n\t\t\t\t (array_other == Py_None)) {\n\t\t\t\t\tPy_XDECREF(array_other);\n\t\t\t\t\tPyErr_Clear();\n\t\t\t\t\tPy_INCREF(Py_True);\n\t\t\t\t\treturn Py_True;\n\t\t\t\t}\n\t\t\t}\n\t\t\telse {\n\t\t\t\tPy_INCREF(other);\n\t\t\t\tarray_other = other;\n\t\t\t}\n\t\t\tresult = PyArray_GenericBinaryFunction(self, \n\t\t\t\t\t\t\t array_other, \n\t\t\t\t\t\t\t n_ops.not_equal);\n\t\t\tPy_DECREF(array_other);\n if (result == NULL) {\n PyErr_Clear();\n Py_INCREF(Py_True);\n return Py_True;\n }\n 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 = PyArray_NDIM(temp)-1;\n\t\treturn temp;\n\t}\n\telse {\n\t\tif (flags) {\n\t\t\ttemp = PyArray_CheckFromAny((PyObject *)arr, NULL, \n 0, 0, flags, NULL);\n\t\t\tif (temp == NULL) return NULL;\n\t\t}\n\t\telse {\n\t\t\tPy_INCREF(arr);\n\t\t\ttemp = (PyObject *)arr;\n\t\t}\n\t}\n\tif (*axis < 0) *axis += n;\n\tif ((*axis < 0) || (*axis >= n)) {\n\t\tPyErr_Format(PyExc_ValueError, \n\t\t\t \"axis(=%d) out of bounds\", *axis);\n\t\tPy_DECREF(temp);\n\t\treturn NULL;\n\t}\n\treturn temp;\n}\n\n#include \"arraymethods.c\"\n\n/* Lifted from numarray */\nstatic PyObject *\nPyArray_IntTupleFromIntp(int len, intp *vals)\n{\n\tint i;\n PyObject *intTuple = PyTuple_New(len);\n if (!intTuple) goto fail;\n for(i=0; i= SIZEOF_INTP\n\t\tif (!(op = PyNumber_Int(seq))) return -1;\n#else\n\t\tif (!(op = PyNumber_Long(seq))) return -1;\n#endif\n\t\tnd = 1;\n#if SIZEOF_LONG >= SIZEOF_INTP\n\t\tvals[0] = (intp ) PyInt_AsLong(op);\n#else\n\t\tvals[0] = (intp ) PyLong_AsLongLong(op);\n#endif\n\t\tPy_DECREF(op);\n\t} else {\n\t\tfor(i=0; i < MIN(nd,maxvals); i++) {\n\t\t\top = PySequence_GetItem(seq, i);\n\t\t\tif (op == NULL) return -1;\n#if SIZEOF_LONG >= SIZEOF_INTP\n\t\t\tvals[i]=(intp )PyInt_AsLong(op);\n#else\n\t\t\tvals[i]=(intp )PyLong_AsLongLong(op);\n#endif\n\t\t\tPy_DECREF(op);\n\t\t\tif(PyErr_Occurred()) return -1;\n\t\t}\n\t}\n\treturn nd;\n}\n\n\n/* Check whether the given array is stored contiguously (row-wise) in\n memory. */\nstatic int\n_IsContiguous(PyArrayObject *ap) \n{\n\tregister intp sd;\n\tregister intp dim;\n\tregister int i;\n \n\n\tif (ap->nd == 0) return 1;\n\tsd = ap->descr->elsize;\n\tif (ap->nd == 1) return (ap->dimensions[0] == 1 || \\\n\t\t\t\t sd == ap->strides[0]);\n\tfor (i = ap->nd-1; i >= 0; --i) {\n\t\tdim = ap->dimensions[i];\n\t\t/* contiguous by definition */\n\t\tif (dim == 0) return 1;\n\t\tif (ap->strides[i] != sd) return 0;\n\t\tsd *= dim;\n\t}\n\treturn 1;\n}\n\n\nstatic int \n_IsFortranContiguous(PyArrayObject *ap) \n{\n\tregister intp sd;\n\tregister intp dim;\n\tregister int i;\n\t\n\tif (ap->nd == 0) return 1;\n\tsd = ap->descr->elsize;\n\tif (ap->nd == 1) return (ap->dimensions[0] == 1 || \\\n\t\t\t\t sd == ap->strides[0]);\n\tfor (i=0; i< ap->nd; ++i) {\n\t\tdim = ap->dimensions[i];\n\t\t/* contiguous by definition */\n\t\tif (dim == 0) return 1; \n\t\tif (ap->strides[i] != sd) return 0;\n\t\tsd *= dim;\n\t}\n\treturn 1;\n}\n\nstatic int\n_IsAligned(PyArrayObject *ap) \n{\n\tint i, alignment, aligned=1;\n\tintp ptr;\n\tint type = ap->descr->type_num;\n\n\tif ((type == PyArray_STRING) || (type == PyArray_VOID))\n\t\treturn 1;\n\n\talignment = ap->descr->alignment;\n\tif (alignment == 1) return 1;\n\n\tptr = (intp) ap->data;\n aligned = (ptr % alignment) == 0;\n for (i=0; i nd; i++)\n aligned &= ((ap->strides[i] % alignment) == 0);\n return aligned != 0;\n}\n\nstatic Bool\n_IsWriteable(PyArrayObject *ap)\n{\n\tPyObject *base=ap->base;\n\tvoid *dummy;\n\tint n;\n\n\t/* If we own our own data, then no-problem */\n\tif ((base == NULL) || (ap->flags & OWN_DATA)) return TRUE;\n\n\t/* Get to the final base object \n\t If it is a writeable array, then return TRUE\n\t If we can find an array object \n\t or a writeable buffer object as the final base object\n\t or a string object (for pickling support memory savings).\n\t - this last could be removed if a proper pickleable \n\t buffer was added to Python.\n\t*/\n\n\twhile(PyArray_Check(base)) {\n\t\tif (PyArray_CHKFLAGS(base, OWN_DATA)) \n\t\t\treturn (Bool) (PyArray_ISWRITEABLE(base));\n\t\tbase = PyArray_BASE(base);\n\t}\n\n\t/* here so pickle support works seamlessly \n\t and unpickled array can be set and reset writeable \n\t -- could be abused -- */\n\tif PyString_Check(base) return TRUE;\n\n\tif (PyObject_AsWriteBuffer(base, &dummy, &n) < 0)\n\t\treturn FALSE;\n\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 For axes with a positive stride this function checks for a walk\n beyond the right end of the buffer, for axes with a negative stride,\n it checks for a walk beyond the left end of the buffer. Zero strides\n are disallowed.\n*/\n/*OBJECT_API*/\nstatic Bool\nPyArray_CheckStrides(int elsize, int nd, intp numbytes, intp offset,\n\t\t intp *dims, intp *newstrides)\n{\n\tint i;\n\t\n\tif (numbytes == 0) \n\t\tnumbytes = PyArray_MultiplyList(dims, nd) * elsize;\n\t\n\tfor (i=0; i 0) {\n\t\t\t/* The last stride does not need to be fully inside\n\t\t\t the buffer, only its first elsize bytes */\n\t\t\tif (offset + stride*(dims[i]-1)+elsize > numbytes) {\n\t\t\t\treturn FALSE;\n\t\t\t}\n\t\t}\n\t\telse if (stride < 0) {\n\t\t\tif (offset + stride*dims[i] < 0) {\n\t\t\t\treturn FALSE;\n\t\t\t}\n\t\t} else {\n\t\t\t/* XXX: Zero strides may be useful, but currently \n\t\t\t XXX: allowing them would lead to strange results,\n\t\t\t XXX: for example :\n\t\t\t XXX: >>> x = arange(5)\n\t\t\t XXX: >>> x.strides = 0\n\t\t\t XXX: >>> x += 1\n\t\t\t XXX: >>> x\n\t\t\t XXX: array([5, 5, 5, 5, 5]) */\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 /* which could also be sub-fields of a VOID array */\n\t\tif (descr->hasobject) {\n if (descr != &OBJECT_Descr) {\n PyErr_SetString(PyExc_TypeError,\n \"fields with object members \" \\\n \"not yet supported.\");\n goto fail;\n }\n\t\t\tmemset(data, 0, sd);\n\t\t}\n\t}\n\telse {\n self->flags &= ~OWN_DATA; /* If data is passed in, \n\t\t\t\t\t this object won't own it \n\t\t\t\t\t by default.\n\t\t\t\t\t Caller must arrange for \n\t\t\t\t\t this to be reset if truly\n\t\t\t\t\t desired */\n }\n self->data = data;\n\n /* call the __array_finalize__\n\t method if a subtype 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, NULL);\n\tif (newarr == NULL) return -1;\n\tfromptr = PyArray_DATA(newarr);\n\tsize=PyArray_SIZE(arr);\n\tswap=!PyArray_ISNOTSWAPPED(arr);\n\tcopyswap = arr->descr->f->copyswap;\n\tif (PyArray_ISONESEGMENT(arr)) {\n\t\tchar *toptr=PyArray_DATA(arr);\n\t\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\", /* XXX ? */\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 strides.ptr, NULL, fortran, NULL);\n if (ret == NULL) {descr=NULL;goto fail;}\n if (type_num == PyArray_OBJECT) { /* place Py_None */\n PyArray_FillObjectArray(ret, Py_None);\n }\n }\n else { /* buffer given -- use it */\n if (dims.len == 1 && dims.ptr[0] == -1) {\n dims.ptr[offset] = 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, offset,\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 offset + (char *)buffer.ptr, \n\t\t\t\t\t buffer.flags, NULL); \n if (ret == NULL) {descr=NULL; goto fail;}\n PyArray_UpdateFlags(ret, UPDATE_ALL_FLAGS);\n ret->base = buffer.base;\n Py_INCREF(buffer.base); \n }\n\n PyDimMem_FREE(dims.ptr);\n if (strides.ptr) PyDimMem_FREE(strides.ptr);\n return (PyObject *)ret;\n \n fail:\n\tPy_XDECREF(descr);\n if (dims.ptr) PyDimMem_FREE(dims.ptr);\n if (strides.ptr) PyDimMem_FREE(strides.ptr);\n return NULL;\n}\n\n\nstatic PyObject *\narray_iter(PyArrayObject *arr)\n{\n\tif (arr->nd == 0) {\n\t\tPyErr_SetString(PyExc_TypeError,\n\t\t\t\t\"iteration over a scalar (0-dim array)\");\n\t\treturn NULL;\n\t}\n\treturn PySeqIter_New((PyObject *)arr);\n}\n\n\n/******************* array attribute get and set routines ******************/\n\nstatic PyObject *\narray_ndim_get(PyArrayObject *self)\n{\n\treturn PyInt_FromLong(self->nd);\n}\n\nstatic PyObject *\narray_flags_get(PyArrayObject *self)\n{\n return 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->data - new->data,\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 *arraydescr_protocol_typestr_get(PyArray_Descr *);\n\nstatic PyObject *\narray_typestr_get(PyArrayObject *self)\n{\n\treturn arraydescr_protocol_typestr_get(self->descr);\n}\n\nstatic PyObject *\narray_descr_get(PyArrayObject *self) \n{\n\tPy_INCREF(self->descr);\n\treturn (PyObject *)self->descr;\n}\n\n\n/* If the type is changed. \n Also needing change: strides, itemsize\n\n Either itemsize is exactly the same\n or the array is single-segment (contiguous or fortran) with\n compatibile dimensions\n\n The shape and strides will be adjusted in that case as well.\n*/\n\nstatic int\narray_descr_set(PyArrayObject *self, PyObject *arg)\n{\n PyArray_Descr *newtype=NULL;\n intp newdim;\n int index;\n char *msg = \"new type not compatible with array.\";\n\n if (!(PyArray_DescrConverter(arg, &newtype)) ||\n newtype == NULL) {\n PyErr_SetString(PyExc_TypeError, \"invalid data-type for array\");\n\t\treturn -1;\n }\n\tif (newtype->type_num == PyArray_OBJECT || \\\n\t self->descr->type_num == PyArray_OBJECT) {\n\t\tPyErr_SetString(PyExc_TypeError, \\\n\t\t\t\t\"Cannot change descriptor for object\"\\\n\t\t\t\t\"array.\");\n\t\tPy_DECREF(newtype);\n\t\treturn -1;\n\t}\n\n\tif ((newtype->elsize != self->descr->elsize) &&\t\t\\\n\t (self->nd == 0 || !PyArray_ISONESEGMENT(self) || \\\n\t newtype->subarray)) goto fail;\n\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\t/* We would decref newtype here --- temp will \n\t\t steal a reference to it */\n\t\ttemp = (PyArrayObject *)\t\t\t\t\\\n\t\t\tPyArray_NewFromDescr(&PyArray_Type, newtype, self->nd,\n\t\t\t\t\t self->dimensions, self->strides,\n\t\t\t\t\t self->data, self->flags, NULL);\n\t\tPyDimMem_FREE(self->dimensions);\n\t\tself->dimensions = temp->dimensions;\n\t\tself->nd = temp->nd;\n\t\tself->strides = temp->strides;\n\t\tnewtype = temp->descr;\n\t\t/* Fool deallocator not to delete these*/\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, \"descr\");\n\tif (res) return res;\n\tPyErr_Clear();\n\n\t/* get default */\n\tdobj = PyTuple_New(2);\n\tif (dobj == NULL) return NULL;\n\tPyTuple_SET_ITEM(dobj, 0, PyString_FromString(\"\"));\n\tPyTuple_SET_ITEM(dobj, 1, array_typestr_get(self));\n\tres = PyList_New(1);\n\tif (res == NULL) {Py_DECREF(dobj); return NULL;}\n\tPyList_SET_ITEM(res, 0, dobj);\n\treturn res;\n}\n\nstatic PyObject *\narray_struct_get(PyArrayObject *self)\n{\n PyArrayInterface *inter;\n \n inter = (PyArrayInterface *)_pya_malloc(sizeof(PyArrayInterface));\n inter->version = 2;\n inter->nd = self->nd;\n inter->typekind = self->descr->kind;\n inter->itemsize = self->descr->elsize;\n inter->flags = self->flags;\n /* reset unused flags */\n\tinter->flags &= ~(UPDATEIFCOPY | OWNDATA); \n\tif (PyArray_ISNOTSWAPPED(self)) inter->flags |= NOTSWAPPED;\n inter->strides = self->strides;\n inter->shape = self->dimensions;\n inter->data = self->data;\n\tPy_INCREF(self);\n return PyCObject_FromVoidPtrAndDesc(inter, self, gentype_struct_free);\n}\n\nstatic PyObject *\narray_base_get(PyArrayObject *self)\n{\n\tif (self->base == NULL) {\n\t\tPy_INCREF(Py_None);\n\t\treturn Py_None;\n\t}\n\telse {\n\t\tPy_INCREF(self->base);\n\t\treturn self->base;\n\t}\n}\n\n\nstatic PyObject *\narray_real_get(PyArrayObject *self)\n{\n\tPyArrayObject *ret;\n\n\tif (PyArray_ISCOMPLEX(self)) {\n\t\tret = (PyArrayObject *)PyArray_New(self->ob_type,\n\t\t\t\t\t\t self->nd,\n\t\t\t\t\t\t self->dimensions,\n\t\t\t\t\t\t self->descr->type_num - \\\n\t\t\t\t\t\t PyArray_NUM_FLOATTYPE,\n\t\t\t\t\t\t self->strides,\n\t\t\t\t\t\t self->data,\n\t\t\t\t\t\t 0,\n\t\t\t\t\t\t self->flags, (PyObject *)self);\n\t\tif (ret == NULL) return NULL;\n\t\tret->flags &= ~CONTIGUOUS;\n\t\tret->flags &= ~FORTRAN;\n\t\tPy_INCREF(self);\n\t\tret->base = (PyObject *)self;\n\t\treturn (PyObject *)ret;\n\t}\n\telse {\n\t\tPy_INCREF(self);\n\t\treturn (PyObject *)self;\n\t}\n}\n\n\nstatic int\narray_real_set(PyArrayObject *self, PyObject *val)\n{\n\tPyArrayObject *ret;\n\tPyArrayObject *new;\n\tint rint;\n\n\tnew = (PyArrayObject *)PyArray_FromAny(val, NULL, 0, 0, 0, NULL);\n\tif (new == NULL) return -1;\n\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, NULL); \n\t\tif (new == NULL) return -1;\n\t\tret = (PyArrayObject *)PyArray_New(self->ob_type,\n\t\t\t\t\t\t self->nd,\n\t\t\t\t\t\t self->dimensions,\n\t\t\t\t\t\t self->descr->type_num - \\\n\t\t\t\t\t\t PyArray_NUM_FLOATTYPE,\n\t\t\t\t\t\t self->strides,\n \t\t\t\t\t\t self->data +\t\t\\\n\t\t\t\t\t\t (self->descr->elsize >> 1),\n\t\t\t\t\t\t 0,\n\t\t\t\t\t\t self->flags, (PyObject *)self);\n\t\tif (ret == NULL) {\n\t\t\tPy_DECREF(new); \n\t\t\treturn -1;\n\t\t}\n\t\tret->flags &= ~CONTIGUOUS;\n\t\tret->flags &= ~FORTRAN;\n\t\tPy_INCREF(self);\n\t\tret->base = (PyObject *)self;\n\t\trint = PyArray_CopyInto(ret, new);\n\t\tPy_DECREF(ret);\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), NULL);\n\tif (arr == NULL) return -1;\n\tarrit = (PyArrayIterObject *)PyArray_IterNew(arr);\n\tif (arrit == NULL) goto exit;\n\tselfit = (PyArrayIterObject *)PyArray_IterNew((PyObject *)self);\n\tif (selfit == NULL) goto exit;\n\n swap = PyArray_ISNOTSWAPPED(self) != PyArray_ISNOTSWAPPED(arr);\n copyswap = self->descr->f->copyswap;\n if (PyArray_ISOBJECT(self)) {\n while(selfit->index < selfit->size) {\n Py_XDECREF(*((PyObject **)selfit->dataptr));\n Py_INCREF(*((PyObject **)arrit->dataptr)); \n memmove(selfit->dataptr, arrit->dataptr, \n sizeof(PyObject *));\n PyArray_ITER_NEXT(selfit);\n PyArray_ITER_NEXT(arrit);\n if (arrit->index == arrit->size) \n PyArray_ITER_RESET(arrit);\n }\n retval = 0; \n goto exit;\n }\n\n\twhile(selfit->index < selfit->size) {\n\t\tmemmove(selfit->dataptr, arrit->dataptr, self->descr->elsize);\n copyswap(selfit->dataptr, NULL, swap, self->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\t{\"dtype\",\n\t (getter)array_descr_get,\n\t (setter)array_descr_set,\n\t \"get(set) data-type-descriptor for array\"},\n {\"real\", \n\t (getter)array_real_get, \n\t (setter)array_real_set, \n\t \"real part of array\"},\n {\"imag\", \n\t (getter)array_imag_get, \n\t (setter)array_imag_set, \n\t \"imaginary part of array\"},\n\t{\"flat\", \n\t (getter)array_flat_get, \n\t (setter)array_flat_set, \n\t \"a 1-d view of a contiguous array\"}, \n\t{\"__array_data__\", \n\t (getter)array_dataptr_get,\n\t NULL,\n\t \"Array protocol: data\"},\n\t{\"__array_typestr__\",\n\t (getter)array_typestr_get,\n\t NULL,\n\t \"Array protocol: typestr\"},\n\t{\"__array_descr__\",\n\t (getter)array_protocol_descr_get,\n\t NULL,\n\t \"Array protocol: descr\"},\n\t{\"__array_shape__\", \n\t (getter)array_shape_get,\n\t NULL,\n\t \"Array protocol: shape\"},\n\t{\"__array_strides__\",\n\t (getter)array_protocol_strides_get,\n\t NULL,\n\t \"Array protocol: strides\"},\n {\"__array_struct__\",\n (getter)array_struct_get,\n NULL,\n \"Array protocol: struct\"},\n\t{\"__array_priority__\",\n\t (getter)array_priority_get,\n\t NULL,\n\t \"Array priority\"},\n \t{NULL, NULL, NULL, NULL}, /* Sentinel */\n};\n\n/****************** end of attribute get and set routines *******************/\n\n\nstatic PyObject *\narray_alloc(PyTypeObject *type, int nitems)\n{\n PyObject *obj;\n /* nitems will always be 0 */ \n obj = (PyObject *)_pya_malloc(sizeof(PyArrayObject));\n PyObject_Init(obj, type);\n return obj;\n}\n\n\nstatic char Arraytype__doc__[] = \n \"A array object represents a multidimensional, homogeneous array\\n\"\n\t\" of fixed-size items. An associated data-type-descriptor object\\n\"\n\t\" details the data-type in an array (including byteorder and any\\n\"\n\t\" fields). An array can be constructed using the numpy.array\\n\"\n\t\" command. Arrays are sequence, mapping and numeric objects.\\n\"\n\t\" More information is available in the numpy module and by looking\\n\"\n\t\" at the methods and attributes of an array.\\n\\n\"\n\t\" ndarray.__new__(subtype, shape=, dtype=int_, buffer=None, \\n\"\n\t\" offset=0, strides=None, fortran=False)\\n\\n\"\n\t\" There are two modes of creating an array using __new__:\\n\"\n\t\" 1) If buffer is None, then only shape, dtype, and fortran \\n\"\n\t\" are used\\n\"\n\t\" 2) If buffer is an object exporting the buffer interface, then\\n\"\n\t\" all keywords are interpreted.\\n\"\n\t\" The dtype parameter can be any object that can be interpreted \\n\"\n\t\" as a numpy.dtype object.\\n\\n\"\n\t\" No __init__ method is needed because the array is fully \\n\"\n\t\" initialized after the __new__ method.\";\n\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, 4*n);\n\t\telse\n\t\t\t*itemsize = MAX(*itemsize, n);\n\t\treturn 0;\n\t}\n\tfor (i=0; i n_lower) n_lower = d[1];\n }\n d[1] = n_lower;\n\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, 4*minsize);\n\t\t}\n\t\telse {\n\t\t\ttestsize = MAX(chksize, minsize);\n\t\t}\n\t\tif (testsize != outtype->elsize) {\n\t\t\tPyArray_DESCR_REPLACE(outtype);\n\t\t\touttype->elsize = testsize;\n\t\t\tPy_XDECREF(outtype->fields);\n\t\t\touttype->fields = NULL;\n\t\t}\n\t}\n\treturn outtype;\n}\n\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#ifndef Py_UNICODE_WIDE\n\t\tchktype->elsize <<= 1;\n#endif\t\t\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\t} else if (PyLong_Check(op)) {\n\t\t/* if integer can fit into a longlong then return that\n\t\t*/\n\t\tif ((PyLong_AsLongLong(op) == -1) && PyErr_Occurred()) {\n\t\t\tPyErr_Clear();\n\t\t\tgoto deflt;\n\t\t}\n\t\tchktype = PyArray_DescrFromType(PyArray_LONGLONG);\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 *= 4;\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\tif (ret->nd > 0) {\n\t\tPyErr_SetString(PyExc_ValueError,\n\t\t\t\t\"shape-mismatch on array construction\");\n\t\tPy_DECREF(ret);\n\t\treturn NULL;\n\t}\n\n ret->descr->f->setitem(op, ret->data, ret);\n\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 */\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\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\t\tgoto fail;\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\t\tgoto fail;\n }\n\t\n\tif(discover_dimensions(s,nd,d, !stop_at_string) == -1) goto fail;\n\n\tif (itemsize == 0 && PyTypeNum_ISEXTENDED(type)) {\n\t\tif (discover_itemsize(s, nd, &itemsize) == -1) goto fail;\n\t\tif (type == PyArray_UNICODE) itemsize*=4;\n\t}\n\n\tif (itemsize != typecode->elsize) {\n\t\tPyArray_DESCR_REPLACE(typecode);\n\t\ttypecode->elsize = itemsize;\n\t}\n\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) return NULL;\n if(Assign_Array(r,s) == -1) {\n\t\tPy_DECREF(r);\n\t\treturn NULL;\n\t}\n return (PyObject*)r;\n\n fail:\n\tPy_DECREF(typecode);\n\treturn NULL;\n}\n\n\n/*OBJECT_API\n Is the typenum valid?\n*/\nstatic int \nPyArray_ValidType(int type) \n{\n\tPyArray_Descr *descr;\n\tint res=TRUE;\n\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 << 2;\n\t\tif (mpd->type_num == PyArray_UNICODE &&\n\t\t at->type_num == PyArray_STRING) \n\t\t\tat->elsize = mpd->elsize >> 2;\n\t\tif (at->type_num == PyArray_VOID)\n\t\t\tat->elsize = mpd->elsize;\n\t}\n\n\tout = PyArray_NewFromDescr(mp->ob_type, at,\n\t\t\t\t mp->nd, \n\t\t\t\t mp->dimensions, \n\t\t\t\t NULL, NULL, \n\t\t\t\t fortran,\n\t\t\t\t (PyObject *)mp);\n\n\tif (out == NULL) return NULL;\n\tret = PyArray_CastTo((PyArrayObject *)out, mp);\n\tif (ret != -1) return out;\n\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 */\n/*OBJECT_API*/\nstatic PyObject *\nPyArray_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 break;\n\tcase PyArray_STRINGLTR:\n\t\ttype_num = PyArray_STRING;\n\t\tbreak;\n\tcase PyArray_UNICODELTR:\n\t\ttype_num = PyArray_UNICODE;\n\t\tsize <<= 2;\n\t\tbreak;\n\tcase 'V':\n\t\ttype_num = PyArray_VOID;\n\t\tbreak;\n\tdefault:\n\t\t_MY_FAIL\n\t}\n\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/* OBJECT_API */\nstatic PyObject *\nPyArray_FromStructInterface(PyObject *input)\n{\n\tPyArray_Descr *thetype;\n\tchar buf[40];\n\tPyArrayInterface *inter;\n\tPyObject *attr, *r;\n\tchar endian = PyArray_NATBYTE;\n \n attr = PyObject_GetAttrString(input, \"__array_struct__\");\n if (attr == NULL) {\n\t\tPyErr_Clear();\n\t\treturn Py_NotImplemented;\n\t}\n if (!PyCObject_Check(attr) || \\\n ((inter=((PyArrayInterface *)\\\n\t\t PyCObject_AsVoidPtr(attr)))->version != 2)) {\n PyErr_SetString(PyExc_ValueError, \"invalid __array_struct__\");\n\t\tPy_DECREF(attr);\n return NULL;\n }\n\tif ((inter->flags & NOTSWAPPED) != NOTSWAPPED) {\n\t\tendian = PyArray_OPPBYTE;\n\t\tinter->flags &= ~NOTSWAPPED;\n\t}\n\n snprintf(buf, 40, \"%c%c%d\", endian, inter->typekind, inter->itemsize);\n if (!(thetype=_array_typedescr_fromstr(buf))) {\n\t\tPy_DECREF(attr);\n return NULL;\n }\n\n r = PyArray_NewFromDescr(&PyArray_Type, thetype,\n\t\t\t\t inter->nd, inter->shape,\n\t\t\t\t inter->strides, inter->data,\n\t\t\t\t inter->flags, NULL);\n\tPy_INCREF(input);\n\tPyArray_BASE(r) = input;\n Py_DECREF(attr);\n PyArray_UpdateFlags((PyArrayObject *)r, UPDATE_ALL_FLAGS);\n return r;\n}\n\n/*OBJECT_API*/\nstatic PyObject *\nPyArray_FromInterface(PyObject *input)\n{\n\tPyObject *attr=NULL, *item=NULL;\n PyObject *tstr=NULL, *shape=NULL; \n PyArrayObject *ret;\n\tPyArray_Descr *type=NULL;\n\tchar *data;\n\tint buffer_len;\n\tint res, i, n;\n\tintp dims[MAX_DIMS], strides[MAX_DIMS];\n\tint dataflags = BEHAVED_FLAGS;\n\n\t/* Get the memory from __array_data__ and __array_offset__ */\n\t/* Get the shape */\n\t/* Get the typestring -- ignore array_descr */\n\t/* Get the strides */\n\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\treturn NULL;\n\t\t}\n\t\tif (n != PyTuple_GET_SIZE(attr)) {\n\t\t\tPyErr_SetString(PyExc_ValueError, \n\t\t\t\t\t\"mismatch in length of \"\\\n\t\t\t\t\t\"__array_strides__ and \"\\\n\t\t\t\t\t\"__array_shape__\");\n\t\t\tPy_DECREF(attr);\n\t\t\tPy_DECREF(ret);\n\t\t\treturn NULL;\n\t\t}\n\t\tfor (i=0; istrides, strides, n*sizeof(intp));\n\t}\n\telse PyErr_Clear();\n\tPyArray_UpdateFlags(ret, UPDATE_ALL_FLAGS);\n\treturn (PyObject *)ret;\n\n fail:\n\tPy_XDECREF(attr);\n\tPy_XDECREF(shape);\n\tPy_XDECREF(tstr);\n\treturn NULL;\n}\n\n/* OBJECT_API*/\nstatic PyObject *\nPyArray_FromArrayAttr(PyObject *op, PyArray_Descr *typecode, PyObject *context) \n{\n PyObject *new;\n PyObject *array_meth;\n\n array_meth = PyObject_GetAttrString(op, \"__array__\");\n if (array_meth == NULL) {PyErr_Clear(); return Py_NotImplemented;}\n if (context == NULL) {\n if (typecode == NULL) new = PyObject_CallFunction(array_meth, NULL);\n else new = PyObject_CallFunction(array_meth, \"O\", typecode);\n }\n else {\n if (typecode == NULL) {\n new = PyObject_CallFunction(array_meth, \"OO\", Py_None, context);\n if (new == NULL && PyErr_ExceptionMatches(PyExc_TypeError)) {\n PyErr_Clear();\n new = PyObject_CallFunction(array_meth, \"\");\n }\n }\n else {\n new = PyObject_CallFunction(array_meth, \"OO\", typecode, context);\n if (new == NULL && PyErr_ExceptionMatches(PyExc_TypeError)) {\n PyErr_Clear();\n new = PyObject_CallFunction(array_meth, \"O\", typecode);\n }\n }\n }\n Py_DECREF(array_meth);\n if (new == NULL) return NULL;\n if (!PyArray_Check(new)) {\n PyErr_SetString(PyExc_ValueError, \n \"object __array__ method not \" \\\n \"producing an array\");\n Py_DECREF(new);\n return NULL;\n }\n return new;\n} \n\n/* Does not check for ENSURECOPY and NOTSWAPPED in flags */\n/* Steals a reference to newtype --- which can be NULL */\n/*OBJECT_API*/\nstatic PyObject *\nPyArray_FromAny(PyObject *op, PyArray_Descr *newtype, int min_depth, \n int max_depth, int flags, PyObject *context) \n{\n /* This is the main code to make a NumPy array from a Python\n Object. It is called from lot's of different places which\n is why there are so many checks. The comments try to\n explain some of the checks. */\n\n PyObject *r=NULL;\n int seq = FALSE;\n \n\t/* Is input object already an array? */\n\t/* This is where the flags are used */\n if (PyArray_Check(op)) \n\t\tr = PyArray_FromArray((PyArrayObject *)op, newtype, flags);\n\telse if (PyArray_IsScalar(op, Generic)) {\n\t\tr = PyArray_FromScalar(op, newtype);\n\t}\n else if (((r = PyArray_FromStructInterface(op))!=Py_NotImplemented)|| \\\n ((r = PyArray_FromInterface(op)) != Py_NotImplemented) || \\\n ((r = PyArray_FromArrayAttr(op, newtype, context)) \\\n != Py_NotImplemented)) {\n PyObject *new;\n if (r == NULL) return NULL;\n if (newtype != NULL || flags != 0) {\n new = PyArray_FromArray((PyArrayObject *)r, newtype, flags);\n Py_DECREF(r);\n r = new;\n }\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\n\t\t\tPy_INCREF(newtype);\n\t\t\tr = Array_FromSequence(op, newtype, flags & FORTRAN,\n\t\t\t\t\t min_depth, max_depth);\n\t\t\tif (PyErr_Occurred() && r == NULL) {\n /* It wasn't really a sequence after all.\n * Try interpreting it as a scalar */\n\t\t\t\tPyErr_Clear();\n\t\t\t}\n else {\n\t\t\t\tseq = TRUE;\n\t\t\t\tPy_DECREF(newtype);\n\t\t\t}\n }\n if (!seq)\n\t\t\tr = Array_FromScalar(op, newtype);\n\t}\n\n /* If we didn't succeed return NULL */\n if (r == NULL) return NULL;\n\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: PyArray_FromAny \"\\\n\t\t\t\t\"not producing an array\");\n\t\tPy_DECREF(r);\n return NULL;\n }\n\n if (min_depth != 0 && ((PyArrayObject *)r)->nd < min_depth) {\n PyErr_SetString(PyExc_ValueError, \n \"object of too small depth for desired array\");\n Py_DECREF(r);\n return NULL;\n }\n if (max_depth != 0 && ((PyArrayObject *)r)->nd > max_depth) {\n PyErr_SetString(PyExc_ValueError, \n \"object too deep for desired array\");\n Py_DECREF(r);\n return NULL;\n }\n return r;\n}\n\n/* new reference -- accepts NULL for mintype*/\n/*OBJECT_API*/\nstatic PyArray_Descr *\nPyArray_DescrFromObject(PyObject *op, PyArray_Descr *mintype)\n{\n\treturn _array_find_type(op, mintype, MAX_DIMS);\n}\n\n/*OBJECT_API\n Return the typecode of the array a Python object would be converted\n to\n*/\nstatic int \nPyArray_ObjectType(PyObject *op, int minimum_type) \n{\n\tPyArray_Descr *intype;\n\tPyArray_Descr *outtype;\n\tint ret;\n\n\tintype = PyArray_DescrFromType(minimum_type);\n\tif (intype == NULL) PyErr_Clear();\n\touttype = _array_find_type(op, intype, MAX_DIMS);\n\tret = outtype->type_num;\n\tPy_DECREF(outtype);\n\tPy_DECREF(intype);\n\treturn ret;\n}\n\n\n/* flags is any of \n CONTIGUOUS, \n FORTRAN,\n ALIGNED, \n WRITEABLE, \n NOTSWAPPED,\n ENSURECOPY, \n UPDATEIFCOPY,\n FORCECAST,\n ENSUREARRAY\n\n or'd (|) together\n\n Any of these flags present means that the returned array should \n guarantee that aspect of the array. Otherwise the returned array\n won't guarantee it -- it will depend on the object as to whether or \n not it has such features. \n\n Note that ENSURECOPY is enough\n to guarantee CONTIGUOUS, ALIGNED and WRITEABLE\n and therefore it is redundant to include those as well. \n\n BEHAVED_FLAGS == ALIGNED | WRITEABLE\n CARRAY_FLAGS = CONTIGUOUS | BEHAVED_FLAGS\n FARRAY_FLAGS = FORTRAN | BEHAVED_FLAGS\n \n FORTRAN can be set in the FLAGS to request a FORTRAN array. \n Fortran arrays are always behaved (aligned, \n notswapped, and writeable) and not (C) CONTIGUOUS (if > 1d). \n\n UPDATEIFCOPY flag sets this flag in the returned array if a copy is\n made and the base argument points to the (possibly) misbehaved array.\n When the new array is deallocated, the original array held in base\n is updated with the contents of the new array. \n\n FORCECAST will cause a cast to occur regardless of whether or not\n it is safe. \n*/\n\n\n/* steals a reference to descr -- accepts NULL */\n/*OBJECT_API*/\nstatic PyObject *\nPyArray_CheckFromAny(PyObject *op, PyArray_Descr *descr, int min_depth, \n int max_depth, int requires, PyObject *context) \n{\n\tif (requires & NOTSWAPPED) {\n\t\tif (!descr && PyArray_Check(op) && \\\n\t\t !PyArray_ISNBO(PyArray_DESCR(op)->byteorder)) {\n\t\t\tdescr = PyArray_DescrNew(PyArray_DESCR(op));\n\t\t}\n\t\telse if ((descr && !PyArray_ISNBO(descr->byteorder))) {\n\t\t\tPyArray_DESCR_REPLACE(descr);\n\t\t}\n\t\tdescr->byteorder = PyArray_NATIVE;\n\t}\n\n\treturn PyArray_FromAny(op, descr, min_depth, max_depth,\n requires, context);\n}\n\n/* This is a quick wrapper around PyArray_FromAny(op, NULL, 0, 0, \n ENSUREARRAY) */\n/* that special cases Arrays and PyArray_Scalars up front */\n/* It *steals a reference* to the object */\n/* It also guarantees that the result is PyArray_Type 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_FromAny(op, NULL, 0, 0, ENSUREARRAY, NULL);\n Py_DECREF(op);\n return new;\n}\n\n/*OBJECT_API\n Check the type coercion rules.\n*/\nstatic int \nPyArray_CanCastSafely(int fromtype, int totype) \n{\n\tPyArray_Descr *from, *to;\n\tregister int felsize, telsize;\n\n if (fromtype == totype) return 1;\n if (fromtype == PyArray_BOOL) return 1;\n\tif (totype == PyArray_BOOL) return 0;\n if (totype == PyArray_OBJECT || totype == PyArray_VOID) return 1;\n\tif (fromtype == PyArray_OBJECT || fromtype == PyArray_VOID) return 0;\n\n\tfrom = PyArray_DescrFromType(fromtype);\n\tto = PyArray_DescrFromType(totype);\n\ttelsize = to->elsize;\n\tfelsize = from->elsize;\n\tPy_DECREF(from);\n\tPy_DECREF(to);\n\n switch(fromtype) {\n case PyArray_BYTE:\n\tcase PyArray_SHORT:\n case PyArray_INT:\n case PyArray_LONG:\n\tcase PyArray_LONGLONG:\n\t\tif (PyTypeNum_ISINTEGER(totype)) {\n\t\t\tif (PyTypeNum_ISUNSIGNED(totype)) {\n\t\t\t\treturn (telsize > felsize);\n\t\t\t}\n\t\t\telse {\n\t\t\t\treturn (telsize >= felsize);\n\t\t\t}\n\t\t}\n\t\telse if (PyTypeNum_ISFLOAT(totype)) {\n if (felsize < 8)\n return (telsize > felsize);\n else\n return (telsize >= felsize);\n\t\t}\n\t\telse if (PyTypeNum_ISCOMPLEX(totype)) {\n if (felsize < 8)\n return ((telsize >> 1) > felsize);\n else\n return ((telsize >> 1) >= felsize);\n\t\t}\n\t\telse return totype > fromtype;\n case PyArray_UBYTE:\n case PyArray_USHORT:\n case PyArray_UINT:\n\tcase PyArray_ULONG:\n\tcase PyArray_ULONGLONG:\n\t\tif (PyTypeNum_ISINTEGER(totype)) {\n\t\t\tif (PyTypeNum_ISSIGNED(totype)) {\n\t\t\t\treturn (telsize > felsize);\n\t\t\t}\n\t\t\telse {\n\t\t\t\treturn (telsize >= felsize);\n\t\t\t}\n\t\t}\n\t\telse if (PyTypeNum_ISFLOAT(totype)) {\n if (felsize < 8)\n return (telsize > felsize);\n else\n return (telsize >= felsize);\n\t\t}\n\t\telse if (PyTypeNum_ISCOMPLEX(totype)) {\n if (felsize < 8)\n return ((telsize >> 1) > felsize);\n else\n return ((telsize >> 1) >= felsize);\n\t\t}\n\t\telse return totype > fromtype;\n case PyArray_FLOAT:\n case PyArray_DOUBLE:\n\tcase PyArray_LONGDOUBLE:\n\t\tif (PyTypeNum_ISCOMPLEX(totype)) \n\t\t\treturn ((telsize >> 1) >= felsize);\n\t\telse\n\t\t\treturn (totype > fromtype);\n case PyArray_CFLOAT:\n case PyArray_CDOUBLE:\n\tcase PyArray_CLONGDOUBLE:\n\t\treturn (totype > fromtype);\n\tcase PyArray_STRING:\n\tcase PyArray_UNICODE:\n\t\treturn (totype > fromtype);\n default:\n return 0;\n }\n}\n\n/* leaves reference count alone --- cannot be NULL*/\n/*OBJECT_API*/\nstatic Bool\nPyArray_CanCastTo(PyArray_Descr *from, PyArray_Descr *to)\n{\n\tint fromtype=from->type_num;\n\tint totype=to->type_num;\n\tBool ret;\n\n\tret = (Bool) PyArray_CanCastSafely(fromtype, totype);\n\tif (ret) { /* Check String and Unicode more closely */\n\t\tif (fromtype == PyArray_STRING) {\n\t\t\tif (totype == PyArray_STRING) {\n\t\t\t\tret = (from->elsize <= to->elsize);\n\t\t\t}\n\t\t\telse if (totype == PyArray_UNICODE) {\n\t\t\t\tret = (from->elsize << 2 \\\n\t\t\t\t <= to->elsize);\n\t\t\t}\n\t\t}\n\t\telse if (fromtype == PyArray_UNICODE) {\n\t\t\tif (totype == PyArray_UNICODE) {\n\t\t\t\tret = (from->elsize <= to->elsize);\n\t\t\t}\n\t\t}\n\t\t/* TODO: If totype is STRING or unicode \n\t\t see if the length is long enough to hold the\n\t\t stringified value of the object.\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, NULL);\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 FORCECAST | ALIGNED, NULL);\n\t\t\tif (new==NULL) goto fail;\n Py_DECREF(obj);\n\t\t\tobj = new;\n\t\t\tr = iter_subscript_int(self, (PyArrayObject *)obj);\n\t\t}\n\t\telse {\n\t\t\tgoto fail;\n\t\t}\n\t\tPy_DECREF(obj);\n\t\treturn r;\n\t}\n\telse Py_DECREF(indtype);\n\n\n fail:\n\tif (!PyErr_Occurred())\n\t\tPyErr_SetString(PyExc_IndexError, \"unsupported iterator index\");\n\tPy_XDECREF(indtype);\n\tPy_XDECREF(obj);\n\treturn NULL;\n\n}\n\n\nstatic int\niter_ass_sub_Bool(PyArrayIterObject *self, PyArrayObject *ind,\n\t\t PyArrayIterObject *val, int swap)\n{\n\tint index, strides, itemsize;\n\tchar *dptr;\n PyArray_CopySwapFunc *copyswap;\n\n\tif (ind->nd != 1) {\n\t\tPyErr_SetString(PyExc_ValueError, \n\t\t\t\t\"boolean index array should have 1 dimension\");\n\t\treturn -1;\n\t}\n\titemsize = self->ao->descr->elsize;\n\tindex = ind->dimensions[0];\n\tstrides = ind->strides[0];\n\tdptr = ind->data;\n\tPyArray_ITER_RESET(self);\n\t/* Loop over Boolean array */\n copyswap = self->ao->descr->f->copyswap;\n\twhile(index--) {\n\t\tif (*((Bool *)dptr) != 0) {\n copyswap(self->dataptr, val->dataptr, swap,\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, NULL);\n\tif (arrval==NULL) return -1;\n\tval_it = (PyArrayIterObject *)PyArray_IterNew(arrval);\n\tif (val_it==NULL) goto finish;\n\n\t/* Check for Boolean -- this is first becasue\n\t Bool is a subclass of Int */\n\n copyswap = PyArray_DESCR(arrval)->f->copyswap;\n\tswap = (PyArray_ISNOTSWAPPED(self->ao)!=PyArray_ISNOTSWAPPED(arrval));\n\tif (PyBool_Check(ind)) {\n\t\tif (PyObject_IsTrue(ind)) {\n copyswap(self->dataptr, PyArray_DATA(arrval), \n swap, 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, NULL);\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_CheckFromAny(obj, indtype, 0, 0, \n FORCECAST | BEHAVED_NS_FLAGS, NULL);\n\t\t\tPy_DECREF(obj);\n\t\t\tobj = new;\n\t\t\tif (new==NULL) goto finish;\n\t\t\tif (iter_ass_sub_int(self, (PyArrayObject *)obj,\n\t\t\t\t\t val_it, swap) < 0)\n\t\t\t\tgoto finish;\n\t\t\tretval=0;\n\t\t}\n\t}\n\n finish:\n\tif (!PyErr_Occurred() && retval < 0)\n\t\tPyErr_SetString(PyExc_IndexError, \n\t\t\t\t\"unsupported iterator index\");\n\tPy_XDECREF(indtype);\n\tPy_XDECREF(obj);\n\tPy_XDECREF(val_it);\n\tPy_XDECREF(arrval);\n\treturn retval;\n\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 {\"index\", T_INT, offsetof(PyArrayIterObject, index), RO, NULL},\n\t{NULL},\n};\n\nstatic PyObject *\niter_coords_get(PyArrayIterObject *self)\n{\n int nd;\n nd = self->ao->nd;\n if (self->contiguous) { /* coordinates not kept track of --- need to generate\n from index */\n intp val;\n int i;\n val = self->index;\n for (i=0;icoordinates[i] = val / self->factors[i];\n val = val % self->factors[i];\n }\n }\n return PyArray_IntTupleFromIntp(nd, self->coordinates);\n}\n\nstatic PyGetSetDef iter_getsets[] = {\n\t{\"coords\", \n\t (getter)iter_coords_get,\n\t NULL,\n\t \"An N-d tuple of current coordinates.\"},\n\t{NULL, NULL, NULL, NULL},\n};\n\nstatic PyTypeObject PyArrayIter_Type = {\n PyObject_HEAD_INIT(NULL)\n 0,\t\t\t\t\t /* ob_size */\n \"numpy.flatiter\",\t\t /* tp_name */\n sizeof(PyArrayIterObject), /* tp_basicsize */\n 0,\t\t\t\t\t /* tp_itemsize */\n /* methods */\n (destructor)arrayiter_dealloc,\t\t/* tp_dealloc */\n 0,\t\t\t\t\t/* tp_print */\n 0,\t\t\t\t\t/* tp_getattr */\n 0,\t\t\t\t\t/* tp_setattr */\n 0,\t\t\t\t\t/* tp_compare */\n 0,\t\t\t\t\t/* tp_repr */\n 0,\t\t\t\t\t/* tp_as_number */\n 0, \t\t\t /* tp_as_sequence */\n &iter_as_mapping, \t /* tp_as_mapping */\n 0,\t\t\t\t\t/* tp_hash */\n 0,\t\t\t\t\t/* tp_call */\n 0,\t\t\t\t\t/* tp_str */\n 0,\t \t/* tp_getattro */\n 0,\t\t\t\t\t/* tp_setattro */\n 0,\t\t\t\t\t/* tp_as_buffer */\n Py_TPFLAGS_DEFAULT, /* tp_flags */\n 0,\t\t\t\t\t/* tp_doc */\n 0, \t /* tp_traverse */\n 0,\t\t\t\t\t/* tp_clear */\n 0,\t\t\t\t\t/* tp_richcompare */\n 0,\t\t\t\t\t/* tp_weaklistoffset */\n 0, \t /* tp_iter */\n (iternextfunc)arrayiter_next,\t\t/* tp_iternext */\n iter_methods,\t\t\t\t/* tp_methods */\n iter_members,\t \t /* tp_members */\n iter_getsets, /* tp_getset */\n\n};\n\n/** END of Array Iterator **/\n\n\n\n/*********************** Subscript Array Iterator *************************\n * *\n * This object handles subscript behavior for array objects. *\n * It is an iterator object with a next method *\n * It abstracts the n-dimensional mapping behavior to make the looping *\n * code more understandable (maybe) *\n * and so that indexing can be set up ahead of time *\n */ \n\n/* convert an indexing object to an INTP indexing array iterator\n if possible -- otherwise, it is a Slice or Ellipsis object\n and has to be interpreted on bind to a particular \n array so leave it NULL for now.\n */\nstatic int\n_convert_obj(PyObject *obj, PyArrayIterObject **iter)\n{\n\tPyArray_Descr *indtype;\n\tPyObject *arr;\n\n\tif (PySlice_Check(obj) || (obj == Py_Ellipsis))\n\t\t*iter = NULL;\n\telse {\n\t\tindtype = PyArray_DescrFromType(PyArray_INTP);\n\t\tarr = PyArray_FromAny(obj, indtype, 0, 0, FORCECAST, NULL);\n\t\tif (arr == NULL) return -1;\n\t\t*iter = (PyArrayIterObject *)PyArray_IterNew(arr);\n\t\tPy_DECREF(arr);\n\t\tif (*iter == NULL) return -1;\n\t}\n\treturn 0;\n}\n\n/* Adjust dimensionality and strides for index object iterators \n --- i.e. broadcast\n */\n/*OBJECT_API*/\nstatic int\nPyArray_Broadcast(PyArrayMultiIterObject *mit)\n{\n\tint i, nd, k, j;\n\tintp tmp;\n\tPyArrayIterObject *it;\n\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\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, NULL);\n\tif (ba == NULL) return -1;\n\tnd = ba->nd;\n\tfor (j=0; jdata;\n\tcount = 0;\n\n\t/* pre-determine how many nonzero entries there are */\n\tfor (i=0; iao->data;\n\t\tcoords[j] = 0;\n\t\tdims_m1[j] = ba->dimensions[j]-1;\n\t}\n\n\tptr = (Bool *)ba->data;\n\n\tif (count == 0) goto finish;\n\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->index = 0;\n \tmit->ait = NULL;\n \tmit->subspace = NULL;\n\tmit->numiter = 0;\n\tmit->consec = 1;\n\tPy_INCREF(indexobj);\n\tmit->indexobj = indexobj;\n\n\tif (fancy == SOBJ_LISTTUP) {\n\t\tPyObject *newobj;\n\t\tnewobj = PySequence_Tuple(indexobj);\n\t\tif (newobj == NULL) goto fail;\n\t\tPy_DECREF(indexobj);\n\t\tindexobj = newobj;\n\t\tmit->indexobj = indexobj;\n\t}\n\n#undef SOBJ_NOTFANCY \n#undef SOBJ_ISFANCY \n#undef SOBJ_BADARRAY \n#undef SOBJ_TOOMANY \n#undef SOBJ_LISTTUP \n \n\tif (oned) return (PyObject *)mit;\n\n\t/* Must have some kind of fancy indexing if we are here */\n\t/* indexobj is either a list, an arrayobject, or a tuple \n\t (with at least 1 list or arrayobject or Bool object), */\n\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, NULL);\n\t\tif (arr == NULL) goto fail;\n\t\tmit->iters[0] = (PyArrayIterObject *)PyArray_IterNew(arr);\n\t\tif (mit->iters[0] == NULL) {Py_DECREF(arr); goto fail;}\n\t\tmit->nd = PyArray_NDIM(arr);\n\t\tmemcpy(mit->dimensions,PyArray_DIMS(arr),mit->nd*sizeof(intp));\n\t\tmit->size = PyArray_SIZE(arr);\n\t\tPy_DECREF(arr);\n\t\tPy_DECREF(mit->indexobj);\n\t\tmit->indexobj = Py_BuildValue(\"(N)\", PyInt_FromLong(0));\n\t}\n\telse { /* must be a tuple */\n\t\tPyObject *obj;\n\t\tPyArrayIterObject *iter;\n\t\tPyObject *new;\n\t\t/* Make a copy of the tuple -- we will be replacing \n\t\t index objects with 0's */\n\t\tn = PyTuple_GET_SIZE(indexobj);\n\t\tnew = PyTuple_New(n);\n\t\tif (new == NULL) goto fail;\n\t\tstarted = 0;\n\t\tnonindex = 0;\n\t\tfor (i=0; iconsec = 0;\n\t\t\t\tmit->iters[(mit->numiter)++] = iter;\n\t\t\t\tPyTuple_SET_ITEM(new,i,\n\t\t\t\t\t\t PyInt_FromLong(0));\n\t\t\t}\n\t\t\telse {\n\t\t\t\tif (started) nonindex = 1;\n\t\t\t\tPy_INCREF(obj);\n\t\t\t\tPyTuple_SET_ITEM(new,i,obj);\n\t\t\t}\n\t\t}\n\t\tPy_DECREF(mit->indexobj);\n\t\tmit->indexobj = new;\n\t\t/* Store the number of iterators actually converted */\n\t\t/* These will be mapped to actual axes at bind time */\n\t\tif (PyArray_Broadcast((PyArrayMultiIterObject *)mit) < 0)\n\t\t\tgoto fail;\n\t}\n\n return (PyObject *)mit;\n \n fail:\n Py_DECREF(mit);\n\treturn NULL;\n}\n\n\nstatic void\narraymapiter_dealloc(PyArrayMapIterObject *mit)\n{\n\tint i;\n\tPy_XDECREF(mit->indexobj);\n Py_XDECREF(mit->ait);\n\tPy_XDECREF(mit->subspace);\n\tfor (i=0; inumiter; i++)\n\t\tPy_XDECREF(mit->iters[i]);\n _pya_free(mit);\n}\n\n/* The mapiter object must be created new each time. It does not work\n to bind to a new array, and continue.\n\n This was the orginal intention, but currently that does not work. \n Do not expose the MapIter_Type to Python.\n\n It's not very useful anyway, since mapiter(indexobj); mapiter.bind(a); \n mapiter is equivalent to a[indexobj].flat but the latter gets to use \n slice syntax.\n*/\n\nstatic PyTypeObject PyArrayMapIter_Type = {\n PyObject_HEAD_INIT(NULL)\n 0,\t\t\t\t\t /* ob_size */\n \"numpy.mapiter\",\t\t \t/* tp_name */\n sizeof(PyArrayIterObject), /* tp_basicsize */\n 0,\t\t\t\t\t /* tp_itemsize */\n /* methods */\n (destructor)arraymapiter_dealloc,\t/* tp_dealloc */\n 0,\t\t\t\t\t/* tp_print */\n 0,\t\t\t\t\t/* tp_getattr */\n 0,\t\t\t\t\t/* tp_setattr */\n 0,\t\t\t\t\t/* tp_compare */\n 0,\t\t\t\t\t/* tp_repr */\n 0,\t\t\t\t\t/* tp_as_number */\n 0,\t\t\t\t\t/* tp_as_sequence */\n 0,\t\t\t\t\t/* tp_as_mapping */\n 0,\t\t\t\t\t/* tp_hash */\n 0,\t\t\t\t\t/* tp_call */\n 0,\t\t\t\t\t/* tp_str */\n 0, \t\t/* tp_getattro */\n 0,\t\t\t\t\t/* tp_setattro */\n 0,\t\t\t\t\t/* tp_as_buffer */\n Py_TPFLAGS_DEFAULT, /* tp_flags */\n 0,\t\t\t\t\t/* tp_doc */\n (traverseproc)0, \t /* tp_traverse */\n 0,\t\t\t\t\t/* tp_clear */\n 0,\t\t\t\t\t/* tp_richcompare */\n 0,\t\t\t\t\t/* tp_weaklistoffset */\n 0,\t\t \t /* tp_iter */\n (iternextfunc)0, \t /* tp_iternext */\n 0, \t /* tp_methods */\n 0,\t\t\t\t\t /* tp_members */\n 0,\t\t\t /* tp_getset */\n 0,\t\t\t\t\t /* tp_base */\n 0,\t\t\t\t\t /* tp_dict */\n 0,\t\t\t\t\t /* tp_descr_get */\n 0,\t\t\t\t\t /* tp_descr_set */\n 0,\t\t\t\t\t /* tp_dictoffset */\n (initproc)0,\t \t /* tp_init */\n 0, \t /* tp_alloc */\n 0,\t /* tp_new */\n 0,\t /* tp_free */\n 0,\t\t\t\t\t /* tp_is_gc */\n 0,\t\t\t\t\t /* tp_bases */\n 0,\t\t\t\t\t /* tp_mro */\n 0,\t\t\t\t\t /* tp_cache */\n 0,\t\t\t\t\t /* tp_subclasses */\n 0\t\t\t\t\t /* tp_weaklist */\n\n};\n\n/** END of Subscript Iterator **/\n\n\n/*OBJECT_API\n Get MultiIterator,\n*/\nstatic PyObject *\nPyArray_MultiIterNew(int n, ...)\n{\n va_list va;\n\tPyArrayMultiIterObject *multi;\n\tPyObject *current;\n\tPyObject *arr;\n\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 dtype objects can be set. \n*/\nstatic PyMemberDef arraydescr_members[] = {\n\t{\"type\", T_OBJECT, offsetof(PyArray_Descr, typeobj), RO, NULL},\n\t{\"kind\", T_CHAR, offsetof(PyArray_Descr, kind), RO, NULL},\n\t{\"char\", T_CHAR, offsetof(PyArray_Descr, type), RO, NULL},\n\t{\"num\", T_INT, offsetof(PyArray_Descr, type_num), RO, NULL},\n\t{\"byteorder\", T_CHAR, offsetof(PyArray_Descr, byteorder), RO, NULL},\n\t{\"itemsize\", T_INT, offsetof(PyArray_Descr, elsize), RO, NULL},\n\t{\"alignment\", T_INT, offsetof(PyArray_Descr, alignment), RO, NULL},\n {\"hasobject\", T_UBYTE, offsetof(PyArray_Descr, hasobject), RO, NULL},\n\t{NULL}, \n};\n\nstatic PyObject *\narraydescr_subdescr_get(PyArray_Descr *self)\n{\n\tif (self->subarray == NULL) {\n\t\tPy_INCREF(Py_None);\n\t\treturn Py_None;\n\t}\n\treturn Py_BuildValue(\"OO\", (PyObject *)self->subarray->base, \n\t\t\t self->subarray->shape);\n}\n\nstatic PyObject *\narraydescr_protocol_typestr_get(PyArray_Descr *self)\n{\n char basic_=self->kind;\n char endian = self->byteorder;\n\tint size=self->elsize;\n\n if (endian == '=') {\n endian = '<';\n if (!PyArray_IsNativeByteOrder(endian)) endian = '>';\n }\n \n\tif (self->type_num == PyArray_UNICODE) {\n\t\tsize >>= 2;\n\t}\n return PyString_FromFormat(\"%c%c%d\", endian, basic_, size);\n}\n\nstatic PyObject *\narraydescr_typename_get(PyArray_Descr *self)\n{\n int len;\n PyTypeObject *typeobj = self->typeobj;\n\tPyObject *res;\n\tstatic int suffix_len=0;\n\n\tif (PyTypeNum_ISUSERDEF(self->type_num)) {\n\t\tres = PyString_FromString(typeobj->tp_name);\n\t}\n\telse {\n\t\tif (suffix_len == 0) \n\t\t\tsuffix_len = strlen(\"scalar\");\n\t\tlen = strlen(typeobj->tp_name) - suffix_len;\n\t\tres = PyString_FromStringAndSize(typeobj->tp_name, len);\n\t}\n\tif (PyTypeNum_ISEXTENDED(self->type_num) && self->elsize != 0) {\n\t\tPyObject *p;\n\t\tp = PyString_FromFormat(\"%d\", self->elsize * 8);\n\t\tPyString_ConcatAndDel(&res, p);\n\t}\n\treturn res;\t\t\t\t\t\t \n}\n\nstatic PyObject *\narraydescr_base_get(PyArray_Descr *self)\n{\n\tif (self->subarray == NULL) {\n\t\tPy_INCREF(self);\n return (PyObject *)self;\n\t}\n Py_INCREF(self->subarray->base);\n return (PyObject *)(self->subarray->base);\n}\n\nstatic PyObject *\narraydescr_shape_get(PyArray_Descr *self)\n{\n\tif (self->subarray == NULL) {\n return Py_BuildValue(\"(N)\", PyInt_FromLong(1));\n\t}\n Py_INCREF(self->subarray->shape);\n return (PyObject *)(self->subarray->shape);\n}\n\nstatic PyObject *\narraydescr_protocol_descr_get(PyArray_Descr *self)\n{\n\tPyObject *dobj, *res;\n\n\tif (self->fields == NULL || self->fields == Py_None) {\n\t\t/* get default */\n\t\tdobj = PyTuple_New(2);\n\t\tif (dobj == NULL) return NULL;\n\t\tPyTuple_SET_ITEM(dobj, 0, PyString_FromString(\"\"));\n\t\tPyTuple_SET_ITEM(dobj, 1, \\\n\t\t\t\t arraydescr_protocol_typestr_get(self));\n\t\tres = PyList_New(1);\n\t\tif (res == NULL) {Py_DECREF(dobj); return NULL;}\n\t\tPyList_SET_ITEM(res, 0, dobj);\n\t\treturn res;\n\t}\n\n return PyObject_CallMethod(_numpy_internal, \"_array_descr\", \n\t\t\t\t \"O\", self);\n}\n\n/* returns 1 for a builtin type\n and 2 for a user-defined data-type descriptor\n return 0 if neither (i.e. it's a copy of one)\n*/\nstatic PyObject *\narraydescr_isbuiltin_get(PyArray_Descr *self) \n{\n\tlong val;\n\tval = 0;\n\tif (self->fields == Py_None) val = 1;\n\tif (PyTypeNum_ISUSERDEF(self->type_num)) val = 2;\n\treturn PyInt_FromLong(val);\n}\n\nstatic PyObject *\narraydescr_isnative_get(PyArray_Descr *self)\n{\n\tPyObject *ret;\n\n\tret = (PyArray_ISNBO(self->byteorder) ? Py_True : Py_False);\n\tPy_INCREF(ret);\n\treturn ret;\n}\n\nstatic PyObject *\narraydescr_fields_get(PyArray_Descr *self)\n{\n\tif (self->fields == NULL || self->fields == Py_None) {\n\t\tPy_INCREF(Py_None);\n\t\treturn Py_None;\n\t}\n\treturn PyDictProxy_New(self->fields);\n}\n\nstatic PyGetSetDef arraydescr_getsets[] = {\n\t{\"subdtype\", \n\t (getter)arraydescr_subdescr_get,\n\t NULL,\n\t \"A tuple of (descr, shape) or None.\"},\n\t{\"descr\",\n\t (getter)arraydescr_protocol_descr_get,\n\t NULL,\n\t \"The array_protocol type descriptor.\"},\n\t{\"str\",\n\t (getter)arraydescr_protocol_typestr_get,\n\t NULL,\n\t \"The array_protocol typestring.\"},\n {\"name\",\n (getter)arraydescr_typename_get,\n NULL,\n \"The name of the true data-type\"},\n\t{\"base\",\n\t (getter)arraydescr_base_get,\n\t NULL,\n\t \"The base data-type or self if no subdtype\"},\n {\"shape\",\n (getter)arraydescr_shape_get,\n NULL,\n \"The shape of the subdtype or (1,)\"},\n \t{\"isbuiltin\",\n\t (getter)arraydescr_isbuiltin_get,\n\t NULL,\n\t \"Is this a buillt-in data-type descriptor?\"},\n\t{\"isnative\",\n\t (getter)arraydescr_isnative_get,\n\t NULL,\n\t \"Is the byte-order of this descriptor native?\"},\n\t{\"fields\",\n\t (getter)arraydescr_fields_get,\n\t NULL,\n\t NULL},\n\t{NULL, NULL, NULL, NULL},\n};\n\nstatic PyArray_Descr *_convert_from_list(PyObject *obj, int align, int try_descr);\nstatic PyArray_Descr *_convert_from_dict(PyObject *obj, int align);\nstatic PyArray_Descr *_convert_from_commastring(PyObject *obj, int align);\nstatic PyArray_Descr *_convert_from_array_descr(PyObject *obj);\n\nstatic PyObject *\narraydescr_new(PyTypeObject *subtype, PyObject *args, PyObject *kwds)\n{\n\tPyObject *odescr;\n\tPyArray_Descr *descr, *conv;\n\tint align=0;\n\tBool copy=FALSE;\n\tstatic char *kwlist[] = {\"dtype\", \"align\", \"copy\", NULL};\n\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, \"dtype\");\n\tPy_DECREF(mod);\n\tif (obj == NULL) {Py_DECREF(ret); return NULL;}\n\tPyTuple_SET_ITEM(ret, 0, obj);\n\tif (PyTypeNum_ISUSERDEF(self->type_num) ||\t\t\\\n\t ((self->type_num == PyArray_VOID &&\t\t\t\\\n\t self->typeobj != &PyVoidArrType_Type))) {\n\t\tobj = (PyObject *)self->typeobj;\n\t\tPy_INCREF(obj);\n\t}\n\telse {\n\t\telsize = self->elsize;\n\t\tif (self->type_num == PyArray_UNICODE) {\n\t\t\telsize >>= 2;\n\t\t}\n\t\tobj = PyString_FromFormat(\"%c%d\",self->kind, elsize);\n\t}\n\tPyTuple_SET_ITEM(ret, 1, Py_BuildValue(\"(Nii)\", obj, 0, 1));\n\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 dtype object\\n\"\n\t\" with altered byteorders. If is not given all byteorders\\n\"\n\t\" are swapped. Otherwise endian can be '>', '<', or '=' to force\\n\"\n\t\" a byteorder. Descriptors in all fields are also updated in the\\n\"\n\t\" new dtype object.\";\n\nstatic PyObject *\narraydescr_newbyteorder(PyArray_Descr *self, PyObject *args) \n{\n\tchar endian=PyArray_SWAP;\n\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);\n\t\tif (self->type_num != PyArray_VOID) {\n\t\t\tPyObject *p;\n\t\t\tPyObject *t=PyString_FromString(\"'\");\n\t\t\tp = arraydescr_protocol_typestr_get(self);\n\t\t\tPyString_Concat(&p, t);\n\t\t\tPyString_ConcatAndDel(&t, p);\n\t\t\tp = PyString_FromString(\"(\");\n\t\t\tPyString_ConcatAndDel(&p, t);\n\t\t\tPyString_ConcatAndDel(&p, PyString_FromString(\", \"));\n\t\t\tPyString_ConcatAndDel(&p, sub);\n\t\t\tPyString_ConcatAndDel(&p, PyString_FromString(\")\"));\n\t\t\tsub = p;\n\t\t}\n\t}\n\telse if (self->subarray) {\n\t\tPyObject *p;\n\t\tPyObject *t = PyString_FromString(\"(\");\n\t\tp = arraydescr_str(self->subarray->base);\n\t\tPyString_ConcatAndDel(&t, p);\n\t\tPyString_ConcatAndDel(&t, PyString_FromString(\",\"));\n\t\tPyString_ConcatAndDel(&t, PyObject_Str(self->subarray->shape));\n\t\tPyString_ConcatAndDel(&t, PyString_FromString(\")\"));\n\t\tsub = t;\n\t}\n\telse {\n\t\tPyObject *t=PyString_FromString(\"'\");\n\t\tsub = arraydescr_protocol_typestr_get(self);\n\t\tPyString_Concat(&sub, t);\n\t\tPyString_ConcatAndDel(&t, sub);\n\t\tsub = t;\n\t}\n\treturn sub;\n}\n\nstatic PyObject *\narraydescr_repr(PyArray_Descr *self)\n{\n\tPyObject *sub, *s;\n\ts = PyString_FromString(\"dtype(\");\n sub = arraydescr_str(self);\n\tPyString_ConcatAndDel(&s, sub);\n\tsub = PyString_FromString(\")\");\n\tPyString_ConcatAndDel(&s, sub);\n\treturn s;\n}\n\nstatic int\narraydescr_compare(PyArray_Descr *self, PyObject *other)\n{\n \tif (!PyArray_DescrCheck(other)) {\n\t\tPyErr_SetString(PyExc_TypeError,\n\t\t\t\t\"not a dtype object.\");\n\t\treturn -1;\n\t}\n\tif (PyArray_EquivTypes(self, (PyArray_Descr *)other)) return 0;\n\tif (PyArray_CanCastTo(self, (PyArray_Descr *)other)) return -1;\n\treturn 1;\n}\n\n/*************************************************************************\n **************** Implement Mapping Protocol ***************************\n *************************************************************************/\n\nstatic int \ndescr_length(PyArray_Descr *self) \n{\n\n\tif (self->fields && self->fields != Py_None)\n\t\t/* Remove the last entry (root) */\n\t\treturn PyDict_Size(self->fields) - 1;\n\telse return 0;\n}\n\nstatic PyObject *\ndescr_subscript(PyArray_Descr *self, PyObject *op) \n{\n\n\tif (self->fields) {\n\t\tif (PyString_Check(op) || PyUnicode_Check(op)) {\n\t\t\tPyObject *obj;\n\t\t\tobj = PyDict_GetItem(self->fields, op);\n\t\t\tif (obj != NULL) {\n\t\t\t\tPyObject *descr;\n\t\t\t\tdescr = PyTuple_GET_ITEM(obj, 0);\n\t\t\t\tPy_INCREF(descr);\n\t\t\t\treturn descr;\n\t\t\t}\n\t\t\telse {\n\t\t\t\tPyErr_Format(PyExc_KeyError, \n\t\t\t\t\t \"field named \\'%s\\' not found.\",\n\t\t\t\t\t PyString_AsString(op));\n\t\t\t}\n\t\t}\n\t\telse {\n\t\t PyErr_SetString(PyExc_ValueError, \n\t\t\t\t \"only strings or unicode values allowed \" \\\n\t\t\t\t \"for getting fields.\");\n\t\t}\n\t}\n\telse {\n\t\tPyErr_Format(PyExc_KeyError, \n\t\t\t \"there are no fields in dtype %s.\",\n\t\t\t PyString_AsString(arraydescr_str(self)));\n\t}\n\n\treturn NULL;\n}\n\nstatic PyMappingMethods descr_as_mapping = {\n (inquiry)descr_length,\t\t /*mp_length*/\n (binaryfunc)descr_subscript,\t /*mp_subscript*/\n (objobjargproc)NULL,\t /*mp_ass_subscript*/\n};\n\n/****************** End of Mapping Protocol ******************************/\n\n\nstatic PyTypeObject PyArrayDescr_Type = {\n PyObject_HEAD_INIT(NULL)\n 0,\t\t\t\t\t /* ob_size */\n \"numpy.dtype\",\t\t \t /* tp_name */\n sizeof(PyArray_Descr), /* tp_basicsize */\n 0,\t\t\t\t\t /* tp_itemsize */\n /* methods */\n (destructor)arraydescr_dealloc,\t\t/* tp_dealloc */\n 0,\t\t\t\t\t/* tp_print */\n 0,\t\t\t\t\t/* tp_getattr */\n 0,\t\t\t\t\t/* tp_setattr */\n\t(cmpfunc)arraydescr_compare,\t\t/* tp_compare */\n (reprfunc)arraydescr_repr,\t /* tp_repr */\n 0,\t\t\t\t\t/* tp_as_number */\n 0, \t\t\t /* tp_as_sequence */\n &descr_as_mapping, \t /* tp_as_mapping */\n 0,\t\t\t\t\t/* tp_hash */\n 0,\t\t\t\t\t/* tp_call */\n (reprfunc)arraydescr_str, /* tp_str */\n 0,\t \t/* tp_getattro */\n 0,\t\t\t\t\t/* tp_setattro */\n 0,\t\t\t\t\t/* tp_as_buffer */\n Py_TPFLAGS_DEFAULT, /* tp_flags */\n 0,\t\t\t\t\t/* tp_doc */\n 0, \t /* tp_traverse */\n 0,\t\t\t\t\t/* tp_clear */\n 0,\t\t\t\t\t/* tp_richcompare */\n 0,\t\t\t\t\t/* tp_weaklistoffset */\n 0, \t /* tp_iter */\n 0,\t \t/* tp_iternext */\n arraydescr_methods,\t \t /* tp_methods */\n arraydescr_members,\t /* tp_members */\n arraydescr_getsets, /* tp_getset */\n 0,\t\t\t\t\t /* tp_base */\n 0,\t\t\t\t\t /* tp_dict */\n 0,\t\t\t\t\t /* tp_descr_get */\n 0,\t\t\t\t\t /* tp_descr_set */\n 0,\t\t\t\t\t /* tp_dictoffset */\n 0, \t \t /* tp_init */\n 0, \t /* tp_alloc */\n arraydescr_new,\t /* tp_new */\n 0,\t /* tp_free */\n 0,\t\t\t\t\t /* tp_is_gc */\n 0,\t\t\t\t\t /* tp_bases */\n 0,\t\t\t\t\t /* tp_mro */\n 0,\t\t\t\t\t /* tp_cache */\n 0,\t\t\t\t\t /* tp_subclasses */\n 0\t\t\t\t\t /* tp_weaklist */\n};\n", + "methods": [ + { + "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": 28, + "end_line": 46, + "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": 67, + "end_line": 95, + "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": 101, + "end_line": 130, + "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": 136, + "end_line": 186, + "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": 209, + "end_line": 240, + "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": 243, + "end_line": 277, + "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": 293, + "end_line": 315, + "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": 321, + "end_line": 342, + "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": 346, + "end_line": 384, + "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": 389, + "end_line": 409, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 21, + "top_nesting_level": 0 + }, + { + "name": "PyArray_PyIntAsIntp", + "long_name": "PyArray_PyIntAsIntp( PyObject * o)", + "filename": "arrayobject.c", + "nloc": 71, + "complexity": 21, + "token_count": 413, + "parameters": [ + "o" + ], + "start_line": 429, + "end_line": 511, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 83, + "top_nesting_level": 0 + }, + { + "name": "PyArray_PyIntAsInt", + "long_name": "PyArray_PyIntAsInt( PyObject * o)", + "filename": "arrayobject.c", + "nloc": 67, + "complexity": 19, + "token_count": 406, + "parameters": [ + "o" + ], + "start_line": 518, + "end_line": 592, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 75, + "top_nesting_level": 0 + }, + { + "name": "index2ptr", + "long_name": "index2ptr( PyArrayObject * mp , intp i)", + "filename": "arrayobject.c", + "nloc": 15, + "complexity": 7, + "token_count": 98, + "parameters": [ + "mp", + "i" + ], + "start_line": 595, + "end_line": 610, + "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": 616, + "end_line": 624, + "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": 640, + "end_line": 720, + "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": 81, + "parameters": [ + "dest", + "src_object" + ], + "start_line": 724, + "end_line": 738, + "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": 751, + "end_line": 777, + "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": 783, + "end_line": 797, + "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": 806, + "end_line": 826, + "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": 103, + "complexity": 17, + "token_count": 616, + "parameters": [ + "data", + "descr", + "base" + ], + "start_line": 835, + "end_line": 951, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 117, + "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": 967, + "end_line": 970, + "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": 980, + "end_line": 1002, + "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": 1016, + "end_line": 1056, + "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": 1071, + "end_line": 1112, + "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": 1119, + "end_line": 1210, + "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": 1216, + "end_line": 1245, + "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": 1248, + "end_line": 1284, + "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": 1293, + "end_line": 1330, + "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": 1337, + "end_line": 1345, + "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": 1348, + "end_line": 1373, + "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": 1376, + "end_line": 1379, + "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": 1383, + "end_line": 1418, + "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": 1424, + "end_line": 1427, + "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": 1433, + "end_line": 1441, + "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": 1447, + "end_line": 1497, + "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": 1504, + "end_line": 1549, + "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": 1553, + "end_line": 1647, + "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": 1650, + "end_line": 1687, + "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": 1699, + "end_line": 1752, + "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": 382, + "parameters": [ + "mit", + "op" + ], + "start_line": 1755, + "end_line": 1815, + "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": 1818, + "end_line": 1845, + "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": 1848, + "end_line": 1867, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 20, + "top_nesting_level": 0 + }, + { + "name": "fancy_indexing_check", + "long_name": "fancy_indexing_check( PyObject * args)", + "filename": "arrayobject.c", + "nloc": 56, + "complexity": 22, + "token_count": 295, + "parameters": [ + "args" + ], + "start_line": 1879, + "end_line": 1941, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 63, + "top_nesting_level": 0 + }, + { + "name": "array_subscript", + "long_name": "array_subscript( PyArrayObject * self , PyObject * op)", + "filename": "arrayobject.c", + "nloc": 103, + "complexity": 28, + "token_count": 666, + "parameters": [ + "self", + "op" + ], + "start_line": 1965, + "end_line": 2083, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 119, + "top_nesting_level": 0 + }, + { + "name": "array_ass_sub", + "long_name": "array_ass_sub( PyArrayObject * self , PyObject * index , PyObject * op)", + "filename": "arrayobject.c", + "nloc": 93, + "complexity": 28, + "token_count": 588, + "parameters": [ + "self", + "index", + "op" + ], + "start_line": 2098, + "end_line": 2203, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 106, + "top_nesting_level": 0 + }, + { + "name": "array_subscript_nice", + "long_name": "array_subscript_nice( PyArrayObject * self , PyObject * op)", + "filename": "arrayobject.c", + "nloc": 4, + "complexity": 1, + "token_count": 27, + "parameters": [ + "self", + "op" + ], + "start_line": 2212, + "end_line": 2215, + "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": 2234, + "end_line": 2246, + "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": 2249, + "end_line": 2264, + "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": 2268, + "end_line": 2277, + "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": 2280, + "end_line": 2291, + "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": 2362, + "end_line": 2395, + "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": 2405, + "end_line": 2444, + "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": 2447, + "end_line": 2470, + "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": 2474, + "end_line": 2497, + "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": 2501, + "end_line": 2508, + "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": 2511, + "end_line": 2518, + "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": 2521, + "end_line": 2529, + "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": 2532, + "end_line": 2535, + "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": 2538, + "end_line": 2541, + "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": 2544, + "end_line": 2547, + "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": 2550, + "end_line": 2553, + "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": 2556, + "end_line": 2559, + "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": 2562, + "end_line": 2565, + "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": 2568, + "end_line": 2571, + "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": 2574, + "end_line": 2577, + "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": 2580, + "end_line": 2583, + "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": 2586, + "end_line": 2589, + "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": 2592, + "end_line": 2595, + "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": 2598, + "end_line": 2601, + "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": 2604, + "end_line": 2607, + "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": 2610, + "end_line": 2613, + "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": 2616, + "end_line": 2619, + "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": 2622, + "end_line": 2625, + "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": 2628, + "end_line": 2631, + "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": 2634, + "end_line": 2637, + "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": 2640, + "end_line": 2643, + "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": 2646, + "end_line": 2649, + "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": 2652, + "end_line": 2655, + "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": 2658, + "end_line": 2661, + "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": 2664, + "end_line": 2667, + "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": 2670, + "end_line": 2673, + "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": 2676, + "end_line": 2679, + "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": 2682, + "end_line": 2685, + "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": 2688, + "end_line": 2691, + "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": 2694, + "end_line": 2698, + "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": 2701, + "end_line": 2705, + "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": 2709, + "end_line": 2727, + "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": 2730, + "end_line": 2747, + "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": 2752, + "end_line": 2767, + "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": 2771, + "end_line": 2797, + "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": 2800, + "end_line": 2825, + "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": 2828, + "end_line": 2850, + "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": 2853, + "end_line": 2875, + "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": 2878, + "end_line": 2900, + "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": 2903, + "end_line": 2907, + "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": 2968, + "end_line": 3008, + "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": 3012, + "end_line": 3033, + "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": 3036, + "end_line": 3048, + "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": 3069, + "end_line": 3116, + "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": 3119, + "end_line": 3155, + "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": 3164, + "end_line": 3181, + "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": 3184, + "end_line": 3196, + "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": 3199, + "end_line": 3211, + "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": 81, + "complexity": 17, + "token_count": 357, + "parameters": [ + "self", + "other", + "cmp_op" + ], + "start_line": 3214, + "end_line": 3311, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 98, + "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": 171, + "parameters": [ + "arr", + "axis", + "flags" + ], + "start_line": 3314, + "end_line": 3343, + "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": 3349, + "end_line": 3369, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 21, + "top_nesting_level": 0 + }, + { + "name": "PyArray_IntpFromSequence", + "long_name": "PyArray_IntpFromSequence( PyObject * seq , intp * vals , int maxvals)", + "filename": "arrayobject.c", + "nloc": 24, + "complexity": 11, + "token_count": 203, + "parameters": [ + "seq", + "vals", + "maxvals" + ], + "start_line": 3377, + "end_line": 3412, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 36, + "top_nesting_level": 0 + }, + { + "name": "_IsContiguous", + "long_name": "_IsContiguous( PyArrayObject * ap)", + "filename": "arrayobject.c", + "nloc": 17, + "complexity": 7, + "token_count": 128, + "parameters": [ + "ap" + ], + "start_line": 3418, + "end_line": 3437, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 20, + "top_nesting_level": 0 + }, + { + "name": "_IsFortranContiguous", + "long_name": "_IsFortranContiguous( PyArrayObject * ap)", + "filename": "arrayobject.c", + "nloc": 17, + "complexity": 7, + "token_count": 126, + "parameters": [ + "ap" + ], + "start_line": 3441, + "end_line": 3459, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 19, + "top_nesting_level": 0 + }, + { + "name": "_IsAligned", + "long_name": "_IsAligned( PyArrayObject * ap)", + "filename": "arrayobject.c", + "nloc": 15, + "complexity": 5, + "token_count": 119, + "parameters": [ + "ap" + ], + "start_line": 3462, + "end_line": 3479, + "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": 3482, + "end_line": 3515, + "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": 3522, + "end_line": 3549, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 28, + "top_nesting_level": 0 + }, + { + "name": "PyArray_CheckStrides", + "long_name": "PyArray_CheckStrides( int elsize , int nd , intp numbytes , intp offset , intp * dims , intp * newstrides)", + "filename": "arrayobject.c", + "nloc": 23, + "complexity": 7, + "token_count": 135, + "parameters": [ + "elsize", + "nd", + "numbytes", + "offset", + "dims", + "newstrides" + ], + "start_line": 3563, + "end_line": 3598, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 36, + "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": 3618, + "end_line": 3642, + "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": 3648, + "end_line": 3670, + "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": 3674, + "end_line": 3716, + "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": 136, + "complexity": 27, + "token_count": 781, + "parameters": [ + "subtype", + "descr", + "nd", + "dims", + "strides", + "data", + "flags", + "obj" + ], + "start_line": 3724, + "end_line": 3889, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 166, + "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": 3898, + "end_line": 3996, + "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": 4002, + "end_line": 4019, + "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": 231, + "parameters": [ + "arr", + "obj" + ], + "start_line": 4023, + "end_line": 4065, + "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": 19, + "token_count": 577, + "parameters": [ + "subtype", + "args", + "kwds" + ], + "start_line": 4068, + "end_line": 4185, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 118, + "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": 4189, + "end_line": 4197, + "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": 4203, + "end_line": 4206, + "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": 4209, + "end_line": 4213, + "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": 4216, + "end_line": 4219, + "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": 4223, + "end_line": 4252, + "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": 4256, + "end_line": 4259, + "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": 37, + "complexity": 7, + "token_count": 239, + "parameters": [ + "self", + "obj" + ], + "start_line": 4262, + "end_line": 4301, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 40, + "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": 4305, + "end_line": 4312, + "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": 4315, + "end_line": 4323, + "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": 4327, + "end_line": 4333, + "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": 4336, + "end_line": 4350, + "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": 4353, + "end_line": 4397, + "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": 4401, + "end_line": 4404, + "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": 4407, + "end_line": 4418, + "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": 4421, + "end_line": 4432, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 12, + "top_nesting_level": 0 + }, + { + "name": "array_typestr_get", + "long_name": "array_typestr_get( PyArrayObject * self)", + "filename": "arrayobject.c", + "nloc": 4, + "complexity": 1, + "token_count": 16, + "parameters": [ + "self" + ], + "start_line": 4438, + "end_line": 4441, + "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": 4444, + "end_line": 4448, + "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": 62, + "complexity": 15, + "token_count": 438, + "parameters": [ + "self", + "arg" + ], + "start_line": 4462, + "end_line": 4548, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 87, + "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": 4551, + "end_line": 4569, + "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": 4572, + "end_line": 4590, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 19, + "top_nesting_level": 0 + }, + { + "name": "array_base_get", + "long_name": "array_base_get( PyArrayObject * self)", + "filename": "arrayobject.c", + "nloc": 11, + "complexity": 2, + "token_count": 41, + "parameters": [ + "self" + ], + "start_line": 4593, + "end_line": 4603, + "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": 4607, + "end_line": 4632, + "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": 191, + "parameters": [ + "self", + "val" + ], + "start_line": 4636, + "end_line": 4669, + "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": 4672, + "end_line": 4705, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 34, + "top_nesting_level": 0 + }, + { + "name": "array_imag_set", + "long_name": "array_imag_set( PyArrayObject * self , PyObject * val)", + "filename": "arrayobject.c", + "nloc": 37, + "complexity": 4, + "token_count": 207, + "parameters": [ + "self", + "val" + ], + "start_line": 4708, + "end_line": 4745, + "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": 4748, + "end_line": 4751, + "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": 348, + "parameters": [ + "self", + "val" + ], + "start_line": 4754, + "end_line": 4804, + "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": 4894, + "end_line": 4901, + "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": 5003, + "end_line": 5036, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 34, + "top_nesting_level": 0 + }, + { + "name": "discover_itemsize", + "long_name": "discover_itemsize( PyObject * s , int nd , int * itemsize)", + "filename": "arrayobject.c", + "nloc": 21, + "complexity": 9, + "token_count": 158, + "parameters": [ + "s", + "nd", + "itemsize" + ], + "start_line": 5039, + "end_line": 5061, + "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": 5068, + "end_line": 5094, + "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": 5100, + "end_line": 5132, + "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": 128, + "complexity": 34, + "token_count": 742, + "parameters": [ + "op", + "minitype", + "max" + ], + "start_line": 5144, + "end_line": 5292, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 149, + "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": 5295, + "end_line": 5318, + "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": 29, + "complexity": 7, + "token_count": 168, + "parameters": [ + "op", + "typecode" + ], + "start_line": 5323, + "end_line": 5357, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 35, + "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": 54, + "complexity": 21, + "token_count": 352, + "parameters": [ + "s", + "typecode", + "fortran", + "min_depth", + "max_depth" + ], + "start_line": 5362, + "end_line": 5425, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 64, + "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": 5432, + "end_line": 5441, + "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": 5447, + "end_line": 5540, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 94, + "top_nesting_level": 0 + }, + { + "name": "PyArray_CastToType", + "long_name": "PyArray_CastToType( PyArrayObject * mp , PyArray_Descr * at , int fortran)", + "filename": "arrayobject.c", + "nloc": 40, + "complexity": 16, + "token_count": 276, + "parameters": [ + "mp", + "at", + "fortran" + ], + "start_line": 5550, + "end_line": 5596, + "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": 5606, + "end_line": 5659, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 54, + "top_nesting_level": 0 + }, + { + "name": "PyArray_FromArray", + "long_name": "PyArray_FromArray( PyArrayObject * arr , PyArray_Descr * newtype , int flags)", + "filename": "arrayobject.c", + "nloc": 114, + "complexity": 33, + "token_count": 676, + "parameters": [ + "arr", + "newtype", + "flags" + ], + "start_line": 5664, + "end_line": 5793, + "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": 501, + "parameters": [ + "str" + ], + "start_line": 5797, + "end_line": 5905, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 109, + "top_nesting_level": 0 + }, + { + "name": "PyArray_FromStructInterface", + "long_name": "PyArray_FromStructInterface( PyObject * input)", + "filename": "arrayobject.c", + "nloc": 38, + "complexity": 6, + "token_count": 234, + "parameters": [ + "input" + ], + "start_line": 5909, + "end_line": 5949, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 41, + "top_nesting_level": 0 + }, + { + "name": "PyArray_FromInterface", + "long_name": "PyArray_FromInterface( PyObject * input)", + "filename": "arrayobject.c", + "nloc": 129, + "complexity": 28, + "token_count": 793, + "parameters": [ + "input" + ], + "start_line": 5953, + "end_line": 6091, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 139, + "top_nesting_level": 0 + }, + { + "name": "PyArray_FromArrayAttr", + "long_name": "PyArray_FromArrayAttr( PyObject * op , PyArray_Descr * typecode , PyObject * context)", + "filename": "arrayobject.c", + "nloc": 37, + "complexity": 11, + "token_count": 221, + "parameters": [ + "op", + "typecode", + "context" + ], + "start_line": 6095, + "end_line": 6132, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 38, + "top_nesting_level": 0 + }, + { + "name": "PyArray_FromAny", + "long_name": "PyArray_FromAny( PyObject * op , PyArray_Descr * newtype , int min_depth , int max_depth , int flags , PyObject * context)", + "filename": "arrayobject.c", + "nloc": 63, + "complexity": 20, + "token_count": 383, + "parameters": [ + "op", + "newtype", + "min_depth", + "max_depth", + "flags", + "context" + ], + "start_line": 6138, + "end_line": 6218, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 81, + "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": 6223, + "end_line": 6226, + "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": 6233, + "end_line": 6246, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 14, + "top_nesting_level": 0 + }, + { + "name": "PyArray_CheckFromAny", + "long_name": "PyArray_CheckFromAny( PyObject * op , PyArray_Descr * descr , int min_depth , int max_depth , int requires , PyObject * context)", + "filename": "arrayobject.c", + "nloc": 16, + "complexity": 7, + "token_count": 111, + "parameters": [ + "op", + "descr", + "min_depth", + "max_depth", + "requires", + "context" + ], + "start_line": 6292, + "end_line": 6308, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 17, + "top_nesting_level": 0 + }, + { + "name": "PyArray_EnsureArray", + "long_name": "PyArray_EnsureArray( PyObject * op)", + "filename": "arrayobject.c", + "nloc": 14, + "complexity": 5, + "token_count": 89, + "parameters": [ + "op" + ], + "start_line": 6321, + "end_line": 6337, + "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": 6343, + "end_line": 6431, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 89, + "top_nesting_level": 0 + }, + { + "name": "PyArray_CanCastTo", + "long_name": "PyArray_CanCastTo( PyArray_Descr * from , PyArray_Descr * to)", + "filename": "arrayobject.c", + "nloc": 24, + "complexity": 7, + "token_count": 132, + "parameters": [ + "from", + "to" + ], + "start_line": 6436, + "end_line": 6464, + "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": 6477, + "end_line": 6515, + "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": 6523, + "end_line": 6540, + "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": 6545, + "end_line": 6555, + "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": 6558, + "end_line": 6562, + "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": 6565, + "end_line": 6568, + "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": 6572, + "end_line": 6622, + "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": 6625, + "end_line": 6679, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 55, + "top_nesting_level": 0 + }, + { + "name": "iter_subscript", + "long_name": "iter_subscript( PyArrayIterObject * self , PyObject * ind)", + "filename": "arrayobject.c", + "nloc": 113, + "complexity": 23, + "token_count": 668, + "parameters": [ + "self", + "ind" + ], + "start_line": 6683, + "end_line": 6816, + "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": 6820, + "end_line": 6852, + "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": 6855, + "end_line": 6897, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 43, + "top_nesting_level": 0 + }, + { + "name": "iter_ass_subscript", + "long_name": "iter_ass_subscript( PyArrayIterObject * self , PyObject * ind , PyObject * val)", + "filename": "arrayobject.c", + "nloc": 115, + "complexity": 27, + "token_count": 698, + "parameters": [ + "self", + "ind", + "val" + ], + "start_line": 6900, + "end_line": 7034, + "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": 7047, + "end_line": 7092, + "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": 7097, + "end_line": 7101, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 5, + "top_nesting_level": 0 + }, + { + "name": "iter_coords_get", + "long_name": "iter_coords_get( PyArrayIterObject * self)", + "filename": "arrayobject.c", + "nloc": 15, + "complexity": 3, + "token_count": 91, + "parameters": [ + "self" + ], + "start_line": 7117, + "end_line": 7132, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 16, + "top_nesting_level": 0 + }, + { + "name": "_convert_obj", + "long_name": "_convert_obj( PyObject * obj , PyArrayIterObject ** iter)", + "filename": "arrayobject.c", + "nloc": 16, + "complexity": 5, + "token_count": 106, + "parameters": [ + "obj", + "iter" + ], + "start_line": 7197, + "end_line": 7213, + "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": 7220, + "end_line": 7289, + "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": 7293, + "end_line": 7330, + "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": 7336, + "end_line": 7380, + "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": 98, + "complexity": 21, + "token_count": 662, + "parameters": [ + "mit", + "arr" + ], + "start_line": 7398, + "end_line": 7526, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 129, + "top_nesting_level": 0 + }, + { + "name": "_nonzero_indices", + "long_name": "_nonzero_indices( PyObject * myBool , PyArrayIterObject ** iters)", + "filename": "arrayobject.c", + "nloc": 60, + "complexity": 15, + "token_count": 462, + "parameters": [ + "myBool", + "iters" + ], + "start_line": 7532, + "end_line": 7604, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 73, + "top_nesting_level": 0 + }, + { + "name": "PyArray_MapIterNew", + "long_name": "PyArray_MapIterNew( PyObject * indexobj , int oned , int fancy)", + "filename": "arrayobject.c", + "nloc": 104, + "complexity": 24, + "token_count": 726, + "parameters": [ + "indexobj", + "oned", + "fancy" + ], + "start_line": 7607, + "end_line": 7733, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 127, + "top_nesting_level": 0 + }, + { + "name": "arraymapiter_dealloc", + "long_name": "arraymapiter_dealloc( PyArrayMapIterObject * mit)", + "filename": "arrayobject.c", + "nloc": 10, + "complexity": 2, + "token_count": 62, + "parameters": [ + "mit" + ], + "start_line": 7737, + "end_line": 7746, + "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": 7817, + "end_line": 7866, + "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": 267, + "parameters": [ + "subtype", + "args", + "kwds" + ], + "start_line": 7869, + "end_line": 7914, + "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": 7917, + "end_line": 7936, + "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": 7939, + "end_line": 7946, + "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": 7949, + "end_line": 7959, + "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": 7962, + "end_line": 7972, + "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": 7975, + "end_line": 7978, + "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": 7981, + "end_line": 7993, + "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": 8023, + "end_line": 8030, + "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": 8089, + "end_line": 8098, + "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": 8116, + "end_line": 8138, + "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": 8144, + "end_line": 8154, + "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": 8173, + "end_line": 8181, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 9, + "top_nesting_level": 0 + }, + { + "name": "arraydescr_protocol_typestr_get", + "long_name": "arraydescr_protocol_typestr_get( PyArray_Descr * self)", + "filename": "arrayobject.c", + "nloc": 14, + "complexity": 4, + "token_count": 79, + "parameters": [ + "self" + ], + "start_line": 8184, + "end_line": 8199, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 16, + "top_nesting_level": 0 + }, + { + "name": "arraydescr_typename_get", + "long_name": "arraydescr_typename_get( PyArray_Descr * self)", + "filename": "arrayobject.c", + "nloc": 22, + "complexity": 5, + "token_count": 132, + "parameters": [ + "self" + ], + "start_line": 8202, + "end_line": 8224, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 23, + "top_nesting_level": 0 + }, + { + "name": "arraydescr_base_get", + "long_name": "arraydescr_base_get( PyArray_Descr * self)", + "filename": "arrayobject.c", + "nloc": 9, + "complexity": 2, + "token_count": 52, + "parameters": [ + "self" + ], + "start_line": 8227, + "end_line": 8235, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 9, + "top_nesting_level": 0 + }, + { + "name": "arraydescr_shape_get", + "long_name": "arraydescr_shape_get( PyArray_Descr * self)", + "filename": "arrayobject.c", + "nloc": 8, + "complexity": 2, + "token_count": 51, + "parameters": [ + "self" + ], + "start_line": 8238, + "end_line": 8245, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 8, + "top_nesting_level": 0 + }, + { + "name": "arraydescr_protocol_descr_get", + "long_name": "arraydescr_protocol_descr_get( PyArray_Descr * self)", + "filename": "arrayobject.c", + "nloc": 17, + "complexity": 5, + "token_count": 119, + "parameters": [ + "self" + ], + "start_line": 8248, + "end_line": 8267, + "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": 8274, + "end_line": 8281, + "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": 8284, + "end_line": 8291, + "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": 8294, + "end_line": 8301, + "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": 8349, + "end_line": 8401, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 53, + "top_nesting_level": 0 + }, + { + "name": "arraydescr_reduce", + "long_name": "arraydescr_reduce( PyArray_Descr * self , PyObject * args)", + "filename": "arrayobject.c", + "nloc": 54, + "complexity": 13, + "token_count": 395, + "parameters": [ + "self", + "args" + ], + "start_line": 8407, + "end_line": 8468, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 62, + "top_nesting_level": 0 + }, + { + "name": "arraydescr_setstate", + "long_name": "arraydescr_setstate( PyArray_Descr * self , PyObject * args)", + "filename": "arrayobject.c", + "nloc": 35, + "complexity": 8, + "token_count": 260, + "parameters": [ + "self", + "args" + ], + "start_line": 8476, + "end_line": 8518, + "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": 8538, + "end_line": 8604, + "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": 8615, + "end_line": 8623, + "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": 8638, + "end_line": 8683, + "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": 8686, + "end_line": 8695, + "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": 8698, + "end_line": 8708, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 11, + "top_nesting_level": 0 + }, + { + "name": "descr_length", + "long_name": "descr_length( PyArray_Descr * self)", + "filename": "arrayobject.c", + "nloc": 6, + "complexity": 3, + "token_count": 34, + "parameters": [ + "self" + ], + "start_line": 8715, + "end_line": 8722, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 8, + "top_nesting_level": 0 + }, + { + "name": "descr_subscript", + "long_name": "descr_subscript( PyArray_Descr * self , PyObject * op)", + "filename": "arrayobject.c", + "nloc": 31, + "complexity": 5, + "token_count": 126, + "parameters": [ + "self", + "op" + ], + "start_line": 8725, + "end_line": 8757, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 33, + "top_nesting_level": 0 + } + ], + "methods_before": [ + { + "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": 28, + "end_line": 46, + "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": 67, + "end_line": 95, + "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": 101, + "end_line": 130, + "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": 136, + "end_line": 186, + "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": 209, + "end_line": 240, + "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": 243, + "end_line": 277, + "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": 293, + "end_line": 315, + "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": 321, + "end_line": 342, + "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": 346, + "end_line": 384, + "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": 389, + "end_line": 409, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 21, + "top_nesting_level": 0 + }, + { + "name": "PyArray_PyIntAsIntp", + "long_name": "PyArray_PyIntAsIntp( PyObject * o)", + "filename": "arrayobject.c", + "nloc": 71, + "complexity": 21, + "token_count": 413, + "parameters": [ + "o" + ], + "start_line": 429, + "end_line": 511, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 83, + "top_nesting_level": 0 + }, + { + "name": "PyArray_PyIntAsInt", + "long_name": "PyArray_PyIntAsInt( PyObject * o)", + "filename": "arrayobject.c", + "nloc": 67, + "complexity": 19, + "token_count": 406, + "parameters": [ + "o" + ], + "start_line": 518, + "end_line": 592, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 75, + "top_nesting_level": 0 + }, + { + "name": "index2ptr", + "long_name": "index2ptr( PyArrayObject * mp , intp i)", + "filename": "arrayobject.c", + "nloc": 15, + "complexity": 7, + "token_count": 98, + "parameters": [ + "mp", + "i" + ], + "start_line": 595, + "end_line": 610, + "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": 616, + "end_line": 624, + "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": 640, + "end_line": 720, + "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": 81, + "parameters": [ + "dest", + "src_object" + ], + "start_line": 724, + "end_line": 738, + "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": 751, + "end_line": 777, + "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": 783, + "end_line": 797, + "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": 806, + "end_line": 826, + "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": 103, + "complexity": 17, + "token_count": 616, + "parameters": [ + "data", + "descr", + "base" + ], + "start_line": 835, + "end_line": 951, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 117, + "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": 967, + "end_line": 970, + "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": 980, + "end_line": 1002, + "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": 1016, + "end_line": 1056, + "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": 1071, + "end_line": 1112, + "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": 1119, + "end_line": 1210, + "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": 1216, + "end_line": 1245, + "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": 1248, + "end_line": 1284, + "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": 1293, + "end_line": 1330, + "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": 1337, + "end_line": 1345, + "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": 1348, + "end_line": 1373, + "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": 1376, + "end_line": 1379, + "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": 1383, + "end_line": 1418, + "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": 1424, + "end_line": 1427, + "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": 1433, + "end_line": 1441, + "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": 1447, + "end_line": 1497, + "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": 1504, + "end_line": 1549, + "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": 1553, + "end_line": 1647, + "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": 1650, + "end_line": 1687, + "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": 1699, + "end_line": 1752, + "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": 382, + "parameters": [ + "mit", + "op" + ], + "start_line": 1755, + "end_line": 1815, + "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": 1818, + "end_line": 1845, + "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": 1848, + "end_line": 1867, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 20, + "top_nesting_level": 0 + }, + { + "name": "fancy_indexing_check", + "long_name": "fancy_indexing_check( PyObject * args)", + "filename": "arrayobject.c", + "nloc": 56, + "complexity": 22, + "token_count": 295, + "parameters": [ + "args" + ], + "start_line": 1879, + "end_line": 1941, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 63, + "top_nesting_level": 0 + }, + { + "name": "array_subscript", + "long_name": "array_subscript( PyArrayObject * self , PyObject * op)", + "filename": "arrayobject.c", + "nloc": 103, + "complexity": 28, + "token_count": 666, + "parameters": [ + "self", + "op" + ], + "start_line": 1965, + "end_line": 2083, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 119, + "top_nesting_level": 0 + }, + { + "name": "array_ass_sub", + "long_name": "array_ass_sub( PyArrayObject * self , PyObject * index , PyObject * op)", + "filename": "arrayobject.c", + "nloc": 93, + "complexity": 28, + "token_count": 588, + "parameters": [ + "self", + "index", + "op" + ], + "start_line": 2098, + "end_line": 2203, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 106, + "top_nesting_level": 0 + }, + { + "name": "array_subscript_nice", + "long_name": "array_subscript_nice( PyArrayObject * self , PyObject * op)", + "filename": "arrayobject.c", + "nloc": 4, + "complexity": 1, + "token_count": 27, + "parameters": [ + "self", + "op" + ], + "start_line": 2212, + "end_line": 2215, + "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": 2234, + "end_line": 2246, + "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": 2249, + "end_line": 2264, + "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": 2268, + "end_line": 2277, + "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": 2280, + "end_line": 2291, + "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": 2362, + "end_line": 2395, + "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": 2405, + "end_line": 2444, + "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": 2447, + "end_line": 2470, + "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": 2474, + "end_line": 2497, + "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": 2501, + "end_line": 2508, + "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": 2511, + "end_line": 2518, + "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": 2521, + "end_line": 2529, + "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": 2532, + "end_line": 2535, + "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": 2538, + "end_line": 2541, + "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": 2544, + "end_line": 2547, + "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": 2550, + "end_line": 2553, + "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": 2556, + "end_line": 2559, + "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": 2562, + "end_line": 2565, + "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": 2568, + "end_line": 2571, + "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": 2574, + "end_line": 2577, + "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": 2580, + "end_line": 2583, + "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": 2586, + "end_line": 2589, + "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": 2592, + "end_line": 2595, + "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": 2598, + "end_line": 2601, + "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": 2604, + "end_line": 2607, + "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": 2610, + "end_line": 2613, + "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": 2616, + "end_line": 2619, + "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": 2622, + "end_line": 2625, + "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": 2628, + "end_line": 2631, + "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": 2634, + "end_line": 2637, + "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": 2640, + "end_line": 2643, + "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": 2646, + "end_line": 2649, + "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": 2652, + "end_line": 2655, + "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": 2658, + "end_line": 2661, + "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": 2664, + "end_line": 2667, + "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": 2670, + "end_line": 2673, + "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": 2676, + "end_line": 2679, + "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": 2682, + "end_line": 2685, + "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": 2688, + "end_line": 2691, + "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": 2694, + "end_line": 2698, + "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": 2701, + "end_line": 2705, + "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": 2709, + "end_line": 2727, + "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": 2730, + "end_line": 2747, + "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": 2752, + "end_line": 2767, + "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": 2771, + "end_line": 2797, + "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": 2800, + "end_line": 2825, + "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": 2828, + "end_line": 2850, + "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": 2853, + "end_line": 2875, + "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": 2878, + "end_line": 2900, + "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": 2903, + "end_line": 2907, + "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": 2968, + "end_line": 3008, + "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": 3012, + "end_line": 3033, + "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": 3036, + "end_line": 3048, + "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": 3069, + "end_line": 3116, + "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": 3119, + "end_line": 3155, + "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": 3164, + "end_line": 3181, + "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": 3184, + "end_line": 3196, + "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": 3199, + "end_line": 3211, + "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": 81, + "complexity": 17, + "token_count": 357, + "parameters": [ + "self", + "other", + "cmp_op" + ], + "start_line": 3214, + "end_line": 3311, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 98, + "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": 171, + "parameters": [ + "arr", + "axis", + "flags" + ], + "start_line": 3314, + "end_line": 3343, + "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": 3349, + "end_line": 3369, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 21, + "top_nesting_level": 0 + }, + { + "name": "PyArray_IntpFromSequence", + "long_name": "PyArray_IntpFromSequence( PyObject * seq , intp * vals , int maxvals)", + "filename": "arrayobject.c", + "nloc": 24, + "complexity": 11, + "token_count": 203, + "parameters": [ + "seq", + "vals", + "maxvals" + ], + "start_line": 3377, + "end_line": 3412, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 36, + "top_nesting_level": 0 + }, + { + "name": "_IsContiguous", + "long_name": "_IsContiguous( PyArrayObject * ap)", + "filename": "arrayobject.c", + "nloc": 17, + "complexity": 7, + "token_count": 128, + "parameters": [ + "ap" + ], + "start_line": 3418, + "end_line": 3437, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 20, + "top_nesting_level": 0 + }, + { + "name": "_IsFortranContiguous", + "long_name": "_IsFortranContiguous( PyArrayObject * ap)", + "filename": "arrayobject.c", + "nloc": 17, + "complexity": 7, + "token_count": 126, + "parameters": [ + "ap" + ], + "start_line": 3441, + "end_line": 3459, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 19, + "top_nesting_level": 0 + }, + { + "name": "_IsAligned", + "long_name": "_IsAligned( PyArrayObject * ap)", + "filename": "arrayobject.c", + "nloc": 15, + "complexity": 5, + "token_count": 119, + "parameters": [ + "ap" + ], + "start_line": 3462, + "end_line": 3479, + "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": 3482, + "end_line": 3515, + "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": 3522, + "end_line": 3549, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 28, + "top_nesting_level": 0 + }, + { + "name": "PyArray_CheckStrides", + "long_name": "PyArray_CheckStrides( int elsize , int nd , intp numbytes , intp offset , intp * dims , intp * newstrides)", + "filename": "arrayobject.c", + "nloc": 23, + "complexity": 7, + "token_count": 135, + "parameters": [ + "elsize", + "nd", + "numbytes", + "offset", + "dims", + "newstrides" + ], + "start_line": 3563, + "end_line": 3598, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 36, + "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": 3618, + "end_line": 3642, + "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": 3648, + "end_line": 3670, + "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": 3674, + "end_line": 3716, + "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": 136, + "complexity": 27, + "token_count": 781, + "parameters": [ + "subtype", + "descr", + "nd", + "dims", + "strides", + "data", + "flags", + "obj" + ], + "start_line": 3724, + "end_line": 3889, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 166, + "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": 3898, + "end_line": 3996, + "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": 4002, + "end_line": 4019, + "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": 231, + "parameters": [ + "arr", + "obj" + ], + "start_line": 4023, + "end_line": 4065, + "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": 19, + "token_count": 577, + "parameters": [ + "subtype", + "args", + "kwds" + ], + "start_line": 4068, + "end_line": 4185, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 118, + "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": 4189, + "end_line": 4197, + "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": 4203, + "end_line": 4206, + "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": 4209, + "end_line": 4213, + "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": 4216, + "end_line": 4219, + "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": 4223, + "end_line": 4252, + "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": 4256, + "end_line": 4259, + "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": 37, + "complexity": 7, + "token_count": 239, + "parameters": [ + "self", + "obj" + ], + "start_line": 4262, + "end_line": 4301, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 40, + "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": 4305, + "end_line": 4312, + "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": 4315, + "end_line": 4323, + "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": 4327, + "end_line": 4333, + "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": 4336, + "end_line": 4350, + "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": 4353, + "end_line": 4397, + "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": 4401, + "end_line": 4404, + "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": 4407, + "end_line": 4418, + "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": 4421, + "end_line": 4432, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 12, + "top_nesting_level": 0 + }, + { + "name": "array_typestr_get", + "long_name": "array_typestr_get( PyArrayObject * self)", + "filename": "arrayobject.c", + "nloc": 4, + "complexity": 1, + "token_count": 16, + "parameters": [ + "self" + ], + "start_line": 4438, + "end_line": 4441, + "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": 4444, + "end_line": 4448, + "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": 62, + "complexity": 15, + "token_count": 438, + "parameters": [ + "self", + "arg" + ], + "start_line": 4462, + "end_line": 4548, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 87, + "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": 4551, + "end_line": 4569, + "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": 4572, + "end_line": 4590, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 19, + "top_nesting_level": 0 + }, + { + "name": "array_base_get", + "long_name": "array_base_get( PyArrayObject * self)", + "filename": "arrayobject.c", + "nloc": 11, + "complexity": 2, + "token_count": 41, + "parameters": [ + "self" + ], + "start_line": 4593, + "end_line": 4603, + "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": 4607, + "end_line": 4632, + "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": 191, + "parameters": [ + "self", + "val" + ], + "start_line": 4636, + "end_line": 4669, + "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": 4672, + "end_line": 4705, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 34, + "top_nesting_level": 0 + }, + { + "name": "array_imag_set", + "long_name": "array_imag_set( PyArrayObject * self , PyObject * val)", + "filename": "arrayobject.c", + "nloc": 37, + "complexity": 4, + "token_count": 207, + "parameters": [ + "self", + "val" + ], + "start_line": 4708, + "end_line": 4745, + "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": 4748, + "end_line": 4751, + "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": 348, + "parameters": [ + "self", + "val" + ], + "start_line": 4754, + "end_line": 4804, + "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": 4894, + "end_line": 4901, + "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": 5003, + "end_line": 5036, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 34, + "top_nesting_level": 0 + }, + { + "name": "discover_itemsize", + "long_name": "discover_itemsize( PyObject * s , int nd , int * itemsize)", + "filename": "arrayobject.c", + "nloc": 21, + "complexity": 9, + "token_count": 158, + "parameters": [ + "s", + "nd", + "itemsize" + ], + "start_line": 5039, + "end_line": 5061, + "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": 5068, + "end_line": 5094, + "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": 5100, + "end_line": 5132, + "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": 128, + "complexity": 34, + "token_count": 742, + "parameters": [ + "op", + "minitype", + "max" + ], + "start_line": 5144, + "end_line": 5292, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 149, + "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": 5295, + "end_line": 5318, + "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": 29, + "complexity": 7, + "token_count": 168, + "parameters": [ + "op", + "typecode" + ], + "start_line": 5323, + "end_line": 5357, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 35, + "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": 54, + "complexity": 21, + "token_count": 352, + "parameters": [ + "s", + "typecode", + "fortran", + "min_depth", + "max_depth" + ], + "start_line": 5362, + "end_line": 5425, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 64, + "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": 5432, + "end_line": 5441, + "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": 5447, + "end_line": 5540, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 94, + "top_nesting_level": 0 + }, + { + "name": "PyArray_CastToType", + "long_name": "PyArray_CastToType( PyArrayObject * mp , PyArray_Descr * at , int fortran)", + "filename": "arrayobject.c", + "nloc": 40, + "complexity": 16, + "token_count": 276, + "parameters": [ + "mp", + "at", + "fortran" + ], + "start_line": 5550, + "end_line": 5596, + "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": 5606, + "end_line": 5659, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 54, + "top_nesting_level": 0 + }, + { + "name": "PyArray_FromArray", + "long_name": "PyArray_FromArray( PyArrayObject * arr , PyArray_Descr * newtype , int flags)", + "filename": "arrayobject.c", + "nloc": 114, + "complexity": 33, + "token_count": 676, + "parameters": [ + "arr", + "newtype", + "flags" + ], + "start_line": 5664, + "end_line": 5793, + "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": 501, + "parameters": [ + "str" + ], + "start_line": 5797, + "end_line": 5905, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 109, + "top_nesting_level": 0 + }, + { + "name": "PyArray_FromStructInterface", + "long_name": "PyArray_FromStructInterface( PyObject * input)", + "filename": "arrayobject.c", + "nloc": 38, + "complexity": 6, + "token_count": 234, + "parameters": [ + "input" + ], + "start_line": 5909, + "end_line": 5949, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 41, + "top_nesting_level": 0 + }, + { + "name": "PyArray_FromInterface", + "long_name": "PyArray_FromInterface( PyObject * input)", + "filename": "arrayobject.c", + "nloc": 129, + "complexity": 28, + "token_count": 793, + "parameters": [ + "input" + ], + "start_line": 5953, + "end_line": 6091, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 139, + "top_nesting_level": 0 + }, + { + "name": "PyArray_FromArrayAttr", + "long_name": "PyArray_FromArrayAttr( PyObject * op , PyArray_Descr * typecode , PyObject * context)", + "filename": "arrayobject.c", + "nloc": 37, + "complexity": 11, + "token_count": 221, + "parameters": [ + "op", + "typecode", + "context" + ], + "start_line": 6095, + "end_line": 6132, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 38, + "top_nesting_level": 0 + }, + { + "name": "PyArray_FromAny", + "long_name": "PyArray_FromAny( PyObject * op , PyArray_Descr * newtype , int min_depth , int max_depth , int flags , PyObject * context)", + "filename": "arrayobject.c", + "nloc": 63, + "complexity": 20, + "token_count": 383, + "parameters": [ + "op", + "newtype", + "min_depth", + "max_depth", + "flags", + "context" + ], + "start_line": 6138, + "end_line": 6218, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 81, + "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": 6223, + "end_line": 6226, + "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": 6233, + "end_line": 6246, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 14, + "top_nesting_level": 0 + }, + { + "name": "PyArray_CheckFromAny", + "long_name": "PyArray_CheckFromAny( PyObject * op , PyArray_Descr * descr , int min_depth , int max_depth , int requires , PyObject * context)", + "filename": "arrayobject.c", + "nloc": 16, + "complexity": 7, + "token_count": 111, + "parameters": [ + "op", + "descr", + "min_depth", + "max_depth", + "requires", + "context" + ], + "start_line": 6292, + "end_line": 6308, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 17, + "top_nesting_level": 0 + }, + { + "name": "PyArray_EnsureArray", + "long_name": "PyArray_EnsureArray( PyObject * op)", + "filename": "arrayobject.c", + "nloc": 14, + "complexity": 5, + "token_count": 89, + "parameters": [ + "op" + ], + "start_line": 6321, + "end_line": 6337, + "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": 6343, + "end_line": 6431, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 89, + "top_nesting_level": 0 + }, + { + "name": "PyArray_CanCastTo", + "long_name": "PyArray_CanCastTo( PyArray_Descr * from , PyArray_Descr * to)", + "filename": "arrayobject.c", + "nloc": 24, + "complexity": 7, + "token_count": 132, + "parameters": [ + "from", + "to" + ], + "start_line": 6436, + "end_line": 6464, + "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": 6477, + "end_line": 6515, + "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": 6523, + "end_line": 6540, + "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": 6545, + "end_line": 6555, + "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": 6558, + "end_line": 6562, + "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": 6565, + "end_line": 6568, + "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": 6572, + "end_line": 6622, + "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": 6625, + "end_line": 6679, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 55, + "top_nesting_level": 0 + }, + { + "name": "iter_subscript", + "long_name": "iter_subscript( PyArrayIterObject * self , PyObject * ind)", + "filename": "arrayobject.c", + "nloc": 113, + "complexity": 23, + "token_count": 668, + "parameters": [ + "self", + "ind" + ], + "start_line": 6683, + "end_line": 6816, + "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": 6820, + "end_line": 6852, + "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": 6855, + "end_line": 6897, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 43, + "top_nesting_level": 0 + }, + { + "name": "iter_ass_subscript", + "long_name": "iter_ass_subscript( PyArrayIterObject * self , PyObject * ind , PyObject * val)", + "filename": "arrayobject.c", + "nloc": 115, + "complexity": 27, + "token_count": 698, + "parameters": [ + "self", + "ind", + "val" + ], + "start_line": 6900, + "end_line": 7034, + "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": 7047, + "end_line": 7092, + "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": 7097, + "end_line": 7101, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 5, + "top_nesting_level": 0 + }, + { + "name": "iter_coords_get", + "long_name": "iter_coords_get( PyArrayIterObject * self)", + "filename": "arrayobject.c", + "nloc": 15, + "complexity": 3, + "token_count": 91, + "parameters": [ + "self" + ], + "start_line": 7117, + "end_line": 7132, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 16, + "top_nesting_level": 0 + }, + { + "name": "_convert_obj", + "long_name": "_convert_obj( PyObject * obj , PyArrayIterObject ** iter)", + "filename": "arrayobject.c", + "nloc": 16, + "complexity": 5, + "token_count": 106, + "parameters": [ + "obj", + "iter" + ], + "start_line": 7197, + "end_line": 7213, + "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": 7220, + "end_line": 7289, + "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": 7293, + "end_line": 7330, + "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": 7336, + "end_line": 7380, + "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": 98, + "complexity": 21, + "token_count": 662, + "parameters": [ + "mit", + "arr" + ], + "start_line": 7398, + "end_line": 7526, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 129, + "top_nesting_level": 0 + }, + { + "name": "_nonzero_indices", + "long_name": "_nonzero_indices( PyObject * myBool , PyArrayIterObject ** iters)", + "filename": "arrayobject.c", + "nloc": 60, + "complexity": 15, + "token_count": 462, + "parameters": [ + "myBool", + "iters" + ], + "start_line": 7532, + "end_line": 7604, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 73, + "top_nesting_level": 0 + }, + { + "name": "PyArray_MapIterNew", + "long_name": "PyArray_MapIterNew( PyObject * indexobj , int oned , int fancy)", + "filename": "arrayobject.c", + "nloc": 104, + "complexity": 24, + "token_count": 726, + "parameters": [ + "indexobj", + "oned", + "fancy" + ], + "start_line": 7607, + "end_line": 7733, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 127, + "top_nesting_level": 0 + }, + { + "name": "arraymapiter_dealloc", + "long_name": "arraymapiter_dealloc( PyArrayMapIterObject * mit)", + "filename": "arrayobject.c", + "nloc": 10, + "complexity": 2, + "token_count": 62, + "parameters": [ + "mit" + ], + "start_line": 7737, + "end_line": 7746, + "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": 7817, + "end_line": 7866, + "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": 267, + "parameters": [ + "subtype", + "args", + "kwds" + ], + "start_line": 7869, + "end_line": 7914, + "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": 7917, + "end_line": 7936, + "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": 7939, + "end_line": 7946, + "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": 7949, + "end_line": 7959, + "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": 7962, + "end_line": 7972, + "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": 7975, + "end_line": 7978, + "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": 7981, + "end_line": 7993, + "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": 8023, + "end_line": 8030, + "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": 8089, + "end_line": 8098, + "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": 8116, + "end_line": 8138, + "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": 8144, + "end_line": 8154, + "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": 8173, + "end_line": 8181, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 9, + "top_nesting_level": 0 + }, + { + "name": "arraydescr_protocol_typestr_get", + "long_name": "arraydescr_protocol_typestr_get( PyArray_Descr * self)", + "filename": "arrayobject.c", + "nloc": 14, + "complexity": 4, + "token_count": 79, + "parameters": [ + "self" + ], + "start_line": 8184, + "end_line": 8199, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 16, + "top_nesting_level": 0 + }, + { + "name": "arraydescr_typename_get", + "long_name": "arraydescr_typename_get( PyArray_Descr * self)", + "filename": "arrayobject.c", + "nloc": 22, + "complexity": 5, + "token_count": 132, + "parameters": [ + "self" + ], + "start_line": 8202, + "end_line": 8224, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 23, + "top_nesting_level": 0 + }, + { + "name": "arraydescr_base_get", + "long_name": "arraydescr_base_get( PyArray_Descr * self)", + "filename": "arrayobject.c", + "nloc": 9, + "complexity": 2, + "token_count": 52, + "parameters": [ + "self" + ], + "start_line": 8227, + "end_line": 8235, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 9, + "top_nesting_level": 0 + }, + { + "name": "arraydescr_shape_get", + "long_name": "arraydescr_shape_get( PyArray_Descr * self)", + "filename": "arrayobject.c", + "nloc": 8, + "complexity": 2, + "token_count": 51, + "parameters": [ + "self" + ], + "start_line": 8238, + "end_line": 8245, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 8, + "top_nesting_level": 0 + }, + { + "name": "arraydescr_protocol_descr_get", + "long_name": "arraydescr_protocol_descr_get( PyArray_Descr * self)", + "filename": "arrayobject.c", + "nloc": 17, + "complexity": 5, + "token_count": 119, + "parameters": [ + "self" + ], + "start_line": 8248, + "end_line": 8267, + "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": 8274, + "end_line": 8281, + "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": 8284, + "end_line": 8291, + "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": 8294, + "end_line": 8301, + "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": 8349, + "end_line": 8401, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 53, + "top_nesting_level": 0 + }, + { + "name": "arraydescr_reduce", + "long_name": "arraydescr_reduce( PyArray_Descr * self , PyObject * args)", + "filename": "arrayobject.c", + "nloc": 54, + "complexity": 13, + "token_count": 395, + "parameters": [ + "self", + "args" + ], + "start_line": 8407, + "end_line": 8468, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 62, + "top_nesting_level": 0 + }, + { + "name": "arraydescr_setstate", + "long_name": "arraydescr_setstate( PyArray_Descr * self , PyObject * args)", + "filename": "arrayobject.c", + "nloc": 35, + "complexity": 8, + "token_count": 260, + "parameters": [ + "self", + "args" + ], + "start_line": 8476, + "end_line": 8518, + "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": 8538, + "end_line": 8604, + "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": 8615, + "end_line": 8623, + "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": 8638, + "end_line": 8683, + "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": 8686, + "end_line": 8695, + "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": 8698, + "end_line": 8708, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 11, + "top_nesting_level": 0 + }, + { + "name": "descr_length", + "long_name": "descr_length( PyArray_Descr * self)", + "filename": "arrayobject.c", + "nloc": 6, + "complexity": 3, + "token_count": 34, + "parameters": [ + "self" + ], + "start_line": 8715, + "end_line": 8722, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 8, + "top_nesting_level": 0 + }, + { + "name": "descr_subscript", + "long_name": "descr_subscript( PyArray_Descr * self , PyObject * op)", + "filename": "arrayobject.c", + "nloc": 31, + "complexity": 5, + "token_count": 126, + "parameters": [ + "self", + "op" + ], + "start_line": 8725, + "end_line": 8757, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 33, + "top_nesting_level": 0 + } + ], + "changed_methods": [ + { + "name": "PyArray_Scalar", + "long_name": "PyArray_Scalar( * data , PyArray_Descr * descr , PyObject * base)", + "filename": "arrayobject.c", + "nloc": 103, + "complexity": 17, + "token_count": 616, + "parameters": [ + "data", + "descr", + "base" + ], + "start_line": 835, + "end_line": 951, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 117, + "top_nesting_level": 0 + } + ], + "nloc": 6981, + "complexity": 1495, + "token_count": 40911, + "diff_parsed": { + "added": [ + "\t\t\tint alloc=0;" + ], + "deleted": [ + "\t\t\tint alloc=1;" + ] + } + }, + { + "old_path": "numpy/core/src/multiarraymodule.c", + "new_path": "numpy/core/src/multiarraymodule.c", + "filename": "multiarraymodule.c", + "extension": "c", + "change_type": "MODIFY", + "diff": "@@ -1411,6 +1411,75 @@ PyArray_Repeat(PyArrayObject *aop, PyObject *op, int axis)\n \treturn NULL;\n }\n \n+\n+static int\n+_signbit_set(PyArrayObject *arr)\n+{\n+\tstatic char bitmask = 0x80;\n+\tchar *ptr; /* points to the byte to test */\n+\tchar byteorder;\n+\tint elsize;\n+\n+\tif (arr==NULL) return 0;\n+\telsize = arr->descr->elsize;\n+\tbyteorder = arr->descr->byteorder;\n+\tptr = arr->data;\n+\tif (elsize > 1 && \\\n+\t (byteorder == PyArray_LITTLE ||\t\\\n+\t (byteorder == PyArray_NATIVE &&\n+\t PyArray_ISNBO(PyArray_LITTLE))))\n+\t\tptr += elsize-1;\n+\t\n+\treturn ((*ptr & bitmask) != 0);\t\n+}\n+\n+\n+/*OBJECT_API*/\n+static char\n+PyArray_ScalarKind(int typenum, PyArrayObject **arr) \n+{\n+\tif (PyTypeNum_ISSIGNED(typenum)) {\n+\t\tif (_signbit_set(*arr)) return UFUNC_INTNEG_SCALAR;\n+\t\telse return UFUNC_INTPOS_SCALAR;\n+\t}\n+\tif (PyTypeNum_ISFLOAT(typenum)) return UFUNC_FLOAT_SCALAR;\n+\tif (PyTypeNum_ISUNSIGNED(typenum)) return UFUNC_INTPOS_SCALAR;\n+\tif (PyTypeNum_ISCOMPLEX(typenum)) return UFUNC_COMPLEX_SCALAR;\n+\tif (PyTypeNum_ISBOOL(typenum)) return UFUNC_BOOL_SCALAR;\n+\n+\treturn UFUNC_OBJECT_SCALAR;\n+}\n+\n+\n+/*OBJECT_API*/\n+static int \n+PyArray_CanCoerceScalar(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+\n+/* This needs to change to allow scalars of a different \"kind\" to alter the input type\n+ */\n+\n /*OBJECT_API*/\n static PyArrayObject **\n PyArray_ConvertToCommonType(PyObject *op, int *retn)\n@@ -1420,6 +1489,7 @@ PyArray_ConvertToCommonType(PyObject *op, int *retn)\n \tPyObject *otmp;\n \tPyArray_Descr *intype=NULL, *stype=NULL;\n \tPyArray_Descr *newtype=NULL;\n+\tchar scalarkind;\n \n \t\n \t*retn = n = PySequence_Length(op);\n@@ -1443,6 +1513,13 @@ PyArray_ConvertToCommonType(PyObject *op, int *retn)\n \t\t\tnewtype = PyArray_DescrFromObject(otmp, stype);\n \t\t\tPy_XDECREF(stype);\n \t\t\tstype = newtype;\n+\t\t\tscalarkind = PyArray_ScalarKind(newtype->type_num, NULL);\n+\t\t\tif (intype && !PyArray_CanCoerceScalar(newtype->type_num,\n+\t\t\t\t\t\t\t intype->type_num, \n+\t\t\t\t\t\t\t scalarkind)) {\n+\t\t\t\tPy_XDECREF(intype);\n+\t\t\t\tintype = stype;\n+\t\t\t}\n \t\t\tmps[i] = (PyArrayObject *)Py_None;\n \t\t\tPy_INCREF(Py_None);\n \t\t}\n@@ -3724,7 +3801,7 @@ _convert_from_dict(PyObject *obj, int align)\n \t\t/* Insert into dictionary */\n \t\tif (PyDict_GetItem(fields, name) != NULL) {\n \t\t\tPyErr_SetString(PyExc_ValueError,\n-\t\t\t\t\t\"two fields with the same name\");\n+\t\t\t\t\t\"name already used as a name or title\");\n \t\t\tret = PY_FAIL;\n \t\t}\n \t\tPyDict_SetItem(fields, name, tup);\n@@ -3732,7 +3809,8 @@ _convert_from_dict(PyObject *obj, int align)\n \t\tif (len == 3) {\n \t\t\tif (PyDict_GetItem(fields, item) != NULL) {\n \t\t\t\tPyErr_SetString(PyExc_ValueError, \n-\t\t\t\t\t\t\"titles cannot be the same as names\");\n+\t\t\t\t\t\t\"title already used as a name or \" \\\n+\t\t\t\t\t\t\" title.\");\n \t\t\t\tret=PY_FAIL;\n \t\t\t}\n \t\t\telse {\n", + "added_lines": 80, + "deleted_lines": 2, + "source_code": "\n/*\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 extensively for numpy 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, \"dtype\");\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, \"dtype\",\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)) == 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\tif (mps[i]->ob_type != subtype) {\n\t\t\tprior2 = PyArray_GetPriority((PyObject *)(mps[i]), 0.0);\n\t\t\tif (prior2 > prior1) {\n\t\t\t\tprior1 = prior2;\n\t\t\t\tsubtype = mps[i]->ob_type;\n\t\t\t\tret = mps[i];\n\t\t\t}\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; idescr->elsize;\n\tbyteorder = arr->descr->byteorder;\n\tptr = arr->data;\n\tif (elsize > 1 && \\\n\t (byteorder == PyArray_LITTLE ||\t\\\n\t (byteorder == PyArray_NATIVE &&\n\t PyArray_ISNBO(PyArray_LITTLE))))\n\t\tptr += elsize-1;\n\t\n\treturn ((*ptr & bitmask) != 0);\t\n}\n\n\n/*OBJECT_API*/\nstatic char\nPyArray_ScalarKind(int typenum, PyArrayObject **arr) \n{\n\tif (PyTypeNum_ISSIGNED(typenum)) {\n\t\tif (_signbit_set(*arr)) return UFUNC_INTNEG_SCALAR;\n\t\telse return UFUNC_INTPOS_SCALAR;\n\t}\n\tif (PyTypeNum_ISFLOAT(typenum)) return UFUNC_FLOAT_SCALAR;\n\tif (PyTypeNum_ISUNSIGNED(typenum)) return UFUNC_INTPOS_SCALAR;\n\tif (PyTypeNum_ISCOMPLEX(typenum)) return UFUNC_COMPLEX_SCALAR;\n\tif (PyTypeNum_ISBOOL(typenum)) return UFUNC_BOOL_SCALAR;\n\n\treturn UFUNC_OBJECT_SCALAR;\n}\n\n\n/*OBJECT_API*/\nstatic int \nPyArray_CanCoerceScalar(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\n/* This needs to change to allow scalars of a different \"kind\" to alter the input type\n */\n\n/*OBJECT_API*/\nstatic PyArrayObject **\nPyArray_ConvertToCommonType(PyObject *op, int *retn)\n{\n\tint i, n, allscalars=0; \n\tPyArrayObject **mps=NULL;\n\tPyObject *otmp;\n\tPyArray_Descr *intype=NULL, *stype=NULL;\n\tPyArray_Descr *newtype=NULL;\n\tchar scalarkind;\n\n\t\n\t*retn = n = PySequence_Length(op);\n\tif (PyErr_Occurred()) {*retn = 0; return NULL;}\n\t\n\tmps = (PyArrayObject **)PyDataMem_NEW(n*sizeof(PyArrayObject *));\n\tif (mps == NULL) {\n\t\t*retn = 0;\n\t\treturn (void*)PyErr_NoMemory();\n\t}\n\t\n\tfor(i=0; itype_num, NULL);\n\t\t\tif (intype && !PyArray_CanCoerceScalar(newtype->type_num,\n\t\t\t\t\t\t\t intype->type_num, \n\t\t\t\t\t\t\t scalarkind)) {\n\t\t\t\tPy_XDECREF(intype);\n\t\t\t\tintype = stype;\n\t\t\t}\n\t\t\tmps[i] = (PyArrayObject *)Py_None;\n\t\t\tPy_INCREF(Py_None);\n\t\t}\n\t\tPy_XDECREF(otmp);\n\t}\n\tif (intype==NULL) { /* all scalars */\n\t\tallscalars = 1;\n\t\tintype = stype;\n\t\tPy_INCREF(intype);\n\t\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, NULL);\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 Make a new empty array, of the passed size, of a type that takes the\n priority of ap1 and ap2 into account.\n */\nstatic PyArrayObject *\nnew_array_for_sum(PyArrayObject *ap1, PyArrayObject *ap2,\n\t\t int nd, intp dimensions[], int typenum)\n{\n\tPyArrayObject *ret;\n\tPyTypeObject *subtype;\n\tdouble prior1, prior2;\n\t/* Need to choose an output array that can hold a sum \n\t -- use priority to determine which subtype.\n\t */\n\tif (ap2->ob_type != ap1->ob_type) {\n\t\tprior2 = PyArray_GetPriority((PyObject *)ap2, 0.0);\n\t\tprior1 = PyArray_GetPriority((PyObject *)ap1, 0.0);\n\n\t\tsubtype = (prior2 > prior1 ? ap2->ob_type : ap1->ob_type);\n\t} else {\n\t\tprior1 = prior2 = 0.0;\n\t\tsubtype = ap1->ob_type;\n\t}\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\treturn ret;\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\tPyArrayIterObject *it1, *it2;\n\tintp i, j, l;\n\tint typenum, nd;\n\tintp is1, is2, os;\n\tchar *op;\n\tintp dimensions[MAX_DIMS];\n\tPyArray_DotFunc *dot;\n\tPyArray_Descr *typec;\n\t\n\ttypenum = PyArray_ObjectType(op1, 0); \n\ttypenum = PyArray_ObjectType(op2, typenum);\n\n\ttypec = PyArray_DescrFromType(typenum);\n\tPy_INCREF(typec);\n\tap1 = (PyArrayObject *)PyArray_FromAny(op1, typec, 0, 0, \n\t\t\t\t\t BEHAVED_FLAGS, NULL);\n\tif (ap1 == NULL) {Py_DECREF(typec); return NULL;}\n\tap2 = (PyArrayObject *)PyArray_FromAny(op2, typec, 0, 0,\n\t\t\t\t\t BEHAVED_FLAGS, NULL);\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\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\tret = new_array_for_sum(ap1, ap2, nd, dimensions, typenum);\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\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\tit1 = (PyArrayIterObject *)\\\n\t\tPyArray_IterAllButAxis((PyObject *)ap1, ap1->nd-1);\n\tit2 = (PyArrayIterObject *)\\\n\t\tPyArray_IterAllButAxis((PyObject *)ap2, ap2->nd-1);\n\n\twhile(1) {\n\t\twhile(it2->index < it2->size) {\n\t\t\tdot(it1->dataptr, is1, it2->dataptr, is2, op, l, ret);\n\t\t\top += os;\n\t\t\tPyArray_ITER_NEXT(it2);\n\t\t}\n\t\tPyArray_ITER_NEXT(it1);\n\t\tif (it1->index >= it1->size) break;\n\t\tPyArray_ITER_RESET(it2);\n\t}\n\tPy_DECREF(it1);\n\tPy_DECREF(it2);\n\n\tif (PyErr_Occurred()) goto fail;\n\t\t\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/* just like inner product but does the swapaxes stuff on the fly */\n/*MULTIARRAY_API\n Numeric.matrixproduct(a,v)\n*/\nstatic PyObject *\nPyArray_MatrixProduct(PyObject *op1, PyObject *op2) \n{\n\tPyArrayObject *ap1, *ap2, *ret=NULL;\n\tPyArrayIterObject *it1, *it2;\n\tintp i, j, l;\n\tint typenum, nd;\n\tintp is1, is2, os;\n\tchar *op;\n\tintp dimensions[MAX_DIMS];\n\tPyArray_DotFunc *dot;\n\tintp matchDim;\n\tPyArray_Descr *typec;\n\n\ttypenum = PyArray_ObjectType(op1, 0); \n\ttypenum = PyArray_ObjectType(op2, typenum);\t\n\t\n\ttypec = PyArray_DescrFromType(typenum);\n\tPy_INCREF(typec);\n\tap1 = (PyArrayObject *)PyArray_FromAny(op1, typec, 0, 0, \n\t\t\t\t\t BEHAVED_FLAGS, NULL);\n\tif (ap1 == NULL) {Py_DECREF(typec); return NULL;}\n\tap2 = (PyArrayObject *)PyArray_FromAny(op2, typec, 0, 0,\n\t\t\t\t\t BEHAVED_FLAGS, NULL);\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\tif (ap2->nd > 1) {\n\t\tmatchDim = ap2->nd - 2;\n\t}\n\telse {\n\t\tmatchDim = 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\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; istrides[ap1->nd-1]; is2 = ap2->strides[matchDim];\n\n /* Choose which subtype to return */\n\tret = new_array_for_sum(ap1, ap2, nd, dimensions, typenum);\n\tif (ret == NULL) goto fail;\n\n\t/* Ensure that multiarray.dot([],[]) -> 0 */\n\tmemset(PyArray_DATA(ret), 0, PyArray_ITEMSIZE(ret));\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\top = ret->data; os = ret->descr->elsize;\n\n\tit1 = (PyArrayIterObject *)\\\n\t\tPyArray_IterAllButAxis((PyObject *)ap1, ap1->nd-1);\n\tit2 = (PyArrayIterObject *)\\\n\t\tPyArray_IterAllButAxis((PyObject *)ap2, matchDim);\n\n\twhile(1) {\n\t\twhile(it2->index < it2->size) {\n\t\t\tdot(it1->dataptr, is1, it2->dataptr, is2, op, l, ret);\n\t\t\top += os;\n\t\t\tPyArray_ITER_NEXT(it2);\n\t\t}\n\t\tPyArray_ITER_NEXT(it1);\n\t\tif (it1->index >= it1->size) break;\n\t\tPyArray_ITER_RESET(it2);\n\t}\n\tPy_DECREF(it1);\n\tPy_DECREF(it2);\n\tif (PyErr_Occurred()) goto fail; /* only for OBJECT arrays */\n\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/*MULTIARRAY_API\n Fast Copy and Transpose\n*/\nstatic PyObject *\nPyArray_CopyAndTranspose(PyObject *op) \n{\n\tPyObject *ret, *arr;\n\tint nd;\n\tintp dims[2];\n\tintp i,j;\n\tint elsize, str2;\n\tchar *iptr;\n\tchar *optr;\n\n\t/* make sure it is well-behaved */\n\tarr = PyArray_FromAny(op, NULL, 0, 0, CARRAY_FLAGS, NULL);\n\tnd = PyArray_NDIM(arr);\n\tif (nd == 1) { /* we will give in to old behavior */\n\t\tret = PyArray_Copy((PyArrayObject *)arr);\n\t\tPy_DECREF(arr);\n\t\treturn ret;\t\t\n\t}\n\telse if (nd != 2) {\n\t\tPy_DECREF(arr);\n\t\tPyErr_SetString(PyExc_ValueError, \n\t\t\t\t\"only 2-d arrays are allowed\");\n\t\treturn NULL;\n\t}\n\n\t/* Now construct output array */\n\tdims[0] = PyArray_DIM(arr,1);\n\tdims[1] = PyArray_DIM(arr,0);\n\telsize = PyArray_ITEMSIZE(arr);\n\t\n\tPy_INCREF(PyArray_DESCR(arr));\n\tret = PyArray_NewFromDescr(arr->ob_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\tret = new_array_for_sum(ap1, ap2, 1, &length, typenum);\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, NULL);\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\tif (type->type_num == PyArray_UNICODE)\n\t\t\ttype->elsize = itemsize << 2; \n\t\telse\n\t\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\tif (type->hasobject) newdescr->hasobject = 1;\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 int hasobject=0;\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; ihasobject)\n hasobject = 1;\n\t\ttup = PyTuple_New(2);\n\t\tPyTuple_SET_ITEM(tup, 0, (PyObject *)conv);\n\t\tPyTuple_SET_ITEM(tup, 1, PyInt_FromLong((long) totalsize));\n\t\ttotalsize += conv->elsize;\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 new->hasobject=hasobject;\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 int hasobject=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; ihasobject)\n\t\t\thasobject=1;\t\t\t\n\t\tPyTuple_SET_ITEM(tup, 0, (PyObject *)conv);\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\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\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 new->hasobject=hasobject;\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 int hasobject=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\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\tPyTuple_SET_ITEM(tup, 1, PyInt_FromLong(totalsize));\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\tif (PyDict_GetItem(fields, name) != NULL) {\n\t\t\tPyErr_SetString(PyExc_ValueError,\n\t\t\t\t\t\"name already used as a name or title\");\n\t\t\tret = PY_FAIL;\n\t\t}\n\t\tPyDict_SetItem(fields, name, tup);\n\t\tPy_DECREF(name);\n\t\tif (len == 3) {\n\t\t\tif (PyDict_GetItem(fields, item) != NULL) {\n\t\t\t\tPyErr_SetString(PyExc_ValueError, \n\t\t\t\t\t\t\"title already used as a name or \" \\\n\t\t\t\t\t\t\" title.\");\n\t\t\t\tret=PY_FAIL;\n\t\t\t}\n\t\t\telse {\n\t\t\t\tPyDict_SetItem(fields, item, tup);\n\t\t\t}\n\t\t}\n\t\tPy_DECREF(tup);\n\t\tif ((ret == PY_FAIL) || (newdescr->elsize == 0)) goto fail;\n if (!hasobject && newdescr->hasobject)\n hasobject = 1;\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 new->hasobject=hasobject;\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 == '|' || (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\tint i;\n\t\t\telsize = atoi(type+1);\n\t\t\t/* check for commas present */\n\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\nstatic PyObject *\n_prepend_ones(PyArrayObject *arr, int nd, int ndmin)\n{\n\tintp newdims[MAX_DIMS];\n\tintp newstrides[MAX_DIMS];\n\tint i,k,num;\n\tPyObject *ret;\n\n\tnum = ndmin-nd;\n\tfor (i=0; idescr->elsize;\n\t}\n\tfor (i=num;idimensions[k];\n\t\tnewstrides[i] = arr->strides[k];\n\t}\n\tPy_INCREF(arr->descr);\n\tret = PyArray_NewFromDescr(arr->ob_type, arr->descr, ndmin,\n\t\t\t\t newdims, newstrides, arr->data, arr->flags,\n\t\t\t\t (PyObject *)arr);\n\t/* steals a reference to arr --- so don't increment\n\t here */\n\tPyArray_BASE(ret) = (PyObject *)arr;\n\treturn ret;\n}\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,ndmin=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\"\\\n\t\"The ndmin argument specifies how many dimensions the returned\\n\"\\\n\t\"array should have as a minimum. 1's will be pre-pended to the\\n\"\\\n\t\"shape as needed to meet this requirement.\";\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\t\t\t \"ndmin\", NULL};\n Bool subok=FALSE;\n\tBool copy=TRUE;\n\tint ndmin=0, nd;\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&i\", 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\t\t\t\t&ndmin)) \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\tret = op;\n\t\t\t\tgoto finish;\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\tgoto finish;\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\tret = op;\n\t\t\t\tgoto finish;\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\tgoto finish;\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_CheckFromAny(op, type, 0, 0, flags, NULL)) == NULL) \n\t\treturn NULL;\n\n finish:\n\n\tif ((nd=PyArray_NDIM(ret)) >= ndmin) return ret;\n\t/* create a new array from the same data with ones in the shape */\n\t/* steals a reference to ret */\n\treturn _prepend_ones((PyArrayObject *)ret, nd, ndmin);\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(dtype,obj) will return a new scalar array of the given type initialized with obj. Mainly for pickle support. The dtype must be a valid data-type descriptor. If dtype 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[] = {\"dtype\",\"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}; /* XXX ? */\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\nstatic int\n_skip_sep(char **ptr, char *sep)\n{\n\tchar *a;\n\tint n;\n\tn = strlen(sep);\n\ta = *ptr;\n\twhile(*a != '\\0' && (strncmp(a, sep, n) != 0))\n\t\ta++;\n\tif (*a == '\\0') return -1;\n\t*ptr = a+strlen(sep);\n\treturn 0;\n}\n\n/* steals a reference to dtype -- accepts NULL */\n/*OBJECT_API*/\nstatic PyObject *\nPyArray_FromString(char *data, intp slen, PyArray_Descr *dtype, \n\t\t intp n, char *sep)\n{\n\tint itemsize;\n\tPyArrayObject *ret;\n\tBool binary;\n\n\tif (dtype == NULL)\n\t\tdtype=PyArray_DescrFromType(PyArray_LONG);\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\n\tbinary = ((sep == NULL) || (strlen(sep) == 0));\t\n\n\tif (binary) {\n\t\tif (dtype == &OBJECT_Descr) {\n\t\t\tPyErr_SetString(PyExc_ValueError, \n\t\t\t\t\t\"Cannot create an object array from\"\\\n\t\t\t\t\t\" a binary string\");\n\t\t\tPy_DECREF(dtype);\n\t\t\treturn NULL;\n\t\t}\t\t\n\t\tif (n < 0 ) {\n\t\t\tif (slen % itemsize != 0) {\n\t\t\t\tPyErr_SetString(PyExc_ValueError, \n\t\t\t\t\t\t\"string size must be a \"\\\n\t\t\t\t\t\t\"multiple of element size\");\n\t\t\t\tPy_DECREF(dtype);\n\t\t\t\treturn NULL;\n\t\t\t}\n\t\t\tn = slen/itemsize;\n\t\t} else {\n\t\t\tif (slen < n*itemsize) {\n\t\t\t\tPyErr_SetString(PyExc_ValueError, \n\t\t\t\t\t\t\"string is smaller than \" \\\n\t\t\t\t\t\t\"requested size\");\n\t\t\t\tPy_DECREF(dtype);\n\t\t\t\treturn NULL;\n\t\t\t}\n\t\t}\n\t\n\t\tif ((ret = (PyArrayObject *)\\\n\t\t PyArray_NewFromDescr(&PyArray_Type, dtype,\n\t\t\t\t\t 1, &n, NULL, NULL,\n\t\t\t\t\t 0, NULL)) == NULL)\n\t\t\treturn NULL;\t\t\n\t\tmemcpy(ret->data, data, n*dtype->elsize);\n\t\treturn (PyObject *)ret;\n\t}\n\telse { /* read from character-based string */\n\t\tchar *ptr;\t\t\n\t\tPyArray_FromStrFunc *fromstr;\n\t\tchar *dptr;\n\t\tintp nread=0;\n\t\tintp index;\n\n\t\tfromstr = dtype->f->fromstr;\n\t\tif (fromstr == 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 strings for given \"\t\\\n\t\t\t\t\t\"array type\");\n\t\t\tPy_DECREF(dtype);\n\t\t\treturn NULL;\n\t\t}\n\n\t\tif (n!=-1) {\n\t\t\tret = (PyArrayObject *) \\\n\t\t\t\tPyArray_NewFromDescr(&PyArray_Type,\n\t\t\t\t\t\t dtype, 1, &n, NULL,\n\t\t\t\t\t\t NULL, 0, NULL);\n\t\t\tif (ret == NULL) return NULL;\n\t\t\tptr = data;\n\t\t\tdptr = ret->data;\n\t\t\tfor (index=0; index < n; index++) {\n\t\t\t\tif (fromstr(ptr, dptr, &ptr, ret) < 0)\n\t\t\t\t\tbreak;\n\t\t\t\tnread += 1;\n\t\t\t\tdptr += dtype->elsize;\n\t\t\t\tif (_skip_sep(&ptr, sep) < 0) \n\t\t\t\t\tbreak;\n\t\t\t}\n\t\t\tif (nread < n) {\n\t\t\t\tfprintf(stderr, \"%ld items requested but \"\\\n\t\t\t\t\t\"only %ld read\\n\", \n\t\t\t\t\t(long) n, (long) nread);\n\t\t\t\tret->data = \\\n\t\t\t\t\tPyDataMem_RENEW(ret->data, \n\t\t\t\t\t\t\tnread *\t\t\\\n\t\t\t\t\t\t\tret->descr->elsize);\n\t\t\t\tPyArray_DIM(ret,0) = nread;\n\t\t\t}\n\t\t}\n\t\telse {\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\t\t\tchar *end;\n\t\t\tint val;\n\n\t\t\tret = (PyArrayObject *)\\\n\t\t\t\tPyArray_NewFromDescr(&PyArray_Type, \n\t\t\t\t\t\t dtype,\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 (ret==NULL) return NULL;\n\t\t\ttotalbytes = bytes = size * dtype->elsize;\n\t\t\tdptr = ret->data;\n\t\t\tptr = data;\n\t\t\tend = data+slen;\n\t\t\twhile (ptr < end) {\n\t\t\t\tval = fromstr(ptr, dptr, &ptr, ret);\n\t\t\t\tif (val < 0) break;\n\t\t\t\tnread += 1;\n\t\t\t\tval = _skip_sep(&ptr, sep);\n\t\t\t\tif (val < 0) break;\n\t\t\t\tthisbuf += 1;\n\t\t\t\tdptr += dtype->elsize;\n\t\t\t\tif (thisbuf == size) {\n\t\t\t\t\ttotalbytes += bytes;\n\t\t\t\t\tret->data = PyDataMem_RENEW(ret->data, \n\t\t\t\t\t\t\t\t totalbytes);\n\t\t\t\t\tdptr = ret->data + \\\n\t\t\t\t\t\t(totalbytes - bytes);\n\t\t\t\t\tthisbuf = 0;\n\t\t\t\t}\n\t\t\t}\n\t\t\tret->data = PyDataMem_RENEW(ret->data, \n\t\t\t\t\t\t nread*ret->descr->elsize);\n\t\t\tPyArray_DIM(ret,0) = nread;\n#undef _FILEBUFNUM\n\t\t}\n\t}\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\tchar *sep=NULL;\n\tint s;\n\tstatic char *kwlist[] = {\"string\", \"dtype\", \"count\", \"sep\", NULL};\n\tPyArray_Descr *descr=NULL;\n\n\tif (!PyArg_ParseTupleAndKeywords(args, keywds, \"s#|O&Ls\", 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, &sep)) {\n\t\treturn NULL;\n\t}\n\n\treturn PyArray_FromString(data, (intp)s, descr, (intp)nin, sep);\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\tPy_DECREF(typecode);\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\tPy_DECREF(typecode);\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\tPy_DECREF(typecode);\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 platform-independent method of persistence. But it can be \\n\"\\\n\t\" useful to 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_BYTES(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_BYTES(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[] = \n\"arange([start,] stop[, step,], dtype=None)\\n\\n\"\n\"For integer arguments, just like range() except it returns an array whose type can\\n\"\n\"be specified by the keyword argument dtype.\\n\\n\"\n\"If dtype is not specified, the type of the result is deduced from the type of the\\n\"\n\"arguments.\\n\\n\"\n\"For floating point arguments, the length of the result is ceil((stop - start)/step).\\n\"\n\"This rule may result in the last element of the result be greater than stop.\";\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_DescrConverter2,\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/*MULTIARRAY_API\n GetNDArrayCVersion\n*/\nstatic unsigned int\nPyArray_GetNDArrayCVersion(void)\n{\n\treturn (unsigned int)NDARRAY_VERSION;\n}\n\nstatic char \ndoc__get_ndarray_c_version[] = \"_get_ndarray_c_version() gets the compile time NDARRAY_VERSION number\";\n\nstatic PyObject *\narray__get_ndarray_c_version(PyObject *dummy, PyObject *args, PyObject *kwds) \n{\n\tstatic char *kwlist[] = {NULL};\n\tif(!PyArg_ParseTupleAndKeywords(args, kwds, \"\", kwlist )) return NULL;\n\t\n\treturn PyInt_FromLong( (long) PyArray_GetNDArrayCVersion() );\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, NULL);\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{\"_get_ndarray_c_version\", (PyCFunction)array__get_ndarray_c_version, \n\t METH_VARARGS|METH_KEYWORDS, doc__get_ndarray_c_version},\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, \"dtype\", (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\tif (!PyErr_Occurred()) {\n\t\tPyErr_SetString(PyExc_RuntimeError, \n\t\t\t\t\"cannot load multiarray module.\");\n\t}\n\treturn;\n}\n\n", + "source_code_before": "\n/*\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 extensively for numpy 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, \"dtype\");\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, \"dtype\",\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)) == 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\tif (mps[i]->ob_type != subtype) {\n\t\t\tprior2 = PyArray_GetPriority((PyObject *)(mps[i]), 0.0);\n\t\t\tif (prior2 > prior1) {\n\t\t\t\tprior1 = prior2;\n\t\t\t\tsubtype = mps[i]->ob_type;\n\t\t\t\tret = mps[i];\n\t\t\t}\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, NULL);\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 Make a new empty array, of the passed size, of a type that takes the\n priority of ap1 and ap2 into account.\n */\nstatic PyArrayObject *\nnew_array_for_sum(PyArrayObject *ap1, PyArrayObject *ap2,\n\t\t int nd, intp dimensions[], int typenum)\n{\n\tPyArrayObject *ret;\n\tPyTypeObject *subtype;\n\tdouble prior1, prior2;\n\t/* Need to choose an output array that can hold a sum \n\t -- use priority to determine which subtype.\n\t */\n\tif (ap2->ob_type != ap1->ob_type) {\n\t\tprior2 = PyArray_GetPriority((PyObject *)ap2, 0.0);\n\t\tprior1 = PyArray_GetPriority((PyObject *)ap1, 0.0);\n\n\t\tsubtype = (prior2 > prior1 ? ap2->ob_type : ap1->ob_type);\n\t} else {\n\t\tprior1 = prior2 = 0.0;\n\t\tsubtype = ap1->ob_type;\n\t}\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\treturn ret;\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\tPyArrayIterObject *it1, *it2;\n\tintp i, j, l;\n\tint typenum, nd;\n\tintp is1, is2, os;\n\tchar *op;\n\tintp dimensions[MAX_DIMS];\n\tPyArray_DotFunc *dot;\n\tPyArray_Descr *typec;\n\t\n\ttypenum = PyArray_ObjectType(op1, 0); \n\ttypenum = PyArray_ObjectType(op2, typenum);\n\n\ttypec = PyArray_DescrFromType(typenum);\n\tPy_INCREF(typec);\n\tap1 = (PyArrayObject *)PyArray_FromAny(op1, typec, 0, 0, \n\t\t\t\t\t BEHAVED_FLAGS, NULL);\n\tif (ap1 == NULL) {Py_DECREF(typec); return NULL;}\n\tap2 = (PyArrayObject *)PyArray_FromAny(op2, typec, 0, 0,\n\t\t\t\t\t BEHAVED_FLAGS, NULL);\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\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\tret = new_array_for_sum(ap1, ap2, nd, dimensions, typenum);\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\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\tit1 = (PyArrayIterObject *)\\\n\t\tPyArray_IterAllButAxis((PyObject *)ap1, ap1->nd-1);\n\tit2 = (PyArrayIterObject *)\\\n\t\tPyArray_IterAllButAxis((PyObject *)ap2, ap2->nd-1);\n\n\twhile(1) {\n\t\twhile(it2->index < it2->size) {\n\t\t\tdot(it1->dataptr, is1, it2->dataptr, is2, op, l, ret);\n\t\t\top += os;\n\t\t\tPyArray_ITER_NEXT(it2);\n\t\t}\n\t\tPyArray_ITER_NEXT(it1);\n\t\tif (it1->index >= it1->size) break;\n\t\tPyArray_ITER_RESET(it2);\n\t}\n\tPy_DECREF(it1);\n\tPy_DECREF(it2);\n\n\tif (PyErr_Occurred()) goto fail;\n\t\t\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/* just like inner product but does the swapaxes stuff on the fly */\n/*MULTIARRAY_API\n Numeric.matrixproduct(a,v)\n*/\nstatic PyObject *\nPyArray_MatrixProduct(PyObject *op1, PyObject *op2) \n{\n\tPyArrayObject *ap1, *ap2, *ret=NULL;\n\tPyArrayIterObject *it1, *it2;\n\tintp i, j, l;\n\tint typenum, nd;\n\tintp is1, is2, os;\n\tchar *op;\n\tintp dimensions[MAX_DIMS];\n\tPyArray_DotFunc *dot;\n\tintp matchDim;\n\tPyArray_Descr *typec;\n\n\ttypenum = PyArray_ObjectType(op1, 0); \n\ttypenum = PyArray_ObjectType(op2, typenum);\t\n\t\n\ttypec = PyArray_DescrFromType(typenum);\n\tPy_INCREF(typec);\n\tap1 = (PyArrayObject *)PyArray_FromAny(op1, typec, 0, 0, \n\t\t\t\t\t BEHAVED_FLAGS, NULL);\n\tif (ap1 == NULL) {Py_DECREF(typec); return NULL;}\n\tap2 = (PyArrayObject *)PyArray_FromAny(op2, typec, 0, 0,\n\t\t\t\t\t BEHAVED_FLAGS, NULL);\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\tif (ap2->nd > 1) {\n\t\tmatchDim = ap2->nd - 2;\n\t}\n\telse {\n\t\tmatchDim = 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\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; istrides[ap1->nd-1]; is2 = ap2->strides[matchDim];\n\n /* Choose which subtype to return */\n\tret = new_array_for_sum(ap1, ap2, nd, dimensions, typenum);\n\tif (ret == NULL) goto fail;\n\n\t/* Ensure that multiarray.dot([],[]) -> 0 */\n\tmemset(PyArray_DATA(ret), 0, PyArray_ITEMSIZE(ret));\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\top = ret->data; os = ret->descr->elsize;\n\n\tit1 = (PyArrayIterObject *)\\\n\t\tPyArray_IterAllButAxis((PyObject *)ap1, ap1->nd-1);\n\tit2 = (PyArrayIterObject *)\\\n\t\tPyArray_IterAllButAxis((PyObject *)ap2, matchDim);\n\n\twhile(1) {\n\t\twhile(it2->index < it2->size) {\n\t\t\tdot(it1->dataptr, is1, it2->dataptr, is2, op, l, ret);\n\t\t\top += os;\n\t\t\tPyArray_ITER_NEXT(it2);\n\t\t}\n\t\tPyArray_ITER_NEXT(it1);\n\t\tif (it1->index >= it1->size) break;\n\t\tPyArray_ITER_RESET(it2);\n\t}\n\tPy_DECREF(it1);\n\tPy_DECREF(it2);\n\tif (PyErr_Occurred()) goto fail; /* only for OBJECT arrays */\n\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/*MULTIARRAY_API\n Fast Copy and Transpose\n*/\nstatic PyObject *\nPyArray_CopyAndTranspose(PyObject *op) \n{\n\tPyObject *ret, *arr;\n\tint nd;\n\tintp dims[2];\n\tintp i,j;\n\tint elsize, str2;\n\tchar *iptr;\n\tchar *optr;\n\n\t/* make sure it is well-behaved */\n\tarr = PyArray_FromAny(op, NULL, 0, 0, CARRAY_FLAGS, NULL);\n\tnd = PyArray_NDIM(arr);\n\tif (nd == 1) { /* we will give in to old behavior */\n\t\tret = PyArray_Copy((PyArrayObject *)arr);\n\t\tPy_DECREF(arr);\n\t\treturn ret;\t\t\n\t}\n\telse if (nd != 2) {\n\t\tPy_DECREF(arr);\n\t\tPyErr_SetString(PyExc_ValueError, \n\t\t\t\t\"only 2-d arrays are allowed\");\n\t\treturn NULL;\n\t}\n\n\t/* Now construct output array */\n\tdims[0] = PyArray_DIM(arr,1);\n\tdims[1] = PyArray_DIM(arr,0);\n\telsize = PyArray_ITEMSIZE(arr);\n\t\n\tPy_INCREF(PyArray_DESCR(arr));\n\tret = PyArray_NewFromDescr(arr->ob_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\tret = new_array_for_sum(ap1, ap2, 1, &length, typenum);\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, NULL);\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\tif (type->type_num == PyArray_UNICODE)\n\t\t\ttype->elsize = itemsize << 2; \n\t\telse\n\t\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\tif (type->hasobject) newdescr->hasobject = 1;\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 int hasobject=0;\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; ihasobject)\n hasobject = 1;\n\t\ttup = PyTuple_New(2);\n\t\tPyTuple_SET_ITEM(tup, 0, (PyObject *)conv);\n\t\tPyTuple_SET_ITEM(tup, 1, PyInt_FromLong((long) totalsize));\n\t\ttotalsize += conv->elsize;\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 new->hasobject=hasobject;\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 int hasobject=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; ihasobject)\n\t\t\thasobject=1;\t\t\t\n\t\tPyTuple_SET_ITEM(tup, 0, (PyObject *)conv);\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\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\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 new->hasobject=hasobject;\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 int hasobject=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\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\tPyTuple_SET_ITEM(tup, 1, PyInt_FromLong(totalsize));\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\tif (PyDict_GetItem(fields, name) != NULL) {\n\t\t\tPyErr_SetString(PyExc_ValueError,\n\t\t\t\t\t\"two fields with the same name\");\n\t\t\tret = PY_FAIL;\n\t\t}\n\t\tPyDict_SetItem(fields, name, tup);\n\t\tPy_DECREF(name);\n\t\tif (len == 3) {\n\t\t\tif (PyDict_GetItem(fields, item) != NULL) {\n\t\t\t\tPyErr_SetString(PyExc_ValueError, \n\t\t\t\t\t\t\"titles cannot be the same as names\");\n\t\t\t\tret=PY_FAIL;\n\t\t\t}\n\t\t\telse {\n\t\t\t\tPyDict_SetItem(fields, item, tup);\n\t\t\t}\n\t\t}\n\t\tPy_DECREF(tup);\n\t\tif ((ret == PY_FAIL) || (newdescr->elsize == 0)) goto fail;\n if (!hasobject && newdescr->hasobject)\n hasobject = 1;\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 new->hasobject=hasobject;\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 == '|' || (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\tint i;\n\t\t\telsize = atoi(type+1);\n\t\t\t/* check for commas present */\n\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\nstatic PyObject *\n_prepend_ones(PyArrayObject *arr, int nd, int ndmin)\n{\n\tintp newdims[MAX_DIMS];\n\tintp newstrides[MAX_DIMS];\n\tint i,k,num;\n\tPyObject *ret;\n\n\tnum = ndmin-nd;\n\tfor (i=0; idescr->elsize;\n\t}\n\tfor (i=num;idimensions[k];\n\t\tnewstrides[i] = arr->strides[k];\n\t}\n\tPy_INCREF(arr->descr);\n\tret = PyArray_NewFromDescr(arr->ob_type, arr->descr, ndmin,\n\t\t\t\t newdims, newstrides, arr->data, arr->flags,\n\t\t\t\t (PyObject *)arr);\n\t/* steals a reference to arr --- so don't increment\n\t here */\n\tPyArray_BASE(ret) = (PyObject *)arr;\n\treturn ret;\n}\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,ndmin=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\"\\\n\t\"The ndmin argument specifies how many dimensions the returned\\n\"\\\n\t\"array should have as a minimum. 1's will be pre-pended to the\\n\"\\\n\t\"shape as needed to meet this requirement.\";\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\t\t\t \"ndmin\", NULL};\n Bool subok=FALSE;\n\tBool copy=TRUE;\n\tint ndmin=0, nd;\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&i\", 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\t\t\t\t&ndmin)) \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\tret = op;\n\t\t\t\tgoto finish;\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\tgoto finish;\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\tret = op;\n\t\t\t\tgoto finish;\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\tgoto finish;\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_CheckFromAny(op, type, 0, 0, flags, NULL)) == NULL) \n\t\treturn NULL;\n\n finish:\n\n\tif ((nd=PyArray_NDIM(ret)) >= ndmin) return ret;\n\t/* create a new array from the same data with ones in the shape */\n\t/* steals a reference to ret */\n\treturn _prepend_ones((PyArrayObject *)ret, nd, ndmin);\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(dtype,obj) will return a new scalar array of the given type initialized with obj. Mainly for pickle support. The dtype must be a valid data-type descriptor. If dtype 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[] = {\"dtype\",\"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}; /* XXX ? */\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\nstatic int\n_skip_sep(char **ptr, char *sep)\n{\n\tchar *a;\n\tint n;\n\tn = strlen(sep);\n\ta = *ptr;\n\twhile(*a != '\\0' && (strncmp(a, sep, n) != 0))\n\t\ta++;\n\tif (*a == '\\0') return -1;\n\t*ptr = a+strlen(sep);\n\treturn 0;\n}\n\n/* steals a reference to dtype -- accepts NULL */\n/*OBJECT_API*/\nstatic PyObject *\nPyArray_FromString(char *data, intp slen, PyArray_Descr *dtype, \n\t\t intp n, char *sep)\n{\n\tint itemsize;\n\tPyArrayObject *ret;\n\tBool binary;\n\n\tif (dtype == NULL)\n\t\tdtype=PyArray_DescrFromType(PyArray_LONG);\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\n\tbinary = ((sep == NULL) || (strlen(sep) == 0));\t\n\n\tif (binary) {\n\t\tif (dtype == &OBJECT_Descr) {\n\t\t\tPyErr_SetString(PyExc_ValueError, \n\t\t\t\t\t\"Cannot create an object array from\"\\\n\t\t\t\t\t\" a binary string\");\n\t\t\tPy_DECREF(dtype);\n\t\t\treturn NULL;\n\t\t}\t\t\n\t\tif (n < 0 ) {\n\t\t\tif (slen % itemsize != 0) {\n\t\t\t\tPyErr_SetString(PyExc_ValueError, \n\t\t\t\t\t\t\"string size must be a \"\\\n\t\t\t\t\t\t\"multiple of element size\");\n\t\t\t\tPy_DECREF(dtype);\n\t\t\t\treturn NULL;\n\t\t\t}\n\t\t\tn = slen/itemsize;\n\t\t} else {\n\t\t\tif (slen < n*itemsize) {\n\t\t\t\tPyErr_SetString(PyExc_ValueError, \n\t\t\t\t\t\t\"string is smaller than \" \\\n\t\t\t\t\t\t\"requested size\");\n\t\t\t\tPy_DECREF(dtype);\n\t\t\t\treturn NULL;\n\t\t\t}\n\t\t}\n\t\n\t\tif ((ret = (PyArrayObject *)\\\n\t\t PyArray_NewFromDescr(&PyArray_Type, dtype,\n\t\t\t\t\t 1, &n, NULL, NULL,\n\t\t\t\t\t 0, NULL)) == NULL)\n\t\t\treturn NULL;\t\t\n\t\tmemcpy(ret->data, data, n*dtype->elsize);\n\t\treturn (PyObject *)ret;\n\t}\n\telse { /* read from character-based string */\n\t\tchar *ptr;\t\t\n\t\tPyArray_FromStrFunc *fromstr;\n\t\tchar *dptr;\n\t\tintp nread=0;\n\t\tintp index;\n\n\t\tfromstr = dtype->f->fromstr;\n\t\tif (fromstr == 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 strings for given \"\t\\\n\t\t\t\t\t\"array type\");\n\t\t\tPy_DECREF(dtype);\n\t\t\treturn NULL;\n\t\t}\n\n\t\tif (n!=-1) {\n\t\t\tret = (PyArrayObject *) \\\n\t\t\t\tPyArray_NewFromDescr(&PyArray_Type,\n\t\t\t\t\t\t dtype, 1, &n, NULL,\n\t\t\t\t\t\t NULL, 0, NULL);\n\t\t\tif (ret == NULL) return NULL;\n\t\t\tptr = data;\n\t\t\tdptr = ret->data;\n\t\t\tfor (index=0; index < n; index++) {\n\t\t\t\tif (fromstr(ptr, dptr, &ptr, ret) < 0)\n\t\t\t\t\tbreak;\n\t\t\t\tnread += 1;\n\t\t\t\tdptr += dtype->elsize;\n\t\t\t\tif (_skip_sep(&ptr, sep) < 0) \n\t\t\t\t\tbreak;\n\t\t\t}\n\t\t\tif (nread < n) {\n\t\t\t\tfprintf(stderr, \"%ld items requested but \"\\\n\t\t\t\t\t\"only %ld read\\n\", \n\t\t\t\t\t(long) n, (long) nread);\n\t\t\t\tret->data = \\\n\t\t\t\t\tPyDataMem_RENEW(ret->data, \n\t\t\t\t\t\t\tnread *\t\t\\\n\t\t\t\t\t\t\tret->descr->elsize);\n\t\t\t\tPyArray_DIM(ret,0) = nread;\n\t\t\t}\n\t\t}\n\t\telse {\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\t\t\tchar *end;\n\t\t\tint val;\n\n\t\t\tret = (PyArrayObject *)\\\n\t\t\t\tPyArray_NewFromDescr(&PyArray_Type, \n\t\t\t\t\t\t dtype,\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 (ret==NULL) return NULL;\n\t\t\ttotalbytes = bytes = size * dtype->elsize;\n\t\t\tdptr = ret->data;\n\t\t\tptr = data;\n\t\t\tend = data+slen;\n\t\t\twhile (ptr < end) {\n\t\t\t\tval = fromstr(ptr, dptr, &ptr, ret);\n\t\t\t\tif (val < 0) break;\n\t\t\t\tnread += 1;\n\t\t\t\tval = _skip_sep(&ptr, sep);\n\t\t\t\tif (val < 0) break;\n\t\t\t\tthisbuf += 1;\n\t\t\t\tdptr += dtype->elsize;\n\t\t\t\tif (thisbuf == size) {\n\t\t\t\t\ttotalbytes += bytes;\n\t\t\t\t\tret->data = PyDataMem_RENEW(ret->data, \n\t\t\t\t\t\t\t\t totalbytes);\n\t\t\t\t\tdptr = ret->data + \\\n\t\t\t\t\t\t(totalbytes - bytes);\n\t\t\t\t\tthisbuf = 0;\n\t\t\t\t}\n\t\t\t}\n\t\t\tret->data = PyDataMem_RENEW(ret->data, \n\t\t\t\t\t\t nread*ret->descr->elsize);\n\t\t\tPyArray_DIM(ret,0) = nread;\n#undef _FILEBUFNUM\n\t\t}\n\t}\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\tchar *sep=NULL;\n\tint s;\n\tstatic char *kwlist[] = {\"string\", \"dtype\", \"count\", \"sep\", NULL};\n\tPyArray_Descr *descr=NULL;\n\n\tif (!PyArg_ParseTupleAndKeywords(args, keywds, \"s#|O&Ls\", 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, &sep)) {\n\t\treturn NULL;\n\t}\n\n\treturn PyArray_FromString(data, (intp)s, descr, (intp)nin, sep);\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\tPy_DECREF(typecode);\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\tPy_DECREF(typecode);\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\tPy_DECREF(typecode);\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 platform-independent method of persistence. But it can be \\n\"\\\n\t\" useful to 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_BYTES(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_BYTES(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[] = \n\"arange([start,] stop[, step,], dtype=None)\\n\\n\"\n\"For integer arguments, just like range() except it returns an array whose type can\\n\"\n\"be specified by the keyword argument dtype.\\n\\n\"\n\"If dtype is not specified, the type of the result is deduced from the type of the\\n\"\n\"arguments.\\n\\n\"\n\"For floating point arguments, the length of the result is ceil((stop - start)/step).\\n\"\n\"This rule may result in the last element of the result be greater than stop.\";\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_DescrConverter2,\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/*MULTIARRAY_API\n GetNDArrayCVersion\n*/\nstatic unsigned int\nPyArray_GetNDArrayCVersion(void)\n{\n\treturn (unsigned int)NDARRAY_VERSION;\n}\n\nstatic char \ndoc__get_ndarray_c_version[] = \"_get_ndarray_c_version() gets the compile time NDARRAY_VERSION number\";\n\nstatic PyObject *\narray__get_ndarray_c_version(PyObject *dummy, PyObject *args, PyObject *kwds) \n{\n\tstatic char *kwlist[] = {NULL};\n\tif(!PyArg_ParseTupleAndKeywords(args, kwds, \"\", kwlist )) return NULL;\n\t\n\treturn PyInt_FromLong( (long) PyArray_GetNDArrayCVersion() );\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, NULL);\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{\"_get_ndarray_c_version\", (PyCFunction)array__get_ndarray_c_version, \n\t METH_VARARGS|METH_KEYWORDS, doc__get_ndarray_c_version},\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, \"dtype\", (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\tif (!PyErr_Occurred()) {\n\t\tPyErr_SetString(PyExc_RuntimeError, \n\t\t\t\t\"cannot load multiarray module.\");\n\t}\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": 35, + "end_line": 50, + "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": 75, + "end_line": 80, + "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": 86, + "end_line": 91, + "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": 97, + "end_line": 105, + "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": 111, + "end_line": 123, + "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": 129, + "end_line": 136, + "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": 143, + "end_line": 173, + "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": 179, + "end_line": 196, + "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": 202, + "end_line": 237, + "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": 248, + "end_line": 257, + "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": 260, + "end_line": 286, + "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": 297, + "end_line": 384, + "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": 393, + "end_line": 428, + "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": 435, + "end_line": 456, + "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": 463, + "end_line": 522, + "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": 529, + "end_line": 539, + "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": 545, + "end_line": 555, + "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": 561, + "end_line": 571, + "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": 577, + "end_line": 588, + "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": 594, + "end_line": 605, + "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": 611, + "end_line": 622, + "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": 102, + "parameters": [ + "self", + "condition", + "axis" + ], + "start_line": 629, + "end_line": 649, + "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": 655, + "end_line": 714, + "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": 720, + "end_line": 750, + "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": 756, + "end_line": 792, + "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": 798, + "end_line": 808, + "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": 776, + "parameters": [ + "self", + "offset", + "axis1", + "axis2" + ], + "start_line": 814, + "end_line": 933, + "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": 402, + "parameters": [ + "op", + "ptr", + "dims", + "nd", + "typedescr" + ], + "start_line": 949, + "end_line": 1000, + "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": 1008, + "end_line": 1018, + "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": 1024, + "end_line": 1036, + "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": 1044, + "end_line": 1055, + "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": 1059, + "end_line": 1087, + "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": 94, + "complexity": 21, + "token_count": 630, + "parameters": [ + "op", + "axis" + ], + "start_line": 1099, + "end_line": 1205, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 107, + "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": 1211, + "end_line": 1252, + "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": 1258, + "end_line": 1311, + "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": 1317, + "end_line": 1412, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 96, + "top_nesting_level": 0 + }, + { + "name": "_signbit_set", + "long_name": "_signbit_set( PyArrayObject * arr)", + "filename": "multiarraymodule.c", + "nloc": 17, + "complexity": 6, + "token_count": 98, + "parameters": [ + "arr" + ], + "start_line": 1416, + "end_line": 1434, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 19, + "top_nesting_level": 0 + }, + { + "name": "PyArray_ScalarKind", + "long_name": "PyArray_ScalarKind( int typenum , PyArrayObject ** arr)", + "filename": "multiarraymodule.c", + "nloc": 12, + "complexity": 7, + "token_count": 78, + "parameters": [ + "typenum", + "arr" + ], + "start_line": 1439, + "end_line": 1451, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 13, + "top_nesting_level": 0 + }, + { + "name": "PyArray_CanCoerceScalar", + "long_name": "PyArray_CanCoerceScalar( char thistype , char neededtype , char scalar)", + "filename": "multiarraymodule.c", + "nloc": 21, + "complexity": 9, + "token_count": 101, + "parameters": [ + "thistype", + "neededtype", + "scalar" + ], + "start_line": 1456, + "end_line": 1477, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 22, + "top_nesting_level": 0 + }, + { + "name": "PyArray_ConvertToCommonType", + "long_name": "PyArray_ConvertToCommonType( PyObject * op , int * retn)", + "filename": "multiarraymodule.c", + "nloc": 73, + "complexity": 15, + "token_count": 482, + "parameters": [ + "op", + "retn" + ], + "start_line": 1485, + "end_line": 1564, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 80, + "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": 1571, + "end_line": 1652, + "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": 1655, + "end_line": 1662, + "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": 1673, + "end_line": 1727, + "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": 1730, + "end_line": 1808, + "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": 1816, + "end_line": 1819, + "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": 355, + "parameters": [ + "op", + "axis", + "which" + ], + "start_line": 1874, + "end_line": 1940, + "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": 1946, + "end_line": 1954, + "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": 1960, + "end_line": 2040, + "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": 2052, + "end_line": 2196, + "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": 2200, + "end_line": 2235, + "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": 2241, + "end_line": 2286, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 46, + "top_nesting_level": 0 + }, + { + "name": "new_array_for_sum", + "long_name": "new_array_for_sum( PyArrayObject * ap1 , PyArrayObject * ap2 , int nd , intp dimensions [ ] , int typenum)", + "filename": "multiarraymodule.c", + "nloc": 20, + "complexity": 4, + "token_count": 147, + "parameters": [ + "ap1", + "ap2", + "nd", + "typenum" + ], + "start_line": 2293, + "end_line": 2317, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 25, + "top_nesting_level": 0 + }, + { + "name": "PyArray_InnerProduct", + "long_name": "PyArray_InnerProduct( PyObject * op1 , PyObject * op2)", + "filename": "multiarraymodule.c", + "nloc": 79, + "complexity": 15, + "token_count": 624, + "parameters": [ + "op1", + "op2" + ], + "start_line": 2326, + "end_line": 2424, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 99, + "top_nesting_level": 0 + }, + { + "name": "PyArray_MatrixProduct", + "long_name": "PyArray_MatrixProduct( PyObject * op1 , PyObject * op2)", + "filename": "multiarraymodule.c", + "nloc": 89, + "complexity": 17, + "token_count": 680, + "parameters": [ + "op1", + "op2" + ], + "start_line": 2432, + "end_line": 2543, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 112, + "top_nesting_level": 0 + }, + { + "name": "PyArray_CopyAndTranspose", + "long_name": "PyArray_CopyAndTranspose( PyObject * op)", + "filename": "multiarraymodule.c", + "nloc": 47, + "complexity": 6, + "token_count": 286, + "parameters": [ + "op" + ], + "start_line": 2549, + "end_line": 2603, + "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": 86, + "complexity": 13, + "token_count": 601, + "parameters": [ + "op1", + "op2", + "mode" + ], + "start_line": 2609, + "end_line": 2706, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 98, + "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": 2713, + "end_line": 2737, + "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": 2743, + "end_line": 2754, + "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": 2760, + "end_line": 2771, + "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": 2777, + "end_line": 2800, + "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": 2807, + "end_line": 2864, + "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": 2871, + "end_line": 2946, + "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": 2952, + "end_line": 3021, + "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": 3027, + "end_line": 3098, + "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": 68, + "parameters": [ + "object", + "address" + ], + "start_line": 3114, + "end_line": 3126, + "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": 3132, + "end_line": 3140, + "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": 3147, + "end_line": 3262, + "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": 3280, + "end_line": 3305, + "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": 3320, + "end_line": 3356, + "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": 3374, + "end_line": 3407, + "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": 65, + "complexity": 16, + "token_count": 399, + "parameters": [ + "obj" + ], + "start_line": 3410, + "end_line": 3487, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 78, + "top_nesting_level": 0 + }, + { + "name": "_convert_from_array_descr", + "long_name": "_convert_from_array_descr( PyObject * obj)", + "filename": "multiarraymodule.c", + "nloc": 69, + "complexity": 14, + "token_count": 442, + "parameters": [ + "obj" + ], + "start_line": 3495, + "end_line": 3566, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 72, + "top_nesting_level": 0 + }, + { + "name": "_convert_from_list", + "long_name": "_convert_from_list( PyObject * obj , int align , int try_descr)", + "filename": "multiarraymodule.c", + "nloc": 70, + "complexity": 13, + "token_count": 428, + "parameters": [ + "obj", + "align", + "try_descr" + ], + "start_line": 3577, + "end_line": 3648, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 72, + "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": 3661, + "end_line": 3677, + "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": 3714, + "end_line": 3719, + "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": 112, + "complexity": 29, + "token_count": 720, + "parameters": [ + "obj", + "align" + ], + "start_line": 3722, + "end_line": 3843, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 122, + "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": 3861, + "end_line": 3868, + "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": 141, + "complexity": 55, + "token_count": 886, + "parameters": [ + "obj", + "at" + ], + "start_line": 3885, + "end_line": 4065, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 181, + "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": 4071, + "end_line": 4103, + "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": 4109, + "end_line": 4135, + "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": 4144, + "end_line": 4163, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 20, + "top_nesting_level": 0 + }, + { + "name": "_prepend_ones", + "long_name": "_prepend_ones( PyArrayObject * arr , int nd , int ndmin)", + "filename": "multiarraymodule.c", + "nloc": 23, + "complexity": 3, + "token_count": 175, + "parameters": [ + "arr", + "nd", + "ndmin" + ], + "start_line": 4168, + "end_line": 4193, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 26, + "top_nesting_level": 0 + }, + { + "name": "_array_fromobject", + "long_name": "_array_fromobject( PyObject * ignored , PyObject * args , PyObject * kws)", + "filename": "multiarraymodule.c", + "nloc": 66, + "complexity": 16, + "token_count": 380, + "parameters": [ + "ignored", + "args", + "kws" + ], + "start_line": 4215, + "end_line": 4290, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 76, + "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": 4298, + "end_line": 4313, + "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": 4319, + "end_line": 4343, + "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": 4348, + "end_line": 4406, + "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": 4415, + "end_line": 4439, + "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": 4445, + "end_line": 4469, + "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": 4476, + "end_line": 4485, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 10, + "top_nesting_level": 0 + }, + { + "name": "_skip_sep", + "long_name": "_skip_sep( char ** ptr , char * sep)", + "filename": "multiarraymodule.c", + "nloc": 12, + "complexity": 4, + "token_count": 78, + "parameters": [ + "ptr", + "sep" + ], + "start_line": 4488, + "end_line": 4499, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 12, + "top_nesting_level": 0 + }, + { + "name": "PyArray_FromString", + "long_name": "PyArray_FromString( char * data , intp slen , PyArray_Descr * dtype , intp n , char * sep)", + "filename": "multiarraymodule.c", + "nloc": 133, + "complexity": 22, + "token_count": 711, + "parameters": [ + "data", + "slen", + "dtype", + "n", + "sep" + ], + "start_line": 4504, + "end_line": 4646, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 143, + "top_nesting_level": 0 + }, + { + "name": "array_fromString", + "long_name": "array_fromString( PyObject * ignored , PyObject * args , PyObject * keywds)", + "filename": "multiarraymodule.c", + "nloc": 16, + "complexity": 2, + "token_count": 116, + "parameters": [ + "ignored", + "args", + "keywds" + ], + "start_line": 4651, + "end_line": 4668, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 18, + "top_nesting_level": 0 + }, + { + "name": "PyArray_FromFile", + "long_name": "PyArray_FromFile( FILE * fp , PyArray_Descr * typecode , intp num , char * sep)", + "filename": "multiarraymodule.c", + "nloc": 114, + "complexity": 22, + "token_count": 664, + "parameters": [ + "fp", + "typecode", + "num", + "sep" + ], + "start_line": 4682, + "end_line": 4810, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 129, + "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": 4828, + "end_line": 4866, + "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": 4870, + "end_line": 4963, + "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": 4979, + "end_line": 4996, + "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": 5002, + "end_line": 5013, + "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": 5020, + "end_line": 5026, + "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": 5033, + "end_line": 5039, + "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": 5043, + "end_line": 5049, + "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": 5053, + "end_line": 5062, + "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": 5069, + "end_line": 5120, + "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": 5126, + "end_line": 5158, + "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": 5165, + "end_line": 5249, + "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": 5262, + "end_line": 5274, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 13, + "top_nesting_level": 0 + }, + { + "name": "PyArray_GetNDArrayCVersion", + "long_name": "PyArray_GetNDArrayCVersion()", + "filename": "multiarraymodule.c", + "nloc": 4, + "complexity": 1, + "token_count": 13, + "parameters": [], + "start_line": 5280, + "end_line": 5283, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 0 + }, + { + "name": "array__get_ndarray_c_version", + "long_name": "array__get_ndarray_c_version( PyObject * dummy , PyObject * args , PyObject * kwds)", + "filename": "multiarraymodule.c", + "nloc": 6, + "complexity": 2, + "token_count": 55, + "parameters": [ + "dummy", + "args", + "kwds" + ], + "start_line": 5289, + "end_line": 5295, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 7, + "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": 5301, + "end_line": 5317, + "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": 5323, + "end_line": 5340, + "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": 233, + "parameters": [ + "condition", + "x", + "y" + ], + "start_line": 5347, + "end_line": 5387, + "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": 5395, + "end_line": 5403, + "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": 5415, + "end_line": 5425, + "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": 5434, + "end_line": 5445, + "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": 5452, + "end_line": 5475, + "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": 5482, + "end_line": 5490, + "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": 5499, + "end_line": 5517, + "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": 5583, + "end_line": 5696, + "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": 5701, + "end_line": 5725, + "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": 64, + "complexity": 15, + "token_count": 435, + "parameters": [], + "start_line": 5730, + "end_line": 5822, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 93, + "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": 35, + "end_line": 50, + "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": 75, + "end_line": 80, + "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": 86, + "end_line": 91, + "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": 97, + "end_line": 105, + "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": 111, + "end_line": 123, + "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": 129, + "end_line": 136, + "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": 143, + "end_line": 173, + "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": 179, + "end_line": 196, + "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": 202, + "end_line": 237, + "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": 248, + "end_line": 257, + "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": 260, + "end_line": 286, + "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": 297, + "end_line": 384, + "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": 393, + "end_line": 428, + "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": 435, + "end_line": 456, + "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": 463, + "end_line": 522, + "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": 529, + "end_line": 539, + "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": 545, + "end_line": 555, + "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": 561, + "end_line": 571, + "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": 577, + "end_line": 588, + "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": 594, + "end_line": 605, + "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": 611, + "end_line": 622, + "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": 102, + "parameters": [ + "self", + "condition", + "axis" + ], + "start_line": 629, + "end_line": 649, + "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": 655, + "end_line": 714, + "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": 720, + "end_line": 750, + "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": 756, + "end_line": 792, + "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": 798, + "end_line": 808, + "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": 776, + "parameters": [ + "self", + "offset", + "axis1", + "axis2" + ], + "start_line": 814, + "end_line": 933, + "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": 402, + "parameters": [ + "op", + "ptr", + "dims", + "nd", + "typedescr" + ], + "start_line": 949, + "end_line": 1000, + "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": 1008, + "end_line": 1018, + "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": 1024, + "end_line": 1036, + "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": 1044, + "end_line": 1055, + "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": 1059, + "end_line": 1087, + "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": 94, + "complexity": 21, + "token_count": 630, + "parameters": [ + "op", + "axis" + ], + "start_line": 1099, + "end_line": 1205, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 107, + "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": 1211, + "end_line": 1252, + "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": 1258, + "end_line": 1311, + "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": 1317, + "end_line": 1412, + "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": 65, + "complexity": 13, + "token_count": 439, + "parameters": [ + "op", + "retn" + ], + "start_line": 1416, + "end_line": 1487, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 72, + "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": 1494, + "end_line": 1575, + "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": 1578, + "end_line": 1585, + "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": 1596, + "end_line": 1650, + "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": 1653, + "end_line": 1731, + "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": 1739, + "end_line": 1742, + "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": 355, + "parameters": [ + "op", + "axis", + "which" + ], + "start_line": 1797, + "end_line": 1863, + "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": 1869, + "end_line": 1877, + "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": 1883, + "end_line": 1963, + "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": 1975, + "end_line": 2119, + "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": 2123, + "end_line": 2158, + "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": 2164, + "end_line": 2209, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 46, + "top_nesting_level": 0 + }, + { + "name": "new_array_for_sum", + "long_name": "new_array_for_sum( PyArrayObject * ap1 , PyArrayObject * ap2 , int nd , intp dimensions [ ] , int typenum)", + "filename": "multiarraymodule.c", + "nloc": 20, + "complexity": 4, + "token_count": 147, + "parameters": [ + "ap1", + "ap2", + "nd", + "typenum" + ], + "start_line": 2216, + "end_line": 2240, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 25, + "top_nesting_level": 0 + }, + { + "name": "PyArray_InnerProduct", + "long_name": "PyArray_InnerProduct( PyObject * op1 , PyObject * op2)", + "filename": "multiarraymodule.c", + "nloc": 79, + "complexity": 15, + "token_count": 624, + "parameters": [ + "op1", + "op2" + ], + "start_line": 2249, + "end_line": 2347, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 99, + "top_nesting_level": 0 + }, + { + "name": "PyArray_MatrixProduct", + "long_name": "PyArray_MatrixProduct( PyObject * op1 , PyObject * op2)", + "filename": "multiarraymodule.c", + "nloc": 89, + "complexity": 17, + "token_count": 680, + "parameters": [ + "op1", + "op2" + ], + "start_line": 2355, + "end_line": 2466, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 112, + "top_nesting_level": 0 + }, + { + "name": "PyArray_CopyAndTranspose", + "long_name": "PyArray_CopyAndTranspose( PyObject * op)", + "filename": "multiarraymodule.c", + "nloc": 47, + "complexity": 6, + "token_count": 286, + "parameters": [ + "op" + ], + "start_line": 2472, + "end_line": 2526, + "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": 86, + "complexity": 13, + "token_count": 601, + "parameters": [ + "op1", + "op2", + "mode" + ], + "start_line": 2532, + "end_line": 2629, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 98, + "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": 2636, + "end_line": 2660, + "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": 2666, + "end_line": 2677, + "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": 2683, + "end_line": 2694, + "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": 2700, + "end_line": 2723, + "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": 2730, + "end_line": 2787, + "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": 2794, + "end_line": 2869, + "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": 2875, + "end_line": 2944, + "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": 2950, + "end_line": 3021, + "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": 68, + "parameters": [ + "object", + "address" + ], + "start_line": 3037, + "end_line": 3049, + "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": 3055, + "end_line": 3063, + "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": 3070, + "end_line": 3185, + "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": 3203, + "end_line": 3228, + "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": 3243, + "end_line": 3279, + "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": 3297, + "end_line": 3330, + "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": 65, + "complexity": 16, + "token_count": 399, + "parameters": [ + "obj" + ], + "start_line": 3333, + "end_line": 3410, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 78, + "top_nesting_level": 0 + }, + { + "name": "_convert_from_array_descr", + "long_name": "_convert_from_array_descr( PyObject * obj)", + "filename": "multiarraymodule.c", + "nloc": 69, + "complexity": 14, + "token_count": 442, + "parameters": [ + "obj" + ], + "start_line": 3418, + "end_line": 3489, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 72, + "top_nesting_level": 0 + }, + { + "name": "_convert_from_list", + "long_name": "_convert_from_list( PyObject * obj , int align , int try_descr)", + "filename": "multiarraymodule.c", + "nloc": 70, + "complexity": 13, + "token_count": 428, + "parameters": [ + "obj", + "align", + "try_descr" + ], + "start_line": 3500, + "end_line": 3571, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 72, + "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": 3584, + "end_line": 3600, + "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": 3637, + "end_line": 3642, + "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": 111, + "complexity": 29, + "token_count": 718, + "parameters": [ + "obj", + "align" + ], + "start_line": 3645, + "end_line": 3765, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 121, + "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": 3783, + "end_line": 3790, + "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": 141, + "complexity": 55, + "token_count": 886, + "parameters": [ + "obj", + "at" + ], + "start_line": 3807, + "end_line": 3987, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 181, + "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": 3993, + "end_line": 4025, + "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": 4031, + "end_line": 4057, + "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": 4066, + "end_line": 4085, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 20, + "top_nesting_level": 0 + }, + { + "name": "_prepend_ones", + "long_name": "_prepend_ones( PyArrayObject * arr , int nd , int ndmin)", + "filename": "multiarraymodule.c", + "nloc": 23, + "complexity": 3, + "token_count": 175, + "parameters": [ + "arr", + "nd", + "ndmin" + ], + "start_line": 4090, + "end_line": 4115, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 26, + "top_nesting_level": 0 + }, + { + "name": "_array_fromobject", + "long_name": "_array_fromobject( PyObject * ignored , PyObject * args , PyObject * kws)", + "filename": "multiarraymodule.c", + "nloc": 66, + "complexity": 16, + "token_count": 380, + "parameters": [ + "ignored", + "args", + "kws" + ], + "start_line": 4137, + "end_line": 4212, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 76, + "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": 4220, + "end_line": 4235, + "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": 4241, + "end_line": 4265, + "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": 4270, + "end_line": 4328, + "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": 4337, + "end_line": 4361, + "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": 4367, + "end_line": 4391, + "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": 4398, + "end_line": 4407, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 10, + "top_nesting_level": 0 + }, + { + "name": "_skip_sep", + "long_name": "_skip_sep( char ** ptr , char * sep)", + "filename": "multiarraymodule.c", + "nloc": 12, + "complexity": 4, + "token_count": 78, + "parameters": [ + "ptr", + "sep" + ], + "start_line": 4410, + "end_line": 4421, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 12, + "top_nesting_level": 0 + }, + { + "name": "PyArray_FromString", + "long_name": "PyArray_FromString( char * data , intp slen , PyArray_Descr * dtype , intp n , char * sep)", + "filename": "multiarraymodule.c", + "nloc": 133, + "complexity": 22, + "token_count": 711, + "parameters": [ + "data", + "slen", + "dtype", + "n", + "sep" + ], + "start_line": 4426, + "end_line": 4568, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 143, + "top_nesting_level": 0 + }, + { + "name": "array_fromString", + "long_name": "array_fromString( PyObject * ignored , PyObject * args , PyObject * keywds)", + "filename": "multiarraymodule.c", + "nloc": 16, + "complexity": 2, + "token_count": 116, + "parameters": [ + "ignored", + "args", + "keywds" + ], + "start_line": 4573, + "end_line": 4590, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 18, + "top_nesting_level": 0 + }, + { + "name": "PyArray_FromFile", + "long_name": "PyArray_FromFile( FILE * fp , PyArray_Descr * typecode , intp num , char * sep)", + "filename": "multiarraymodule.c", + "nloc": 114, + "complexity": 22, + "token_count": 664, + "parameters": [ + "fp", + "typecode", + "num", + "sep" + ], + "start_line": 4604, + "end_line": 4732, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 129, + "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": 4750, + "end_line": 4788, + "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": 4792, + "end_line": 4885, + "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": 4901, + "end_line": 4918, + "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": 4924, + "end_line": 4935, + "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": 4942, + "end_line": 4948, + "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": 4955, + "end_line": 4961, + "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": 4965, + "end_line": 4971, + "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": 4975, + "end_line": 4984, + "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": 4991, + "end_line": 5042, + "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": 5048, + "end_line": 5080, + "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": 5087, + "end_line": 5171, + "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": 5184, + "end_line": 5196, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 13, + "top_nesting_level": 0 + }, + { + "name": "PyArray_GetNDArrayCVersion", + "long_name": "PyArray_GetNDArrayCVersion()", + "filename": "multiarraymodule.c", + "nloc": 4, + "complexity": 1, + "token_count": 13, + "parameters": [], + "start_line": 5202, + "end_line": 5205, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 0 + }, + { + "name": "array__get_ndarray_c_version", + "long_name": "array__get_ndarray_c_version( PyObject * dummy , PyObject * args , PyObject * kwds)", + "filename": "multiarraymodule.c", + "nloc": 6, + "complexity": 2, + "token_count": 55, + "parameters": [ + "dummy", + "args", + "kwds" + ], + "start_line": 5211, + "end_line": 5217, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 7, + "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": 5223, + "end_line": 5239, + "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": 5245, + "end_line": 5262, + "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": 233, + "parameters": [ + "condition", + "x", + "y" + ], + "start_line": 5269, + "end_line": 5309, + "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": 5317, + "end_line": 5325, + "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": 5337, + "end_line": 5347, + "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": 5356, + "end_line": 5367, + "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": 5374, + "end_line": 5397, + "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": 5404, + "end_line": 5412, + "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": 5421, + "end_line": 5439, + "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": 5505, + "end_line": 5618, + "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": 5623, + "end_line": 5647, + "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": 64, + "complexity": 15, + "token_count": 435, + "parameters": [], + "start_line": 5652, + "end_line": 5744, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 93, + "top_nesting_level": 0 + } + ], + "changed_methods": [ + { + "name": "PyArray_ScalarKind", + "long_name": "PyArray_ScalarKind( int typenum , PyArrayObject ** arr)", + "filename": "multiarraymodule.c", + "nloc": 12, + "complexity": 7, + "token_count": 78, + "parameters": [ + "typenum", + "arr" + ], + "start_line": 1439, + "end_line": 1451, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 13, + "top_nesting_level": 0 + }, + { + "name": "_convert_from_dict", + "long_name": "_convert_from_dict( PyObject * obj , int align)", + "filename": "multiarraymodule.c", + "nloc": 112, + "complexity": 29, + "token_count": 720, + "parameters": [ + "obj", + "align" + ], + "start_line": 3722, + "end_line": 3843, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 122, + "top_nesting_level": 0 + }, + { + "name": "PyArray_ConvertToCommonType", + "long_name": "PyArray_ConvertToCommonType( PyObject * op , int * retn)", + "filename": "multiarraymodule.c", + "nloc": 73, + "complexity": 15, + "token_count": 482, + "parameters": [ + "op", + "retn" + ], + "start_line": 1485, + "end_line": 1564, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 80, + "top_nesting_level": 0 + }, + { + "name": "PyArray_CanCoerceScalar", + "long_name": "PyArray_CanCoerceScalar( char thistype , char neededtype , char scalar)", + "filename": "multiarraymodule.c", + "nloc": 21, + "complexity": 9, + "token_count": 101, + "parameters": [ + "thistype", + "neededtype", + "scalar" + ], + "start_line": 1456, + "end_line": 1477, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 22, + "top_nesting_level": 0 + }, + { + "name": "_signbit_set", + "long_name": "_signbit_set( PyArrayObject * arr)", + "filename": "multiarraymodule.c", + "nloc": 17, + "complexity": 6, + "token_count": 98, + "parameters": [ + "arr" + ], + "start_line": 1416, + "end_line": 1434, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 19, + "top_nesting_level": 0 + } + ], + "nloc": 4413, + "complexity": 968, + "token_count": 28559, + "diff_parsed": { + "added": [ + "", + "static int", + "_signbit_set(PyArrayObject *arr)", + "{", + "\tstatic char bitmask = 0x80;", + "\tchar *ptr; /* points to the byte to test */", + "\tchar byteorder;", + "\tint elsize;", + "", + "\tif (arr==NULL) return 0;", + "\telsize = arr->descr->elsize;", + "\tbyteorder = arr->descr->byteorder;", + "\tptr = arr->data;", + "\tif (elsize > 1 && \\", + "\t (byteorder == PyArray_LITTLE ||\t\\", + "\t (byteorder == PyArray_NATIVE &&", + "\t PyArray_ISNBO(PyArray_LITTLE))))", + "\t\tptr += elsize-1;", + "", + "\treturn ((*ptr & bitmask) != 0);", + "}", + "", + "", + "/*OBJECT_API*/", + "static char", + "PyArray_ScalarKind(int typenum, PyArrayObject **arr)", + "{", + "\tif (PyTypeNum_ISSIGNED(typenum)) {", + "\t\tif (_signbit_set(*arr)) return UFUNC_INTNEG_SCALAR;", + "\t\telse return UFUNC_INTPOS_SCALAR;", + "\t}", + "\tif (PyTypeNum_ISFLOAT(typenum)) return UFUNC_FLOAT_SCALAR;", + "\tif (PyTypeNum_ISUNSIGNED(typenum)) return UFUNC_INTPOS_SCALAR;", + "\tif (PyTypeNum_ISCOMPLEX(typenum)) return UFUNC_COMPLEX_SCALAR;", + "\tif (PyTypeNum_ISBOOL(typenum)) return UFUNC_BOOL_SCALAR;", + "", + "\treturn UFUNC_OBJECT_SCALAR;", + "}", + "", + "", + "/*OBJECT_API*/", + "static int", + "PyArray_CanCoerceScalar(char thistype, char neededtype, char scalar)", + "{", + "", + "\tswitch(scalar) {", + "\tcase UFUNC_NOSCALAR:", + "\tcase UFUNC_BOOL_SCALAR:", + "\tcase UFUNC_OBJECT_SCALAR:", + "\t\treturn PyArray_CanCastSafely(thistype, neededtype);", + "\tcase UFUNC_INTPOS_SCALAR:", + "\t\treturn (neededtype >= PyArray_UBYTE);", + "\tcase UFUNC_INTNEG_SCALAR:", + "\t\treturn (neededtype >= PyArray_BYTE) &&\t\t\\", + "\t\t\t!(PyTypeNum_ISUNSIGNED(neededtype));", + "\tcase UFUNC_FLOAT_SCALAR:", + "\t\treturn (neededtype >= PyArray_FLOAT);", + "\tcase UFUNC_COMPLEX_SCALAR:", + "\t\treturn (neededtype >= PyArray_CFLOAT);", + "\t}", + "\tfprintf(stderr, \"\\n**Error** coerce fall through: %d %d %d\\n\\n\",", + "\t\tthistype, neededtype, scalar);", + "\treturn 1; /* should never get here... */", + "}", + "", + "", + "/* This needs to change to allow scalars of a different \"kind\" to alter the input type", + " */", + "", + "\tchar scalarkind;", + "\t\t\tscalarkind = PyArray_ScalarKind(newtype->type_num, NULL);", + "\t\t\tif (intype && !PyArray_CanCoerceScalar(newtype->type_num,", + "\t\t\t\t\t\t\t intype->type_num,", + "\t\t\t\t\t\t\t scalarkind)) {", + "\t\t\t\tPy_XDECREF(intype);", + "\t\t\t\tintype = stype;", + "\t\t\t}", + "\t\t\t\t\t\"name already used as a name or title\");", + "\t\t\t\t\t\t\"title already used as a name or \" \\", + "\t\t\t\t\t\t\" title.\");" + ], + "deleted": [ + "\t\t\t\t\t\"two fields with the same name\");", + "\t\t\t\t\t\t\"titles cannot be the same as names\");" + ] + } + }, + { + "old_path": "numpy/core/src/ufuncobject.c", + "new_path": "numpy/core/src/ufuncobject.c", + "filename": "ufuncobject.c", + "extension": "c", + "change_type": "MODIFY", + "diff": "@@ -528,15 +528,6 @@ PyUFunc_clearfperr()\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@@ -579,31 +570,6 @@ _lowest_type(char intype)\n /* Called to determine coercion\n */\n \n-static 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-\n static int \n select_types(PyUFuncObject *self, int *arg_types, \n PyUFuncGenericFunction *function, void **data,\n@@ -669,9 +635,9 @@ select_types(PyUFuncObject *self, int *arg_types,\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\tif (!PyArray_CanCoerceScalar(arg_types[j], \n+\t\t\t\t\t\t self->types[i*self->nargs+j],\n+\t\t\t\t\t\t scalars[j]))\n \t\t\t\tbreak;\n \t\t}\n \t\tif (j == self->nin) break;\n@@ -772,42 +738,6 @@ PyUFunc_GetPyValues(char *name, int *bufsize, int *errmask, PyObject **errobj)\n \treturn 0;\n }\n \n-static int\n-_signbit_set(PyArrayObject *arr)\n-{\n-\tstatic char bitmask = 0x80;\n-\tchar *ptr; /* points to the byte to test */\n-\tchar byteorder;\n-\tint elsize;\n-\n-\telsize = arr->descr->elsize;\n-\tbyteorder = arr->descr->byteorder;\n-\tptr = arr->data;\n-\tif (elsize > 1 && \\\n-\t (byteorder == PyArray_LITTLE ||\t\\\n-\t (byteorder == PyArray_NATIVE &&\n-\t PyArray_ISNBO(PyArray_LITTLE))))\n-\t\tptr += elsize-1;\n-\t\n-\treturn ((*ptr & bitmask) != 0);\t\n-}\n-\n-static char\n-_scalar_kind(int typenum, PyArrayObject **arr) \n-{\n-\tif (PyTypeNum_ISSIGNED(typenum)) {\n-\t\tif (_signbit_set(*arr)) return UFUNC_INTNEG_SCALAR;\n-\t\telse return UFUNC_INTPOS_SCALAR;\n-\t}\n-\tif (PyTypeNum_ISFLOAT(typenum)) return UFUNC_FLOAT_SCALAR;\n-\tif (PyTypeNum_ISUNSIGNED(typenum)) return UFUNC_INTPOS_SCALAR;\n-\tif (PyTypeNum_ISCOMPLEX(typenum)) return UFUNC_COMPLEX_SCALAR;\n-\tif (PyTypeNum_ISBOOL(typenum)) return UFUNC_BOOL_SCALAR;\n-\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@@ -925,7 +855,7 @@ construct_matrices(PyUFuncLoopObject *loop, PyObject *args, PyArrayObject **mps)\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+\t\telse scalars[i] = PyArray_ScalarKind(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", + "added_lines": 4, + "deleted_lines": 74, + "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#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 \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 (!PyArray_CanCoerceScalar(arg_types[j], \n\t\t\t\t\t\t self->types[i*self->nargs+j],\n\t\t\t\t\t\t scalars[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/* 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, NULL);\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\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 PyObject *context=NULL;\n PyObject *obj;\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 /* Get each input argument */\n for (i=0; inin; i++) {\n obj = PyTuple_GET_ITEM(args,i);\n if (!PyArray_Check(obj) && !PyArray_IsScalar(obj, Generic)) {\n context = Py_BuildValue(\"OOi\", self, args, i);\n }\n else context = NULL;\n mps[i] = (PyArrayObject *)PyArray_FromAny(obj, NULL, 0, 0, 0, context);\n Py_XDECREF(context);\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] = PyArray_ScalarKind(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, NULL);\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\tchar **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\tchar **bufptr = loop->bufptr;\n\t\tchar **buffer = loop->buffer;\n\t\tchar **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 = (PyObject **)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, NULL);\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, NULL);\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, *context; \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, NULL);\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 if (!PyArray_Check(op) && !PyArray_IsScalar(op, Generic)) {\n context = Py_BuildValue(\"O(O)i\", self, op, 0);\n }\n else {\n context = NULL;\n }\n\tmp = (PyArrayObject *)PyArray_FromAny(op, NULL, 0, 0, 0, context);\n Py_XDECREF(context);\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\nstatic PyObject *\n_find_array_wrap(PyObject *args)\n{\n\tint nargs, i;\n\tint np = 0;\n\tdouble priority, maxpriority;\n\tPyObject *with_wrap[MAX_ARGS], *wraps[MAX_ARGS];\n\tPyObject *obj, *wrap = NULL;\n\n\tnargs = PyTuple_GET_SIZE(args);\n\tfor (i=0; i maxpriority) {\n\t\t\tmaxpriority = priority;\n\t\t\tPy_DECREF(wrap);\n\t\t\twrap = wraps[i];\n\t\t} else {\n\t\t\tPy_DECREF(wraps[i]);\n\t\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 *wrap;\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\twrap = _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 (wrap != NULL) {\n\t\t\tres = PyObject_CallFunction(wrap, \"O(OOi)\",\n\t\t\t\t\t\t mps[j], self, args, i);\n\t\t\tif (res == NULL && PyErr_ExceptionMatches(PyExc_TypeError)) {\n\t\t\t\tPyErr_Clear();\n\t\t\t\tres = PyObject_CallFunctionObjArgs(wrap, mps[j], NULL);\n\t\t\t}\n\t\t\tPy_DECREF(wrap);\n\t\t\tif (res == NULL) goto fail;\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}\n fail:\n\tfor(i=self->nin; inargs; i++) Py_XDECREF(mps[i]);\n\treturn NULL;\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 **)(((char *)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\nstatic int\n_signbit_set(PyArrayObject *arr)\n{\n\tstatic char bitmask = 0x80;\n\tchar *ptr; /* points to the byte to test */\n\tchar byteorder;\n\tint elsize;\n\n\telsize = arr->descr->elsize;\n\tbyteorder = arr->descr->byteorder;\n\tptr = arr->data;\n\tif (elsize > 1 && \\\n\t (byteorder == PyArray_LITTLE ||\t\\\n\t (byteorder == PyArray_NATIVE &&\n\t PyArray_ISNBO(PyArray_LITTLE))))\n\t\tptr += elsize-1;\n\t\n\treturn ((*ptr & bitmask) != 0);\t\n}\n\nstatic char\n_scalar_kind(int typenum, PyArrayObject **arr) \n{\n\tif (PyTypeNum_ISSIGNED(typenum)) {\n\t\tif (_signbit_set(*arr)) return UFUNC_INTNEG_SCALAR;\n\t\telse return UFUNC_INTPOS_SCALAR;\n\t}\n\tif (PyTypeNum_ISFLOAT(typenum)) return UFUNC_FLOAT_SCALAR;\n\tif (PyTypeNum_ISUNSIGNED(typenum)) return UFUNC_INTPOS_SCALAR;\n\tif (PyTypeNum_ISCOMPLEX(typenum)) return UFUNC_COMPLEX_SCALAR;\n\tif (PyTypeNum_ISBOOL(typenum)) return UFUNC_BOOL_SCALAR;\n\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, NULL);\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\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 PyObject *context=NULL;\n PyObject *obj;\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 /* Get each input argument */\n for (i=0; inin; i++) {\n obj = PyTuple_GET_ITEM(args,i);\n if (!PyArray_Check(obj) && !PyArray_IsScalar(obj, Generic)) {\n context = Py_BuildValue(\"OOi\", self, args, i);\n }\n else context = NULL;\n mps[i] = (PyArrayObject *)PyArray_FromAny(obj, NULL, 0, 0, 0, context);\n Py_XDECREF(context);\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, NULL);\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\tchar **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\tchar **bufptr = loop->bufptr;\n\t\tchar **buffer = loop->buffer;\n\t\tchar **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 = (PyObject **)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, NULL);\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, NULL);\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, *context; \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, NULL);\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 if (!PyArray_Check(op) && !PyArray_IsScalar(op, Generic)) {\n context = Py_BuildValue(\"O(O)i\", self, op, 0);\n }\n else {\n context = NULL;\n }\n\tmp = (PyArrayObject *)PyArray_FromAny(op, NULL, 0, 0, 0, context);\n Py_XDECREF(context);\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\nstatic PyObject *\n_find_array_wrap(PyObject *args)\n{\n\tint nargs, i;\n\tint np = 0;\n\tdouble priority, maxpriority;\n\tPyObject *with_wrap[MAX_ARGS], *wraps[MAX_ARGS];\n\tPyObject *obj, *wrap = NULL;\n\n\tnargs = PyTuple_GET_SIZE(args);\n\tfor (i=0; i maxpriority) {\n\t\t\tmaxpriority = priority;\n\t\t\tPy_DECREF(wrap);\n\t\t\twrap = wraps[i];\n\t\t} else {\n\t\t\tPy_DECREF(wraps[i]);\n\t\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 *wrap;\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\twrap = _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 (wrap != NULL) {\n\t\t\tres = PyObject_CallFunction(wrap, \"O(OOi)\",\n\t\t\t\t\t\t mps[j], self, args, i);\n\t\t\tif (res == NULL && PyErr_ExceptionMatches(PyExc_TypeError)) {\n\t\t\t\tPyErr_Clear();\n\t\t\t\tres = PyObject_CallFunctionObjArgs(wrap, mps[j], NULL);\n\t\t\t}\n\t\t\tPy_DECREF(wrap);\n\t\t\tif (res == NULL) goto fail;\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}\n fail:\n\tfor(i=self->nin; inargs; i++) Py_XDECREF(mps[i]);\n\treturn NULL;\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 **)(((char *)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": 542, + "end_line": 568, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 27, + "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": 574, + "end_line": 661, + "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": 667, + "end_line": 739, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 73, + "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": 236, + "parameters": [ + "loop", + "arg_types", + "mps" + ], + "start_line": 747, + "end_line": 785, + "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": 791, + "end_line": 807, + "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": 289, + "complexity": 76, + "token_count": 2255, + "parameters": [ + "loop", + "args", + "mps" + ], + "start_line": 812, + "end_line": 1204, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 393, + "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": 1207, + "end_line": 1219, + "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": 1222, + "end_line": 1234, + "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": 1237, + "end_line": 1274, + "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": 1407, + "parameters": [ + "self", + "args", + "mps" + ], + "start_line": 1346, + "end_line": 1614, + "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": 119, + "parameters": [ + "self", + "otype", + "str" + ], + "start_line": 1617, + "end_line": 1638, + "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": 127, + "parameters": [ + "loop", + "arr", + "rtype" + ], + "start_line": 1641, + "end_line": 1671, + "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": 1674, + "end_line": 1887, + "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": 1899, + "end_line": 2034, + "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": 2038, + "end_line": 2176, + "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": 2198, + "end_line": 2327, + "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": 121, + "complexity": 32, + "token_count": 759, + "parameters": [ + "self", + "args", + "kwds", + "operation" + ], + "start_line": 2336, + "end_line": 2471, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 136, + "top_nesting_level": 0 + }, + { + "name": "_find_array_wrap", + "long_name": "_find_array_wrap( PyObject * args)", + "filename": "ufuncobject.c", + "nloc": 44, + "complexity": 10, + "token_count": 244, + "parameters": [ + "args" + ], + "start_line": 2474, + "end_line": 2518, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 45, + "top_nesting_level": 0 + }, + { + "name": "ufunc_generic_call", + "long_name": "ufunc_generic_call( PyUFuncObject * self , PyObject * args)", + "filename": "ufuncobject.c", + "nloc": 61, + "complexity": 16, + "token_count": 449, + "parameters": [ + "self", + "args" + ], + "start_line": 2521, + "end_line": 2600, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 80, + "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": 2603, + "end_line": 2621, + "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": 534, + "parameters": [ + "dummy", + "args", + "kwds" + ], + "start_line": 2629, + "end_line": 2718, + "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": 2723, + "end_line": 2755, + "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": 2759, + "end_line": 2803, + "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": 2806, + "end_line": 2812, + "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": 2815, + "end_line": 2822, + "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": 2834, + "end_line": 2903, + "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": 2907, + "end_line": 2911, + "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": 2914, + "end_line": 2918, + "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": 2921, + "end_line": 2924, + "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": 2944, + "end_line": 2966, + "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": 2969, + "end_line": 2977, + "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": 2980, + "end_line": 3063, + "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": 3068, + "end_line": 3071, + "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": "_signbit_set", + "long_name": "_signbit_set( PyArrayObject * arr)", + "filename": "ufuncobject.c", + "nloc": 16, + "complexity": 5, + "token_count": 89, + "parameters": [ + "arr" + ], + "start_line": 776, + "end_line": 793, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 18, + "top_nesting_level": 0 + }, + { + "name": "_scalar_kind", + "long_name": "_scalar_kind( int typenum , PyArrayObject ** arr)", + "filename": "ufuncobject.c", + "nloc": 12, + "complexity": 7, + "token_count": 78, + "parameters": [ + "typenum", + "arr" + ], + "start_line": 796, + "end_line": 808, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 13, + "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": 236, + "parameters": [ + "loop", + "arg_types", + "mps" + ], + "start_line": 817, + "end_line": 855, + "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": 861, + "end_line": 877, + "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": 289, + "complexity": 76, + "token_count": 2255, + "parameters": [ + "loop", + "args", + "mps" + ], + "start_line": 882, + "end_line": 1274, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 393, + "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": 1277, + "end_line": 1289, + "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": 1292, + "end_line": 1304, + "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": 1307, + "end_line": 1344, + "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": 1407, + "parameters": [ + "self", + "args", + "mps" + ], + "start_line": 1416, + "end_line": 1684, + "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": 119, + "parameters": [ + "self", + "otype", + "str" + ], + "start_line": 1687, + "end_line": 1708, + "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": 127, + "parameters": [ + "loop", + "arr", + "rtype" + ], + "start_line": 1711, + "end_line": 1741, + "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": 1744, + "end_line": 1957, + "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": 1969, + "end_line": 2104, + "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": 2108, + "end_line": 2246, + "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": 2268, + "end_line": 2397, + "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": 121, + "complexity": 32, + "token_count": 759, + "parameters": [ + "self", + "args", + "kwds", + "operation" + ], + "start_line": 2406, + "end_line": 2541, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 136, + "top_nesting_level": 0 + }, + { + "name": "_find_array_wrap", + "long_name": "_find_array_wrap( PyObject * args)", + "filename": "ufuncobject.c", + "nloc": 44, + "complexity": 10, + "token_count": 244, + "parameters": [ + "args" + ], + "start_line": 2544, + "end_line": 2588, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 45, + "top_nesting_level": 0 + }, + { + "name": "ufunc_generic_call", + "long_name": "ufunc_generic_call( PyUFuncObject * self , PyObject * args)", + "filename": "ufuncobject.c", + "nloc": 61, + "complexity": 16, + "token_count": 449, + "parameters": [ + "self", + "args" + ], + "start_line": 2591, + "end_line": 2670, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 80, + "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": 2673, + "end_line": 2691, + "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": 534, + "parameters": [ + "dummy", + "args", + "kwds" + ], + "start_line": 2699, + "end_line": 2788, + "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": 2793, + "end_line": 2825, + "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": 2829, + "end_line": 2873, + "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": 2876, + "end_line": 2882, + "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": 2885, + "end_line": 2892, + "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": 2904, + "end_line": 2973, + "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": 2977, + "end_line": 2981, + "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": 2984, + "end_line": 2988, + "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": 2991, + "end_line": 2994, + "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": 3014, + "end_line": 3036, + "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": 3039, + "end_line": 3047, + "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": 3050, + "end_line": 3133, + "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": 3138, + "end_line": 3141, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 0 + } + ], + "changed_methods": [ + { + "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": "construct_matrices", + "long_name": "construct_matrices( PyUFuncLoopObject * loop , PyObject * args , PyArrayObject ** mps)", + "filename": "ufuncobject.c", + "nloc": 289, + "complexity": 76, + "token_count": 2255, + "parameters": [ + "loop", + "args", + "mps" + ], + "start_line": 812, + "end_line": 1204, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 393, + "top_nesting_level": 0 + }, + { + "name": "_signbit_set", + "long_name": "_signbit_set( PyArrayObject * arr)", + "filename": "ufuncobject.c", + "nloc": 16, + "complexity": 5, + "token_count": 89, + "parameters": [ + "arr" + ], + "start_line": 776, + "end_line": 793, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 18, + "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": 574, + "end_line": 661, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 88, + "top_nesting_level": 0 + }, + { + "name": "_scalar_kind", + "long_name": "_scalar_kind( int typenum , PyArrayObject ** arr)", + "filename": "ufuncobject.c", + "nloc": 12, + "complexity": 7, + "token_count": 78, + "parameters": [ + "typenum", + "arr" + ], + "start_line": 796, + "end_line": 808, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 13, + "top_nesting_level": 0 + } + ], + "nloc": 2291, + "complexity": 503, + "token_count": 17217, + "diff_parsed": { + "added": [ + "\t\t\tif (!PyArray_CanCoerceScalar(arg_types[j],", + "\t\t\t\t\t\t self->types[i*self->nargs+j],", + "\t\t\t\t\t\t scalars[j]))", + "\t\telse scalars[i] = PyArray_ScalarKind(arg_types[i], &(mps[i]));" + ], + "deleted": [ + "", + "#define UFUNC_NOSCALAR 0", + "#define UFUNC_BOOL_SCALAR 1", + "#define UFUNC_INTPOS_SCALAR 2", + "#define UFUNC_INTNEG_SCALAR 3", + "#define UFUNC_FLOAT_SCALAR 4", + "#define UFUNC_COMPLEX_SCALAR 5", + "#define UFUNC_OBJECT_SCALAR 6", + "", + "static int", + "_cancoerce(char thistype, char neededtype, char scalar)", + "{", + "", + "\tswitch(scalar) {", + "\tcase UFUNC_NOSCALAR:", + "\tcase UFUNC_BOOL_SCALAR:", + "\tcase UFUNC_OBJECT_SCALAR:", + "\t\treturn PyArray_CanCastSafely(thistype, neededtype);", + "\tcase UFUNC_INTPOS_SCALAR:", + "\t\treturn (neededtype >= PyArray_UBYTE);", + "\tcase UFUNC_INTNEG_SCALAR:", + "\t\treturn (neededtype >= PyArray_BYTE) &&\t\t\\", + "\t\t\t!(PyTypeNum_ISUNSIGNED(neededtype));", + "\tcase UFUNC_FLOAT_SCALAR:", + "\t\treturn (neededtype >= PyArray_FLOAT);", + "\tcase UFUNC_COMPLEX_SCALAR:", + "\t\treturn (neededtype >= PyArray_CFLOAT);", + "\t}", + "\tfprintf(stderr, \"\\n**Error** coerce fall through: %d %d %d\\n\\n\",", + "\t\tthistype, neededtype, scalar);", + "\treturn 1; /* should never get here... */", + "}", + "", + "", + "\t\t\tif (!_cancoerce(arg_types[j],", + "\t\t\t\t\tself->types[i*self->nargs+j],", + "\t\t\t\t\tscalars[j]))", + "static int", + "_signbit_set(PyArrayObject *arr)", + "{", + "\tstatic char bitmask = 0x80;", + "\tchar *ptr; /* points to the byte to test */", + "\tchar byteorder;", + "\tint elsize;", + "", + "\telsize = arr->descr->elsize;", + "\tbyteorder = arr->descr->byteorder;", + "\tptr = arr->data;", + "\tif (elsize > 1 && \\", + "\t (byteorder == PyArray_LITTLE ||\t\\", + "\t (byteorder == PyArray_NATIVE &&", + "\t PyArray_ISNBO(PyArray_LITTLE))))", + "\t\tptr += elsize-1;", + "", + "\treturn ((*ptr & bitmask) != 0);", + "}", + "", + "static char", + "_scalar_kind(int typenum, PyArrayObject **arr)", + "{", + "\tif (PyTypeNum_ISSIGNED(typenum)) {", + "\t\tif (_signbit_set(*arr)) return UFUNC_INTNEG_SCALAR;", + "\t\telse return UFUNC_INTPOS_SCALAR;", + "\t}", + "\tif (PyTypeNum_ISFLOAT(typenum)) return UFUNC_FLOAT_SCALAR;", + "\tif (PyTypeNum_ISUNSIGNED(typenum)) return UFUNC_INTPOS_SCALAR;", + "\tif (PyTypeNum_ISCOMPLEX(typenum)) return UFUNC_COMPLEX_SCALAR;", + "\tif (PyTypeNum_ISBOOL(typenum)) return UFUNC_BOOL_SCALAR;", + "", + "\treturn UFUNC_OBJECT_SCALAR;", + "}", + "", + "", + "\t\telse scalars[i] = _scalar_kind(arg_types[i], &(mps[i]));" + ] + } + } + ] + }, + { + "hash": "2236762d7c08265d5bd59685a0e761a91a3d1f9b", + "msg": "Fix .view to not return scalars.", + "author": { + "name": "Travis Oliphant", + "email": "oliphant@enthought.com" + }, + "committer": { + "name": "Travis Oliphant", + "email": "oliphant@enthought.com" + }, + "author_date": "2006-02-14T00:41:38+00:00", + "author_timezone": 0, + "committer_date": "2006-02-14T00:41:38+00:00", + "committer_timezone": 0, + "branches": [ + "main" + ], + "in_main_branch": true, + "merge": false, + "parents": [ + "b3746796dc5608645ff5a9f4e46b4ef697a51a77" + ], + "project_name": "repo_copy", + "project_path": "/tmp/tmpdjwupkfu/repo_copy", + "deletions": 9, + "insertions": 13, + "lines": 22, + "files": 2, + "dmm_unit_size": null, + "dmm_unit_complexity": null, + "dmm_unit_interfacing": null, + "modified_files": [ + { + "old_path": "numpy/core/src/arraymethods.c", + "new_path": "numpy/core/src/arraymethods.c", + "filename": "arraymethods.c", + "extension": "c", + "change_type": "MODIFY", + "diff": "@@ -155,8 +155,6 @@ array_squeeze(PyArrayObject *self, PyObject *args)\n return _ARET(PyArray_Squeeze(self));\n }\n \n-\n-\n static char doc_view[] = \"a.view() return a new view of array with same data. type can be either a new sub-type object or a data-descriptor object\";\n \n static PyObject *\n@@ -171,15 +169,15 @@ array_view(PyArrayObject *self, PyObject *args)\n \t\tif (PyType_Check(otype) &&\t\t\t\t\\\n \t\t PyType_IsSubtype((PyTypeObject *)otype, \n \t\t\t\t &PyBigArray_Type)) {\n-\t\t\treturn _ARET(PyArray_View(self, NULL, \n-\t\t\t\t\t\t (PyTypeObject *)otype));\n-\t\t}\n+\t\t\treturn PyArray_View(self, NULL, \n+ (PyTypeObject *)otype);\n+ }\n \t\telse {\n \t\t\tif (PyArray_DescrConverter(otype, &type) == PY_FAIL) \n \t\t\t\treturn NULL;\n \t\t}\n \t}\n-\treturn _ARET(PyArray_View(self, type, NULL));\n+\treturn PyArray_View(self, type, NULL);\n }\n \n static char doc_argmax[] = \"a.argmax(axis=None)\";\n@@ -1521,7 +1519,7 @@ array_setflags(PyArrayObject *self, PyObject *args, PyObject *kwds)\n }\n \n static char doc_newbyteorder[] = \"a.newbyteorder() is equivalent\\n\" \\\n-\t\" to a.view(a.dtypedescr.newbytorder())\\n\";\n+\t\" to a.view(a.dtype.newbytorder())\\n\";\n \n static PyObject *\n array_newbyteorder(PyArrayObject *self, PyObject *args) \n@@ -1534,7 +1532,7 @@ array_newbyteorder(PyArrayObject *self, PyObject *args)\n \n \tnew = PyArray_DescrNewByteorder(self->descr, endian);\n \tif (!new) return NULL;\n-\treturn _ARET(PyArray_View(self,\tnew, NULL));\n+\treturn PyArray_View(self, new, NULL));\n \n }\n \n", + "added_lines": 6, + "deleted_lines": 8, + "source_code": "\n/* Should only be used if x is known to be an nd-array */\n#define _ARET(x) PyArray_Return((PyArrayObject *)(x))\n\nstatic char doc_take[] = \"a.take(indices, axis=None). Selects the elements \"\\\n\t\"in indices from array a along the given axis.\";\n\nstatic PyObject *\narray_take(PyArrayObject *self, PyObject *args, PyObject *kwds) \n{\n\tint dimension=MAX_DIMS;\n\tPyObject *indices;\n\tstatic char *kwlist[] = {\"indices\", \"axis\", NULL};\n\t\n\tdimension=0;\n\tif (!PyArg_ParseTupleAndKeywords(args, kwds, \"O|O&\", kwlist, \n\t\t\t\t\t &indices, PyArray_AxisConverter,\n\t\t\t\t\t &dimension))\n\t\treturn NULL;\n\t\n\treturn _ARET(PyArray_Take(self, indices, dimension));\n}\n\nstatic char doc_fill[] = \"a.fill(value) places the scalar value at every\"\\\n\t\"position in the array.\";\n\nstatic PyObject *\narray_fill(PyArrayObject *self, PyObject *args)\n{\n\tPyObject *obj;\n\tif (!PyArg_ParseTuple(args, \"O\", &obj))\n\t\treturn NULL;\n\tif (PyArray_FillWithScalar(self, obj) < 0) return NULL;\n\tPy_INCREF(Py_None);\n\treturn Py_None;\n}\n\nstatic char doc_put[] = \"a.put(values, indices) sets a.flat[n] = v[n] \"\\\n\t\"for each n in indices. v can be scalar or shorter than indices, \"\\\n\t\"will repeat.\";\n\nstatic PyObject *\narray_put(PyArrayObject *self, PyObject *args, PyObject *kwds) \n{\n\tPyObject *indices, *values;\n\tstatic char *kwlist[] = {\"values\", \"indices\", NULL};\n\t\n\tif (!PyArg_ParseTupleAndKeywords(args, kwds, \"OO\", kwlist,\n\t\t\t\t\t &values, &indices))\n\t\treturn NULL;\n\treturn PyArray_Put(self, values, indices);\n}\n\nstatic char doc_putmask[] = \"a.putmask(values, mask) sets a.flat[n] = v[n] \"\\\n\t\"for each n where mask.flat[n] is TRUE. v can be scalar.\";\n\nstatic PyObject *\narray_putmask(PyArrayObject *self, PyObject *args, PyObject *kwds) \n{\n\tPyObject *mask, *values;\n\n\tstatic char *kwlist[] = {\"values\", \"mask\", NULL};\n\t\n\tif (!PyArg_ParseTupleAndKeywords(args, kwds, \"OO\", kwlist,\n\t\t\t\t\t &values, &mask))\n\t\treturn NULL;\n\treturn PyArray_PutMask(self, values, mask);\n}\n\n/* Used to reshape a Fortran Array */\nstatic void\n_reverse_shape(PyArray_Dims *newshape)\n{\n\tint i, n = newshape->len;\n\tintp *ptr = newshape->ptr;\n\tintp *eptr;\n\tintp tmp;\n\tint len = n >> 1;\n\n\teptr = ptr+n-1;\n\tfor(i=0; i) return a new view of array with same data. type can be either a new sub-type object or a data-descriptor object\";\n\nstatic PyObject *\narray_view(PyArrayObject *self, PyObject *args)\n{\n\tPyObject *otype=NULL;\n PyArray_Descr *type=NULL;\n\n\tif (!PyArg_ParseTuple(args, \"|O\", &otype)) return NULL;\n\n\tif (otype) {\n\t\tif (PyType_Check(otype) &&\t\t\t\t\\\n\t\t PyType_IsSubtype((PyTypeObject *)otype, \n\t\t\t\t &PyBigArray_Type)) {\n\t\t\treturn PyArray_View(self, NULL, \n (PyTypeObject *)otype);\n }\n\t\telse {\n\t\t\tif (PyArray_DescrConverter(otype, &type) == PY_FAIL) \n\t\t\t\treturn NULL;\n\t\t}\n\t}\n\treturn PyArray_View(self, type, NULL);\n}\n\nstatic char doc_argmax[] = \"a.argmax(axis=None)\";\n\nstatic PyObject *\narray_argmax(PyArrayObject *self, PyObject *args) \n{\n\tint axis=MAX_DIMS;\n\t\n\tif (!PyArg_ParseTuple(args, \"|O&\", PyArray_AxisConverter, \n\t\t\t &axis)) return NULL;\n\t\n\treturn _ARET(PyArray_ArgMax(self, axis));\n}\n\nstatic char doc_argmin[] = \"a.argmin(axis=None)\";\n\nstatic PyObject *\narray_argmin(PyArrayObject *self, PyObject *args) \n{\n\tint axis=MAX_DIMS;\n\t\n\tif (!PyArg_ParseTuple(args, \"|O&\", PyArray_AxisConverter, \n\t\t\t &axis)) return NULL;\n\t\n\treturn _ARET(PyArray_ArgMin(self, axis));\n}\n\nstatic char doc_max[] = \"a.max(axis=None)\";\n\nstatic PyObject *\narray_max(PyArrayObject *self, PyObject *args) \n{\n\tint axis=MAX_DIMS;\n\t\n\tif (!PyArg_ParseTuple(args, \"|O&\", PyArray_AxisConverter, \n\t\t\t &axis)) return NULL;\n\t\n\treturn PyArray_Max(self, axis);\n}\n\nstatic char doc_ptp[] = \"a.ptp(axis=None) a.max(axis)-a.min(axis)\";\n\nstatic PyObject *\narray_ptp(PyArrayObject *self, PyObject *args) \n{\n\tint axis=MAX_DIMS;\n\t\n\tif (!PyArg_ParseTuple(args, \"|O&\", PyArray_AxisConverter, \n\t\t\t &axis)) return NULL;\n\t\n\treturn PyArray_Ptp(self, axis);\n}\n\n\nstatic char doc_min[] = \"a.min(axis=None)\";\n\nstatic PyObject *\narray_min(PyArrayObject *self, PyObject *args) \n{\n\tint axis=MAX_DIMS;\n\t\n\tif (!PyArg_ParseTuple(args, \"|O&\", PyArray_AxisConverter, \n\t\t\t &axis)) return NULL;\n\t\n\treturn PyArray_Min(self, axis);\n}\n\n\nstatic char doc_swapaxes[] = \"a.swapaxes(axis1, axis2) returns new view with axes swapped.\";\n\nstatic PyObject *\narray_swapaxes(PyArrayObject *self, PyObject *args)\n{\n\tint axis1, axis2;\n\n\tif (!PyArg_ParseTuple(args, \"ii\", &axis1, &axis2)) return NULL;\n\n\treturn PyArray_SwapAxes(self, axis1, axis2);\n}\n\nstatic char doc_getfield[] = \"m.getfield(dtype, offset) returns a field \"\\\n\t\" of the given array as a certain type. A field is a view of \"\\\n\t\" the array's data with each itemsize determined by the given type\"\\\n\t\" and the offset into the current array.\";\n\n/* steals typed reference */\n/*OBJECT_API\n Get a subset of bytes from each element of the array\n*/\nstatic PyObject *\nPyArray_GetField(PyArrayObject *self, PyArray_Descr *typed, int offset)\n{\n\tPyObject *ret=NULL;\n\n\tif (offset < 0 || (offset + typed->elsize) > self->descr->elsize) {\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 self->descr->elsize-typed->elsize, offset);\n\t\tPy_DECREF(typed);\n\t\treturn NULL;\n\t}\n\tret = PyArray_NewFromDescr(self->ob_type, \n\t\t\t\t typed,\n\t\t\t\t self->nd, self->dimensions,\n\t\t\t\t self->strides, \n\t\t\t\t self->data + offset,\n\t\t\t\t self->flags, (PyObject *)self);\n\tif (ret == NULL) return NULL;\n\tPy_INCREF(self);\n\t((PyArrayObject *)ret)->base = (PyObject *)self; \n\n\tPyArray_UpdateFlags((PyArrayObject *)ret, UPDATE_ALL_FLAGS);\n\treturn ret;\n}\n\nstatic PyObject *\narray_getfield(PyArrayObject *self, PyObject *args, PyObject *kwds)\n{\n\n PyArray_Descr *dtype;\n\tint offset = 0;\n\tstatic char *kwlist[] = {\"dtype\", \"offset\", 0};\n\t\n\tif (!PyArg_ParseTupleAndKeywords(args, kwds, \"O&|i\", kwlist,\n\t\t\t\t\t PyArray_DescrConverter,\n\t\t\t\t\t &dtype, &offset)) return NULL;\n\t\n\treturn _ARET(PyArray_GetField(self, dtype, offset));\n}\n\n\nstatic char doc_setfield[] = \"m.setfield(value, dtype, offset) places val \"\\\n\t\"into field of the given array defined by the data type and offset.\";\n\n/*OBJECT_API\n Set a subset of bytes from each element of the array\n*/\nstatic int\nPyArray_SetField(PyArrayObject *self, PyArray_Descr *dtype,\n\t\t int offset, PyObject *val)\n{\n\tPyObject *ret=NULL;\n\tint retval = 0;\n \n\tif (offset < 0 || (offset + dtype->elsize) > self->descr->elsize) {\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 self->descr->elsize-dtype->elsize, offset);\n\t\tPy_DECREF(dtype);\n\t\treturn -1;\n\t}\n\tret = PyArray_NewFromDescr(self->ob_type, \n\t\t\t\t dtype, self->nd, self->dimensions,\n\t\t\t\t self->strides, self->data + offset,\n\t\t\t\t self->flags, (PyObject *)self);\n\tif (ret == NULL) return -1;\n\tPy_INCREF(self);\n\t((PyArrayObject *)ret)->base = (PyObject *)self;\n\n\tPyArray_UpdateFlags((PyArrayObject *)ret, UPDATE_ALL_FLAGS);\t\n\tretval = PyArray_CopyObject((PyArrayObject *)ret, val);\n\tPy_DECREF(ret);\n\treturn retval;\n}\n\nstatic PyObject *\narray_setfield(PyArrayObject *self, PyObject *args, PyObject *kwds)\n{\n PyArray_Descr *dtype;\n\tint offset = 0;\n\tPyObject *value;\n\tstatic char *kwlist[] = {\"value\", \"dtype\", \"offset\", 0};\n\t\n\tif (!PyArg_ParseTupleAndKeywords(args, kwds, \"OO&|i\", kwlist,\n\t\t\t\t\t &value, PyArray_DescrConverter,\n\t\t\t\t\t &dtype, &offset)) return NULL;\n\n\tif (PyArray_SetField(self, dtype, offset, value) < 0)\n\t\treturn NULL;\n\tPy_INCREF(Py_None);\n\treturn Py_None;\n}\n\n/* This doesn't change the descriptor just the actual data...\n */\n\n/*OBJECT_API*/\nstatic PyObject *\nPyArray_Byteswap(PyArrayObject *self, Bool inplace)\n{\n PyArrayObject *ret;\n\tintp size;\n\tPyArray_CopySwapNFunc *copyswapn;\n\tPyArray_CopySwapFunc *copyswap;\n\tPyArrayIterObject *it;\n\n\tif (inplace) {\n\t\tcopyswapn = self->descr->f->copyswapn;\n\t\t\n\t\tsize = PyArray_SIZE(self);\n\t\tif (PyArray_ISONESEGMENT(self)) {\n\t\t\tcopyswapn(self->data, NULL, size, 1, \n\t\t\t\t self->descr->elsize);\n\t\t}\n\t\telse { /* Use iterator */\n\t\t\t\n\t\t\tit = (PyArrayIterObject *)\\\n\t\t\t\tPyArray_IterNew((PyObject *)self);\n\t\t\tcopyswap = self->descr->f->copyswap;\n\t\t\twhile (it->index < it->size) {\n\t\t\t\tcopyswap(it->dataptr, NULL, 1, \n\t\t\t\t\t self->descr->elsize);\n\t\t\t\tPyArray_ITER_NEXT(it);\n\t\t\t}\n\t\t\tPy_DECREF(it);\n\t\t}\n\t\t\n\t\tPy_INCREF(self);\n\t\treturn (PyObject *)self;\n\t}\n\telse {\n\t\tif ((ret = (PyArrayObject *)PyArray_NewCopy(self,-1)) == NULL) \n\t\t\treturn NULL;\n\t\t\n\t\tsize = PyArray_SIZE(self);\n\n\t\t/* now ret has the same dtypedescr as self (including\n\t\t byteorder)\n\t\t*/\n\n\t\tret->descr->f->copyswapn(ret->data, NULL, size, 1, \n\t\t\t\t\t ret->descr->elsize);\n\n\t\treturn (PyObject *)ret;\n\t}\n}\n\nstatic char doc_byteswap[] = \"m.byteswap(False) Swap the bytes in\"\\\n\t\" the array. Return the byteswapped array. If the first argument\"\\\n\t\" is TRUE, byteswap in-place and return a reference to self.\";\n\nstatic PyObject *\narray_byteswap(PyArrayObject *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\treturn PyArray_Byteswap(self, inplace);\n}\n\nstatic char doc_tolist[] = \"m.tolist().\t Copy the data portion of the array\"\\\n\t\" to a hierarchical python list and return that list.\";\n\nstatic PyObject *\narray_tolist(PyArrayObject *self, PyObject *args) \n{\n if (!PyArg_ParseTuple(args, \"\")) return NULL;\n if (self->nd <= 0) {\n PyErr_SetString(PyExc_ValueError, \n\t\t\t\t\"can't convert a 0-d array to a list\");\n return NULL;\n }\n\t\n return PyArray_ToList(self);\n}\n\nstatic char doc_tostring[] = \"m.tostring() Construct a Python string \"\\\n \"containing the raw bytes in the array\";\n\nstatic PyObject *\narray_tostring(PyArrayObject *self, PyObject *args)\n{\n if (!PyArg_ParseTuple(args, \"\")) return NULL;\n return PyArray_ToString(self);\n}\n\nstatic char doc_tofile[] = \"m.tofile(fid, sep=\"\") write the data to a file.\";\n\nstatic PyObject *\narray_tofile(PyArrayObject *self, PyObject *args, PyObject *kwds)\n{\n\tint ret;\n PyObject *file;\n\tFILE *fd;\n char *sep=\"\";\n\tchar *format=\"\";\n\tchar *mode=\"\";\n\tstatic char *kwlist[] = {\"file\", \"sep\", \"format\", NULL};\n \n\tif (!PyArg_ParseTupleAndKeywords(args, kwds, \"O|ss\", kwlist, \n &file, &sep, &format)) return NULL;\n\n\tif (PyString_Check(file)) {\n\t\tif (sep == \"\") mode=\"wb\";\n\t\telse mode=\"w\";\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\tfd = PyFile_AsFile(file);\n\tif (fd == NULL) {\n\t\tPyErr_SetString(PyExc_IOError, \"first argument must be a \" \\\n\t\t\t\t\"string or open file\");\n\t\tPy_DECREF(file);\n\t\treturn NULL;\n\t}\n\tret = PyArray_ToFile(self, fd, sep, format);\n\tPy_DECREF(file);\n\tif (ret < 0) return NULL;\n Py_INCREF(Py_None);\n return Py_None;\n}\n\nstatic char doc_toscalar[] = \"m.item(). Copy the first data point of \"\\\n\t\"the array to a standard Python scalar and return it.\";\n\nstatic PyObject *\narray_toscalar(PyArrayObject *self, PyObject *args) {\n if (!PyArg_ParseTuple(args, \"\")) return NULL;\n\tif (self->nd == 0 || PyArray_SIZE(self) == 1) \n\t\treturn self->descr->f->getitem(self->data, self);\n\telse {\n\t\tPyErr_SetString(PyExc_ValueError, \"can only convert an\"\t\\\n\t\t\t\t\" array of size 1 to Python scalar.\");\n\t\treturn NULL;\n\t}\n}\n\nstatic char doc_cast[] = \"m.astype(t).\tCast array m to type t.\t \\n\\n\"\\\n\t\"t can be either a string representing a typecode, or a python type\"\\\n\t\" object of type int, float, or complex.\";\n\nstatic PyObject *\narray_cast(PyArrayObject *self, PyObject *args) \n{\n\tPyArray_Descr *descr=NULL;\n\tPyObject *obj;\n\t\n if (!PyArg_ParseTuple(args, \"O&\", PyArray_DescrConverter,\n\t\t\t &descr)) return NULL;\n\t\n\tif (descr == self->descr) {\n\t\tobj = _ARET(PyArray_NewCopy(self,0));\n\t\tPy_XDECREF(descr);\n\t\treturn obj;\n\t}\n\treturn _ARET(PyArray_CastToType(self, descr, 0));\n}\t \n\n/* default sub-type implementation */\n\nstatic char doc_wraparray[] = \"m.__array_wrap__(obj) returns an object of \"\\\n\t\"type m from the ndarray object obj\";\n\nstatic PyObject *\narray_wraparray(PyArrayObject *self, PyObject *args)\n{\n\tPyObject *arr;\n\tPyObject *ret;\n\t\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}\t\n\n\tPy_INCREF(PyArray_DESCR(arr));\n\tret = PyArray_NewFromDescr(self->ob_type, \n\t\t\t\t PyArray_DESCR(arr),\n\t\t\t\t PyArray_NDIM(arr),\n\t\t\t\t PyArray_DIMS(arr), \n\t\t\t\t PyArray_STRIDES(arr), PyArray_DATA(arr),\n\t\t\t\t PyArray_FLAGS(arr), (PyObject *)self);\n\tif (ret == NULL) return NULL;\n\tPy_INCREF(arr);\n\tPyArray_BASE(ret) = arr;\n\treturn ret;\n}\n\n/* NO-OP --- just so all subclasses will have one by default. */\nstatic PyObject *\narray_finalize(PyArrayObject *self, PyObject *args)\n{\n\tPy_INCREF(Py_None);\n\treturn Py_None;\n}\n\n\nstatic char doc_array_getarray[] = \"m.__array__(|dtype) just returns either a new reference to self if dtype is not given or a new array of provided data type if dtype is different from the current dtype of the array.\";\n\nstatic PyObject *\narray_getarray(PyArrayObject *self, PyObject *args) \n{\n\tPyArray_Descr *newtype=NULL;\n\tPyObject *ret;\n\t\n\tif (!PyArg_ParseTuple(args, \"|O&\", PyArray_DescrConverter,\n\t\t\t &newtype)) return NULL;\n\t\n\t/* convert to PyArray_Type or PyBigArray_Type */\n\tif (!PyArray_CheckExact(self) || !PyBigArray_CheckExact(self)) {\n\t\tPyObject *new;\n\t\tPyTypeObject *subtype = &PyArray_Type;\n\n\t\tif (!PyType_IsSubtype(self->ob_type, &PyArray_Type)) {\n\t\t\tsubtype = &PyBigArray_Type;\n\t\t}\n\t\t\n\t\tPy_INCREF(PyArray_DESCR(self));\n\t\tnew = PyArray_NewFromDescr(subtype, \n\t\t\t\t\t PyArray_DESCR(self),\n\t\t\t\t\t PyArray_NDIM(self),\n\t\t\t\t\t PyArray_DIMS(self), \n\t\t\t\t\t PyArray_STRIDES(self), \n\t\t\t\t\t PyArray_DATA(self),\n\t\t\t\t\t PyArray_FLAGS(self), NULL);\n\t\tif (new == NULL) return NULL;\n\t\tPy_INCREF(self);\n\t\tPyArray_BASE(new) = (PyObject *)self;\n\t\tself = (PyArrayObject *)new;\n\t}\n\telse {\n\t\tPy_INCREF(self);\n\t}\n\t\t\n\tif ((newtype == NULL) || \\\n\t PyArray_EquivTypes(self->descr, newtype)) {\n\t\treturn (PyObject *)self;\n\t}\n\telse {\n\t\tret = PyArray_CastToType(self, newtype, 0);\n\t\tPy_DECREF(self);\n\t\treturn ret;\n\t}\n}\n\nstatic char doc_copy[] = \"m.copy(|fortran). Return a copy of the array.\\n\"\\\n\t\"If fortran == 0 then the result is contiguous (default). \\n\"\\\n\t\"If fortran > 0 then the result has fortran data order. \\n\"\\\n\t\"If fortran < 0 then the result has fortran data order only if m\\n\"\n\t\" is already in fortran order.\";\n\nstatic PyObject *\narray_copy(PyArrayObject *self, PyObject *args) \n{\n\tint fortran=0;\n if (!PyArg_ParseTuple(args, \"|i\", &fortran)) return NULL;\n\t\n return PyArray_NewCopy(self, fortran);\n}\n\nstatic char doc_resize[] = \"self.resize(new_shape). \"\\\n\t\"Change size and shape of self inplace.\\n\"\\\n\t\"\\n Array must own its own memory and not be referenced by other \" \\\n\t\"arrays\\n Returns None.\";\n\nstatic PyObject *\narray_resize(PyArrayObject *self, PyObject *args) \n{\n PyArray_Dims newshape;\n PyObject *ret;\n\tint n;\n\t\n\tn = PyTuple_Size(args);\n\tif (n <= 1) {\n\t\tif (!PyArg_ParseTuple(args, \"O&\", PyArray_IntpConverter, \n\t\t\t\t &newshape)) return NULL;\n\t}\n else {\n\t\tif (!PyArray_IntpConverter(args, &newshape)) {\n\t\t\tif (!PyErr_Occurred()) {\n\t\t\t\tPyErr_SetString(PyExc_TypeError, \n\t\t\t\t\t\t\"invalid shape\");\n\t\t\t} \n\t\t\treturn NULL;\t\t\t\n\t\t}\n\t}\n\tret = PyArray_Resize(self, &newshape);\n PyDimMem_FREE(newshape.ptr);\n if (ret == NULL) return NULL;\n\tPy_DECREF(ret);\n\tPy_INCREF(Py_None);\n\treturn Py_None;\n}\n\nstatic char doc_repeat[] = \"a.repeat(repeats=, axis=None)\\n\"\\\n\t\"\\n\"\\\n\t\" Copy elements of a, repeats times. The repeats argument must\\n\"\\\n\t\" be a sequence of length a.shape[axis] or a scalar.\";\n\nstatic PyObject *\narray_repeat(PyArrayObject *self, PyObject *args, PyObject *kwds) {\n\tPyObject *repeats;\n\tint axis=MAX_DIMS;\n\tstatic char *kwlist[] = {\"repeats\", \"axis\", NULL};\n\t\n\tif (!PyArg_ParseTupleAndKeywords(args, kwds, \"O|O&\", kwlist, \n\t\t\t\t\t &repeats, PyArray_AxisConverter,\n\t\t\t\t\t &axis)) return NULL;\n\t\n\treturn _ARET(PyArray_Repeat(self, repeats, axis));\n}\n\nstatic char doc_choose[] = \"a.choose(b0, b1, ..., bn)\\n\"\\\n\t\"\\n\"\\\n\t\"Return an array with elements chosen from 'a' at the positions\\n\"\\\n \"of the given arrays b_i. The array 'a' should be an integer array\\n\"\\\n \"with entries from 0 to n+1, and the b_i arrays should have the same\\n\"\\\n \"shape as 'a'.\";\n\nstatic PyObject *\narray_choose(PyArrayObject *self, PyObject *args) \n{\n\tPyObject *choices;\n\tint n;\n\t\n\tn = PyTuple_Size(args);\n\tif (n <= 1) {\n\t\tif (!PyArg_ParseTuple(args, \"O\", &choices))\n\t\t\treturn NULL;\n\t}\n else {\n\t\tchoices = args;\n\t}\n\t\n\treturn _ARET(PyArray_Choose(self, choices));\n}\n\nstatic char doc_sort[] = \"a.sort(axis=-1,kind='quicksort') sorts in place along axis. Return is None and kind can be 'quicksort', 'mergesort', or 'heapsort'\";\n\nstatic PyObject *\narray_sort(PyArrayObject *self, PyObject *args, PyObject *kwds) \n{\n\tint axis=-1;\n\tint val;\n\tPyArray_SORTKIND which=PyArray_QUICKSORT;\n\tstatic char *kwlist[] = {\"axis\", \"kind\", NULL};\n\t\n\tif (!PyArg_ParseTupleAndKeywords(args, kwds, \"|iO&\", kwlist, &axis,\n\t\t\t\t\t PyArray_SortkindConverter, &which))\n\t\treturn NULL;\n\t\n\tval = PyArray_Sort(self, axis, which);\n\tif (val < 0) return NULL;\n\tPy_INCREF(Py_None);\n\treturn Py_None;\n}\n\nstatic char doc_argsort[] = \"a.argsort(axis=-1,kind='quicksort')\\n\"\\\n\t\" Return the indexes into a that would sort it along the\"\\\n\t\" given axis; kind can be 'quicksort', 'mergesort', or 'heapsort'\";\n\nstatic PyObject *\narray_argsort(PyArrayObject *self, PyObject *args, PyObject *kwds) \n{\n\tint axis=-1;\n\tPyArray_SORTKIND which=PyArray_QUICKSORT;\n\tstatic char *kwlist[] = {\"axis\", \"kind\", NULL};\n\t\n\tif (!PyArg_ParseTupleAndKeywords(args, kwds, \"|iO&\", kwlist, &axis,\n\t\t\t\t\t PyArray_SortkindConverter, &which))\n\t\treturn NULL;\n\t\n\treturn _ARET(PyArray_ArgSort(self, axis, which));\n}\n\nstatic char doc_searchsorted[] = \"a.searchsorted(v)\\n\"\\\n\t\" Assuming that a is a 1-D array, in ascending order and\\n\"\\\n\t\" represents bin boundaries, then a.searchsorted(values) gives an\\n\"\\\n\t\" array of bin numbers, giving the bin into which each value would\\n\"\\\n\t\" be placed. This method is helpful for histograming. \\n\"\\\n\t\" Note: No warning is given if the boundaries, in a, are not \\n\"\\\n\t\" in ascending order.\";\n\nstatic PyObject *\narray_searchsorted(PyArrayObject *self, PyObject *args) \n{\n\tPyObject *values;\n\t\n\tif (!PyArg_ParseTuple(args, \"O\", &values)) return NULL;\n\t\n\treturn _ARET(PyArray_SearchSorted(self, values));\n}\n\nstatic char doc_deepcopy[] = \"Used if copy.deepcopy is called on an array.\";\n\nstatic PyObject *\narray_deepcopy(PyArrayObject *self, PyObject *args) \n{\n PyObject* visit;\n PyObject **optr;\n PyArrayIterObject *it;\n PyObject *copy, *ret, *deepcopy, *temp, *res;\n\n if (!PyArg_ParseTuple(args, \"O\", &visit)) return NULL;\n ret = PyArray_Copy(self);\n if (PyArray_ISOBJECT(self)) {\n copy = PyImport_ImportModule(\"copy\");\n if (copy == NULL) return NULL;\n deepcopy = PyObject_GetAttrString(copy, \"deepcopy\");\n Py_DECREF(copy);\n if (deepcopy == NULL) return NULL;\n it = (PyArrayIterObject *)PyArray_IterNew((PyObject *)self);\n if (it == NULL) {Py_DECREF(deepcopy); return NULL;}\n optr = (PyObject **)PyArray_DATA(ret);\n while(it->index < it->size) {\n temp = *((PyObject **)it->dataptr);\n Py_INCREF(temp);\n /* call deepcopy on this argument */\n res = PyObject_CallFunctionObjArgs(deepcopy, \n temp, visit, NULL);\n Py_DECREF(temp);\n Py_DECREF(*optr);\n *optr++ = res;\n PyArray_ITER_NEXT(it);\n }\n Py_DECREF(deepcopy);\n Py_DECREF(it);\n }\n return _ARET(ret);\n}\n\n/* Convert Object Array to flat list and pickle the flat list string */\nstatic PyObject *\n_getobject_pkl(PyArrayObject *self)\n{\n\tPyObject *theobject;\n\tPyArrayIterObject *iter=NULL;\n\tPyObject *list;\n\n\t\n\titer = (PyArrayIterObject *)PyArray_IterNew((PyObject *)self);\n\tif (iter == NULL) return NULL;\n\tlist = PyList_New(iter->size);\n\tif (list == NULL) {Py_DECREF(iter); return NULL;}\n\twhile (iter->index < iter->size) {\n\t\ttheobject = *((PyObject **)iter->dataptr);\n\t\tPy_INCREF(theobject);\n\t\tPyList_SET_ITEM(list, (int) iter->index, theobject);\n\t\tPyArray_ITER_NEXT(iter);\n\t}\n\tPy_DECREF(iter);\n\treturn list;\n}\n\nstatic int\n_setobject_pkl(PyArrayObject *self, PyObject *list)\n{\n\tPyObject *theobject;\n\tPyArrayIterObject *iter=NULL;\n\tint size;\n\n\tsize = self->descr->elsize;\n\t\n\titer = (PyArrayIterObject *)PyArray_IterNew((PyObject *)self);\n\tif (iter == NULL) return -1;\n\twhile(iter->index < iter->size) {\n\t\ttheobject = PyList_GET_ITEM(list, (int) iter->index);\n\t\tPy_INCREF(theobject);\n\t\t*((PyObject **)iter->dataptr) = theobject;\n\t\tPyArray_ITER_NEXT(iter);\n\t}\n\tPy_XDECREF(iter);\n\treturn 0;\n}\n\nstatic char doc_reduce[] = \"a.__reduce__() for pickling.\";\n\nstatic PyObject *\narray_reduce(PyArrayObject *self, PyObject *args)\n{\n\tPyObject *ret=NULL, *state=NULL, *obj=NULL, *mod=NULL;\n\tPyObject *mybool, *thestr=NULL;\n\tPyArray_Descr *descr;\n\n\t/* Return a tuple of (callable object, arguments, object's state) */\n\t/* We will put everything in the object's state, so that on UnPickle\n\t it can use the string object as memory without a copy */\n\n\tret = PyTuple_New(3);\n\tif (ret == NULL) return NULL;\n\tmod = PyImport_ImportModule(\"numpy.core._internal\");\n\tif (mod == NULL) {Py_DECREF(ret); return NULL;}\n\tobj = PyObject_GetAttrString(mod, \"_reconstruct\");\n\tPy_DECREF(mod);\n\tPyTuple_SET_ITEM(ret, 0, obj);\n\tPyTuple_SET_ITEM(ret, 1, \n\t\t\t Py_BuildValue(\"ONN\",\n\t\t\t\t (PyObject *)self->ob_type,\n\t\t\t\t Py_BuildValue(\"(N)\",\n\t\t\t\t\t\t PyInt_FromLong(0)),\n\t\t\t\t PyObject_GetAttrString((PyObject *)(self->descr),\n\t\t\t\t\t\t\t \"char\")));\n\t\n\t/* Now fill in object's state. This is a tuple with \n\t 4 arguments\n\n\t 1) a Tuple giving the shape\n\t 2) a PyArray_Descr Object (with correct bytorder set)\n\t 3) a Bool stating if Fortran or not\n\t 4) a binary string with the data (or a list for Object arrays)\n\n\t Notice because Python does not describe a mechanism to write \n\t raw data to the pickle, this performs a copy to a string first\n\t*/\n\n\tstate = PyTuple_New(4);\n\tif (state == NULL) {\n\t\tPy_DECREF(ret); return NULL;\n\t}\n\tPyTuple_SET_ITEM(state, 0, PyObject_GetAttrString((PyObject *)self, \n\t\t\t\t\t\t\t \"shape\"));\n\tdescr = self->descr;\n\tPy_INCREF(descr);\n\tPyTuple_SET_ITEM(state, 1, (PyObject *)descr);\n\tmybool = (PyArray_ISFORTRAN(self) ? Py_True : Py_False);\n\tPy_INCREF(mybool);\n\tPyTuple_SET_ITEM(state, 2, mybool);\n\tif (PyArray_ISOBJECT(self)) {\n\t\tthestr = _getobject_pkl(self);\n\t}\n\telse {\n thestr = PyArray_ToString(self);\n\t}\n\tif (thestr == NULL) {\n\t\tPy_DECREF(ret);\n\t\tPy_DECREF(state);\n\t\treturn NULL;\n\t}\n\tPyTuple_SET_ITEM(state, 3, thestr);\n\tPyTuple_SET_ITEM(ret, 2, state);\n\treturn ret;\n}\n\nstatic char doc_setstate[] = \"a.__setstate__(tuple) for unpickling.\";\n\n/*\n\t 1) a Tuple giving the shape\n\t 2) a PyArray_Descr Object\n\t 3) a Bool stating if Fortran or not\n\t 4) a binary string with the data (or a list if Object array) \n*/\n\nstatic intp _array_fill_strides(intp *, intp *, int, intp, int, int *);\n\nstatic int _IsAligned(PyArrayObject *); \n\nstatic PyArray_Descr * _array_typedescr_fromstr(char *);\n\nstatic PyObject *\narray_setstate(PyArrayObject *self, PyObject *args)\n{\n\tPyObject *shape;\n\tPyArray_Descr *typecode;\n\tlong fortran;\n\tPyObject *rawdata;\n\tchar *datastr;\n\tint len;\n\tintp dimensions[MAX_DIMS];\n\tint nd;\n\t\n\t/* This will free any memory associated with a and\n\t use the string in setstate as the (writeable) memory.\n\t*/\n\tif (!PyArg_ParseTuple(args, \"(O!O!iO)\", &PyTuple_Type,\n\t\t\t &shape, &PyArrayDescr_Type, &typecode, \n\t\t\t &fortran, &rawdata))\n\t\treturn NULL;\n\n\tPy_XDECREF(self->descr);\n\tself->descr = typecode;\n\tPy_INCREF(typecode);\n\tnd = PyArray_IntpFromSequence(shape, dimensions, MAX_DIMS);\n\tif (typecode->type_num == PyArray_OBJECT) {\n\t\tif (!PyList_Check(rawdata)) {\n\t\t\tPyErr_SetString(PyExc_TypeError, \n\t\t\t\t\t\"object pickle not returning list\");\n\t\t\treturn NULL;\n\t\t}\n\t}\n\telse {\n\t\tif (!PyString_Check(rawdata)) {\n\t\t\tPyErr_SetString(PyExc_TypeError, \n\t\t\t\t\t\"pickle not returning string\");\n\t\t\treturn NULL;\n\t\t}\n\n\t\tif (PyString_AsStringAndSize(rawdata, &datastr, &len))\n\t\t\treturn NULL;\n\n\t\tif ((len != (self->descr->elsize *\t\t\t\\\n\t\t\t (int) PyArray_MultiplyList(dimensions, nd)))) {\n\t\t\tPyErr_SetString(PyExc_ValueError, \n\t\t\t\t\t\"buffer size does not\"\t\\\n\t\t\t\t\t\" match array size\");\n\t\t\treturn NULL;\n\t\t}\n\t}\n\n if ((self->flags & OWN_DATA)) {\n\t\tif (self->data != NULL)\n\t\t\tPyDataMem_FREE(self->data);\n\t\tself->flags &= ~OWN_DATA;\n }\n\tPy_XDECREF(self->base);\n\n\tself->flags &= ~UPDATEIFCOPY;\n\n if (self->dimensions != NULL) {\n PyDimMem_FREE(self->dimensions); \n\t\tself->dimensions = NULL;\n\t}\n\n\tself->flags = DEFAULT_FLAGS;\n\n\tself->nd = nd;\n\n\tif (nd > 0) {\n\t\tself->dimensions = PyDimMem_NEW(nd * 2);\n\t\tself->strides = self->dimensions + nd;\n\t\tmemcpy(self->dimensions, dimensions, sizeof(intp)*nd);\n\t\t(void) _array_fill_strides(self->strides, dimensions, nd,\n\t\t\t\t\t self->descr->elsize, fortran, \n\t\t\t\t\t &(self->flags));\n\t}\n\n\tif (typecode->type_num != PyArray_OBJECT) {\n\t\tself->data = datastr;\n\t\tif (!_IsAligned(self)) {\n\t\t\tintp num = PyArray_NBYTES(self);\n\t\t\tself->data = PyDataMem_NEW(num);\n\t\t\tif (self->data == NULL) {\n\t\t\t\tself->nd = 0;\n\t\t\t\tPyDimMem_FREE(self->dimensions);\n\t\t\t\treturn PyErr_NoMemory();\n\t\t\t}\n\t\t\tmemcpy(self->data, datastr, num);\n\t\t\tself->flags |= OWN_DATA;\n\t\t\tself->base = NULL;\n\t\t}\n\t\telse {\n\t\t\tself->base = rawdata;\n\t\t\tPy_INCREF(self->base);\n\t\t}\n\t}\n\telse {\n\t\tself->data = PyDataMem_NEW(PyArray_NBYTES(self));\n\t\tif (self->data == NULL) { \n\t\t\tself->nd = 0;\n\t\t\tself->data = PyDataMem_NEW(self->descr->elsize);\n\t\t\tif (self->dimensions) PyDimMem_FREE(self->dimensions);\n\t\t\treturn PyErr_NoMemory();\n\t\t}\n\t\tself->flags |= OWN_DATA;\n\t\tself->base = NULL;\n\t\tif (_setobject_pkl(self, rawdata) < 0) \n\t\t\treturn NULL;\n\t}\n\n\tPyArray_UpdateFlags(self, UPDATE_ALL_FLAGS);\n\t\n\tPy_INCREF(Py_None);\n\treturn Py_None;\t\n}\n\n/*OBJECT_API*/\nstatic int\nPyArray_Dump(PyObject *self, PyObject *file, int protocol)\n{\n\tPyObject *cpick=NULL;\n\tPyObject *ret;\n\tif (protocol < 0) protocol = 2;\n\n\tcpick = PyImport_ImportModule(\"cPickle\");\n\tif (cpick==NULL) return -1;\n\n\tif PyString_Check(file) {\n\t\tfile = PyFile_FromString(PyString_AS_STRING(file), \"wb\");\n\t\tif (file==NULL) return -1;\n\t}\n\telse Py_INCREF(file);\n\tret = PyObject_CallMethod(cpick, \"dump\", \"OOi\", self, \n\t\t\t\t file, protocol);\n\tPy_XDECREF(ret);\n\tPy_DECREF(file);\n\tPy_DECREF(cpick);\n\tif (PyErr_Occurred()) return -1;\n\treturn 0;\n}\n\n/*OBJECT_API*/\nstatic PyObject *\nPyArray_Dumps(PyObject *self, int protocol)\n{\n\tPyObject *cpick=NULL;\n\tPyObject *ret;\n\tif (protocol < 0) protocol = 2;\n\n\tcpick = PyImport_ImportModule(\"cPickle\");\n\tif (cpick==NULL) return NULL;\n\tret = PyObject_CallMethod(cpick, \"dumps\", \"Oi\", self, protocol);\n\tPy_DECREF(cpick);\n\treturn ret;\n}\n\n\nstatic char doc_dump[] = \"m.dump(file)\";\n\nstatic PyObject *\narray_dump(PyArrayObject *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((PyObject *)self, file, 2);\n\tif (ret < 0) return NULL;\n\tPy_INCREF(Py_None);\n\treturn Py_None;\n}\n\nstatic char doc_dumps[] = \"m.dumps()\";\n\nstatic PyObject *\narray_dumps(PyArrayObject *self, PyObject *args)\n{\n\tif (!PyArg_ParseTuple(args, \"\"))\n\t\treturn NULL;\n\treturn PyArray_Dumps((PyObject *)self, 2);\n}\n\n\nstatic char doc_transpose[] = \"m.transpose()\";\n\nstatic PyObject *\narray_transpose(PyArrayObject *self, PyObject *args) \n{\n\tPyObject *shape=Py_None;\n\tint n;\n\tPyArray_Dims permute;\n\tPyObject *ret;\n\n\tn = PyTuple_Size(args);\n\tif (n > 1) shape = args;\n\telse if (n == 1) shape = PyTuple_GET_ITEM(args, 0);\n\t\n\tif (shape == Py_None)\n\t\tret = PyArray_Transpose(self, NULL);\n\telse {\n\t\tif (!PyArray_IntpConverter(shape, &permute)) return NULL;\n\t\tret = PyArray_Transpose(self, &permute);\n\t\tPyDimMem_FREE(permute.ptr);\n\t}\n\t\n\treturn _ARET(ret);\n}\n\nstatic char doc_mean[] = \"a.mean(axis=None, dtype=None)\\n\\n\"\\\n \"Average the array over the given axis. If the axis is None, average\\n\"\\\n \"over all dimensions of the array.\\n\"\\\n \"\\n\"\\\n \"If an integer axis is given, this equals:\\n\"\\\n \" a.sum(axis, dtype) * 1.0 / len(a)\\n\"\\\n \"\\n\"\\\n \"If axis is None, this equals:\\n\"\\\n \" a.sum(axis, dtype) * 1.0 / product(a.shape)\\n\"\\\n \"\\n\"\\\n \"The optional dtype argument is the data type for intermediate\\n\"\\\n \"calculations in the sum.\";\n\n#define _CHKTYPENUM(typ) ((typ) ? (typ)->type_num : PyArray_NOTYPE)\n\nstatic PyObject *\narray_mean(PyArrayObject *self, PyObject *args, PyObject *kwds) \n{\n\tint axis=MAX_DIMS;\n\tPyArray_Descr *dtype=NULL;\n\tstatic char *kwlist[] = {\"axis\", \"dtype\", NULL};\n\t\n\tif (!PyArg_ParseTupleAndKeywords(args, kwds, \"|O&O&\", kwlist,\n\t\t\t\t\t PyArray_AxisConverter, \n\t\t\t\t\t &axis, PyArray_DescrConverter2,\n\t\t\t\t\t &dtype)) return NULL;\n\n\treturn PyArray_Mean(self, axis, _CHKTYPENUM(dtype));\n}\n\nstatic char doc_sum[] = \"a.sum(axis=None, dtype=None)\\n\\n\"\\\n \"Sum the array over the given axis. If the axis is None, sum over all\\n\"\\\n \"dimensions of the array.\\n\"\\\n \"\\n\"\\\n \"The optional dtype argument is the data type for the returned value\\n\"\\\n \"and intermediate calculations. The default is to upcast (promote)\\n\"\\\n \"smaller integer types to the platform-dependent int. For example, on\\n\"\\\n \"32-bit platforms:\\n\"\\\n \"\\n\"\\\n \" a.dtype default sum() dtype\\n\"\\\n \" ---------------------------------------------------\\n\"\\\n \" bool, int8, int16, int32 int32\\n\"\\\n \"\\n\"\\\n \"Examples:\\n\"\\\n \"\\n\"\\\n \">>> array([0.5, 1.5]).sum()\\n\"\\\n \"2.0\\n\"\\\n \">>> array([0.5, 1.5]).sum(dtype=int32)\\n\"\\\n \"1\\n\"\\\n \">>> array([[0, 1], [0, 5]]).sum()\\n\"\\\n \"array([0, 6])\\n\"\\\n \">>> array([[0, 1], [0, 5]]).sum(axis=1)\\n\"\\\n \"array([1, 5])\";\n\nstatic PyObject *\narray_sum(PyArrayObject *self, PyObject *args, PyObject *kwds) \n{\n\tint axis=MAX_DIMS;\n\tPyArray_Descr *dtype=NULL;\n\tstatic char *kwlist[] = {\"axis\", \"dtype\", NULL};\n\n\tif (!PyArg_ParseTupleAndKeywords(args, kwds, \"|O&O&\", kwlist, \n\t\t\t\t\t PyArray_AxisConverter, \n\t\t\t\t\t &axis, PyArray_DescrConverter2,\n\t\t\t\t\t &dtype)) return NULL;\n\t\n\treturn PyArray_Sum(self, axis, _CHKTYPENUM(dtype));\n}\n\n\nstatic char doc_cumsum[] = \"a.cumsum(axis=None, dtype=None)\";\n\nstatic PyObject *\narray_cumsum(PyArrayObject *self, PyObject *args, PyObject *kwds) \n{\n\tint axis=MAX_DIMS;\n\tPyArray_Descr *dtype=NULL;\n\tstatic char *kwlist[] = {\"axis\", \"dtype\", NULL};\n\t\n\tif (!PyArg_ParseTupleAndKeywords(args, kwds, \"|O&O&\", kwlist, \n\t\t\t\t\t PyArray_AxisConverter, \n\t\t\t\t\t &axis, PyArray_DescrConverter2,\n\t\t\t\t\t &dtype)) return NULL;\n\t\n\treturn PyArray_CumSum(self, axis, _CHKTYPENUM(dtype));\n}\n\nstatic char doc_prod[] = \"a.prod(axis=None, dtype=None)\";\n\nstatic PyObject *\narray_prod(PyArrayObject *self, PyObject *args, PyObject *kwds) \n{\n\tint axis=MAX_DIMS;\n\tPyArray_Descr *dtype=NULL;\n\tstatic char *kwlist[] = {\"axis\", \"dtype\", NULL};\n\t\n\tif (!PyArg_ParseTupleAndKeywords(args, kwds, \"|O&O&\", kwlist, \n\t\t\t\t\t PyArray_AxisConverter, \n\t\t\t\t\t &axis, PyArray_DescrConverter2,\n\t\t\t\t\t &dtype)) return NULL;\n\t\n\treturn PyArray_Prod(self, axis, _CHKTYPENUM(dtype));\n}\n\n\nstatic char doc_cumprod[] = \"a.cumprod(axis=None, dtype=None)\";\n\nstatic PyObject *\narray_cumprod(PyArrayObject *self, PyObject *args, PyObject *kwds) \n{\n\tint axis=MAX_DIMS;\n\tPyArray_Descr *dtype=NULL;\n\tstatic char *kwlist[] = {\"axis\", \"dtype\", NULL};\n\t\n\tif (!PyArg_ParseTupleAndKeywords(args, kwds, \"|O&O&\", kwlist, \n\t\t\t\t\t PyArray_AxisConverter, \n\t\t\t\t\t &axis, PyArray_DescrConverter2,\n\t\t\t\t\t &dtype)) return NULL;\n\t\n\treturn PyArray_CumProd(self, axis, _CHKTYPENUM(dtype));\n}\n\n\nstatic char doc_any[] = \"a.any(axis=None)\";\n\nstatic PyObject *\narray_any(PyArrayObject *self, PyObject *args) \n{\n\tint axis=MAX_DIMS;\n\t\n\tif (!PyArg_ParseTuple(args, \"|O&\", PyArray_AxisConverter, \n\t\t\t &axis)) return NULL;\n\t\n\treturn PyArray_Any(self, axis);\n}\n\nstatic char doc_all[] = \"a.all(axis=None)\";\n\nstatic PyObject *\narray_all(PyArrayObject *self, PyObject *args) \n{\n\tint axis=MAX_DIMS;\n\t\n\tif (!PyArg_ParseTuple(args, \"|O&\", PyArray_AxisConverter, \n\t\t\t &axis)) return NULL;\n\t\n\treturn PyArray_All(self, axis);\n}\n\nstatic char doc_stddev[] = \"a.std(axis=None, dtype=None)\";\n\nstatic PyObject *\narray_stddev(PyArrayObject *self, PyObject *args, PyObject *kwds) \n{\n\tint axis=MAX_DIMS;\n\tPyArray_Descr *dtype=NULL;\n\tstatic char *kwlist[] = {\"axis\", \"dtype\", NULL};\n\t\n\tif (!PyArg_ParseTupleAndKeywords(args, kwds, \"|O&O&\", kwlist, \n\t\t\t\t\t PyArray_AxisConverter, \n\t\t\t\t\t &axis, PyArray_DescrConverter2,\n\t\t\t\t\t &dtype)) return NULL;\n\t\n\treturn PyArray_Std(self, axis, _CHKTYPENUM(dtype), 0);\n}\n\nstatic char doc_variance[] = \"a.var(axis=None, dtype=None)\";\n\nstatic PyObject *\narray_variance(PyArrayObject *self, PyObject *args, PyObject *kwds) \n{\n\tint axis=MAX_DIMS;\n\tPyArray_Descr *dtype=NULL;\n\tstatic char *kwlist[] = {\"axis\", \"dtype\", NULL};\n\t\n\tif (!PyArg_ParseTupleAndKeywords(args, kwds, \"|O&O&\", kwlist, \n\t\t\t\t\t PyArray_AxisConverter, \n\t\t\t\t\t &axis, PyArray_DescrConverter2,\n\t\t\t\t\t &dtype)) return NULL;\n\t\n\treturn PyArray_Std(self, axis, _CHKTYPENUM(dtype), 1);\n}\n\nstatic char doc_compress[] = \"a.compress(condition=, axis=None)\";\n\nstatic PyObject *\narray_compress(PyArrayObject *self, PyObject *args, PyObject *kwds) \n{\n\tint axis=MAX_DIMS;\n\tPyObject *condition;\t\n\tstatic char *kwlist[] = {\"condition\", \"axis\", NULL};\n\t\n\tif (!PyArg_ParseTupleAndKeywords(args, kwds, \"O|O&\", kwlist, \n\t\t\t\t\t &condition, PyArray_AxisConverter,\n\t\t\t\t\t &axis)) return NULL;\n\n\treturn _ARET(PyArray_Compress(self, condition, axis));\n}\n\nstatic char doc_nonzero[] = \"a.nonzero() return a tuple of indices referencing\"\\\n\t\"the elements of a that are nonzero.\";\n\nstatic PyObject *\narray_nonzero(PyArrayObject *self, PyObject *args)\n{\n\tif (!PyArg_ParseTuple(args, \"\")) return NULL;\n\n\treturn _ARET(PyArray_Nonzero(self));\n}\n\n\nstatic char doc_trace[] = \"a.trace(offset=0, axis1=0, axis2=1, dtype=None) \\n\"\\\n\t\"return the sum along the offset diagonal of the arrays indicated\\n\" \\\n\t\"axis1 and axis2.\";\n\nstatic PyObject *\narray_trace(PyArrayObject *self, PyObject *args, PyObject *kwds) \n{\n\tint axis1=0, axis2=1, offset=0;\n\tPyArray_Descr *dtype=NULL;\n\tstatic char *kwlist[] = {\"offset\", \"axis1\", \"axis2\", \"dtype\", NULL};\n\t\n\tif (!PyArg_ParseTupleAndKeywords(args, kwds, \"|iiiO&\", kwlist, \n\t\t\t\t\t &offset, &axis1, &axis2,\n\t\t\t\t\t PyArray_DescrConverter2, &dtype))\n\t\treturn NULL;\n\t\n\treturn _ARET(PyArray_Trace(self, offset, axis1, axis2, \n\t\t\t\t _CHKTYPENUM(dtype)));\n}\n\n#undef _CHKTYPENUM\n\n\nstatic char doc_clip[] = \"a.clip(min=, max=)\";\n\nstatic PyObject *\narray_clip(PyArrayObject *self, PyObject *args, PyObject *kwds) \n{\n\tPyObject *min, *max;\n\tstatic char *kwlist[] = {\"min\", \"max\", NULL};\n\n\tif (!PyArg_ParseTupleAndKeywords(args, kwds, \"OO\", kwlist,\n\t\t\t\t\t &min, &max)) \n\t\treturn NULL;\n\t\n\treturn _ARET(PyArray_Clip(self, min, max));\n}\n\nstatic char doc_conj[] = \"a.conj()\";\n\nstatic char doc_conjugate[] = \"a.conjugate()\";\n\nstatic PyObject *\narray_conjugate(PyArrayObject *self, PyObject *args) \n{\n\n\tif (!PyArg_ParseTuple(args, \"\")) return NULL;\n\t\n\treturn PyArray_Conjugate(self);\n}\n\n\nstatic char doc_diagonal[] = \"a.diagonal(offset=0, axis1=0, axis2=1)\";\n\nstatic PyObject *\narray_diagonal(PyArrayObject *self, PyObject *args, PyObject *kwds) \n{\n\tint axis1=0, axis2=1, offset=0;\n\tstatic char *kwlist[] = {\"offset\", \"axis1\", \"axis2\", NULL};\n\t\n\tif (!PyArg_ParseTupleAndKeywords(args, kwds, \"|iii\", kwlist, \n\t\t\t\t\t &offset, &axis1, &axis2))\n\t\treturn NULL;\n\t\n\treturn _ARET(PyArray_Diagonal(self, offset, axis1, axis2));\n}\n\nstatic char doc_flatten[] = \"a.flatten([fortran]) return a 1-d array (always copy)\";\n\nstatic PyObject *\narray_flatten(PyArrayObject *self, PyObject *args)\n{\n\tint fortran=0;\n\n\tif (!PyArg_ParseTuple(args, \"|i\", &fortran)) return NULL;\n \n\treturn PyArray_Flatten(self, (int) fortran);\n}\n\nstatic char doc_ravel[] = \"a.ravel([fortran]) return a 1-d array (copy only if needed)\";\n\nstatic PyObject *\narray_ravel(PyArrayObject *self, PyObject *args)\n{\n\tint fortran=0;\n\n\tif (!PyArg_ParseTuple(args, \"|i\", &fortran)) return NULL;\n\n\treturn PyArray_Ravel(self, fortran);\n}\n\n\n\nstatic char doc_setflags[] = \"a.setflags(write=None, align=None, uic=None)\";\n\nstatic int _IsAligned(PyArrayObject *);\nstatic Bool _IsWriteable(PyArrayObject *);\n\nstatic PyObject *\narray_setflags(PyArrayObject *self, PyObject *args, PyObject *kwds)\n{\n\tstatic char *kwlist[] = {\"write\", \"align\", \"uic\", NULL};\n\tPyObject *write=Py_None;\n\tPyObject *align=Py_None;\n\tPyObject *uic=Py_None;\n\tint flagback = self->flags;\n\t\t\n\tif (!PyArg_ParseTupleAndKeywords(args, kwds, \"|OOO\", kwlist,\n\t\t\t\t\t &write, &align, &uic))\n\t\treturn NULL;\n\n\tif (align != Py_None) {\n\t\tif (PyObject_Not(align)) self->flags &= ~ALIGNED;\n\t\telse if (_IsAligned(self)) self->flags |= ALIGNED;\n\t\telse {\n\t\t\tPyErr_SetString(PyExc_ValueError, \n\t\t\t\t\t\"cannot set aligned flag of mis-\"\\\n\t\t\t\t\t\"aligned array to True\");\n\t\t\treturn NULL;\n\t\t}\n\t}\n\t\n\tif (uic != Py_None) {\n if (PyObject_IsTrue(uic)) {\n\t\t\tself->flags = flagback;\n PyErr_SetString(PyExc_ValueError, \n \"cannot set UPDATEIFCOPY\" \\\n \"flag to True\");\n return NULL;\n }\n else {\n self->flags &= ~UPDATEIFCOPY;\n Py_DECREF(self->base);\n self->base = NULL;\n }\n }\n \n if (write != Py_None) {\n if (PyObject_IsTrue(write)) \n\t\t\tif (_IsWriteable(self)) {\n\t\t\t\tself->flags |= WRITEABLE;\n\t\t\t}\n\t\t\telse {\n\t\t\t\tself->flags = flagback;\n\t\t\t\tPyErr_SetString(PyExc_ValueError, \n\t\t\t\t\t\t\"cannot set WRITEABLE \"\t\\\n\t\t\t\t\t\t\"flag to True of this \"\t\\\n\t\t\t\t\t\t\"array\");\t\t\\\n\t\t\t\treturn NULL;\n\t\t\t}\n else\n self->flags &= ~WRITEABLE;\n }\n \n Py_INCREF(Py_None);\n return Py_None;\n}\n\nstatic char doc_newbyteorder[] = \"a.newbyteorder() is equivalent\\n\" \\\n\t\" to a.view(a.dtype.newbytorder())\\n\";\n\nstatic PyObject *\narray_newbyteorder(PyArrayObject *self, PyObject *args) \n{\n\tchar endian = PyArray_SWAP;\n\tPyArray_Descr *new;\n\t\n\tif (!PyArg_ParseTuple(args, \"|O&\", PyArray_ByteorderConverter,\n\t\t\t &endian)) return NULL;\n\n\tnew = PyArray_DescrNewByteorder(self->descr, endian);\n\tif (!new) return NULL;\n\treturn PyArray_View(self, new, NULL));\n\n}\n\nstatic PyMethodDef array_methods[] = {\n {\"tolist\",\t (PyCFunction)array_tolist,\t1, doc_tolist},\n {\"item\", (PyCFunction)array_toscalar, METH_VARARGS, doc_toscalar},\n\t{\"tofile\", (PyCFunction)array_tofile, \n METH_VARARGS | METH_KEYWORDS, doc_tofile},\n {\"tostring\", (PyCFunction)array_tostring, METH_VARARGS, doc_tostring},\n {\"byteswap\", (PyCFunction)array_byteswap,\t1, doc_byteswap},\n {\"astype\", (PyCFunction)array_cast, 1, doc_cast},\n\t{\"getfield\", (PyCFunction)array_getfield, \n\t METH_VARARGS | METH_KEYWORDS, doc_getfield},\n\t{\"setfield\", (PyCFunction)array_setfield, \n\t METH_VARARGS | METH_KEYWORDS, doc_setfield},\n {\"copy\", (PyCFunction)array_copy, 1, doc_copy}, \n {\"resize\", (PyCFunction)array_resize, 1, doc_resize}, \n\n\t/* for subtypes */\n\t{\"__array__\", (PyCFunction)array_getarray, 1, doc_array_getarray},\n\t{\"__array_wrap__\", (PyCFunction)array_wraparray, 1, doc_wraparray},\n\t/* default version so it is found... -- only used for subclasses */\n\t{\"__array_finalize__\", (PyCFunction)array_finalize, 1, NULL},\n\t\n\t\n\t/* for the copy module */\n {\"__copy__\", (PyCFunction)array_copy, 1, doc_copy},\t \n {\"__deepcopy__\", (PyCFunction)array_deepcopy, 1, doc_deepcopy}, \n\t\n /* for Pickling */\n {\"__reduce__\", (PyCFunction) array_reduce, 1, doc_reduce},\t\n\t{\"__setstate__\", (PyCFunction) array_setstate, 1, doc_setstate},\n\t{\"dumps\", (PyCFunction) array_dumps, 1, doc_dumps},\n\t{\"dump\", (PyCFunction) array_dump, 1, doc_dump},\n\n\t/* Extended methods added 2005 */\n\t{\"fill\", (PyCFunction)array_fill,\n\t METH_VARARGS, doc_fill},\n\t{\"transpose\",\t(PyCFunction)array_transpose, \n\t METH_VARARGS, doc_transpose},\n\t{\"take\",\t(PyCFunction)array_take, \n\t METH_VARARGS|METH_KEYWORDS, doc_take},\n\t{\"put\",\t(PyCFunction)array_put, \n\t METH_VARARGS|METH_KEYWORDS, doc_put},\n\t{\"putmask\",\t(PyCFunction)array_putmask, \n\t METH_VARARGS|METH_KEYWORDS, doc_putmask},\n\t{\"repeat\",\t(PyCFunction)array_repeat, \n\t METH_VARARGS|METH_KEYWORDS, doc_repeat},\n\t{\"choose\",\t(PyCFunction)array_choose, \n\t METH_VARARGS, doc_choose},\t\n\t{\"sort\",\t(PyCFunction)array_sort, \n\t METH_VARARGS|METH_KEYWORDS, doc_sort},\n\t{\"argsort\",\t(PyCFunction)array_argsort, \n\t METH_VARARGS|METH_KEYWORDS, doc_argsort},\n\t{\"searchsorted\", (PyCFunction)array_searchsorted, \n\t METH_VARARGS, doc_searchsorted},\t\n\t{\"argmax\",\t(PyCFunction)array_argmax, \n\t METH_VARARGS, doc_argmax},\n\t{\"argmin\", (PyCFunction)array_argmin,\n\t METH_VARARGS, doc_argmin},\n\t{\"reshape\",\t(PyCFunction)array_reshape, \n\t METH_VARARGS, doc_reshape},\n\t{\"squeeze\",\t(PyCFunction)array_squeeze,\n\t METH_VARARGS, doc_squeeze},\n\t{\"view\", (PyCFunction)array_view, \n\t METH_VARARGS, doc_view},\n\t{\"swapaxes\", (PyCFunction)array_swapaxes,\n\t METH_VARARGS, doc_swapaxes},\n\t{\"max\", (PyCFunction)array_max,\n\t METH_VARARGS, doc_max},\n\t{\"min\", (PyCFunction)array_min,\n\t METH_VARARGS, doc_min},\n\t{\"ptp\", (PyCFunction)array_ptp,\n\t METH_VARARGS, doc_ptp},\n\t{\"mean\", (PyCFunction)array_mean,\n\t METH_VARARGS|METH_KEYWORDS, doc_mean},\n\t{\"trace\", (PyCFunction)array_trace,\n\t METH_VARARGS|METH_KEYWORDS, doc_trace},\n\t{\"diagonal\", (PyCFunction)array_diagonal,\n\t METH_VARARGS|METH_KEYWORDS, doc_diagonal},\n\t{\"clip\", (PyCFunction)array_clip,\n\t METH_VARARGS|METH_KEYWORDS, doc_clip},\n\t{\"conj\", (PyCFunction)array_conjugate,\n\t METH_VARARGS, doc_conj},\n\t{\"conjugate\", (PyCFunction)array_conjugate,\n\t METH_VARARGS, doc_conjugate},\n\t{\"nonzero\", (PyCFunction)array_nonzero,\n\t METH_VARARGS, doc_nonzero},\n\t{\"std\", (PyCFunction)array_stddev,\n\t METH_VARARGS|METH_KEYWORDS, doc_stddev},\n\t{\"var\", (PyCFunction)array_variance,\n\t METH_VARARGS|METH_KEYWORDS, doc_variance},\n\t{\"sum\", (PyCFunction)array_sum,\n\t METH_VARARGS|METH_KEYWORDS, doc_sum},\n\t{\"cumsum\", (PyCFunction)array_cumsum,\n\t METH_VARARGS|METH_KEYWORDS, doc_cumsum},\n\t{\"prod\", (PyCFunction)array_prod,\n\t METH_VARARGS|METH_KEYWORDS, doc_prod},\n\t{\"cumprod\", (PyCFunction)array_cumprod,\n\t METH_VARARGS|METH_KEYWORDS, doc_cumprod},\n\t{\"all\", (PyCFunction)array_all,\n\t METH_VARARGS, doc_all},\n\t{\"any\", (PyCFunction)array_any,\n\t METH_VARARGS, doc_any},\n\t{\"compress\", (PyCFunction)array_compress,\n\t METH_VARARGS|METH_KEYWORDS, doc_compress},\n\t{\"flatten\", (PyCFunction)array_flatten,\n\t METH_VARARGS, doc_flatten},\n\t{\"ravel\", (PyCFunction)array_ravel,\n\t METH_VARARGS, doc_ravel},\n\t{\"setflags\", (PyCFunction)array_setflags,\n\t METH_VARARGS|METH_KEYWORDS, doc_setflags},\n\t{\"newbyteorder\", (PyCFunction)array_newbyteorder,\n\t METH_VARARGS, doc_newbyteorder},\n {NULL,\t\tNULL}\t\t/* sentinel */\n};\n\n#undef _ARET\n\n\n", + "source_code_before": "\n/* Should only be used if x is known to be an nd-array */\n#define _ARET(x) PyArray_Return((PyArrayObject *)(x))\n\nstatic char doc_take[] = \"a.take(indices, axis=None). Selects the elements \"\\\n\t\"in indices from array a along the given axis.\";\n\nstatic PyObject *\narray_take(PyArrayObject *self, PyObject *args, PyObject *kwds) \n{\n\tint dimension=MAX_DIMS;\n\tPyObject *indices;\n\tstatic char *kwlist[] = {\"indices\", \"axis\", NULL};\n\t\n\tdimension=0;\n\tif (!PyArg_ParseTupleAndKeywords(args, kwds, \"O|O&\", kwlist, \n\t\t\t\t\t &indices, PyArray_AxisConverter,\n\t\t\t\t\t &dimension))\n\t\treturn NULL;\n\t\n\treturn _ARET(PyArray_Take(self, indices, dimension));\n}\n\nstatic char doc_fill[] = \"a.fill(value) places the scalar value at every\"\\\n\t\"position in the array.\";\n\nstatic PyObject *\narray_fill(PyArrayObject *self, PyObject *args)\n{\n\tPyObject *obj;\n\tif (!PyArg_ParseTuple(args, \"O\", &obj))\n\t\treturn NULL;\n\tif (PyArray_FillWithScalar(self, obj) < 0) return NULL;\n\tPy_INCREF(Py_None);\n\treturn Py_None;\n}\n\nstatic char doc_put[] = \"a.put(values, indices) sets a.flat[n] = v[n] \"\\\n\t\"for each n in indices. v can be scalar or shorter than indices, \"\\\n\t\"will repeat.\";\n\nstatic PyObject *\narray_put(PyArrayObject *self, PyObject *args, PyObject *kwds) \n{\n\tPyObject *indices, *values;\n\tstatic char *kwlist[] = {\"values\", \"indices\", NULL};\n\t\n\tif (!PyArg_ParseTupleAndKeywords(args, kwds, \"OO\", kwlist,\n\t\t\t\t\t &values, &indices))\n\t\treturn NULL;\n\treturn PyArray_Put(self, values, indices);\n}\n\nstatic char doc_putmask[] = \"a.putmask(values, mask) sets a.flat[n] = v[n] \"\\\n\t\"for each n where mask.flat[n] is TRUE. v can be scalar.\";\n\nstatic PyObject *\narray_putmask(PyArrayObject *self, PyObject *args, PyObject *kwds) \n{\n\tPyObject *mask, *values;\n\n\tstatic char *kwlist[] = {\"values\", \"mask\", NULL};\n\t\n\tif (!PyArg_ParseTupleAndKeywords(args, kwds, \"OO\", kwlist,\n\t\t\t\t\t &values, &mask))\n\t\treturn NULL;\n\treturn PyArray_PutMask(self, values, mask);\n}\n\n/* Used to reshape a Fortran Array */\nstatic void\n_reverse_shape(PyArray_Dims *newshape)\n{\n\tint i, n = newshape->len;\n\tintp *ptr = newshape->ptr;\n\tintp *eptr;\n\tintp tmp;\n\tint len = n >> 1;\n\n\teptr = ptr+n-1;\n\tfor(i=0; i) return a new view of array with same data. type can be either a new sub-type object or a data-descriptor object\";\n\nstatic PyObject *\narray_view(PyArrayObject *self, PyObject *args)\n{\n\tPyObject *otype=NULL;\n PyArray_Descr *type=NULL;\n\n\tif (!PyArg_ParseTuple(args, \"|O\", &otype)) return NULL;\n\n\tif (otype) {\n\t\tif (PyType_Check(otype) &&\t\t\t\t\\\n\t\t PyType_IsSubtype((PyTypeObject *)otype, \n\t\t\t\t &PyBigArray_Type)) {\n\t\t\treturn _ARET(PyArray_View(self, NULL, \n\t\t\t\t\t\t (PyTypeObject *)otype));\n\t\t}\n\t\telse {\n\t\t\tif (PyArray_DescrConverter(otype, &type) == PY_FAIL) \n\t\t\t\treturn NULL;\n\t\t}\n\t}\n\treturn _ARET(PyArray_View(self, type, NULL));\n}\n\nstatic char doc_argmax[] = \"a.argmax(axis=None)\";\n\nstatic PyObject *\narray_argmax(PyArrayObject *self, PyObject *args) \n{\n\tint axis=MAX_DIMS;\n\t\n\tif (!PyArg_ParseTuple(args, \"|O&\", PyArray_AxisConverter, \n\t\t\t &axis)) return NULL;\n\t\n\treturn _ARET(PyArray_ArgMax(self, axis));\n}\n\nstatic char doc_argmin[] = \"a.argmin(axis=None)\";\n\nstatic PyObject *\narray_argmin(PyArrayObject *self, PyObject *args) \n{\n\tint axis=MAX_DIMS;\n\t\n\tif (!PyArg_ParseTuple(args, \"|O&\", PyArray_AxisConverter, \n\t\t\t &axis)) return NULL;\n\t\n\treturn _ARET(PyArray_ArgMin(self, axis));\n}\n\nstatic char doc_max[] = \"a.max(axis=None)\";\n\nstatic PyObject *\narray_max(PyArrayObject *self, PyObject *args) \n{\n\tint axis=MAX_DIMS;\n\t\n\tif (!PyArg_ParseTuple(args, \"|O&\", PyArray_AxisConverter, \n\t\t\t &axis)) return NULL;\n\t\n\treturn PyArray_Max(self, axis);\n}\n\nstatic char doc_ptp[] = \"a.ptp(axis=None) a.max(axis)-a.min(axis)\";\n\nstatic PyObject *\narray_ptp(PyArrayObject *self, PyObject *args) \n{\n\tint axis=MAX_DIMS;\n\t\n\tif (!PyArg_ParseTuple(args, \"|O&\", PyArray_AxisConverter, \n\t\t\t &axis)) return NULL;\n\t\n\treturn PyArray_Ptp(self, axis);\n}\n\n\nstatic char doc_min[] = \"a.min(axis=None)\";\n\nstatic PyObject *\narray_min(PyArrayObject *self, PyObject *args) \n{\n\tint axis=MAX_DIMS;\n\t\n\tif (!PyArg_ParseTuple(args, \"|O&\", PyArray_AxisConverter, \n\t\t\t &axis)) return NULL;\n\t\n\treturn PyArray_Min(self, axis);\n}\n\n\nstatic char doc_swapaxes[] = \"a.swapaxes(axis1, axis2) returns new view with axes swapped.\";\n\nstatic PyObject *\narray_swapaxes(PyArrayObject *self, PyObject *args)\n{\n\tint axis1, axis2;\n\n\tif (!PyArg_ParseTuple(args, \"ii\", &axis1, &axis2)) return NULL;\n\n\treturn PyArray_SwapAxes(self, axis1, axis2);\n}\n\nstatic char doc_getfield[] = \"m.getfield(dtype, offset) returns a field \"\\\n\t\" of the given array as a certain type. A field is a view of \"\\\n\t\" the array's data with each itemsize determined by the given type\"\\\n\t\" and the offset into the current array.\";\n\n/* steals typed reference */\n/*OBJECT_API\n Get a subset of bytes from each element of the array\n*/\nstatic PyObject *\nPyArray_GetField(PyArrayObject *self, PyArray_Descr *typed, int offset)\n{\n\tPyObject *ret=NULL;\n\n\tif (offset < 0 || (offset + typed->elsize) > self->descr->elsize) {\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 self->descr->elsize-typed->elsize, offset);\n\t\tPy_DECREF(typed);\n\t\treturn NULL;\n\t}\n\tret = PyArray_NewFromDescr(self->ob_type, \n\t\t\t\t typed,\n\t\t\t\t self->nd, self->dimensions,\n\t\t\t\t self->strides, \n\t\t\t\t self->data + offset,\n\t\t\t\t self->flags, (PyObject *)self);\n\tif (ret == NULL) return NULL;\n\tPy_INCREF(self);\n\t((PyArrayObject *)ret)->base = (PyObject *)self; \n\n\tPyArray_UpdateFlags((PyArrayObject *)ret, UPDATE_ALL_FLAGS);\n\treturn ret;\n}\n\nstatic PyObject *\narray_getfield(PyArrayObject *self, PyObject *args, PyObject *kwds)\n{\n\n PyArray_Descr *dtype;\n\tint offset = 0;\n\tstatic char *kwlist[] = {\"dtype\", \"offset\", 0};\n\t\n\tif (!PyArg_ParseTupleAndKeywords(args, kwds, \"O&|i\", kwlist,\n\t\t\t\t\t PyArray_DescrConverter,\n\t\t\t\t\t &dtype, &offset)) return NULL;\n\t\n\treturn _ARET(PyArray_GetField(self, dtype, offset));\n}\n\n\nstatic char doc_setfield[] = \"m.setfield(value, dtype, offset) places val \"\\\n\t\"into field of the given array defined by the data type and offset.\";\n\n/*OBJECT_API\n Set a subset of bytes from each element of the array\n*/\nstatic int\nPyArray_SetField(PyArrayObject *self, PyArray_Descr *dtype,\n\t\t int offset, PyObject *val)\n{\n\tPyObject *ret=NULL;\n\tint retval = 0;\n \n\tif (offset < 0 || (offset + dtype->elsize) > self->descr->elsize) {\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 self->descr->elsize-dtype->elsize, offset);\n\t\tPy_DECREF(dtype);\n\t\treturn -1;\n\t}\n\tret = PyArray_NewFromDescr(self->ob_type, \n\t\t\t\t dtype, self->nd, self->dimensions,\n\t\t\t\t self->strides, self->data + offset,\n\t\t\t\t self->flags, (PyObject *)self);\n\tif (ret == NULL) return -1;\n\tPy_INCREF(self);\n\t((PyArrayObject *)ret)->base = (PyObject *)self;\n\n\tPyArray_UpdateFlags((PyArrayObject *)ret, UPDATE_ALL_FLAGS);\t\n\tretval = PyArray_CopyObject((PyArrayObject *)ret, val);\n\tPy_DECREF(ret);\n\treturn retval;\n}\n\nstatic PyObject *\narray_setfield(PyArrayObject *self, PyObject *args, PyObject *kwds)\n{\n PyArray_Descr *dtype;\n\tint offset = 0;\n\tPyObject *value;\n\tstatic char *kwlist[] = {\"value\", \"dtype\", \"offset\", 0};\n\t\n\tif (!PyArg_ParseTupleAndKeywords(args, kwds, \"OO&|i\", kwlist,\n\t\t\t\t\t &value, PyArray_DescrConverter,\n\t\t\t\t\t &dtype, &offset)) return NULL;\n\n\tif (PyArray_SetField(self, dtype, offset, value) < 0)\n\t\treturn NULL;\n\tPy_INCREF(Py_None);\n\treturn Py_None;\n}\n\n/* This doesn't change the descriptor just the actual data...\n */\n\n/*OBJECT_API*/\nstatic PyObject *\nPyArray_Byteswap(PyArrayObject *self, Bool inplace)\n{\n PyArrayObject *ret;\n\tintp size;\n\tPyArray_CopySwapNFunc *copyswapn;\n\tPyArray_CopySwapFunc *copyswap;\n\tPyArrayIterObject *it;\n\n\tif (inplace) {\n\t\tcopyswapn = self->descr->f->copyswapn;\n\t\t\n\t\tsize = PyArray_SIZE(self);\n\t\tif (PyArray_ISONESEGMENT(self)) {\n\t\t\tcopyswapn(self->data, NULL, size, 1, \n\t\t\t\t self->descr->elsize);\n\t\t}\n\t\telse { /* Use iterator */\n\t\t\t\n\t\t\tit = (PyArrayIterObject *)\\\n\t\t\t\tPyArray_IterNew((PyObject *)self);\n\t\t\tcopyswap = self->descr->f->copyswap;\n\t\t\twhile (it->index < it->size) {\n\t\t\t\tcopyswap(it->dataptr, NULL, 1, \n\t\t\t\t\t self->descr->elsize);\n\t\t\t\tPyArray_ITER_NEXT(it);\n\t\t\t}\n\t\t\tPy_DECREF(it);\n\t\t}\n\t\t\n\t\tPy_INCREF(self);\n\t\treturn (PyObject *)self;\n\t}\n\telse {\n\t\tif ((ret = (PyArrayObject *)PyArray_NewCopy(self,-1)) == NULL) \n\t\t\treturn NULL;\n\t\t\n\t\tsize = PyArray_SIZE(self);\n\n\t\t/* now ret has the same dtypedescr as self (including\n\t\t byteorder)\n\t\t*/\n\n\t\tret->descr->f->copyswapn(ret->data, NULL, size, 1, \n\t\t\t\t\t ret->descr->elsize);\n\n\t\treturn (PyObject *)ret;\n\t}\n}\n\nstatic char doc_byteswap[] = \"m.byteswap(False) Swap the bytes in\"\\\n\t\" the array. Return the byteswapped array. If the first argument\"\\\n\t\" is TRUE, byteswap in-place and return a reference to self.\";\n\nstatic PyObject *\narray_byteswap(PyArrayObject *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\treturn PyArray_Byteswap(self, inplace);\n}\n\nstatic char doc_tolist[] = \"m.tolist().\t Copy the data portion of the array\"\\\n\t\" to a hierarchical python list and return that list.\";\n\nstatic PyObject *\narray_tolist(PyArrayObject *self, PyObject *args) \n{\n if (!PyArg_ParseTuple(args, \"\")) return NULL;\n if (self->nd <= 0) {\n PyErr_SetString(PyExc_ValueError, \n\t\t\t\t\"can't convert a 0-d array to a list\");\n return NULL;\n }\n\t\n return PyArray_ToList(self);\n}\n\nstatic char doc_tostring[] = \"m.tostring() Construct a Python string \"\\\n \"containing the raw bytes in the array\";\n\nstatic PyObject *\narray_tostring(PyArrayObject *self, PyObject *args)\n{\n if (!PyArg_ParseTuple(args, \"\")) return NULL;\n return PyArray_ToString(self);\n}\n\nstatic char doc_tofile[] = \"m.tofile(fid, sep=\"\") write the data to a file.\";\n\nstatic PyObject *\narray_tofile(PyArrayObject *self, PyObject *args, PyObject *kwds)\n{\n\tint ret;\n PyObject *file;\n\tFILE *fd;\n char *sep=\"\";\n\tchar *format=\"\";\n\tchar *mode=\"\";\n\tstatic char *kwlist[] = {\"file\", \"sep\", \"format\", NULL};\n \n\tif (!PyArg_ParseTupleAndKeywords(args, kwds, \"O|ss\", kwlist, \n &file, &sep, &format)) return NULL;\n\n\tif (PyString_Check(file)) {\n\t\tif (sep == \"\") mode=\"wb\";\n\t\telse mode=\"w\";\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\tfd = PyFile_AsFile(file);\n\tif (fd == NULL) {\n\t\tPyErr_SetString(PyExc_IOError, \"first argument must be a \" \\\n\t\t\t\t\"string or open file\");\n\t\tPy_DECREF(file);\n\t\treturn NULL;\n\t}\n\tret = PyArray_ToFile(self, fd, sep, format);\n\tPy_DECREF(file);\n\tif (ret < 0) return NULL;\n Py_INCREF(Py_None);\n return Py_None;\n}\n\nstatic char doc_toscalar[] = \"m.item(). Copy the first data point of \"\\\n\t\"the array to a standard Python scalar and return it.\";\n\nstatic PyObject *\narray_toscalar(PyArrayObject *self, PyObject *args) {\n if (!PyArg_ParseTuple(args, \"\")) return NULL;\n\tif (self->nd == 0 || PyArray_SIZE(self) == 1) \n\t\treturn self->descr->f->getitem(self->data, self);\n\telse {\n\t\tPyErr_SetString(PyExc_ValueError, \"can only convert an\"\t\\\n\t\t\t\t\" array of size 1 to Python scalar.\");\n\t\treturn NULL;\n\t}\n}\n\nstatic char doc_cast[] = \"m.astype(t).\tCast array m to type t.\t \\n\\n\"\\\n\t\"t can be either a string representing a typecode, or a python type\"\\\n\t\" object of type int, float, or complex.\";\n\nstatic PyObject *\narray_cast(PyArrayObject *self, PyObject *args) \n{\n\tPyArray_Descr *descr=NULL;\n\tPyObject *obj;\n\t\n if (!PyArg_ParseTuple(args, \"O&\", PyArray_DescrConverter,\n\t\t\t &descr)) return NULL;\n\t\n\tif (descr == self->descr) {\n\t\tobj = _ARET(PyArray_NewCopy(self,0));\n\t\tPy_XDECREF(descr);\n\t\treturn obj;\n\t}\n\treturn _ARET(PyArray_CastToType(self, descr, 0));\n}\t \n\n/* default sub-type implementation */\n\nstatic char doc_wraparray[] = \"m.__array_wrap__(obj) returns an object of \"\\\n\t\"type m from the ndarray object obj\";\n\nstatic PyObject *\narray_wraparray(PyArrayObject *self, PyObject *args)\n{\n\tPyObject *arr;\n\tPyObject *ret;\n\t\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}\t\n\n\tPy_INCREF(PyArray_DESCR(arr));\n\tret = PyArray_NewFromDescr(self->ob_type, \n\t\t\t\t PyArray_DESCR(arr),\n\t\t\t\t PyArray_NDIM(arr),\n\t\t\t\t PyArray_DIMS(arr), \n\t\t\t\t PyArray_STRIDES(arr), PyArray_DATA(arr),\n\t\t\t\t PyArray_FLAGS(arr), (PyObject *)self);\n\tif (ret == NULL) return NULL;\n\tPy_INCREF(arr);\n\tPyArray_BASE(ret) = arr;\n\treturn ret;\n}\n\n/* NO-OP --- just so all subclasses will have one by default. */\nstatic PyObject *\narray_finalize(PyArrayObject *self, PyObject *args)\n{\n\tPy_INCREF(Py_None);\n\treturn Py_None;\n}\n\n\nstatic char doc_array_getarray[] = \"m.__array__(|dtype) just returns either a new reference to self if dtype is not given or a new array of provided data type if dtype is different from the current dtype of the array.\";\n\nstatic PyObject *\narray_getarray(PyArrayObject *self, PyObject *args) \n{\n\tPyArray_Descr *newtype=NULL;\n\tPyObject *ret;\n\t\n\tif (!PyArg_ParseTuple(args, \"|O&\", PyArray_DescrConverter,\n\t\t\t &newtype)) return NULL;\n\t\n\t/* convert to PyArray_Type or PyBigArray_Type */\n\tif (!PyArray_CheckExact(self) || !PyBigArray_CheckExact(self)) {\n\t\tPyObject *new;\n\t\tPyTypeObject *subtype = &PyArray_Type;\n\n\t\tif (!PyType_IsSubtype(self->ob_type, &PyArray_Type)) {\n\t\t\tsubtype = &PyBigArray_Type;\n\t\t}\n\t\t\n\t\tPy_INCREF(PyArray_DESCR(self));\n\t\tnew = PyArray_NewFromDescr(subtype, \n\t\t\t\t\t PyArray_DESCR(self),\n\t\t\t\t\t PyArray_NDIM(self),\n\t\t\t\t\t PyArray_DIMS(self), \n\t\t\t\t\t PyArray_STRIDES(self), \n\t\t\t\t\t PyArray_DATA(self),\n\t\t\t\t\t PyArray_FLAGS(self), NULL);\n\t\tif (new == NULL) return NULL;\n\t\tPy_INCREF(self);\n\t\tPyArray_BASE(new) = (PyObject *)self;\n\t\tself = (PyArrayObject *)new;\n\t}\n\telse {\n\t\tPy_INCREF(self);\n\t}\n\t\t\n\tif ((newtype == NULL) || \\\n\t PyArray_EquivTypes(self->descr, newtype)) {\n\t\treturn (PyObject *)self;\n\t}\n\telse {\n\t\tret = PyArray_CastToType(self, newtype, 0);\n\t\tPy_DECREF(self);\n\t\treturn ret;\n\t}\n}\n\nstatic char doc_copy[] = \"m.copy(|fortran). Return a copy of the array.\\n\"\\\n\t\"If fortran == 0 then the result is contiguous (default). \\n\"\\\n\t\"If fortran > 0 then the result has fortran data order. \\n\"\\\n\t\"If fortran < 0 then the result has fortran data order only if m\\n\"\n\t\" is already in fortran order.\";\n\nstatic PyObject *\narray_copy(PyArrayObject *self, PyObject *args) \n{\n\tint fortran=0;\n if (!PyArg_ParseTuple(args, \"|i\", &fortran)) return NULL;\n\t\n return PyArray_NewCopy(self, fortran);\n}\n\nstatic char doc_resize[] = \"self.resize(new_shape). \"\\\n\t\"Change size and shape of self inplace.\\n\"\\\n\t\"\\n Array must own its own memory and not be referenced by other \" \\\n\t\"arrays\\n Returns None.\";\n\nstatic PyObject *\narray_resize(PyArrayObject *self, PyObject *args) \n{\n PyArray_Dims newshape;\n PyObject *ret;\n\tint n;\n\t\n\tn = PyTuple_Size(args);\n\tif (n <= 1) {\n\t\tif (!PyArg_ParseTuple(args, \"O&\", PyArray_IntpConverter, \n\t\t\t\t &newshape)) return NULL;\n\t}\n else {\n\t\tif (!PyArray_IntpConverter(args, &newshape)) {\n\t\t\tif (!PyErr_Occurred()) {\n\t\t\t\tPyErr_SetString(PyExc_TypeError, \n\t\t\t\t\t\t\"invalid shape\");\n\t\t\t} \n\t\t\treturn NULL;\t\t\t\n\t\t}\n\t}\n\tret = PyArray_Resize(self, &newshape);\n PyDimMem_FREE(newshape.ptr);\n if (ret == NULL) return NULL;\n\tPy_DECREF(ret);\n\tPy_INCREF(Py_None);\n\treturn Py_None;\n}\n\nstatic char doc_repeat[] = \"a.repeat(repeats=, axis=None)\\n\"\\\n\t\"\\n\"\\\n\t\" Copy elements of a, repeats times. The repeats argument must\\n\"\\\n\t\" be a sequence of length a.shape[axis] or a scalar.\";\n\nstatic PyObject *\narray_repeat(PyArrayObject *self, PyObject *args, PyObject *kwds) {\n\tPyObject *repeats;\n\tint axis=MAX_DIMS;\n\tstatic char *kwlist[] = {\"repeats\", \"axis\", NULL};\n\t\n\tif (!PyArg_ParseTupleAndKeywords(args, kwds, \"O|O&\", kwlist, \n\t\t\t\t\t &repeats, PyArray_AxisConverter,\n\t\t\t\t\t &axis)) return NULL;\n\t\n\treturn _ARET(PyArray_Repeat(self, repeats, axis));\n}\n\nstatic char doc_choose[] = \"a.choose(b0, b1, ..., bn)\\n\"\\\n\t\"\\n\"\\\n\t\"Return an array with elements chosen from 'a' at the positions\\n\"\\\n \"of the given arrays b_i. The array 'a' should be an integer array\\n\"\\\n \"with entries from 0 to n+1, and the b_i arrays should have the same\\n\"\\\n \"shape as 'a'.\";\n\nstatic PyObject *\narray_choose(PyArrayObject *self, PyObject *args) \n{\n\tPyObject *choices;\n\tint n;\n\t\n\tn = PyTuple_Size(args);\n\tif (n <= 1) {\n\t\tif (!PyArg_ParseTuple(args, \"O\", &choices))\n\t\t\treturn NULL;\n\t}\n else {\n\t\tchoices = args;\n\t}\n\t\n\treturn _ARET(PyArray_Choose(self, choices));\n}\n\nstatic char doc_sort[] = \"a.sort(axis=-1,kind='quicksort') sorts in place along axis. Return is None and kind can be 'quicksort', 'mergesort', or 'heapsort'\";\n\nstatic PyObject *\narray_sort(PyArrayObject *self, PyObject *args, PyObject *kwds) \n{\n\tint axis=-1;\n\tint val;\n\tPyArray_SORTKIND which=PyArray_QUICKSORT;\n\tstatic char *kwlist[] = {\"axis\", \"kind\", NULL};\n\t\n\tif (!PyArg_ParseTupleAndKeywords(args, kwds, \"|iO&\", kwlist, &axis,\n\t\t\t\t\t PyArray_SortkindConverter, &which))\n\t\treturn NULL;\n\t\n\tval = PyArray_Sort(self, axis, which);\n\tif (val < 0) return NULL;\n\tPy_INCREF(Py_None);\n\treturn Py_None;\n}\n\nstatic char doc_argsort[] = \"a.argsort(axis=-1,kind='quicksort')\\n\"\\\n\t\" Return the indexes into a that would sort it along the\"\\\n\t\" given axis; kind can be 'quicksort', 'mergesort', or 'heapsort'\";\n\nstatic PyObject *\narray_argsort(PyArrayObject *self, PyObject *args, PyObject *kwds) \n{\n\tint axis=-1;\n\tPyArray_SORTKIND which=PyArray_QUICKSORT;\n\tstatic char *kwlist[] = {\"axis\", \"kind\", NULL};\n\t\n\tif (!PyArg_ParseTupleAndKeywords(args, kwds, \"|iO&\", kwlist, &axis,\n\t\t\t\t\t PyArray_SortkindConverter, &which))\n\t\treturn NULL;\n\t\n\treturn _ARET(PyArray_ArgSort(self, axis, which));\n}\n\nstatic char doc_searchsorted[] = \"a.searchsorted(v)\\n\"\\\n\t\" Assuming that a is a 1-D array, in ascending order and\\n\"\\\n\t\" represents bin boundaries, then a.searchsorted(values) gives an\\n\"\\\n\t\" array of bin numbers, giving the bin into which each value would\\n\"\\\n\t\" be placed. This method is helpful for histograming. \\n\"\\\n\t\" Note: No warning is given if the boundaries, in a, are not \\n\"\\\n\t\" in ascending order.\";\n\nstatic PyObject *\narray_searchsorted(PyArrayObject *self, PyObject *args) \n{\n\tPyObject *values;\n\t\n\tif (!PyArg_ParseTuple(args, \"O\", &values)) return NULL;\n\t\n\treturn _ARET(PyArray_SearchSorted(self, values));\n}\n\nstatic char doc_deepcopy[] = \"Used if copy.deepcopy is called on an array.\";\n\nstatic PyObject *\narray_deepcopy(PyArrayObject *self, PyObject *args) \n{\n PyObject* visit;\n PyObject **optr;\n PyArrayIterObject *it;\n PyObject *copy, *ret, *deepcopy, *temp, *res;\n\n if (!PyArg_ParseTuple(args, \"O\", &visit)) return NULL;\n ret = PyArray_Copy(self);\n if (PyArray_ISOBJECT(self)) {\n copy = PyImport_ImportModule(\"copy\");\n if (copy == NULL) return NULL;\n deepcopy = PyObject_GetAttrString(copy, \"deepcopy\");\n Py_DECREF(copy);\n if (deepcopy == NULL) return NULL;\n it = (PyArrayIterObject *)PyArray_IterNew((PyObject *)self);\n if (it == NULL) {Py_DECREF(deepcopy); return NULL;}\n optr = (PyObject **)PyArray_DATA(ret);\n while(it->index < it->size) {\n temp = *((PyObject **)it->dataptr);\n Py_INCREF(temp);\n /* call deepcopy on this argument */\n res = PyObject_CallFunctionObjArgs(deepcopy, \n temp, visit, NULL);\n Py_DECREF(temp);\n Py_DECREF(*optr);\n *optr++ = res;\n PyArray_ITER_NEXT(it);\n }\n Py_DECREF(deepcopy);\n Py_DECREF(it);\n }\n return _ARET(ret);\n}\n\n/* Convert Object Array to flat list and pickle the flat list string */\nstatic PyObject *\n_getobject_pkl(PyArrayObject *self)\n{\n\tPyObject *theobject;\n\tPyArrayIterObject *iter=NULL;\n\tPyObject *list;\n\n\t\n\titer = (PyArrayIterObject *)PyArray_IterNew((PyObject *)self);\n\tif (iter == NULL) return NULL;\n\tlist = PyList_New(iter->size);\n\tif (list == NULL) {Py_DECREF(iter); return NULL;}\n\twhile (iter->index < iter->size) {\n\t\ttheobject = *((PyObject **)iter->dataptr);\n\t\tPy_INCREF(theobject);\n\t\tPyList_SET_ITEM(list, (int) iter->index, theobject);\n\t\tPyArray_ITER_NEXT(iter);\n\t}\n\tPy_DECREF(iter);\n\treturn list;\n}\n\nstatic int\n_setobject_pkl(PyArrayObject *self, PyObject *list)\n{\n\tPyObject *theobject;\n\tPyArrayIterObject *iter=NULL;\n\tint size;\n\n\tsize = self->descr->elsize;\n\t\n\titer = (PyArrayIterObject *)PyArray_IterNew((PyObject *)self);\n\tif (iter == NULL) return -1;\n\twhile(iter->index < iter->size) {\n\t\ttheobject = PyList_GET_ITEM(list, (int) iter->index);\n\t\tPy_INCREF(theobject);\n\t\t*((PyObject **)iter->dataptr) = theobject;\n\t\tPyArray_ITER_NEXT(iter);\n\t}\n\tPy_XDECREF(iter);\n\treturn 0;\n}\n\nstatic char doc_reduce[] = \"a.__reduce__() for pickling.\";\n\nstatic PyObject *\narray_reduce(PyArrayObject *self, PyObject *args)\n{\n\tPyObject *ret=NULL, *state=NULL, *obj=NULL, *mod=NULL;\n\tPyObject *mybool, *thestr=NULL;\n\tPyArray_Descr *descr;\n\n\t/* Return a tuple of (callable object, arguments, object's state) */\n\t/* We will put everything in the object's state, so that on UnPickle\n\t it can use the string object as memory without a copy */\n\n\tret = PyTuple_New(3);\n\tif (ret == NULL) return NULL;\n\tmod = PyImport_ImportModule(\"numpy.core._internal\");\n\tif (mod == NULL) {Py_DECREF(ret); return NULL;}\n\tobj = PyObject_GetAttrString(mod, \"_reconstruct\");\n\tPy_DECREF(mod);\n\tPyTuple_SET_ITEM(ret, 0, obj);\n\tPyTuple_SET_ITEM(ret, 1, \n\t\t\t Py_BuildValue(\"ONN\",\n\t\t\t\t (PyObject *)self->ob_type,\n\t\t\t\t Py_BuildValue(\"(N)\",\n\t\t\t\t\t\t PyInt_FromLong(0)),\n\t\t\t\t PyObject_GetAttrString((PyObject *)(self->descr),\n\t\t\t\t\t\t\t \"char\")));\n\t\n\t/* Now fill in object's state. This is a tuple with \n\t 4 arguments\n\n\t 1) a Tuple giving the shape\n\t 2) a PyArray_Descr Object (with correct bytorder set)\n\t 3) a Bool stating if Fortran or not\n\t 4) a binary string with the data (or a list for Object arrays)\n\n\t Notice because Python does not describe a mechanism to write \n\t raw data to the pickle, this performs a copy to a string first\n\t*/\n\n\tstate = PyTuple_New(4);\n\tif (state == NULL) {\n\t\tPy_DECREF(ret); return NULL;\n\t}\n\tPyTuple_SET_ITEM(state, 0, PyObject_GetAttrString((PyObject *)self, \n\t\t\t\t\t\t\t \"shape\"));\n\tdescr = self->descr;\n\tPy_INCREF(descr);\n\tPyTuple_SET_ITEM(state, 1, (PyObject *)descr);\n\tmybool = (PyArray_ISFORTRAN(self) ? Py_True : Py_False);\n\tPy_INCREF(mybool);\n\tPyTuple_SET_ITEM(state, 2, mybool);\n\tif (PyArray_ISOBJECT(self)) {\n\t\tthestr = _getobject_pkl(self);\n\t}\n\telse {\n thestr = PyArray_ToString(self);\n\t}\n\tif (thestr == NULL) {\n\t\tPy_DECREF(ret);\n\t\tPy_DECREF(state);\n\t\treturn NULL;\n\t}\n\tPyTuple_SET_ITEM(state, 3, thestr);\n\tPyTuple_SET_ITEM(ret, 2, state);\n\treturn ret;\n}\n\nstatic char doc_setstate[] = \"a.__setstate__(tuple) for unpickling.\";\n\n/*\n\t 1) a Tuple giving the shape\n\t 2) a PyArray_Descr Object\n\t 3) a Bool stating if Fortran or not\n\t 4) a binary string with the data (or a list if Object array) \n*/\n\nstatic intp _array_fill_strides(intp *, intp *, int, intp, int, int *);\n\nstatic int _IsAligned(PyArrayObject *); \n\nstatic PyArray_Descr * _array_typedescr_fromstr(char *);\n\nstatic PyObject *\narray_setstate(PyArrayObject *self, PyObject *args)\n{\n\tPyObject *shape;\n\tPyArray_Descr *typecode;\n\tlong fortran;\n\tPyObject *rawdata;\n\tchar *datastr;\n\tint len;\n\tintp dimensions[MAX_DIMS];\n\tint nd;\n\t\n\t/* This will free any memory associated with a and\n\t use the string in setstate as the (writeable) memory.\n\t*/\n\tif (!PyArg_ParseTuple(args, \"(O!O!iO)\", &PyTuple_Type,\n\t\t\t &shape, &PyArrayDescr_Type, &typecode, \n\t\t\t &fortran, &rawdata))\n\t\treturn NULL;\n\n\tPy_XDECREF(self->descr);\n\tself->descr = typecode;\n\tPy_INCREF(typecode);\n\tnd = PyArray_IntpFromSequence(shape, dimensions, MAX_DIMS);\n\tif (typecode->type_num == PyArray_OBJECT) {\n\t\tif (!PyList_Check(rawdata)) {\n\t\t\tPyErr_SetString(PyExc_TypeError, \n\t\t\t\t\t\"object pickle not returning list\");\n\t\t\treturn NULL;\n\t\t}\n\t}\n\telse {\n\t\tif (!PyString_Check(rawdata)) {\n\t\t\tPyErr_SetString(PyExc_TypeError, \n\t\t\t\t\t\"pickle not returning string\");\n\t\t\treturn NULL;\n\t\t}\n\n\t\tif (PyString_AsStringAndSize(rawdata, &datastr, &len))\n\t\t\treturn NULL;\n\n\t\tif ((len != (self->descr->elsize *\t\t\t\\\n\t\t\t (int) PyArray_MultiplyList(dimensions, nd)))) {\n\t\t\tPyErr_SetString(PyExc_ValueError, \n\t\t\t\t\t\"buffer size does not\"\t\\\n\t\t\t\t\t\" match array size\");\n\t\t\treturn NULL;\n\t\t}\n\t}\n\n if ((self->flags & OWN_DATA)) {\n\t\tif (self->data != NULL)\n\t\t\tPyDataMem_FREE(self->data);\n\t\tself->flags &= ~OWN_DATA;\n }\n\tPy_XDECREF(self->base);\n\n\tself->flags &= ~UPDATEIFCOPY;\n\n if (self->dimensions != NULL) {\n PyDimMem_FREE(self->dimensions); \n\t\tself->dimensions = NULL;\n\t}\n\n\tself->flags = DEFAULT_FLAGS;\n\n\tself->nd = nd;\n\n\tif (nd > 0) {\n\t\tself->dimensions = PyDimMem_NEW(nd * 2);\n\t\tself->strides = self->dimensions + nd;\n\t\tmemcpy(self->dimensions, dimensions, sizeof(intp)*nd);\n\t\t(void) _array_fill_strides(self->strides, dimensions, nd,\n\t\t\t\t\t self->descr->elsize, fortran, \n\t\t\t\t\t &(self->flags));\n\t}\n\n\tif (typecode->type_num != PyArray_OBJECT) {\n\t\tself->data = datastr;\n\t\tif (!_IsAligned(self)) {\n\t\t\tintp num = PyArray_NBYTES(self);\n\t\t\tself->data = PyDataMem_NEW(num);\n\t\t\tif (self->data == NULL) {\n\t\t\t\tself->nd = 0;\n\t\t\t\tPyDimMem_FREE(self->dimensions);\n\t\t\t\treturn PyErr_NoMemory();\n\t\t\t}\n\t\t\tmemcpy(self->data, datastr, num);\n\t\t\tself->flags |= OWN_DATA;\n\t\t\tself->base = NULL;\n\t\t}\n\t\telse {\n\t\t\tself->base = rawdata;\n\t\t\tPy_INCREF(self->base);\n\t\t}\n\t}\n\telse {\n\t\tself->data = PyDataMem_NEW(PyArray_NBYTES(self));\n\t\tif (self->data == NULL) { \n\t\t\tself->nd = 0;\n\t\t\tself->data = PyDataMem_NEW(self->descr->elsize);\n\t\t\tif (self->dimensions) PyDimMem_FREE(self->dimensions);\n\t\t\treturn PyErr_NoMemory();\n\t\t}\n\t\tself->flags |= OWN_DATA;\n\t\tself->base = NULL;\n\t\tif (_setobject_pkl(self, rawdata) < 0) \n\t\t\treturn NULL;\n\t}\n\n\tPyArray_UpdateFlags(self, UPDATE_ALL_FLAGS);\n\t\n\tPy_INCREF(Py_None);\n\treturn Py_None;\t\n}\n\n/*OBJECT_API*/\nstatic int\nPyArray_Dump(PyObject *self, PyObject *file, int protocol)\n{\n\tPyObject *cpick=NULL;\n\tPyObject *ret;\n\tif (protocol < 0) protocol = 2;\n\n\tcpick = PyImport_ImportModule(\"cPickle\");\n\tif (cpick==NULL) return -1;\n\n\tif PyString_Check(file) {\n\t\tfile = PyFile_FromString(PyString_AS_STRING(file), \"wb\");\n\t\tif (file==NULL) return -1;\n\t}\n\telse Py_INCREF(file);\n\tret = PyObject_CallMethod(cpick, \"dump\", \"OOi\", self, \n\t\t\t\t file, protocol);\n\tPy_XDECREF(ret);\n\tPy_DECREF(file);\n\tPy_DECREF(cpick);\n\tif (PyErr_Occurred()) return -1;\n\treturn 0;\n}\n\n/*OBJECT_API*/\nstatic PyObject *\nPyArray_Dumps(PyObject *self, int protocol)\n{\n\tPyObject *cpick=NULL;\n\tPyObject *ret;\n\tif (protocol < 0) protocol = 2;\n\n\tcpick = PyImport_ImportModule(\"cPickle\");\n\tif (cpick==NULL) return NULL;\n\tret = PyObject_CallMethod(cpick, \"dumps\", \"Oi\", self, protocol);\n\tPy_DECREF(cpick);\n\treturn ret;\n}\n\n\nstatic char doc_dump[] = \"m.dump(file)\";\n\nstatic PyObject *\narray_dump(PyArrayObject *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((PyObject *)self, file, 2);\n\tif (ret < 0) return NULL;\n\tPy_INCREF(Py_None);\n\treturn Py_None;\n}\n\nstatic char doc_dumps[] = \"m.dumps()\";\n\nstatic PyObject *\narray_dumps(PyArrayObject *self, PyObject *args)\n{\n\tif (!PyArg_ParseTuple(args, \"\"))\n\t\treturn NULL;\n\treturn PyArray_Dumps((PyObject *)self, 2);\n}\n\n\nstatic char doc_transpose[] = \"m.transpose()\";\n\nstatic PyObject *\narray_transpose(PyArrayObject *self, PyObject *args) \n{\n\tPyObject *shape=Py_None;\n\tint n;\n\tPyArray_Dims permute;\n\tPyObject *ret;\n\n\tn = PyTuple_Size(args);\n\tif (n > 1) shape = args;\n\telse if (n == 1) shape = PyTuple_GET_ITEM(args, 0);\n\t\n\tif (shape == Py_None)\n\t\tret = PyArray_Transpose(self, NULL);\n\telse {\n\t\tif (!PyArray_IntpConverter(shape, &permute)) return NULL;\n\t\tret = PyArray_Transpose(self, &permute);\n\t\tPyDimMem_FREE(permute.ptr);\n\t}\n\t\n\treturn _ARET(ret);\n}\n\nstatic char doc_mean[] = \"a.mean(axis=None, dtype=None)\\n\\n\"\\\n \"Average the array over the given axis. If the axis is None, average\\n\"\\\n \"over all dimensions of the array.\\n\"\\\n \"\\n\"\\\n \"If an integer axis is given, this equals:\\n\"\\\n \" a.sum(axis, dtype) * 1.0 / len(a)\\n\"\\\n \"\\n\"\\\n \"If axis is None, this equals:\\n\"\\\n \" a.sum(axis, dtype) * 1.0 / product(a.shape)\\n\"\\\n \"\\n\"\\\n \"The optional dtype argument is the data type for intermediate\\n\"\\\n \"calculations in the sum.\";\n\n#define _CHKTYPENUM(typ) ((typ) ? (typ)->type_num : PyArray_NOTYPE)\n\nstatic PyObject *\narray_mean(PyArrayObject *self, PyObject *args, PyObject *kwds) \n{\n\tint axis=MAX_DIMS;\n\tPyArray_Descr *dtype=NULL;\n\tstatic char *kwlist[] = {\"axis\", \"dtype\", NULL};\n\t\n\tif (!PyArg_ParseTupleAndKeywords(args, kwds, \"|O&O&\", kwlist,\n\t\t\t\t\t PyArray_AxisConverter, \n\t\t\t\t\t &axis, PyArray_DescrConverter2,\n\t\t\t\t\t &dtype)) return NULL;\n\n\treturn PyArray_Mean(self, axis, _CHKTYPENUM(dtype));\n}\n\nstatic char doc_sum[] = \"a.sum(axis=None, dtype=None)\\n\\n\"\\\n \"Sum the array over the given axis. If the axis is None, sum over all\\n\"\\\n \"dimensions of the array.\\n\"\\\n \"\\n\"\\\n \"The optional dtype argument is the data type for the returned value\\n\"\\\n \"and intermediate calculations. The default is to upcast (promote)\\n\"\\\n \"smaller integer types to the platform-dependent int. For example, on\\n\"\\\n \"32-bit platforms:\\n\"\\\n \"\\n\"\\\n \" a.dtype default sum() dtype\\n\"\\\n \" ---------------------------------------------------\\n\"\\\n \" bool, int8, int16, int32 int32\\n\"\\\n \"\\n\"\\\n \"Examples:\\n\"\\\n \"\\n\"\\\n \">>> array([0.5, 1.5]).sum()\\n\"\\\n \"2.0\\n\"\\\n \">>> array([0.5, 1.5]).sum(dtype=int32)\\n\"\\\n \"1\\n\"\\\n \">>> array([[0, 1], [0, 5]]).sum()\\n\"\\\n \"array([0, 6])\\n\"\\\n \">>> array([[0, 1], [0, 5]]).sum(axis=1)\\n\"\\\n \"array([1, 5])\";\n\nstatic PyObject *\narray_sum(PyArrayObject *self, PyObject *args, PyObject *kwds) \n{\n\tint axis=MAX_DIMS;\n\tPyArray_Descr *dtype=NULL;\n\tstatic char *kwlist[] = {\"axis\", \"dtype\", NULL};\n\n\tif (!PyArg_ParseTupleAndKeywords(args, kwds, \"|O&O&\", kwlist, \n\t\t\t\t\t PyArray_AxisConverter, \n\t\t\t\t\t &axis, PyArray_DescrConverter2,\n\t\t\t\t\t &dtype)) return NULL;\n\t\n\treturn PyArray_Sum(self, axis, _CHKTYPENUM(dtype));\n}\n\n\nstatic char doc_cumsum[] = \"a.cumsum(axis=None, dtype=None)\";\n\nstatic PyObject *\narray_cumsum(PyArrayObject *self, PyObject *args, PyObject *kwds) \n{\n\tint axis=MAX_DIMS;\n\tPyArray_Descr *dtype=NULL;\n\tstatic char *kwlist[] = {\"axis\", \"dtype\", NULL};\n\t\n\tif (!PyArg_ParseTupleAndKeywords(args, kwds, \"|O&O&\", kwlist, \n\t\t\t\t\t PyArray_AxisConverter, \n\t\t\t\t\t &axis, PyArray_DescrConverter2,\n\t\t\t\t\t &dtype)) return NULL;\n\t\n\treturn PyArray_CumSum(self, axis, _CHKTYPENUM(dtype));\n}\n\nstatic char doc_prod[] = \"a.prod(axis=None, dtype=None)\";\n\nstatic PyObject *\narray_prod(PyArrayObject *self, PyObject *args, PyObject *kwds) \n{\n\tint axis=MAX_DIMS;\n\tPyArray_Descr *dtype=NULL;\n\tstatic char *kwlist[] = {\"axis\", \"dtype\", NULL};\n\t\n\tif (!PyArg_ParseTupleAndKeywords(args, kwds, \"|O&O&\", kwlist, \n\t\t\t\t\t PyArray_AxisConverter, \n\t\t\t\t\t &axis, PyArray_DescrConverter2,\n\t\t\t\t\t &dtype)) return NULL;\n\t\n\treturn PyArray_Prod(self, axis, _CHKTYPENUM(dtype));\n}\n\n\nstatic char doc_cumprod[] = \"a.cumprod(axis=None, dtype=None)\";\n\nstatic PyObject *\narray_cumprod(PyArrayObject *self, PyObject *args, PyObject *kwds) \n{\n\tint axis=MAX_DIMS;\n\tPyArray_Descr *dtype=NULL;\n\tstatic char *kwlist[] = {\"axis\", \"dtype\", NULL};\n\t\n\tif (!PyArg_ParseTupleAndKeywords(args, kwds, \"|O&O&\", kwlist, \n\t\t\t\t\t PyArray_AxisConverter, \n\t\t\t\t\t &axis, PyArray_DescrConverter2,\n\t\t\t\t\t &dtype)) return NULL;\n\t\n\treturn PyArray_CumProd(self, axis, _CHKTYPENUM(dtype));\n}\n\n\nstatic char doc_any[] = \"a.any(axis=None)\";\n\nstatic PyObject *\narray_any(PyArrayObject *self, PyObject *args) \n{\n\tint axis=MAX_DIMS;\n\t\n\tif (!PyArg_ParseTuple(args, \"|O&\", PyArray_AxisConverter, \n\t\t\t &axis)) return NULL;\n\t\n\treturn PyArray_Any(self, axis);\n}\n\nstatic char doc_all[] = \"a.all(axis=None)\";\n\nstatic PyObject *\narray_all(PyArrayObject *self, PyObject *args) \n{\n\tint axis=MAX_DIMS;\n\t\n\tif (!PyArg_ParseTuple(args, \"|O&\", PyArray_AxisConverter, \n\t\t\t &axis)) return NULL;\n\t\n\treturn PyArray_All(self, axis);\n}\n\nstatic char doc_stddev[] = \"a.std(axis=None, dtype=None)\";\n\nstatic PyObject *\narray_stddev(PyArrayObject *self, PyObject *args, PyObject *kwds) \n{\n\tint axis=MAX_DIMS;\n\tPyArray_Descr *dtype=NULL;\n\tstatic char *kwlist[] = {\"axis\", \"dtype\", NULL};\n\t\n\tif (!PyArg_ParseTupleAndKeywords(args, kwds, \"|O&O&\", kwlist, \n\t\t\t\t\t PyArray_AxisConverter, \n\t\t\t\t\t &axis, PyArray_DescrConverter2,\n\t\t\t\t\t &dtype)) return NULL;\n\t\n\treturn PyArray_Std(self, axis, _CHKTYPENUM(dtype), 0);\n}\n\nstatic char doc_variance[] = \"a.var(axis=None, dtype=None)\";\n\nstatic PyObject *\narray_variance(PyArrayObject *self, PyObject *args, PyObject *kwds) \n{\n\tint axis=MAX_DIMS;\n\tPyArray_Descr *dtype=NULL;\n\tstatic char *kwlist[] = {\"axis\", \"dtype\", NULL};\n\t\n\tif (!PyArg_ParseTupleAndKeywords(args, kwds, \"|O&O&\", kwlist, \n\t\t\t\t\t PyArray_AxisConverter, \n\t\t\t\t\t &axis, PyArray_DescrConverter2,\n\t\t\t\t\t &dtype)) return NULL;\n\t\n\treturn PyArray_Std(self, axis, _CHKTYPENUM(dtype), 1);\n}\n\nstatic char doc_compress[] = \"a.compress(condition=, axis=None)\";\n\nstatic PyObject *\narray_compress(PyArrayObject *self, PyObject *args, PyObject *kwds) \n{\n\tint axis=MAX_DIMS;\n\tPyObject *condition;\t\n\tstatic char *kwlist[] = {\"condition\", \"axis\", NULL};\n\t\n\tif (!PyArg_ParseTupleAndKeywords(args, kwds, \"O|O&\", kwlist, \n\t\t\t\t\t &condition, PyArray_AxisConverter,\n\t\t\t\t\t &axis)) return NULL;\n\n\treturn _ARET(PyArray_Compress(self, condition, axis));\n}\n\nstatic char doc_nonzero[] = \"a.nonzero() return a tuple of indices referencing\"\\\n\t\"the elements of a that are nonzero.\";\n\nstatic PyObject *\narray_nonzero(PyArrayObject *self, PyObject *args)\n{\n\tif (!PyArg_ParseTuple(args, \"\")) return NULL;\n\n\treturn _ARET(PyArray_Nonzero(self));\n}\n\n\nstatic char doc_trace[] = \"a.trace(offset=0, axis1=0, axis2=1, dtype=None) \\n\"\\\n\t\"return the sum along the offset diagonal of the arrays indicated\\n\" \\\n\t\"axis1 and axis2.\";\n\nstatic PyObject *\narray_trace(PyArrayObject *self, PyObject *args, PyObject *kwds) \n{\n\tint axis1=0, axis2=1, offset=0;\n\tPyArray_Descr *dtype=NULL;\n\tstatic char *kwlist[] = {\"offset\", \"axis1\", \"axis2\", \"dtype\", NULL};\n\t\n\tif (!PyArg_ParseTupleAndKeywords(args, kwds, \"|iiiO&\", kwlist, \n\t\t\t\t\t &offset, &axis1, &axis2,\n\t\t\t\t\t PyArray_DescrConverter2, &dtype))\n\t\treturn NULL;\n\t\n\treturn _ARET(PyArray_Trace(self, offset, axis1, axis2, \n\t\t\t\t _CHKTYPENUM(dtype)));\n}\n\n#undef _CHKTYPENUM\n\n\nstatic char doc_clip[] = \"a.clip(min=, max=)\";\n\nstatic PyObject *\narray_clip(PyArrayObject *self, PyObject *args, PyObject *kwds) \n{\n\tPyObject *min, *max;\n\tstatic char *kwlist[] = {\"min\", \"max\", NULL};\n\n\tif (!PyArg_ParseTupleAndKeywords(args, kwds, \"OO\", kwlist,\n\t\t\t\t\t &min, &max)) \n\t\treturn NULL;\n\t\n\treturn _ARET(PyArray_Clip(self, min, max));\n}\n\nstatic char doc_conj[] = \"a.conj()\";\n\nstatic char doc_conjugate[] = \"a.conjugate()\";\n\nstatic PyObject *\narray_conjugate(PyArrayObject *self, PyObject *args) \n{\n\n\tif (!PyArg_ParseTuple(args, \"\")) return NULL;\n\t\n\treturn PyArray_Conjugate(self);\n}\n\n\nstatic char doc_diagonal[] = \"a.diagonal(offset=0, axis1=0, axis2=1)\";\n\nstatic PyObject *\narray_diagonal(PyArrayObject *self, PyObject *args, PyObject *kwds) \n{\n\tint axis1=0, axis2=1, offset=0;\n\tstatic char *kwlist[] = {\"offset\", \"axis1\", \"axis2\", NULL};\n\t\n\tif (!PyArg_ParseTupleAndKeywords(args, kwds, \"|iii\", kwlist, \n\t\t\t\t\t &offset, &axis1, &axis2))\n\t\treturn NULL;\n\t\n\treturn _ARET(PyArray_Diagonal(self, offset, axis1, axis2));\n}\n\nstatic char doc_flatten[] = \"a.flatten([fortran]) return a 1-d array (always copy)\";\n\nstatic PyObject *\narray_flatten(PyArrayObject *self, PyObject *args)\n{\n\tint fortran=0;\n\n\tif (!PyArg_ParseTuple(args, \"|i\", &fortran)) return NULL;\n \n\treturn PyArray_Flatten(self, (int) fortran);\n}\n\nstatic char doc_ravel[] = \"a.ravel([fortran]) return a 1-d array (copy only if needed)\";\n\nstatic PyObject *\narray_ravel(PyArrayObject *self, PyObject *args)\n{\n\tint fortran=0;\n\n\tif (!PyArg_ParseTuple(args, \"|i\", &fortran)) return NULL;\n\n\treturn PyArray_Ravel(self, fortran);\n}\n\n\n\nstatic char doc_setflags[] = \"a.setflags(write=None, align=None, uic=None)\";\n\nstatic int _IsAligned(PyArrayObject *);\nstatic Bool _IsWriteable(PyArrayObject *);\n\nstatic PyObject *\narray_setflags(PyArrayObject *self, PyObject *args, PyObject *kwds)\n{\n\tstatic char *kwlist[] = {\"write\", \"align\", \"uic\", NULL};\n\tPyObject *write=Py_None;\n\tPyObject *align=Py_None;\n\tPyObject *uic=Py_None;\n\tint flagback = self->flags;\n\t\t\n\tif (!PyArg_ParseTupleAndKeywords(args, kwds, \"|OOO\", kwlist,\n\t\t\t\t\t &write, &align, &uic))\n\t\treturn NULL;\n\n\tif (align != Py_None) {\n\t\tif (PyObject_Not(align)) self->flags &= ~ALIGNED;\n\t\telse if (_IsAligned(self)) self->flags |= ALIGNED;\n\t\telse {\n\t\t\tPyErr_SetString(PyExc_ValueError, \n\t\t\t\t\t\"cannot set aligned flag of mis-\"\\\n\t\t\t\t\t\"aligned array to True\");\n\t\t\treturn NULL;\n\t\t}\n\t}\n\t\n\tif (uic != Py_None) {\n if (PyObject_IsTrue(uic)) {\n\t\t\tself->flags = flagback;\n PyErr_SetString(PyExc_ValueError, \n \"cannot set UPDATEIFCOPY\" \\\n \"flag to True\");\n return NULL;\n }\n else {\n self->flags &= ~UPDATEIFCOPY;\n Py_DECREF(self->base);\n self->base = NULL;\n }\n }\n \n if (write != Py_None) {\n if (PyObject_IsTrue(write)) \n\t\t\tif (_IsWriteable(self)) {\n\t\t\t\tself->flags |= WRITEABLE;\n\t\t\t}\n\t\t\telse {\n\t\t\t\tself->flags = flagback;\n\t\t\t\tPyErr_SetString(PyExc_ValueError, \n\t\t\t\t\t\t\"cannot set WRITEABLE \"\t\\\n\t\t\t\t\t\t\"flag to True of this \"\t\\\n\t\t\t\t\t\t\"array\");\t\t\\\n\t\t\t\treturn NULL;\n\t\t\t}\n else\n self->flags &= ~WRITEABLE;\n }\n \n Py_INCREF(Py_None);\n return Py_None;\n}\n\nstatic char doc_newbyteorder[] = \"a.newbyteorder() is equivalent\\n\" \\\n\t\" to a.view(a.dtypedescr.newbytorder())\\n\";\n\nstatic PyObject *\narray_newbyteorder(PyArrayObject *self, PyObject *args) \n{\n\tchar endian = PyArray_SWAP;\n\tPyArray_Descr *new;\n\t\n\tif (!PyArg_ParseTuple(args, \"|O&\", PyArray_ByteorderConverter,\n\t\t\t &endian)) return NULL;\n\n\tnew = PyArray_DescrNewByteorder(self->descr, endian);\n\tif (!new) return NULL;\n\treturn _ARET(PyArray_View(self,\tnew, NULL));\n\n}\n\nstatic PyMethodDef array_methods[] = {\n {\"tolist\",\t (PyCFunction)array_tolist,\t1, doc_tolist},\n {\"item\", (PyCFunction)array_toscalar, METH_VARARGS, doc_toscalar},\n\t{\"tofile\", (PyCFunction)array_tofile, \n METH_VARARGS | METH_KEYWORDS, doc_tofile},\n {\"tostring\", (PyCFunction)array_tostring, METH_VARARGS, doc_tostring},\n {\"byteswap\", (PyCFunction)array_byteswap,\t1, doc_byteswap},\n {\"astype\", (PyCFunction)array_cast, 1, doc_cast},\n\t{\"getfield\", (PyCFunction)array_getfield, \n\t METH_VARARGS | METH_KEYWORDS, doc_getfield},\n\t{\"setfield\", (PyCFunction)array_setfield, \n\t METH_VARARGS | METH_KEYWORDS, doc_setfield},\n {\"copy\", (PyCFunction)array_copy, 1, doc_copy}, \n {\"resize\", (PyCFunction)array_resize, 1, doc_resize}, \n\n\t/* for subtypes */\n\t{\"__array__\", (PyCFunction)array_getarray, 1, doc_array_getarray},\n\t{\"__array_wrap__\", (PyCFunction)array_wraparray, 1, doc_wraparray},\n\t/* default version so it is found... -- only used for subclasses */\n\t{\"__array_finalize__\", (PyCFunction)array_finalize, 1, NULL},\n\t\n\t\n\t/* for the copy module */\n {\"__copy__\", (PyCFunction)array_copy, 1, doc_copy},\t \n {\"__deepcopy__\", (PyCFunction)array_deepcopy, 1, doc_deepcopy}, \n\t\n /* for Pickling */\n {\"__reduce__\", (PyCFunction) array_reduce, 1, doc_reduce},\t\n\t{\"__setstate__\", (PyCFunction) array_setstate, 1, doc_setstate},\n\t{\"dumps\", (PyCFunction) array_dumps, 1, doc_dumps},\n\t{\"dump\", (PyCFunction) array_dump, 1, doc_dump},\n\n\t/* Extended methods added 2005 */\n\t{\"fill\", (PyCFunction)array_fill,\n\t METH_VARARGS, doc_fill},\n\t{\"transpose\",\t(PyCFunction)array_transpose, \n\t METH_VARARGS, doc_transpose},\n\t{\"take\",\t(PyCFunction)array_take, \n\t METH_VARARGS|METH_KEYWORDS, doc_take},\n\t{\"put\",\t(PyCFunction)array_put, \n\t METH_VARARGS|METH_KEYWORDS, doc_put},\n\t{\"putmask\",\t(PyCFunction)array_putmask, \n\t METH_VARARGS|METH_KEYWORDS, doc_putmask},\n\t{\"repeat\",\t(PyCFunction)array_repeat, \n\t METH_VARARGS|METH_KEYWORDS, doc_repeat},\n\t{\"choose\",\t(PyCFunction)array_choose, \n\t METH_VARARGS, doc_choose},\t\n\t{\"sort\",\t(PyCFunction)array_sort, \n\t METH_VARARGS|METH_KEYWORDS, doc_sort},\n\t{\"argsort\",\t(PyCFunction)array_argsort, \n\t METH_VARARGS|METH_KEYWORDS, doc_argsort},\n\t{\"searchsorted\", (PyCFunction)array_searchsorted, \n\t METH_VARARGS, doc_searchsorted},\t\n\t{\"argmax\",\t(PyCFunction)array_argmax, \n\t METH_VARARGS, doc_argmax},\n\t{\"argmin\", (PyCFunction)array_argmin,\n\t METH_VARARGS, doc_argmin},\n\t{\"reshape\",\t(PyCFunction)array_reshape, \n\t METH_VARARGS, doc_reshape},\n\t{\"squeeze\",\t(PyCFunction)array_squeeze,\n\t METH_VARARGS, doc_squeeze},\n\t{\"view\", (PyCFunction)array_view, \n\t METH_VARARGS, doc_view},\n\t{\"swapaxes\", (PyCFunction)array_swapaxes,\n\t METH_VARARGS, doc_swapaxes},\n\t{\"max\", (PyCFunction)array_max,\n\t METH_VARARGS, doc_max},\n\t{\"min\", (PyCFunction)array_min,\n\t METH_VARARGS, doc_min},\n\t{\"ptp\", (PyCFunction)array_ptp,\n\t METH_VARARGS, doc_ptp},\n\t{\"mean\", (PyCFunction)array_mean,\n\t METH_VARARGS|METH_KEYWORDS, doc_mean},\n\t{\"trace\", (PyCFunction)array_trace,\n\t METH_VARARGS|METH_KEYWORDS, doc_trace},\n\t{\"diagonal\", (PyCFunction)array_diagonal,\n\t METH_VARARGS|METH_KEYWORDS, doc_diagonal},\n\t{\"clip\", (PyCFunction)array_clip,\n\t METH_VARARGS|METH_KEYWORDS, doc_clip},\n\t{\"conj\", (PyCFunction)array_conjugate,\n\t METH_VARARGS, doc_conj},\n\t{\"conjugate\", (PyCFunction)array_conjugate,\n\t METH_VARARGS, doc_conjugate},\n\t{\"nonzero\", (PyCFunction)array_nonzero,\n\t METH_VARARGS, doc_nonzero},\n\t{\"std\", (PyCFunction)array_stddev,\n\t METH_VARARGS|METH_KEYWORDS, doc_stddev},\n\t{\"var\", (PyCFunction)array_variance,\n\t METH_VARARGS|METH_KEYWORDS, doc_variance},\n\t{\"sum\", (PyCFunction)array_sum,\n\t METH_VARARGS|METH_KEYWORDS, doc_sum},\n\t{\"cumsum\", (PyCFunction)array_cumsum,\n\t METH_VARARGS|METH_KEYWORDS, doc_cumsum},\n\t{\"prod\", (PyCFunction)array_prod,\n\t METH_VARARGS|METH_KEYWORDS, doc_prod},\n\t{\"cumprod\", (PyCFunction)array_cumprod,\n\t METH_VARARGS|METH_KEYWORDS, doc_cumprod},\n\t{\"all\", (PyCFunction)array_all,\n\t METH_VARARGS, doc_all},\n\t{\"any\", (PyCFunction)array_any,\n\t METH_VARARGS, doc_any},\n\t{\"compress\", (PyCFunction)array_compress,\n\t METH_VARARGS|METH_KEYWORDS, doc_compress},\n\t{\"flatten\", (PyCFunction)array_flatten,\n\t METH_VARARGS, doc_flatten},\n\t{\"ravel\", (PyCFunction)array_ravel,\n\t METH_VARARGS, doc_ravel},\n\t{\"setflags\", (PyCFunction)array_setflags,\n\t METH_VARARGS|METH_KEYWORDS, doc_setflags},\n\t{\"newbyteorder\", (PyCFunction)array_newbyteorder,\n\t METH_VARARGS, doc_newbyteorder},\n {NULL,\t\tNULL}\t\t/* sentinel */\n};\n\n#undef _ARET\n\n\n", + "methods": [ + { + "name": "array_take", + "long_name": "array_take( PyArrayObject * self , PyObject * args , PyObject * kwds)", + "filename": "arraymethods.c", + "nloc": 12, + "complexity": 2, + "token_count": 82, + "parameters": [ + "self", + "args", + "kwds" + ], + "start_line": 9, + "end_line": 22, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 14, + "top_nesting_level": 0 + }, + { + "name": "array_fill", + "long_name": "array_fill( PyArrayObject * self , PyObject * args)", + "filename": "arraymethods.c", + "nloc": 9, + "complexity": 3, + "token_count": 54, + "parameters": [ + "self", + "args" + ], + "start_line": 28, + "end_line": 36, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 9, + "top_nesting_level": 0 + }, + { + "name": "array_put", + "long_name": "array_put( PyArrayObject * self , PyObject * args , PyObject * kwds)", + "filename": "arraymethods.c", + "nloc": 9, + "complexity": 2, + "token_count": 71, + "parameters": [ + "self", + "args", + "kwds" + ], + "start_line": 43, + "end_line": 52, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 10, + "top_nesting_level": 0 + }, + { + "name": "array_putmask", + "long_name": "array_putmask( PyArrayObject * self , PyObject * args , PyObject * kwds)", + "filename": "arraymethods.c", + "nloc": 9, + "complexity": 2, + "token_count": 71, + "parameters": [ + "self", + "args", + "kwds" + ], + "start_line": 58, + "end_line": 68, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 11, + "top_nesting_level": 0 + }, + { + "name": "_reverse_shape", + "long_name": "_reverse_shape( PyArray_Dims * newshape)", + "filename": "arraymethods.c", + "nloc": 14, + "complexity": 2, + "token_count": 81, + "parameters": [ + "newshape" + ], + "start_line": 72, + "end_line": 86, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 15, + "top_nesting_level": 0 + }, + { + "name": "array_reshape", + "long_name": "array_reshape( PyArrayObject * self , PyObject * args)", + "filename": "arraymethods.c", + "nloc": 50, + "complexity": 13, + "token_count": 299, + "parameters": [ + "self", + "args" + ], + "start_line": 94, + "end_line": 147, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 54, + "top_nesting_level": 0 + }, + { + "name": "array_squeeze", + "long_name": "array_squeeze( PyArrayObject * self , PyObject * args)", + "filename": "arraymethods.c", + "nloc": 5, + "complexity": 2, + "token_count": 34, + "parameters": [ + "self", + "args" + ], + "start_line": 152, + "end_line": 156, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 5, + "top_nesting_level": 0 + }, + { + "name": "array_view", + "long_name": "array_view( PyArrayObject * self , PyObject * args)", + "filename": "arraymethods.c", + "nloc": 19, + "complexity": 6, + "token_count": 110, + "parameters": [ + "self", + "args" + ], + "start_line": 161, + "end_line": 181, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 21, + "top_nesting_level": 0 + }, + { + "name": "array_argmax", + "long_name": "array_argmax( PyArrayObject * self , PyObject * args)", + "filename": "arraymethods.c", + "nloc": 7, + "complexity": 2, + "token_count": 46, + "parameters": [ + "self", + "args" + ], + "start_line": 186, + "end_line": 194, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 9, + "top_nesting_level": 0 + }, + { + "name": "array_argmin", + "long_name": "array_argmin( PyArrayObject * self , PyObject * args)", + "filename": "arraymethods.c", + "nloc": 7, + "complexity": 2, + "token_count": 46, + "parameters": [ + "self", + "args" + ], + "start_line": 199, + "end_line": 207, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 9, + "top_nesting_level": 0 + }, + { + "name": "array_max", + "long_name": "array_max( PyArrayObject * self , PyObject * args)", + "filename": "arraymethods.c", + "nloc": 7, + "complexity": 2, + "token_count": 43, + "parameters": [ + "self", + "args" + ], + "start_line": 212, + "end_line": 220, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 9, + "top_nesting_level": 0 + }, + { + "name": "array_ptp", + "long_name": "array_ptp( PyArrayObject * self , PyObject * args)", + "filename": "arraymethods.c", + "nloc": 7, + "complexity": 2, + "token_count": 43, + "parameters": [ + "self", + "args" + ], + "start_line": 225, + "end_line": 233, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 9, + "top_nesting_level": 0 + }, + { + "name": "array_min", + "long_name": "array_min( PyArrayObject * self , PyObject * args)", + "filename": "arraymethods.c", + "nloc": 7, + "complexity": 2, + "token_count": 43, + "parameters": [ + "self", + "args" + ], + "start_line": 239, + "end_line": 247, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 9, + "top_nesting_level": 0 + }, + { + "name": "array_swapaxes", + "long_name": "array_swapaxes( PyArrayObject * self , PyObject * args)", + "filename": "arraymethods.c", + "nloc": 6, + "complexity": 2, + "token_count": 46, + "parameters": [ + "self", + "args" + ], + "start_line": 253, + "end_line": 260, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 8, + "top_nesting_level": 0 + }, + { + "name": "PyArray_GetField", + "long_name": "PyArray_GetField( PyArrayObject * self , PyArray_Descr * typed , int offset)", + "filename": "arraymethods.c", + "nloc": 23, + "complexity": 4, + "token_count": 155, + "parameters": [ + "self", + "typed", + "offset" + ], + "start_line": 272, + "end_line": 296, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 25, + "top_nesting_level": 0 + }, + { + "name": "array_getfield", + "long_name": "array_getfield( PyArrayObject * self , PyObject * args , PyObject * kwds)", + "filename": "arraymethods.c", + "nloc": 10, + "complexity": 2, + "token_count": 78, + "parameters": [ + "self", + "args", + "kwds" + ], + "start_line": 299, + "end_line": 311, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 13, + "top_nesting_level": 0 + }, + { + "name": "PyArray_SetField", + "long_name": "PyArray_SetField( PyArrayObject * self , PyArray_Descr * dtype , int offset , PyObject * val)", + "filename": "arraymethods.c", + "nloc": 25, + "complexity": 4, + "token_count": 184, + "parameters": [ + "self", + "dtype", + "offset", + "val" + ], + "start_line": 321, + "end_line": 347, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 27, + "top_nesting_level": 0 + }, + { + "name": "array_setfield", + "long_name": "array_setfield( PyArrayObject * self , PyObject * args , PyObject * kwds)", + "filename": "arraymethods.c", + "nloc": 14, + "complexity": 3, + "token_count": 100, + "parameters": [ + "self", + "args", + "kwds" + ], + "start_line": 350, + "end_line": 365, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 16, + "top_nesting_level": 0 + }, + { + "name": "PyArray_Byteswap", + "long_name": "PyArray_Byteswap( PyArrayObject * self , Bool inplace)", + "filename": "arraymethods.c", + "nloc": 37, + "complexity": 5, + "token_count": 226, + "parameters": [ + "self", + "inplace" + ], + "start_line": 372, + "end_line": 419, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 48, + "top_nesting_level": 0 + }, + { + "name": "array_byteswap", + "long_name": "array_byteswap( PyArrayObject * self , PyObject * args)", + "filename": "arraymethods.c", + "nloc": 7, + "complexity": 2, + "token_count": 43, + "parameters": [ + "self", + "args" + ], + "start_line": 426, + "end_line": 434, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 9, + "top_nesting_level": 0 + }, + { + "name": "array_tolist", + "long_name": "array_tolist( PyArrayObject * self , PyObject * args)", + "filename": "arraymethods.c", + "nloc": 10, + "complexity": 3, + "token_count": 51, + "parameters": [ + "self", + "args" + ], + "start_line": 440, + "end_line": 450, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 11, + "top_nesting_level": 0 + }, + { + "name": "array_tostring", + "long_name": "array_tostring( PyArrayObject * self , PyObject * args)", + "filename": "arraymethods.c", + "nloc": 5, + "complexity": 2, + "token_count": 31, + "parameters": [ + "self", + "args" + ], + "start_line": 456, + "end_line": 460, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 5, + "top_nesting_level": 0 + }, + { + "name": "array_tofile", + "long_name": "array_tofile( PyArrayObject * self , PyObject * args , PyObject * kwds)", + "filename": "arraymethods.c", + "nloc": 33, + "complexity": 7, + "token_count": 208, + "parameters": [ + "self", + "args", + "kwds" + ], + "start_line": 465, + "end_line": 499, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 35, + "top_nesting_level": 0 + }, + { + "name": "array_toscalar", + "long_name": "array_toscalar( PyArrayObject * self , PyObject * args)", + "filename": "arraymethods.c", + "nloc": 10, + "complexity": 4, + "token_count": 71, + "parameters": [ + "self", + "args" + ], + "start_line": 505, + "end_line": 514, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 10, + "top_nesting_level": 0 + }, + { + "name": "array_cast", + "long_name": "array_cast( PyArrayObject * self , PyObject * args)", + "filename": "arraymethods.c", + "nloc": 13, + "complexity": 3, + "token_count": 83, + "parameters": [ + "self", + "args" + ], + "start_line": 521, + "end_line": 535, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 15, + "top_nesting_level": 0 + }, + { + "name": "array_wraparray", + "long_name": "array_wraparray( PyArrayObject * self , PyObject * args)", + "filename": "arraymethods.c", + "nloc": 27, + "complexity": 4, + "token_count": 147, + "parameters": [ + "self", + "args" + ], + "start_line": 543, + "end_line": 571, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 29, + "top_nesting_level": 0 + }, + { + "name": "array_finalize", + "long_name": "array_finalize( PyArrayObject * self , PyObject * args)", + "filename": "arraymethods.c", + "nloc": 5, + "complexity": 1, + "token_count": 20, + "parameters": [ + "self", + "args" + ], + "start_line": 575, + "end_line": 579, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 5, + "top_nesting_level": 0 + }, + { + "name": "array_getarray", + "long_name": "array_getarray( PyArrayObject * self , PyObject * args)", + "filename": "arraymethods.c", + "nloc": 38, + "complexity": 8, + "token_count": 224, + "parameters": [ + "self", + "args" + ], + "start_line": 585, + "end_line": 628, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 44, + "top_nesting_level": 0 + }, + { + "name": "array_copy", + "long_name": "array_copy( PyArrayObject * self , PyObject * args)", + "filename": "arraymethods.c", + "nloc": 6, + "complexity": 2, + "token_count": 41, + "parameters": [ + "self", + "args" + ], + "start_line": 637, + "end_line": 643, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 7, + "top_nesting_level": 0 + }, + { + "name": "array_resize", + "long_name": "array_resize( PyArrayObject * self , PyObject * args)", + "filename": "arraymethods.c", + "nloc": 26, + "complexity": 6, + "token_count": 129, + "parameters": [ + "self", + "args" + ], + "start_line": 651, + "end_line": 677, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 27, + "top_nesting_level": 0 + }, + { + "name": "array_repeat", + "long_name": "array_repeat( PyArrayObject * self , PyObject * args , PyObject * kwds)", + "filename": "arraymethods.c", + "nloc": 9, + "complexity": 2, + "token_count": 78, + "parameters": [ + "self", + "args", + "kwds" + ], + "start_line": 685, + "end_line": 695, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 11, + "top_nesting_level": 0 + }, + { + "name": "array_choose", + "long_name": "array_choose( PyArrayObject * self , PyObject * args)", + "filename": "arraymethods.c", + "nloc": 14, + "complexity": 3, + "token_count": 68, + "parameters": [ + "self", + "args" + ], + "start_line": 705, + "end_line": 720, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 16, + "top_nesting_level": 0 + }, + { + "name": "array_sort", + "long_name": "array_sort( PyArrayObject * self , PyObject * args , PyObject * kwds)", + "filename": "arraymethods.c", + "nloc": 14, + "complexity": 3, + "token_count": 98, + "parameters": [ + "self", + "args", + "kwds" + ], + "start_line": 725, + "end_line": 740, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 16, + "top_nesting_level": 0 + }, + { + "name": "array_argsort", + "long_name": "array_argsort( PyArrayObject * self , PyObject * args , PyObject * kwds)", + "filename": "arraymethods.c", + "nloc": 10, + "complexity": 2, + "token_count": 80, + "parameters": [ + "self", + "args", + "kwds" + ], + "start_line": 747, + "end_line": 758, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 12, + "top_nesting_level": 0 + }, + { + "name": "array_searchsorted", + "long_name": "array_searchsorted( PyArrayObject * self , PyObject * args)", + "filename": "arraymethods.c", + "nloc": 6, + "complexity": 2, + "token_count": 43, + "parameters": [ + "self", + "args" + ], + "start_line": 769, + "end_line": 776, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 8, + "top_nesting_level": 0 + }, + { + "name": "array_deepcopy", + "long_name": "array_deepcopy( PyArrayObject * self , PyObject * args)", + "filename": "arraymethods.c", + "nloc": 32, + "complexity": 7, + "token_count": 234, + "parameters": [ + "self", + "args" + ], + "start_line": 781, + "end_line": 814, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 34, + "top_nesting_level": 0 + }, + { + "name": "_getobject_pkl", + "long_name": "_getobject_pkl( PyArrayObject * self)", + "filename": "arraymethods.c", + "nloc": 18, + "complexity": 4, + "token_count": 128, + "parameters": [ + "self" + ], + "start_line": 818, + "end_line": 837, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 20, + "top_nesting_level": 0 + }, + { + "name": "_setobject_pkl", + "long_name": "_setobject_pkl( PyArrayObject * self , PyObject * list)", + "filename": "arraymethods.c", + "nloc": 17, + "complexity": 3, + "token_count": 115, + "parameters": [ + "self", + "list" + ], + "start_line": 840, + "end_line": 858, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 19, + "top_nesting_level": 0 + }, + { + "name": "array_reduce", + "long_name": "array_reduce( PyArrayObject * self , PyObject * args)", + "filename": "arraymethods.c", + "nloc": 46, + "complexity": 7, + "token_count": 313, + "parameters": [ + "self", + "args" + ], + "start_line": 863, + "end_line": 926, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 64, + "top_nesting_level": 0 + }, + { + "name": "array_setstate", + "long_name": "array_setstate( PyArrayObject * self , PyObject * args)", + "filename": "arraymethods.c", + "nloc": 98, + "complexity": 17, + "token_count": 579, + "parameters": [ + "self", + "args" + ], + "start_line": 944, + "end_line": 1057, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 114, + "top_nesting_level": 0 + }, + { + "name": "PyArray_Dump", + "long_name": "PyArray_Dump( PyObject * self , PyObject * file , int protocol)", + "filename": "arraymethods.c", + "nloc": 20, + "complexity": 6, + "token_count": 132, + "parameters": [ + "self", + "file", + "protocol" + ], + "start_line": 1061, + "end_line": 1082, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 22, + "top_nesting_level": 0 + }, + { + "name": "PyArray_Dumps", + "long_name": "PyArray_Dumps( PyObject * self , int protocol)", + "filename": "arraymethods.c", + "nloc": 11, + "complexity": 3, + "token_count": 70, + "parameters": [ + "self", + "protocol" + ], + "start_line": 1086, + "end_line": 1097, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 12, + "top_nesting_level": 0 + }, + { + "name": "array_dump", + "long_name": "array_dump( PyArrayObject * self , PyObject * args)", + "filename": "arraymethods.c", + "nloc": 11, + "complexity": 3, + "token_count": 69, + "parameters": [ + "self", + "args" + ], + "start_line": 1103, + "end_line": 1114, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 12, + "top_nesting_level": 0 + }, + { + "name": "array_dumps", + "long_name": "array_dumps( PyArrayObject * self , PyObject * args)", + "filename": "arraymethods.c", + "nloc": 6, + "complexity": 2, + "token_count": 37, + "parameters": [ + "self", + "args" + ], + "start_line": 1119, + "end_line": 1124, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 6, + "top_nesting_level": 0 + }, + { + "name": "array_transpose", + "long_name": "array_transpose( PyArrayObject * self , PyObject * args)", + "filename": "arraymethods.c", + "nloc": 18, + "complexity": 5, + "token_count": 116, + "parameters": [ + "self", + "args" + ], + "start_line": 1130, + "end_line": 1150, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 21, + "top_nesting_level": 0 + }, + { + "name": "array_mean", + "long_name": "array_mean( PyArrayObject * self , PyObject * args , PyObject * kwds)", + "filename": "arraymethods.c", + "nloc": 11, + "complexity": 2, + "token_count": 82, + "parameters": [ + "self", + "args", + "kwds" + ], + "start_line": 1168, + "end_line": 1180, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 13, + "top_nesting_level": 0 + }, + { + "name": "array_sum", + "long_name": "array_sum( PyArrayObject * self , PyObject * args , PyObject * kwds)", + "filename": "arraymethods.c", + "nloc": 11, + "complexity": 2, + "token_count": 82, + "parameters": [ + "self", + "args", + "kwds" + ], + "start_line": 1207, + "end_line": 1219, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 13, + "top_nesting_level": 0 + }, + { + "name": "array_cumsum", + "long_name": "array_cumsum( PyArrayObject * self , PyObject * args , PyObject * kwds)", + "filename": "arraymethods.c", + "nloc": 11, + "complexity": 2, + "token_count": 82, + "parameters": [ + "self", + "args", + "kwds" + ], + "start_line": 1225, + "end_line": 1237, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 13, + "top_nesting_level": 0 + }, + { + "name": "array_prod", + "long_name": "array_prod( PyArrayObject * self , PyObject * args , PyObject * kwds)", + "filename": "arraymethods.c", + "nloc": 11, + "complexity": 2, + "token_count": 82, + "parameters": [ + "self", + "args", + "kwds" + ], + "start_line": 1242, + "end_line": 1254, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 13, + "top_nesting_level": 0 + }, + { + "name": "array_cumprod", + "long_name": "array_cumprod( PyArrayObject * self , PyObject * args , PyObject * kwds)", + "filename": "arraymethods.c", + "nloc": 11, + "complexity": 2, + "token_count": 82, + "parameters": [ + "self", + "args", + "kwds" + ], + "start_line": 1260, + "end_line": 1272, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 13, + "top_nesting_level": 0 + }, + { + "name": "array_any", + "long_name": "array_any( PyArrayObject * self , PyObject * args)", + "filename": "arraymethods.c", + "nloc": 7, + "complexity": 2, + "token_count": 43, + "parameters": [ + "self", + "args" + ], + "start_line": 1278, + "end_line": 1286, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 9, + "top_nesting_level": 0 + }, + { + "name": "array_all", + "long_name": "array_all( PyArrayObject * self , PyObject * args)", + "filename": "arraymethods.c", + "nloc": 7, + "complexity": 2, + "token_count": 43, + "parameters": [ + "self", + "args" + ], + "start_line": 1291, + "end_line": 1299, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 9, + "top_nesting_level": 0 + }, + { + "name": "array_stddev", + "long_name": "array_stddev( PyArrayObject * self , PyObject * args , PyObject * kwds)", + "filename": "arraymethods.c", + "nloc": 11, + "complexity": 2, + "token_count": 84, + "parameters": [ + "self", + "args", + "kwds" + ], + "start_line": 1304, + "end_line": 1316, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 13, + "top_nesting_level": 0 + }, + { + "name": "array_variance", + "long_name": "array_variance( PyArrayObject * self , PyObject * args , PyObject * kwds)", + "filename": "arraymethods.c", + "nloc": 11, + "complexity": 2, + "token_count": 84, + "parameters": [ + "self", + "args", + "kwds" + ], + "start_line": 1321, + "end_line": 1333, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 13, + "top_nesting_level": 0 + }, + { + "name": "array_compress", + "long_name": "array_compress( PyArrayObject * self , PyObject * args , PyObject * kwds)", + "filename": "arraymethods.c", + "nloc": 10, + "complexity": 2, + "token_count": 78, + "parameters": [ + "self", + "args", + "kwds" + ], + "start_line": 1338, + "end_line": 1349, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 12, + "top_nesting_level": 0 + }, + { + "name": "array_nonzero", + "long_name": "array_nonzero( PyArrayObject * self , PyObject * args)", + "filename": "arraymethods.c", + "nloc": 5, + "complexity": 2, + "token_count": 34, + "parameters": [ + "self", + "args" + ], + "start_line": 1355, + "end_line": 1360, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 6, + "top_nesting_level": 0 + }, + { + "name": "array_trace", + "long_name": "array_trace( PyArrayObject * self , PyObject * args , PyObject * kwds)", + "filename": "arraymethods.c", + "nloc": 12, + "complexity": 2, + "token_count": 105, + "parameters": [ + "self", + "args", + "kwds" + ], + "start_line": 1368, + "end_line": 1381, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 14, + "top_nesting_level": 0 + }, + { + "name": "array_clip", + "long_name": "array_clip( PyArrayObject * self , PyObject * args , PyObject * kwds)", + "filename": "arraymethods.c", + "nloc": 9, + "complexity": 2, + "token_count": 74, + "parameters": [ + "self", + "args", + "kwds" + ], + "start_line": 1389, + "end_line": 1399, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 11, + "top_nesting_level": 0 + }, + { + "name": "array_conjugate", + "long_name": "array_conjugate( PyArrayObject * self , PyObject * args)", + "filename": "arraymethods.c", + "nloc": 5, + "complexity": 2, + "token_count": 31, + "parameters": [ + "self", + "args" + ], + "start_line": 1406, + "end_line": 1412, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 7, + "top_nesting_level": 0 + }, + { + "name": "array_diagonal", + "long_name": "array_diagonal( PyArrayObject * self , PyObject * args , PyObject * kwds)", + "filename": "arraymethods.c", + "nloc": 9, + "complexity": 2, + "token_count": 87, + "parameters": [ + "self", + "args", + "kwds" + ], + "start_line": 1418, + "end_line": 1428, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 11, + "top_nesting_level": 0 + }, + { + "name": "array_flatten", + "long_name": "array_flatten( PyArrayObject * self , PyObject * args)", + "filename": "arraymethods.c", + "nloc": 6, + "complexity": 2, + "token_count": 44, + "parameters": [ + "self", + "args" + ], + "start_line": 1433, + "end_line": 1440, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 8, + "top_nesting_level": 0 + }, + { + "name": "array_ravel", + "long_name": "array_ravel( PyArrayObject * self , PyObject * args)", + "filename": "arraymethods.c", + "nloc": 6, + "complexity": 2, + "token_count": 41, + "parameters": [ + "self", + "args" + ], + "start_line": 1445, + "end_line": 1452, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 8, + "top_nesting_level": 0 + }, + { + "name": "array_setflags", + "long_name": "array_setflags( PyArrayObject * self , PyObject * args , PyObject * kwds)", + "filename": "arraymethods.c", + "nloc": 53, + "complexity": 10, + "token_count": 260, + "parameters": [ + "self", + "args", + "kwds" + ], + "start_line": 1462, + "end_line": 1519, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 58, + "top_nesting_level": 0 + }, + { + "name": "array_newbyteorder", + "long_name": "array_newbyteorder( PyArrayObject * self , PyObject * args)", + "filename": "arraymethods.c", + "nloc": 10, + "complexity": 3, + "token_count": 69, + "parameters": [ + "self", + "args" + ], + "start_line": 1525, + "end_line": 1537, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 13, + "top_nesting_level": 0 + } + ], + "methods_before": [ + { + "name": "array_take", + "long_name": "array_take( PyArrayObject * self , PyObject * args , PyObject * kwds)", + "filename": "arraymethods.c", + "nloc": 12, + "complexity": 2, + "token_count": 82, + "parameters": [ + "self", + "args", + "kwds" + ], + "start_line": 9, + "end_line": 22, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 14, + "top_nesting_level": 0 + }, + { + "name": "array_fill", + "long_name": "array_fill( PyArrayObject * self , PyObject * args)", + "filename": "arraymethods.c", + "nloc": 9, + "complexity": 3, + "token_count": 54, + "parameters": [ + "self", + "args" + ], + "start_line": 28, + "end_line": 36, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 9, + "top_nesting_level": 0 + }, + { + "name": "array_put", + "long_name": "array_put( PyArrayObject * self , PyObject * args , PyObject * kwds)", + "filename": "arraymethods.c", + "nloc": 9, + "complexity": 2, + "token_count": 71, + "parameters": [ + "self", + "args", + "kwds" + ], + "start_line": 43, + "end_line": 52, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 10, + "top_nesting_level": 0 + }, + { + "name": "array_putmask", + "long_name": "array_putmask( PyArrayObject * self , PyObject * args , PyObject * kwds)", + "filename": "arraymethods.c", + "nloc": 9, + "complexity": 2, + "token_count": 71, + "parameters": [ + "self", + "args", + "kwds" + ], + "start_line": 58, + "end_line": 68, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 11, + "top_nesting_level": 0 + }, + { + "name": "_reverse_shape", + "long_name": "_reverse_shape( PyArray_Dims * newshape)", + "filename": "arraymethods.c", + "nloc": 14, + "complexity": 2, + "token_count": 81, + "parameters": [ + "newshape" + ], + "start_line": 72, + "end_line": 86, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 15, + "top_nesting_level": 0 + }, + { + "name": "array_reshape", + "long_name": "array_reshape( PyArrayObject * self , PyObject * args)", + "filename": "arraymethods.c", + "nloc": 50, + "complexity": 13, + "token_count": 299, + "parameters": [ + "self", + "args" + ], + "start_line": 94, + "end_line": 147, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 54, + "top_nesting_level": 0 + }, + { + "name": "array_squeeze", + "long_name": "array_squeeze( PyArrayObject * self , PyObject * args)", + "filename": "arraymethods.c", + "nloc": 5, + "complexity": 2, + "token_count": 34, + "parameters": [ + "self", + "args" + ], + "start_line": 152, + "end_line": 156, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 5, + "top_nesting_level": 0 + }, + { + "name": "array_view", + "long_name": "array_view( PyArrayObject * self , PyObject * args)", + "filename": "arraymethods.c", + "nloc": 19, + "complexity": 6, + "token_count": 116, + "parameters": [ + "self", + "args" + ], + "start_line": 163, + "end_line": 183, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 21, + "top_nesting_level": 0 + }, + { + "name": "array_argmax", + "long_name": "array_argmax( PyArrayObject * self , PyObject * args)", + "filename": "arraymethods.c", + "nloc": 7, + "complexity": 2, + "token_count": 46, + "parameters": [ + "self", + "args" + ], + "start_line": 188, + "end_line": 196, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 9, + "top_nesting_level": 0 + }, + { + "name": "array_argmin", + "long_name": "array_argmin( PyArrayObject * self , PyObject * args)", + "filename": "arraymethods.c", + "nloc": 7, + "complexity": 2, + "token_count": 46, + "parameters": [ + "self", + "args" + ], + "start_line": 201, + "end_line": 209, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 9, + "top_nesting_level": 0 + }, + { + "name": "array_max", + "long_name": "array_max( PyArrayObject * self , PyObject * args)", + "filename": "arraymethods.c", + "nloc": 7, + "complexity": 2, + "token_count": 43, + "parameters": [ + "self", + "args" + ], + "start_line": 214, + "end_line": 222, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 9, + "top_nesting_level": 0 + }, + { + "name": "array_ptp", + "long_name": "array_ptp( PyArrayObject * self , PyObject * args)", + "filename": "arraymethods.c", + "nloc": 7, + "complexity": 2, + "token_count": 43, + "parameters": [ + "self", + "args" + ], + "start_line": 227, + "end_line": 235, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 9, + "top_nesting_level": 0 + }, + { + "name": "array_min", + "long_name": "array_min( PyArrayObject * self , PyObject * args)", + "filename": "arraymethods.c", + "nloc": 7, + "complexity": 2, + "token_count": 43, + "parameters": [ + "self", + "args" + ], + "start_line": 241, + "end_line": 249, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 9, + "top_nesting_level": 0 + }, + { + "name": "array_swapaxes", + "long_name": "array_swapaxes( PyArrayObject * self , PyObject * args)", + "filename": "arraymethods.c", + "nloc": 6, + "complexity": 2, + "token_count": 46, + "parameters": [ + "self", + "args" + ], + "start_line": 255, + "end_line": 262, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 8, + "top_nesting_level": 0 + }, + { + "name": "PyArray_GetField", + "long_name": "PyArray_GetField( PyArrayObject * self , PyArray_Descr * typed , int offset)", + "filename": "arraymethods.c", + "nloc": 23, + "complexity": 4, + "token_count": 155, + "parameters": [ + "self", + "typed", + "offset" + ], + "start_line": 274, + "end_line": 298, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 25, + "top_nesting_level": 0 + }, + { + "name": "array_getfield", + "long_name": "array_getfield( PyArrayObject * self , PyObject * args , PyObject * kwds)", + "filename": "arraymethods.c", + "nloc": 10, + "complexity": 2, + "token_count": 78, + "parameters": [ + "self", + "args", + "kwds" + ], + "start_line": 301, + "end_line": 313, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 13, + "top_nesting_level": 0 + }, + { + "name": "PyArray_SetField", + "long_name": "PyArray_SetField( PyArrayObject * self , PyArray_Descr * dtype , int offset , PyObject * val)", + "filename": "arraymethods.c", + "nloc": 25, + "complexity": 4, + "token_count": 184, + "parameters": [ + "self", + "dtype", + "offset", + "val" + ], + "start_line": 323, + "end_line": 349, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 27, + "top_nesting_level": 0 + }, + { + "name": "array_setfield", + "long_name": "array_setfield( PyArrayObject * self , PyObject * args , PyObject * kwds)", + "filename": "arraymethods.c", + "nloc": 14, + "complexity": 3, + "token_count": 100, + "parameters": [ + "self", + "args", + "kwds" + ], + "start_line": 352, + "end_line": 367, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 16, + "top_nesting_level": 0 + }, + { + "name": "PyArray_Byteswap", + "long_name": "PyArray_Byteswap( PyArrayObject * self , Bool inplace)", + "filename": "arraymethods.c", + "nloc": 37, + "complexity": 5, + "token_count": 226, + "parameters": [ + "self", + "inplace" + ], + "start_line": 374, + "end_line": 421, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 48, + "top_nesting_level": 0 + }, + { + "name": "array_byteswap", + "long_name": "array_byteswap( PyArrayObject * self , PyObject * args)", + "filename": "arraymethods.c", + "nloc": 7, + "complexity": 2, + "token_count": 43, + "parameters": [ + "self", + "args" + ], + "start_line": 428, + "end_line": 436, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 9, + "top_nesting_level": 0 + }, + { + "name": "array_tolist", + "long_name": "array_tolist( PyArrayObject * self , PyObject * args)", + "filename": "arraymethods.c", + "nloc": 10, + "complexity": 3, + "token_count": 51, + "parameters": [ + "self", + "args" + ], + "start_line": 442, + "end_line": 452, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 11, + "top_nesting_level": 0 + }, + { + "name": "array_tostring", + "long_name": "array_tostring( PyArrayObject * self , PyObject * args)", + "filename": "arraymethods.c", + "nloc": 5, + "complexity": 2, + "token_count": 31, + "parameters": [ + "self", + "args" + ], + "start_line": 458, + "end_line": 462, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 5, + "top_nesting_level": 0 + }, + { + "name": "array_tofile", + "long_name": "array_tofile( PyArrayObject * self , PyObject * args , PyObject * kwds)", + "filename": "arraymethods.c", + "nloc": 33, + "complexity": 7, + "token_count": 208, + "parameters": [ + "self", + "args", + "kwds" + ], + "start_line": 467, + "end_line": 501, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 35, + "top_nesting_level": 0 + }, + { + "name": "array_toscalar", + "long_name": "array_toscalar( PyArrayObject * self , PyObject * args)", + "filename": "arraymethods.c", + "nloc": 10, + "complexity": 4, + "token_count": 71, + "parameters": [ + "self", + "args" + ], + "start_line": 507, + "end_line": 516, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 10, + "top_nesting_level": 0 + }, + { + "name": "array_cast", + "long_name": "array_cast( PyArrayObject * self , PyObject * args)", + "filename": "arraymethods.c", + "nloc": 13, + "complexity": 3, + "token_count": 83, + "parameters": [ + "self", + "args" + ], + "start_line": 523, + "end_line": 537, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 15, + "top_nesting_level": 0 + }, + { + "name": "array_wraparray", + "long_name": "array_wraparray( PyArrayObject * self , PyObject * args)", + "filename": "arraymethods.c", + "nloc": 27, + "complexity": 4, + "token_count": 147, + "parameters": [ + "self", + "args" + ], + "start_line": 545, + "end_line": 573, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 29, + "top_nesting_level": 0 + }, + { + "name": "array_finalize", + "long_name": "array_finalize( PyArrayObject * self , PyObject * args)", + "filename": "arraymethods.c", + "nloc": 5, + "complexity": 1, + "token_count": 20, + "parameters": [ + "self", + "args" + ], + "start_line": 577, + "end_line": 581, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 5, + "top_nesting_level": 0 + }, + { + "name": "array_getarray", + "long_name": "array_getarray( PyArrayObject * self , PyObject * args)", + "filename": "arraymethods.c", + "nloc": 38, + "complexity": 8, + "token_count": 224, + "parameters": [ + "self", + "args" + ], + "start_line": 587, + "end_line": 630, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 44, + "top_nesting_level": 0 + }, + { + "name": "array_copy", + "long_name": "array_copy( PyArrayObject * self , PyObject * args)", + "filename": "arraymethods.c", + "nloc": 6, + "complexity": 2, + "token_count": 41, + "parameters": [ + "self", + "args" + ], + "start_line": 639, + "end_line": 645, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 7, + "top_nesting_level": 0 + }, + { + "name": "array_resize", + "long_name": "array_resize( PyArrayObject * self , PyObject * args)", + "filename": "arraymethods.c", + "nloc": 26, + "complexity": 6, + "token_count": 129, + "parameters": [ + "self", + "args" + ], + "start_line": 653, + "end_line": 679, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 27, + "top_nesting_level": 0 + }, + { + "name": "array_repeat", + "long_name": "array_repeat( PyArrayObject * self , PyObject * args , PyObject * kwds)", + "filename": "arraymethods.c", + "nloc": 9, + "complexity": 2, + "token_count": 78, + "parameters": [ + "self", + "args", + "kwds" + ], + "start_line": 687, + "end_line": 697, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 11, + "top_nesting_level": 0 + }, + { + "name": "array_choose", + "long_name": "array_choose( PyArrayObject * self , PyObject * args)", + "filename": "arraymethods.c", + "nloc": 14, + "complexity": 3, + "token_count": 68, + "parameters": [ + "self", + "args" + ], + "start_line": 707, + "end_line": 722, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 16, + "top_nesting_level": 0 + }, + { + "name": "array_sort", + "long_name": "array_sort( PyArrayObject * self , PyObject * args , PyObject * kwds)", + "filename": "arraymethods.c", + "nloc": 14, + "complexity": 3, + "token_count": 98, + "parameters": [ + "self", + "args", + "kwds" + ], + "start_line": 727, + "end_line": 742, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 16, + "top_nesting_level": 0 + }, + { + "name": "array_argsort", + "long_name": "array_argsort( PyArrayObject * self , PyObject * args , PyObject * kwds)", + "filename": "arraymethods.c", + "nloc": 10, + "complexity": 2, + "token_count": 80, + "parameters": [ + "self", + "args", + "kwds" + ], + "start_line": 749, + "end_line": 760, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 12, + "top_nesting_level": 0 + }, + { + "name": "array_searchsorted", + "long_name": "array_searchsorted( PyArrayObject * self , PyObject * args)", + "filename": "arraymethods.c", + "nloc": 6, + "complexity": 2, + "token_count": 43, + "parameters": [ + "self", + "args" + ], + "start_line": 771, + "end_line": 778, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 8, + "top_nesting_level": 0 + }, + { + "name": "array_deepcopy", + "long_name": "array_deepcopy( PyArrayObject * self , PyObject * args)", + "filename": "arraymethods.c", + "nloc": 32, + "complexity": 7, + "token_count": 234, + "parameters": [ + "self", + "args" + ], + "start_line": 783, + "end_line": 816, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 34, + "top_nesting_level": 0 + }, + { + "name": "_getobject_pkl", + "long_name": "_getobject_pkl( PyArrayObject * self)", + "filename": "arraymethods.c", + "nloc": 18, + "complexity": 4, + "token_count": 128, + "parameters": [ + "self" + ], + "start_line": 820, + "end_line": 839, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 20, + "top_nesting_level": 0 + }, + { + "name": "_setobject_pkl", + "long_name": "_setobject_pkl( PyArrayObject * self , PyObject * list)", + "filename": "arraymethods.c", + "nloc": 17, + "complexity": 3, + "token_count": 115, + "parameters": [ + "self", + "list" + ], + "start_line": 842, + "end_line": 860, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 19, + "top_nesting_level": 0 + }, + { + "name": "array_reduce", + "long_name": "array_reduce( PyArrayObject * self , PyObject * args)", + "filename": "arraymethods.c", + "nloc": 46, + "complexity": 7, + "token_count": 313, + "parameters": [ + "self", + "args" + ], + "start_line": 865, + "end_line": 928, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 64, + "top_nesting_level": 0 + }, + { + "name": "array_setstate", + "long_name": "array_setstate( PyArrayObject * self , PyObject * args)", + "filename": "arraymethods.c", + "nloc": 98, + "complexity": 17, + "token_count": 579, + "parameters": [ + "self", + "args" + ], + "start_line": 946, + "end_line": 1059, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 114, + "top_nesting_level": 0 + }, + { + "name": "PyArray_Dump", + "long_name": "PyArray_Dump( PyObject * self , PyObject * file , int protocol)", + "filename": "arraymethods.c", + "nloc": 20, + "complexity": 6, + "token_count": 132, + "parameters": [ + "self", + "file", + "protocol" + ], + "start_line": 1063, + "end_line": 1084, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 22, + "top_nesting_level": 0 + }, + { + "name": "PyArray_Dumps", + "long_name": "PyArray_Dumps( PyObject * self , int protocol)", + "filename": "arraymethods.c", + "nloc": 11, + "complexity": 3, + "token_count": 70, + "parameters": [ + "self", + "protocol" + ], + "start_line": 1088, + "end_line": 1099, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 12, + "top_nesting_level": 0 + }, + { + "name": "array_dump", + "long_name": "array_dump( PyArrayObject * self , PyObject * args)", + "filename": "arraymethods.c", + "nloc": 11, + "complexity": 3, + "token_count": 69, + "parameters": [ + "self", + "args" + ], + "start_line": 1105, + "end_line": 1116, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 12, + "top_nesting_level": 0 + }, + { + "name": "array_dumps", + "long_name": "array_dumps( PyArrayObject * self , PyObject * args)", + "filename": "arraymethods.c", + "nloc": 6, + "complexity": 2, + "token_count": 37, + "parameters": [ + "self", + "args" + ], + "start_line": 1121, + "end_line": 1126, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 6, + "top_nesting_level": 0 + }, + { + "name": "array_transpose", + "long_name": "array_transpose( PyArrayObject * self , PyObject * args)", + "filename": "arraymethods.c", + "nloc": 18, + "complexity": 5, + "token_count": 116, + "parameters": [ + "self", + "args" + ], + "start_line": 1132, + "end_line": 1152, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 21, + "top_nesting_level": 0 + }, + { + "name": "array_mean", + "long_name": "array_mean( PyArrayObject * self , PyObject * args , PyObject * kwds)", + "filename": "arraymethods.c", + "nloc": 11, + "complexity": 2, + "token_count": 82, + "parameters": [ + "self", + "args", + "kwds" + ], + "start_line": 1170, + "end_line": 1182, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 13, + "top_nesting_level": 0 + }, + { + "name": "array_sum", + "long_name": "array_sum( PyArrayObject * self , PyObject * args , PyObject * kwds)", + "filename": "arraymethods.c", + "nloc": 11, + "complexity": 2, + "token_count": 82, + "parameters": [ + "self", + "args", + "kwds" + ], + "start_line": 1209, + "end_line": 1221, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 13, + "top_nesting_level": 0 + }, + { + "name": "array_cumsum", + "long_name": "array_cumsum( PyArrayObject * self , PyObject * args , PyObject * kwds)", + "filename": "arraymethods.c", + "nloc": 11, + "complexity": 2, + "token_count": 82, + "parameters": [ + "self", + "args", + "kwds" + ], + "start_line": 1227, + "end_line": 1239, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 13, + "top_nesting_level": 0 + }, + { + "name": "array_prod", + "long_name": "array_prod( PyArrayObject * self , PyObject * args , PyObject * kwds)", + "filename": "arraymethods.c", + "nloc": 11, + "complexity": 2, + "token_count": 82, + "parameters": [ + "self", + "args", + "kwds" + ], + "start_line": 1244, + "end_line": 1256, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 13, + "top_nesting_level": 0 + }, + { + "name": "array_cumprod", + "long_name": "array_cumprod( PyArrayObject * self , PyObject * args , PyObject * kwds)", + "filename": "arraymethods.c", + "nloc": 11, + "complexity": 2, + "token_count": 82, + "parameters": [ + "self", + "args", + "kwds" + ], + "start_line": 1262, + "end_line": 1274, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 13, + "top_nesting_level": 0 + }, + { + "name": "array_any", + "long_name": "array_any( PyArrayObject * self , PyObject * args)", + "filename": "arraymethods.c", + "nloc": 7, + "complexity": 2, + "token_count": 43, + "parameters": [ + "self", + "args" + ], + "start_line": 1280, + "end_line": 1288, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 9, + "top_nesting_level": 0 + }, + { + "name": "array_all", + "long_name": "array_all( PyArrayObject * self , PyObject * args)", + "filename": "arraymethods.c", + "nloc": 7, + "complexity": 2, + "token_count": 43, + "parameters": [ + "self", + "args" + ], + "start_line": 1293, + "end_line": 1301, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 9, + "top_nesting_level": 0 + }, + { + "name": "array_stddev", + "long_name": "array_stddev( PyArrayObject * self , PyObject * args , PyObject * kwds)", + "filename": "arraymethods.c", + "nloc": 11, + "complexity": 2, + "token_count": 84, + "parameters": [ + "self", + "args", + "kwds" + ], + "start_line": 1306, + "end_line": 1318, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 13, + "top_nesting_level": 0 + }, + { + "name": "array_variance", + "long_name": "array_variance( PyArrayObject * self , PyObject * args , PyObject * kwds)", + "filename": "arraymethods.c", + "nloc": 11, + "complexity": 2, + "token_count": 84, + "parameters": [ + "self", + "args", + "kwds" + ], + "start_line": 1323, + "end_line": 1335, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 13, + "top_nesting_level": 0 + }, + { + "name": "array_compress", + "long_name": "array_compress( PyArrayObject * self , PyObject * args , PyObject * kwds)", + "filename": "arraymethods.c", + "nloc": 10, + "complexity": 2, + "token_count": 78, + "parameters": [ + "self", + "args", + "kwds" + ], + "start_line": 1340, + "end_line": 1351, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 12, + "top_nesting_level": 0 + }, + { + "name": "array_nonzero", + "long_name": "array_nonzero( PyArrayObject * self , PyObject * args)", + "filename": "arraymethods.c", + "nloc": 5, + "complexity": 2, + "token_count": 34, + "parameters": [ + "self", + "args" + ], + "start_line": 1357, + "end_line": 1362, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 6, + "top_nesting_level": 0 + }, + { + "name": "array_trace", + "long_name": "array_trace( PyArrayObject * self , PyObject * args , PyObject * kwds)", + "filename": "arraymethods.c", + "nloc": 12, + "complexity": 2, + "token_count": 105, + "parameters": [ + "self", + "args", + "kwds" + ], + "start_line": 1370, + "end_line": 1383, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 14, + "top_nesting_level": 0 + }, + { + "name": "array_clip", + "long_name": "array_clip( PyArrayObject * self , PyObject * args , PyObject * kwds)", + "filename": "arraymethods.c", + "nloc": 9, + "complexity": 2, + "token_count": 74, + "parameters": [ + "self", + "args", + "kwds" + ], + "start_line": 1391, + "end_line": 1401, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 11, + "top_nesting_level": 0 + }, + { + "name": "array_conjugate", + "long_name": "array_conjugate( PyArrayObject * self , PyObject * args)", + "filename": "arraymethods.c", + "nloc": 5, + "complexity": 2, + "token_count": 31, + "parameters": [ + "self", + "args" + ], + "start_line": 1408, + "end_line": 1414, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 7, + "top_nesting_level": 0 + }, + { + "name": "array_diagonal", + "long_name": "array_diagonal( PyArrayObject * self , PyObject * args , PyObject * kwds)", + "filename": "arraymethods.c", + "nloc": 9, + "complexity": 2, + "token_count": 87, + "parameters": [ + "self", + "args", + "kwds" + ], + "start_line": 1420, + "end_line": 1430, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 11, + "top_nesting_level": 0 + }, + { + "name": "array_flatten", + "long_name": "array_flatten( PyArrayObject * self , PyObject * args)", + "filename": "arraymethods.c", + "nloc": 6, + "complexity": 2, + "token_count": 44, + "parameters": [ + "self", + "args" + ], + "start_line": 1435, + "end_line": 1442, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 8, + "top_nesting_level": 0 + }, + { + "name": "array_ravel", + "long_name": "array_ravel( PyArrayObject * self , PyObject * args)", + "filename": "arraymethods.c", + "nloc": 6, + "complexity": 2, + "token_count": 41, + "parameters": [ + "self", + "args" + ], + "start_line": 1447, + "end_line": 1454, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 8, + "top_nesting_level": 0 + }, + { + "name": "array_setflags", + "long_name": "array_setflags( PyArrayObject * self , PyObject * args , PyObject * kwds)", + "filename": "arraymethods.c", + "nloc": 53, + "complexity": 10, + "token_count": 260, + "parameters": [ + "self", + "args", + "kwds" + ], + "start_line": 1464, + "end_line": 1521, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 58, + "top_nesting_level": 0 + }, + { + "name": "array_newbyteorder", + "long_name": "array_newbyteorder( PyArrayObject * self , PyObject * args)", + "filename": "arraymethods.c", + "nloc": 10, + "complexity": 3, + "token_count": 71, + "parameters": [ + "self", + "args" + ], + "start_line": 1527, + "end_line": 1539, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 13, + "top_nesting_level": 0 + } + ], + "changed_methods": [ + { + "name": "array_newbyteorder", + "long_name": "array_newbyteorder( PyArrayObject * self , PyObject * args)", + "filename": "arraymethods.c", + "nloc": 10, + "complexity": 3, + "token_count": 69, + "parameters": [ + "self", + "args" + ], + "start_line": 1525, + "end_line": 1537, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 13, + "top_nesting_level": 0 + }, + { + "name": "array_view", + "long_name": "array_view( PyArrayObject * self , PyObject * args)", + "filename": "arraymethods.c", + "nloc": 19, + "complexity": 6, + "token_count": 110, + "parameters": [ + "self", + "args" + ], + "start_line": 161, + "end_line": 181, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 21, + "top_nesting_level": 0 + } + ], + "nloc": 1311, + "complexity": 220, + "token_count": 8165, + "diff_parsed": { + "added": [ + "\t\t\treturn PyArray_View(self, NULL,", + " (PyTypeObject *)otype);", + " }", + "\treturn PyArray_View(self, type, NULL);", + "\t\" to a.view(a.dtype.newbytorder())\\n\";", + "\treturn PyArray_View(self, new, NULL));" + ], + "deleted": [ + "", + "", + "\t\t\treturn _ARET(PyArray_View(self, NULL,", + "\t\t\t\t\t\t (PyTypeObject *)otype));", + "\t\t}", + "\treturn _ARET(PyArray_View(self, type, NULL));", + "\t\" to a.view(a.dtypedescr.newbytorder())\\n\";", + "\treturn _ARET(PyArray_View(self,\tnew, NULL));" + ] + } + }, + { + "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": "@@ -2071,7 +2071,13 @@ DL_EXPORT(void) initumath(void) {\n \tm = Py_InitModule(\"umath\", methods);\n \n \t/* Import the array */\n-\tif (import_array() < 0) return;\n+\tif (import_array() < 0) {\n+ if (!PyErr_Occurred()) {\n+ PyErr_SetString(PyExc_ImportError, \n+ \"umath failed: Could not import array core.\");\n+ }\n+ return;\n+ }\n \n \t/* Initialize the types */\n \tif (PyType_Ready(&PyUFunc_Type) < 0)\n", + "added_lines": 7, + "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\n#ifdef log1pf\n#undef log1pf\n#endif\n#ifdef logf\n#undef logf\n#endif\n#ifdef sqrtf\n#undef sqrtf\n#endif\nfloat log1pf(float);\nfloat logf(float);\nfloat sqrtf(float);\n#ifdef acoshf\n#undef acoshf\n#endif\nstatic float acoshf(float x)\n{\n\treturn 2*logf(sqrtf((x+1.0)/2)+sqrtf((x-1.0)/2));\n}\n\n#ifdef asinhf\n#undef asinhf\n#endif\nstatic float asinhf(float xx)\n{\n\tfloat x, d;\n\tint sign;\n\tif (xx < 0.0) {\n\t\tsign = -1;\n\t\tx = -xx;\n\t}\n\telse {\n\t\tsign = 1;\n\t\tx = xx;\n\t}\n\tif (x > 1e5) {\n\t\td = x;\n\t} else {\n\t\td = sqrtf(x*x + 1);\n\t}\n\treturn sign*log1pf(x*(1.0 + x/(d+1)));\n}\n\n#ifdef atanhf\n#undef atanhf\n#endif\nstatic float atanhf(float x)\n{\n\treturn 0.5*log1pf(2.0*x/(1.0-x));\n}\n#else\n#ifdef acoshf\n#undef acoshf\n#endif\nstatic float acoshf(float x)\n{\n return (float)acosh((double)(x));\n}\n\n#ifdef asinhf\n#undef asinhf\n#endif\nstatic float asinhf(float x)\n{\n return (float)asinh((double)(x));\n}\n\n#ifdef atanhf\n#undef atanhf\n#endif\nstatic float atanhf(float x)\n{\n return (float)atanh((double)(x));\n}\n#endif\n#endif\n\n\n#if !defined(HAVE_INVERSE_HYPERBOLIC_LONGDOUBLE)\n#ifdef HAVE_LONGDOUBLE_FUNCS\n#ifdef logl\n#undef logl\n#endif\n#ifdef sqrtl\n#undef sqrtl\n#endif\n#ifdef log1pl\n#undef log1pl\n#endif\nlongdouble logl(longdouble);\nlongdouble sqrtl(longdouble);\nlongdouble log1pl(longdouble);\n#ifdef acoshl\n#undef acoshl\n#endif\nstatic longdouble acoshl(longdouble x)\n{\n\treturn 2*logl(sqrtl((x+1.0)/2)+sqrtl((x-1.0)/2));\n}\n\n#ifdef asinhl\n#undef asinhl\n#endif\nstatic longdouble asinhl(longdouble xx)\n{\n\tlongdouble x, d;\n\tint sign;\n\tif (xx < 0.0) {\n\t\tsign = -1;\n\t\tx = -xx;\n\t}\n\telse {\n\t\tsign = 1;\n\t\tx = xx;\n\t}\n\tif (x > 1e17) {\n\t\td = x;\n\t} else {\n\t\td = sqrtl(x*x + 1);\n\t}\n\treturn sign*log1pl(x*(1.0 + x/(d+1)));\n}\n\n#ifdef atanhl\n#undef atanhl\n#endif\nstatic longdouble atanhl(longdouble x)\n{\n\treturn 0.5*log1pl(2.0*x/(1.0-x));\n}\n\n#else\n\n#ifdef acoshl\n#undef acoshl\n#endif\nstatic longdouble acoshl(longdouble x)\n{\n return (longdouble)acosh((double)(x));\n}\n\n#ifdef asinhl\n#undef asinhl\n#endif\nstatic longdouble asinhl(longdouble x)\n{\n return (longdouble)asinh((double)(x));\n}\n\n#ifdef atanhl\n#undef atanhl\n#endif\nstatic longdouble atanhl(longdouble x)\n{\n return (longdouble)atanh((double)(x));\n}\n\n#endif\n#endif\n\n\n#ifdef HAVE_HYPOT\n#if !defined(NeXT) && !defined(_MSC_VER)\nextern double hypot(double, double);\n#endif\n#else\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#ifdef @kind@@c@\n#undef @kind@@c@\n#endif\n@typ@ @kind@@c@(@typ@ x) {\n\treturn (@typ@) @kind@((double)x);\n}\n#endif\n/**end repeat**/\n\n/**begin repeat\n\n#kind=(atan2,hypot,pow,fmod)*2#\n#typ=longdouble*4, float*4#\n#c=l*4,f*4#\n#TYPE=LONGDOUBLE*4,FLOAT*4#\n*/\n#ifndef HAVE_@TYPE@_FUNCS\n#ifdef @kind@@c@\n#undef @kind@@c@\n#endif\n@typ@ @kind@@c@(@typ@ x, @typ@ y) {\n\treturn (@typ@) @kind@((double)x, (double) y);\n}\n#endif\n/**end repeat**/\n\n/**begin repeat\n#kind=modf*2#\n#typ=longdouble, float#\n#c=l,f#\n#TYPE=LONGDOUBLE, FLOAT#\n*/\n#ifndef HAVE_@TYPE@_FUNCS\n#ifdef modf@c@\n#undef modf@c@\n#endif\n@typ@ modf@c@(@typ@ x, @typ@ *iptr) {\n double nx, niptr, y;\n nx = (double) x;\n y = modf(nx, &niptr);\n *iptr = (@typ@) niptr;\n return (@typ@) y;\n}\n#endif\n/**end repeat**/\n\n\n\n#ifndef HAVE_LOG1P\ndouble log1p(double x)\n{\n\tdouble u = 1. + x;\n\tif (u == 1.0) {\n\t\treturn x;\n\t} else {\n\t\treturn log(u) * x / (u-1.);\n\t}\n}\n#endif\n\n#if !defined(HAVE_LOG1P) || !defined(HAVE_LONGDOUBLE_FUNCS)\n#ifdef log1pl\n#undef log1pl\n#endif\nlongdouble log1pl(longdouble x)\n{\n\tlongdouble u = 1. + x;\n\tif (u == 1.0) {\n\t\treturn x;\n\t} else {\n\t\treturn logl(u) * x / (u-1.);\n\t}\n}\n#endif\n\n#if !defined(HAVE_LOG1P) || !defined(HAVE_FLOAT_FUNCS)\n#ifdef log1pf\n#undef log1pf\n#endif\nfloat log1pf(float x)\n{\n\tfloat u = 1. + x;\n\tif (u == 1.0) {\n\t\treturn x;\n\t} else {\n\t\treturn logf(u) * x / (u-1.);\n\t}\n}\n#endif\n\n#ifndef HAVE_EXPM1\nstatic double expm1(double x)\n{\n\tdouble u = exp(x);\n\tif (u == 1.0) {\n\t\treturn x;\n\t} else if (u-1.0 == -1.0) {\n\t\treturn -1;\n\t} else {\n\t\treturn (u-1.0) * x/log(u);\n\t}\n}\n#endif\n\n#if !defined(HAVE_EXPM1) || !defined(HAVE_LONGDOUBLE_FUNCS)\n#ifdef expml1\n#undef expml1\n#endif\nstatic longdouble expm1l(longdouble x)\n{\n\tlongdouble u = expl(x);\n\tif (u == 1.0) {\n\t\treturn x;\n\t} else if (u-1.0 == -1.0) {\n\t\treturn -1;\n\t} else {\n\t\treturn (u-1.0) * x/logl(u);\n\t}\n}\n#endif\n\n#if !defined(HAVE_EXPM1) || !defined(HAVE_FLOAT_FUNCS)\n#ifdef expm1f\n#undef expm1f\n#endif\nstatic float expm1f(float x)\n{\n\tfloat u = expf(x);\n\tif (u == 1.0) {\n\t\treturn x;\n\t} else if (u-1.0 == -1.0) {\n\t\treturn -1;\n\t} else {\n\t\treturn (u-1.0) * x/logf(u);\n\t}\n}\n#endif\n\n\n\n\n/* Don't pass structures between functions (only pointers) because how\n structures are passed is compiler dependent and could cause\n segfaults if ufuncobject.c is compiled with a different compiler\n than an extension that makes use of the UFUNC API\n*/\n\n/**begin repeat\n\n#typ=float, double, longdouble#\n#c=f,,l#\n*/\n\n/* constants */\nstatic c@typ@ nc_1@c@ = {1., 0.};\nstatic c@typ@ nc_half@c@ = {0.5, 0.};\nstatic c@typ@ nc_i@c@ = {0., 1.};\nstatic c@typ@ nc_i2@c@ = {0., 0.5};\n/*\nstatic c@typ@ nc_mi@c@ = {0., -1.};\nstatic c@typ@ nc_pi2@c@ = {M_PI/2., 0.};\n*/\n\nstatic void\nnc_sum@c@(c@typ@ *a, c@typ@ *b, c@typ@ *r)\n{\n\tr->real = a->real + b->real;\n\tr->imag = a->imag + b->imag;\n\treturn;\n}\n\nstatic void\nnc_diff@c@(c@typ@ *a, c@typ@ *b, c@typ@ *r)\n{\n\tr->real = a->real - b->real;\n\tr->imag = a->imag - b->imag;\n\treturn;\n}\n\nstatic void\nnc_neg@c@(c@typ@ *a, c@typ@ *r)\n{\n\tr->real = -a->real;\n\tr->imag = -a->imag;\n\treturn;\n}\n\nstatic void\nnc_prod@c@(c@typ@ *a, c@typ@ *b, c@typ@ *r)\n{\n\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=bitwise_and*10, bitwise_or*10, bitwise_xor*10, left_shift*10, right_shift*10#\n\n*/\nstatic void\n@TYPE@_@kind@(char **args, intp *dimensions, intp *steps, void *func)\n{\n\tregister intp i;\n\tintp is1=steps[0],is2=steps[1],os=steps[2], n=dimensions[0];\n\tregister char *i1=args[0], *i2=args[1], *op=args[2];\n\tif (is1 == 0) {\n\t\tregister @typ@ t1 = *((@typ@ *)i1);\n\t\tfor (i=0; ireal || ((@typ@ *)i1)->imag;\n\t\tp2 = ((@typ@ *)i2)->real || ((@typ@ *)i2)->imag;\n\t\t*((Bool *)op)= (p1 || p2) && !(p1 && p2);\n\t}\n}\n/**end repeat**/\n\n\n\n/**begin repeat\n\n#TYPE=(BOOL,BYTE,UBYTE,SHORT,USHORT,INT,UINT,LONG,ULONG,LONGLONG,ULONGLONG,FLOAT,DOUBLE,LONGDOUBLE)*2#\n#OP= >*14, <*14#\n#typ=(Bool, byte, ubyte, short, ushort, int, uint, long, ulong, longlong, ulonglong, float, double, longdouble)*2#\n#kind= maximum*14, minimum*14#\n*/\nstatic void\n@TYPE@_@kind@(char **args, intp *dimensions, intp *steps, void *func)\n{\n\tregister intp i;\n\tintp is1=steps[0],is2=steps[1],os=steps[2], n=dimensions[0];\n\tchar *i1=args[0], *i2=args[1], *op=args[2];\n\tfor(i=0; i*3, <*3#\n#typ=(cfloat, cdouble, clongdouble)*2#\n#kind= maximum*3, minimum*3#\n*/\nstatic void\n@TYPE@_@kind@(char **args, intp *dimensions, intp *steps, void *func)\n{\n\tregister intp i;\n\tintp is1=steps[0],is2=steps[1],os=steps[2], n=dimensions[0];\n\tchar *i1=args[0], *i2=args[1], *op=args[2];\n @typ@ *i1c, *i2c;\n\tfor(i=0; ireal @OP@ i2c->real) || \\\n ((i1c->real==i2c->real) && (i1c->imag @OP@ i2c->imag)))\n 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\n#ifdef log1pf\n#undef log1pf\n#endif\n#ifdef logf\n#undef logf\n#endif\n#ifdef sqrtf\n#undef sqrtf\n#endif\nfloat log1pf(float);\nfloat logf(float);\nfloat sqrtf(float);\n#ifdef acoshf\n#undef acoshf\n#endif\nstatic float acoshf(float x)\n{\n\treturn 2*logf(sqrtf((x+1.0)/2)+sqrtf((x-1.0)/2));\n}\n\n#ifdef asinhf\n#undef asinhf\n#endif\nstatic float asinhf(float xx)\n{\n\tfloat x, d;\n\tint sign;\n\tif (xx < 0.0) {\n\t\tsign = -1;\n\t\tx = -xx;\n\t}\n\telse {\n\t\tsign = 1;\n\t\tx = xx;\n\t}\n\tif (x > 1e5) {\n\t\td = x;\n\t} else {\n\t\td = sqrtf(x*x + 1);\n\t}\n\treturn sign*log1pf(x*(1.0 + x/(d+1)));\n}\n\n#ifdef atanhf\n#undef atanhf\n#endif\nstatic float atanhf(float x)\n{\n\treturn 0.5*log1pf(2.0*x/(1.0-x));\n}\n#else\n#ifdef acoshf\n#undef acoshf\n#endif\nstatic float acoshf(float x)\n{\n return (float)acosh((double)(x));\n}\n\n#ifdef asinhf\n#undef asinhf\n#endif\nstatic float asinhf(float x)\n{\n return (float)asinh((double)(x));\n}\n\n#ifdef atanhf\n#undef atanhf\n#endif\nstatic float atanhf(float x)\n{\n return (float)atanh((double)(x));\n}\n#endif\n#endif\n\n\n#if !defined(HAVE_INVERSE_HYPERBOLIC_LONGDOUBLE)\n#ifdef HAVE_LONGDOUBLE_FUNCS\n#ifdef logl\n#undef logl\n#endif\n#ifdef sqrtl\n#undef sqrtl\n#endif\n#ifdef log1pl\n#undef log1pl\n#endif\nlongdouble logl(longdouble);\nlongdouble sqrtl(longdouble);\nlongdouble log1pl(longdouble);\n#ifdef acoshl\n#undef acoshl\n#endif\nstatic longdouble acoshl(longdouble x)\n{\n\treturn 2*logl(sqrtl((x+1.0)/2)+sqrtl((x-1.0)/2));\n}\n\n#ifdef asinhl\n#undef asinhl\n#endif\nstatic longdouble asinhl(longdouble xx)\n{\n\tlongdouble x, d;\n\tint sign;\n\tif (xx < 0.0) {\n\t\tsign = -1;\n\t\tx = -xx;\n\t}\n\telse {\n\t\tsign = 1;\n\t\tx = xx;\n\t}\n\tif (x > 1e17) {\n\t\td = x;\n\t} else {\n\t\td = sqrtl(x*x + 1);\n\t}\n\treturn sign*log1pl(x*(1.0 + x/(d+1)));\n}\n\n#ifdef atanhl\n#undef atanhl\n#endif\nstatic longdouble atanhl(longdouble x)\n{\n\treturn 0.5*log1pl(2.0*x/(1.0-x));\n}\n\n#else\n\n#ifdef acoshl\n#undef acoshl\n#endif\nstatic longdouble acoshl(longdouble x)\n{\n return (longdouble)acosh((double)(x));\n}\n\n#ifdef asinhl\n#undef asinhl\n#endif\nstatic longdouble asinhl(longdouble x)\n{\n return (longdouble)asinh((double)(x));\n}\n\n#ifdef atanhl\n#undef atanhl\n#endif\nstatic longdouble atanhl(longdouble x)\n{\n return (longdouble)atanh((double)(x));\n}\n\n#endif\n#endif\n\n\n#ifdef HAVE_HYPOT\n#if !defined(NeXT) && !defined(_MSC_VER)\nextern double hypot(double, double);\n#endif\n#else\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#ifdef @kind@@c@\n#undef @kind@@c@\n#endif\n@typ@ @kind@@c@(@typ@ x) {\n\treturn (@typ@) @kind@((double)x);\n}\n#endif\n/**end repeat**/\n\n/**begin repeat\n\n#kind=(atan2,hypot,pow,fmod)*2#\n#typ=longdouble*4, float*4#\n#c=l*4,f*4#\n#TYPE=LONGDOUBLE*4,FLOAT*4#\n*/\n#ifndef HAVE_@TYPE@_FUNCS\n#ifdef @kind@@c@\n#undef @kind@@c@\n#endif\n@typ@ @kind@@c@(@typ@ x, @typ@ y) {\n\treturn (@typ@) @kind@((double)x, (double) y);\n}\n#endif\n/**end repeat**/\n\n/**begin repeat\n#kind=modf*2#\n#typ=longdouble, float#\n#c=l,f#\n#TYPE=LONGDOUBLE, FLOAT#\n*/\n#ifndef HAVE_@TYPE@_FUNCS\n#ifdef modf@c@\n#undef modf@c@\n#endif\n@typ@ modf@c@(@typ@ x, @typ@ *iptr) {\n double nx, niptr, y;\n nx = (double) x;\n y = modf(nx, &niptr);\n *iptr = (@typ@) niptr;\n return (@typ@) y;\n}\n#endif\n/**end repeat**/\n\n\n\n#ifndef HAVE_LOG1P\ndouble log1p(double x)\n{\n\tdouble u = 1. + x;\n\tif (u == 1.0) {\n\t\treturn x;\n\t} else {\n\t\treturn log(u) * x / (u-1.);\n\t}\n}\n#endif\n\n#if !defined(HAVE_LOG1P) || !defined(HAVE_LONGDOUBLE_FUNCS)\n#ifdef log1pl\n#undef log1pl\n#endif\nlongdouble log1pl(longdouble x)\n{\n\tlongdouble u = 1. + x;\n\tif (u == 1.0) {\n\t\treturn x;\n\t} else {\n\t\treturn logl(u) * x / (u-1.);\n\t}\n}\n#endif\n\n#if !defined(HAVE_LOG1P) || !defined(HAVE_FLOAT_FUNCS)\n#ifdef log1pf\n#undef log1pf\n#endif\nfloat log1pf(float x)\n{\n\tfloat u = 1. + x;\n\tif (u == 1.0) {\n\t\treturn x;\n\t} else {\n\t\treturn logf(u) * x / (u-1.);\n\t}\n}\n#endif\n\n#ifndef HAVE_EXPM1\nstatic double expm1(double x)\n{\n\tdouble u = exp(x);\n\tif (u == 1.0) {\n\t\treturn x;\n\t} else if (u-1.0 == -1.0) {\n\t\treturn -1;\n\t} else {\n\t\treturn (u-1.0) * x/log(u);\n\t}\n}\n#endif\n\n#if !defined(HAVE_EXPM1) || !defined(HAVE_LONGDOUBLE_FUNCS)\n#ifdef expml1\n#undef expml1\n#endif\nstatic longdouble expm1l(longdouble x)\n{\n\tlongdouble u = expl(x);\n\tif (u == 1.0) {\n\t\treturn x;\n\t} else if (u-1.0 == -1.0) {\n\t\treturn -1;\n\t} else {\n\t\treturn (u-1.0) * x/logl(u);\n\t}\n}\n#endif\n\n#if !defined(HAVE_EXPM1) || !defined(HAVE_FLOAT_FUNCS)\n#ifdef expm1f\n#undef expm1f\n#endif\nstatic float expm1f(float x)\n{\n\tfloat u = expf(x);\n\tif (u == 1.0) {\n\t\treturn x;\n\t} else if (u-1.0 == -1.0) {\n\t\treturn -1;\n\t} else {\n\t\treturn (u-1.0) * x/logf(u);\n\t}\n}\n#endif\n\n\n\n\n/* Don't pass structures between functions (only pointers) because how\n structures are passed is compiler dependent and could cause\n segfaults if ufuncobject.c is compiled with a different compiler\n than an extension that makes use of the UFUNC API\n*/\n\n/**begin repeat\n\n#typ=float, double, longdouble#\n#c=f,,l#\n*/\n\n/* constants */\nstatic c@typ@ nc_1@c@ = {1., 0.};\nstatic c@typ@ nc_half@c@ = {0.5, 0.};\nstatic c@typ@ nc_i@c@ = {0., 1.};\nstatic c@typ@ nc_i2@c@ = {0., 0.5};\n/*\nstatic c@typ@ nc_mi@c@ = {0., -1.};\nstatic c@typ@ nc_pi2@c@ = {M_PI/2., 0.};\n*/\n\nstatic void\nnc_sum@c@(c@typ@ *a, c@typ@ *b, c@typ@ *r)\n{\n\tr->real = a->real + b->real;\n\tr->imag = a->imag + b->imag;\n\treturn;\n}\n\nstatic void\nnc_diff@c@(c@typ@ *a, c@typ@ *b, c@typ@ *r)\n{\n\tr->real = a->real - b->real;\n\tr->imag = a->imag - b->imag;\n\treturn;\n}\n\nstatic void\nnc_neg@c@(c@typ@ *a, c@typ@ *r)\n{\n\tr->real = -a->real;\n\tr->imag = -a->imag;\n\treturn;\n}\n\nstatic void\nnc_prod@c@(c@typ@ *a, c@typ@ *b, c@typ@ *r)\n{\n\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=bitwise_and*10, bitwise_or*10, bitwise_xor*10, left_shift*10, right_shift*10#\n\n*/\nstatic void\n@TYPE@_@kind@(char **args, intp *dimensions, intp *steps, void *func)\n{\n\tregister intp i;\n\tintp is1=steps[0],is2=steps[1],os=steps[2], n=dimensions[0];\n\tregister char *i1=args[0], *i2=args[1], *op=args[2];\n\tif (is1 == 0) {\n\t\tregister @typ@ t1 = *((@typ@ *)i1);\n\t\tfor (i=0; ireal || ((@typ@ *)i1)->imag;\n\t\tp2 = ((@typ@ *)i2)->real || ((@typ@ *)i2)->imag;\n\t\t*((Bool *)op)= (p1 || p2) && !(p1 && p2);\n\t}\n}\n/**end repeat**/\n\n\n\n/**begin repeat\n\n#TYPE=(BOOL,BYTE,UBYTE,SHORT,USHORT,INT,UINT,LONG,ULONG,LONGLONG,ULONGLONG,FLOAT,DOUBLE,LONGDOUBLE)*2#\n#OP= >*14, <*14#\n#typ=(Bool, byte, ubyte, short, ushort, int, uint, long, ulong, longlong, ulonglong, float, double, longdouble)*2#\n#kind= maximum*14, minimum*14#\n*/\nstatic void\n@TYPE@_@kind@(char **args, intp *dimensions, intp *steps, void *func)\n{\n\tregister intp i;\n\tintp is1=steps[0],is2=steps[1],os=steps[2], n=dimensions[0];\n\tchar *i1=args[0], *i2=args[1], *op=args[2];\n\tfor(i=0; i*3, <*3#\n#typ=(cfloat, cdouble, clongdouble)*2#\n#kind= maximum*3, minimum*3#\n*/\nstatic void\n@TYPE@_@kind@(char **args, intp *dimensions, intp *steps, void *func)\n{\n\tregister intp i;\n\tintp is1=steps[0],is2=steps[1],os=steps[2], n=dimensions[0];\n\tchar *i1=args[0], *i2=args[1], *op=args[2];\n @typ@ *i1c, *i2c;\n\tfor(i=0; ireal @OP@ i2c->real) || \\\n ((i1c->real==i2c->real) && (i1c->imag @OP@ i2c->imag)))\n 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#define MAX_BYTE SCHAR_MAX\n#define MIN_BYTE SCHAR_MIN\n#define MAX_UBYTE UCHAR_MAX\n#define MAX_SHORT SHRT_MAX\n#define MIN_SHORT SHRT_MIN\n#define MAX_USHORT USHRT_MAX\n#define MAX_INT INT_MAX\n#ifndef INT_MIN\n#define INT_MIN (-INT_MAX - 1)\n#endif\n#define MIN_INT INT_MIN\n#define MAX_UINT UINT_MAX\n#define MAX_LONG LONG_MAX\n#define MIN_LONG LONG_MIN\n#define MAX_ULONG ULONG_MAX\n\n#define SIZEOF_LONGDOUBLE SIZEOF_LONG_DOUBLE\n#define SIZEOF_LONGLONG SIZEOF_LONG_LONG\n#define BITSOF_BOOL sizeof(Bool)*CHAR_BIT\n#define BITSOF_CHAR CHAR_BIT\n#define BITSOF_SHORT (SIZEOF_SHORT*CHAR_BIT)\n#define BITSOF_INT (SIZEOF_INT*CHAR_BIT)\n#define BITSOF_LONG (SIZEOF_LONG*CHAR_BIT)\n#define BITSOF_LONGLONG (SIZEOF_LONGLONG*CHAR_BIT)\n#define BITSOF_FLOAT (SIZEOF_FLOAT*CHAR_BIT)\n#define BITSOF_DOUBLE (SIZEOF_DOUBLE*CHAR_BIT)\n#define BITSOF_LONGDOUBLE (SIZEOF_LONGDOUBLE*CHAR_BIT)\n\n\n#if BITSOF_LONG == 8\n#define PyArray_INT8 PyArray_LONG\n#define PyArray_UINT8 PyArray_ULONG\n\ttypedef long Int8;\n\ttypedef unsigned long UInt8;\n#define STRBITSOF_LONG \"8\"\n#elif BITSOF_LONG == 16\n#define PyArray_INT16 PyArray_LONG\n#define PyArray_UINT16 PyArray_ULONG\n\ttypedef long Int16;\n\ttypedef unsigned long UInt16;\n#define STRBITSOF_LONG \"16\"\n#elif BITSOF_LONG == 32\n#define PyArray_INT32 PyArray_LONG\n#define PyArray_UINT32 PyArray_ULONG\n\ttypedef long Int32;\n\ttypedef unsigned long UInt32;\n\ttypedef unsigned long PyArray_UCS4;\n#define STRBITSOF_LONG \"32\"\n#elif BITSOF_LONG == 64\n#define PyArray_INT64 PyArray_LONG\n#define PyArray_UINT64 PyArray_ULONG\n\ttypedef long Int64;\n\ttypedef unsigned long UInt64;\n#define STRBITSOF_LONG \"64\"\n#elif BITSOF_LONG == 128\n#define PyArray_INT128 PyArray_LONG\n#define PyArray_UINT128 PyArray_ULONG\n\ttypedef long Int128;\n\ttypedef unsigned long UInt128;\n#define STRBITSOF_LONG \"128\"\n#endif\n\n#if BITSOF_LONGLONG == 8\n# ifndef PyArray_INT8\n# define PyArray_INT8 PyArray_LONGLONG\n# define PyArray_UINT8 PyArray_ULONGLONG\n\ttypedef longlong Int8;\n\ttypedef ulonglong UInt8;\n# endif\n# define MAX_LONGLONG MAX_INT8\n# define MIN_LONGLONG MIN_INT8\n# define MAX_ULONGLONG MAX_UINT8\n#define STRBITSOF_LONGLONG \"8\"\n#elif BITSOF_LONGLONG == 16\n# ifndef PyArray_INT16\n# define PyArray_INT16 PyArray_LONGLONG\n# define PyArray_UINT16 PyArray_ULONGLONG\n\ttypedef longlong Int16;\n\ttypedef ulonglong UInt16;\n# endif\n# define MAX_LONGLONG MAX_INT16\n# define MIN_LONGLONG MIN_INT16\n# define MAX_ULONGLONG MAX_UINT16\n#define STRBITSOF_LONGLONG \"16\"\n#elif BITSOF_LONGLONG == 32\n# ifndef PyArray_INT32\n# define PyArray_INT32 PyArray_LONGLONG\n# define PyArray_UINT32 PyArray_ULONGLONG\n\ttypedef longlong Int32;\n\ttypedef ulonglong UInt32;\n\ttypedef ulonglong PyArray_UCS4;\n# endif\n# define MAX_LONGLONG MAX_INT32\n# define MIN_LONGLONG MIN_INT32\n# define MAX_ULONGLONG MAX_UINT32\n#define STRBITSOF_LONGLONG \"32\"\n#elif BITSOF_LONGLONG == 64\n# ifndef PyArray_INT64\n# define PyArray_INT64 PyArray_LONGLONG\n# define PyArray_UINT64 PyArray_ULONGLONG\n\ttypedef longlong Int64;\n\ttypedef ulonglong UInt64;\n# endif\n# define MAX_LONGLONG MAX_INT64\n# define MIN_LONGLONG MIN_INT64\n# define MAX_ULONGLONG MAX_UINT64\n#define STRBITSOF_LONGLONG \"64\"\n#elif BITSOF_LONGLONG == 128\n# ifndef PyArray_INT128\n# define PyArray_INT128 PyArray_LONGLONG\n# define PyArray_UINT128 PyArray_ULONGLONG\n\ttypedef longlong Int128;\n\ttypedef ulonglong UInt128;\n# endif\n# define MAX_LONGLONG MAX_INT128\n# define MIN_LONGLONG MIN_INT128\n# define MAX_ULONGLONG MAX_UINT128\n#define STRBITSOF_LONGLONG \"128\"\n#elif BITSOF_LONGLONG == 256\n# define PyArray_INT256 PyArray_LONGLONG\n# define PyArray_UINT256 PyArray_ULONGLONG\n\ttypedef longlong Int256;\n\ttypedef ulonglong UInt256;\n# define MAX_LONGLONG MAX_INT256\n# define MIN_LONGLONG MIN_INT256\n# define MAX_ULONGLONG MAX_UINT256\n#define STRBITSOF_LONGLONG \"256\"\n#endif\n\n#if BITSOF_INT == 8\n#ifndef PyArray_INT8\n#define PyArray_INT8 PyArray_INT\n#define PyArray_UINT8 PyArray_UINT\n\ttypedef int Int8;\n\ttypedef unsigned int UInt8;\n#endif\n#define STRBITSOF_INT \"8\"\n#elif BITSOF_INT == 16\n#ifndef PyArray_INT16\n#define PyArray_INT16 PyArray_INT\n#define PyArray_UINT16 PyArray_UINT\n\ttypedef int Int16;\n\ttypedef unsigned int UInt16;\n#endif\n#define STRBITSOF_INT \"16\"\n#elif BITSOF_INT == 32\n#ifndef PyArray_INT32\n#define PyArray_INT32 PyArray_INT\n#define PyArray_UINT32 PyArray_UINT\n\ttypedef int Int32;\n\ttypedef unsigned int UInt32;\n\ttypedef unsigned int PyArray_UCS4;\n#endif\n#define STRBITSOF_INT \"32\"\n#elif BITSOF_INT == 64\n#ifndef PyArray_INT64\n#define PyArray_INT64 PyArray_INT\n#define PyArray_UINT64 PyArray_UINT\n\ttypedef int Int64;\n\ttypedef unsigned int UInt64;\n#endif\n#define STRBITSOF_INT \"64\"\n#elif BITSOF_INT == 128\n#ifndef PyArray_INT128\n#define PyArray_INT128 PyArray_INT\n#define PyArray_UINT128 PyArray_UINT\n\ttypedef int Int128;\n\ttypedef unsigned int UInt128;\n#endif\n#define STRBITSOF_INT \"128\"\n#endif\n\n#if BITSOF_SHORT == 8\n#ifndef PyArray_INT8\n#define PyArray_INT8 PyArray_SHORT\n#define PyArray_UINT8 PyArray_USHORT\n\ttypedef short Int8;\n\ttypedef unsigned short UInt8;\n#endif\n#define STRBITSOF_SHORT \"8\"\n#elif BITSOF_SHORT == 16\n#ifndef PyArray_INT16\n#define PyArray_INT16 PyArray_SHORT\n#define PyArray_UINT16 PyArray_USHORT\n\ttypedef short Int16;\n\ttypedef unsigned short UInt16;\n#endif\n#define STRBITSOF_SHORT \"16\"\n#elif BITSOF_SHORT == 32\n#ifndef PyArray_INT32\n#define PyArray_INT32 PyArray_SHORT\n#define PyArray_UINT32 PyArray_USHORT\n\ttypedef short Int32;\n\ttypedef unsigned short UInt32;\n\ttypedef unsigned short PyArray_UCS4;\n#endif\n#define STRBITSOF_SHORT \"32\"\n#elif BITSOF_SHORT == 64\n#ifndef PyArray_INT64\n#define PyArray_INT64 PyArray_SHORT\n#define PyArray_UINT64 PyArray_USHORT\n\ttypedef short Int64;\n\ttypedef unsigned short UInt64;\n#endif\n#define STRBITSOF_SHORT \"64\"\n#elif BITSOF_SHORT == 128\n#ifndef PyArray_INT128\n#define PyArray_INT128 PyArray_SHORT\n#define PyArray_UINT128 PyArray_USHORT\n\ttypedef short Int128;\n\ttypedef unsigned short UInt128;\n#endif\n#define STRBITSOF_SHORT \"128\"\n#endif\n\n\n#if BITSOF_CHAR == 8\n#ifndef PyArray_INT8\n#define PyArray_INT8 PyArray_BYTE\n#define PyArray_UINT8 PyArray_UBYTE\n\ttypedef signed char Int8;\n\ttypedef unsigned char UInt8;\n#endif\n#define STRBITSOF_CHAR \"8\"\n#elif BITSOF_CHAR == 16\n#ifndef PyArray_INT16\n#define PyArray_INT16 PyArray_BYTE\n#define PyArray_UINT16 PyArray_UBYTE\n\ttypedef signed char Int16;\n\ttypedef unsigned char UInt16;\n#endif\n#define STRBITSOF_CHAR \"16\"\n#elif BITSOF_CHAR == 32\n#ifndef PyArray_INT32\n#define PyArray_INT32 PyArray_BYTE\n#define PyArray_UINT32 PyArray_UBYTE\n\ttypedef signed char Int32;\n\ttypedef unsigned char UInt32;\n\ttypedef unsigned char PyArray_UCS4;\n#endif\n#define STRBITSOF_CHAR \"32\"\n#elif BITSOF_CHAR == 64\n#ifndef PyArray_INT64\n#define PyArray_INT64 PyArray_BYTE\n#define PyArray_UINT64 PyArray_UBYTE\n\ttypedef signed char Int64;\n\ttypedef unsigned char UInt64;\n#endif\n#define STRBITSOF_CHAR \"64\"\n#elif BITSOF_CHAR == 128\n#ifndef PyArray_INT128\n#define PyArray_INT128 PyArray_BYTE\n#define PyArray_UINT128 PyArray_UBYTE\n\ttypedef signed char Int128;\n\ttypedef unsigned char UInt128;\n#endif\n#define STRBITSOF_CHAR \"128\"\n#endif\n\n\n\n#if BITSOF_DOUBLE == 16\n#define STRBITSOF_DOUBLE \"16\"\n#define STRBITSOF_CDOUBLE \"32\"\n#ifndef PyArray_FLOAT16\n#define PyArray_FLOAT16 PyArray_DOUBLE\n#define PyArray_COMPLEX32 PyArray_CDOUBLE\n\ttypedef double Float16;\n\ttypedef cdouble Complex32;\n#endif\n#elif BITSOF_DOUBLE == 32\n#define STRBITSOF_DOUBLE \"32\"\n#define STRBITSOF_CDOUBLE \"64\"\n#ifndef PyArray_FLOAT32\n#define PyArray_FLOAT32 PyArray_DOUBLE\n#define PyArray_COMPLEX64 PyArray_CDOUBLE\n\ttypedef double Float32;\n\ttypedef cdouble Complex64;\n#endif\n#elif BITSOF_DOUBLE == 64\n#define STRBITSOF_DOUBLE \"64\"\n#define STRBITSOF_CDOUBLE \"128\"\n#ifndef PyArray_FLOAT64\n#define PyArray_FLOAT64 PyArray_DOUBLE\n#define PyArray_COMPLEX128 PyArray_CDOUBLE\n\ttypedef double Float64;\n\ttypedef cdouble Complex128;\n#endif\n#elif BITSOF_DOUBLE == 80\n#define STRBITSOF_DOUBLE \"80\"\n#define STRBITSOF_CDOUBLE \"160\"\n#ifndef PyArray_FLOAT80\n#define PyArray_FLOAT80 PyArray_DOUBLE\n#define PyArray_COMPLEX160 PyArray_CDOUBLE\n\ttypedef double Float80;\n\ttypedef cdouble Complex160;\n#endif\n#elif BITSOF_DOUBLE == 96\n#define STRBITSOF_DOUBLE \"96\"\n#define STRBITSOF_CDOUBLE \"192\"\n#ifndef PyArray_FLOAT96\n#define PyArray_FLOAT96 PyArray_DOUBLE\n#define PyArray_COMPLEX192 PyArray_CDOUBLE\n\ttypedef double Float96;\n\ttypedef cdouble Complex192;\n#endif\n#elif BITSOF_DOUBLE == 128\n#define STRBITSOF_DOUBLE \"128\"\n#define STRBITSOF_CDOUBLE \"256\"\n#ifndef PyArray_FLOAT128\n#define PyArray_FLOAT128 PyArray_DOUBLE\n#define PyArray_COMPLEX256 PyArray_CDOUBLE\n\ttypedef double Float128;\n\ttypedef cdouble Complex256;\n#endif\n#endif\n\n\n\n#if BITSOF_FLOAT == 16\n#define STRBITSOF_FLOAT \"16\"\n#define STRBITSOF_CFLOAT \"32\"\n#ifndef PyArray_FLOAT16\n#define PyArray_FLOAT16 PyArray_FLOAT\n#define PyArray_COMPLEX32 PyArray_CFLOAT\n\ttypedef float Float16;\n\ttypedef cfloat Complex32;\n#endif\n#elif BITSOF_FLOAT == 32\n#define STRBITSOF_FLOAT \"32\"\n#define STRBITSOF_CFLOAT \"64\"\n#ifndef PyArray_FLOAT32\n#define PyArray_FLOAT32 PyArray_FLOAT\n#define PyArray_COMPLEX64 PyArray_CFLOAT\n\ttypedef float Float32;\n\ttypedef cfloat Complex64;\n#endif\n#elif BITSOF_FLOAT == 64\n#define STRBITSOF_FLOAT \"64\"\n#define STRBITSOF_CFLOAT \"128\"\n#ifndef PyArray_FLOAT64\n#define PyArray_FLOAT64 PyArray_FLOAT\n#define PyArray_COMPLEX128 PyArray_CFLOAT\n\ttypedef float Float64;\n\ttypedef cfloat Complex128;\n#endif\n#elif BITSOF_FLOAT == 80\n#define STRBITSOF_FLOAT \"80\"\n#define STRBITSOF_CFLOAT \"160\"\n#ifndef PyArray_FLOAT80\n#define PyArray_FLOAT80 PyArray_FLOAT\n#define PyArray_COMPLEX160 PyArray_CFLOAT\n\ttypedef float Float80;\n\ttypedef cfloat Complex160;\n#endif\n#elif BITSOF_FLOAT == 96\n#define STRBITSOF_FLOAT \"96\"\n#define STRBITSOF_CFLOAT \"192\"\n#ifndef PyArray_FLOAT96\n#define PyArray_FLOAT96 PyArray_FLOAT\n#define PyArray_COMPLEX192 PyArray_CFLOAT\n\ttypedef float Float96;\n\ttypedef cfloat Complex192;\n#endif\n#elif BITSOF_FLOAT == 128\n#define STRBITSOF_FLOAT \"128\"\n#define STRBITSOF_CFLOAT \"256\"\n#ifndef PyArray_FLOAT128\n#define PyArray_FLOAT128 PyArray_FLOAT\n#define PyArray_COMPLEX256 PyArray_CFLOAT\n\ttypedef float Float128;\n\ttypedef cfloat Complex256;\n#endif\n#endif\n\n\n#if BITSOF_LONGDOUBLE == 16\n#define STRBITSOF_LONGDOUBLE \"16\"\n#define STRBITSOF_CLONGDOUBLE \"32\"\n#ifndef PyArray_FLOAT16\n#define PyArray_FLOAT16 PyArray_LONGDOUBLE\n#define PyArray_COMPLEX32 PyArray_CLONGDOUBLE\n\ttypedef longdouble Float16;\n\ttypedef clongdouble Complex32;\n#endif\n#elif BITSOF_LONGDOUBLE == 32\n#define STRBITSOF_LONGDOUBLE \"32\"\n#define STRBITSOF_CLONGDOUBLE \"64\"\n#ifndef PyArray_FLOAT32\n#define PyArray_FLOAT32 PyArray_LONGDOUBLE\n#define PyArray_COMPLEX64 PyArray_CLONGDOUBLE\n\ttypedef longdouble Float32;\n\ttypedef clongdouble Complex64;\n#endif\n#elif BITSOF_LONGDOUBLE == 64\n#define STRBITSOF_LONGDOUBLE \"64\"\n#define STRBITSOF_CLONGDOUBLE \"128\"\n#ifndef PyArray_FLOAT64\n#define PyArray_FLOAT64 PyArray_LONGDOUBLE\n#define PyArray_COMPLEX128 PyArray_CLONGDOUBLE\n\ttypedef longdouble Float64;\n\ttypedef clongdouble Complex128;\n#endif\n#elif BITSOF_LONGDOUBLE == 80\n#define STRBITSOF_LONGDOUBLE \"80\"\n#define STRBITSOF_CLONGDOUBLE \"160\"\n#ifndef PyArray_FLOAT80\n#define PyArray_FLOAT80 PyArray_LONGDOUBLE\n#define PyArray_COMPLEX160 PyArray_CLONGDOUBLE\n\ttypedef longdouble Float80;\n\ttypedef clongdouble Complex160;\n#endif\n#elif BITSOF_LONGDOUBLE == 96\n#define STRBITSOF_LONGDOUBLE \"96\"\n#define STRBITSOF_CLONGDOUBLE \"192\"\n#ifndef PyArray_FLOAT96\n#define PyArray_FLOAT96 PyArray_LONGDOUBLE\n#define PyArray_COMPLEX192 PyArray_CLONGDOUBLE\n\ttypedef longdouble Float96;\n\ttypedef clongdouble Complex192;\n#endif\n#elif BITSOF_LONGDOUBLE == 128\n#define STRBITSOF_LONGDOUBLE \"128\"\n#define STRBITSOF_CLONGDOUBLE \"256\"\n#ifndef PyArray_FLOAT128\n#define PyArray_FLOAT128 PyArray_LONGDOUBLE\n#define PyArray_COMPLEX256 PyArray_CLONGDOUBLE\n\ttypedef longdouble Float128;\n\ttypedef clongdouble Complex256;\n#endif\n#elif BITSOF_LONGDOUBLE == 256\n#define STRBITSOF_LONGDOUBLE \"256\"\n#define STRBITSOF_CLONGDOUBLE \"512\"\n#define PyArray_FLOAT256 PyArray_LONGDOUBLE\n#define PyArray_COMPLEX512 PyArray_CLONGDOUBLE\n\ttypedef longdouble Float256;\n\ttypedef clongdouble Complex512;\n#endif\n\n\n\t/* End of typedefs for numarray style bit-width names */\n\n/* This is to typedef Intp to the appropriate pointer size for this platform.\n * Py_intptr_t, Py_uintptr_t are defined in pyport.h. */\ntypedef Py_intptr_t intp;\ntypedef Py_uintptr_t uintp;\n#define SIZEOF_INTP SIZEOF_PY_INTPTR_T\n#define SIZEOF_UINTP SIZEOF_PY_INTPTR_T\n\n#define INTP_FMT \"d\"\n\n#if SIZEOF_PY_INTPTR_T == SIZEOF_INT\n\t#define PyArray_INTP PyArray_INT\n\t#define PyArray_UINTP PyArray_UINT\n #define PyIntpArrType_Type PyIntArrType_Type\n #define PyUIntpArrType_Type PyUIntArrType_Type\n\t#define MAX_INTP MAX_INT\n\t#define MIN_INTP MIN_INT\n\t#define MAX_UINTP MAX_UINT\n#elif SIZEOF_PY_INTPTR_T == SIZEOF_LONG\n\t#define PyArray_INTP PyArray_LONG\n\t#define PyArray_UINTP PyArray_ULONG\n #define PyIntpArrType_Type PyLongArrType_Type\n #define PyUIntpArrType_Type PyULongArrType_Type\n\t#define MAX_INTP MAX_LONG\n\t#define MIN_INTP MIN_LONG\n\t#define MAX_UINTP MAX_ULONG\n #undef INTP_FMT\n #define INTP_FMT \"ld\"\n#elif defined(PY_LONG_LONG) && (SIZEOF_PY_INTPTR_T == SIZEOF_LONG_LONG)\n\t#define PyArray_INTP PyArray_LONGLONG\n\t#define PyArray_UINTP PyArray_ULONGLONG\n #define PyIntpArrType_Type PyLongLongArrType_Type\n #define PyUIntpArrType_Type PyULongLongArrType_Type\n\t#define MAX_INTP MAX_LONGLONG\n\t#define MIN_INTP MIN_LONGLONG\n\t#define MAX_UINTP MAX_ULONGLONG\n #undef INTP_FMT\n #define INTP_FMT \"Ld\"\n#endif\n\n#define ERR(str) fprintf(stderr, #str); fflush(stderr);\n#define ERR2(str) fprintf(stderr, str); fflush(stderr);\n\n /* Macros to define how array, and dimension/strides data is\n allocated.\n */\n\n /* Data buffer */\n#define PyDataMem_NEW(size) ((char *)malloc(size))\n /* #define PyArrayMem_NEW(size) PyMem_NEW(char, size)*/\n#define PyDataMem_FREE(ptr) free(ptr)\n /* #define PyArrayMem_FREE(ptr) PyMem_Free(ptr) */\n#define PyDataMem_RENEW(ptr,size) ((char *)realloc(ptr,size))\n\n#define PyArray_USE_PYMEM 0\n\n#if PyArray_USE_PYMEM == 1\n#define _pya_malloc PyObject_Malloc\n#define _pya_free PyObject_Free\n#define _pya_realloc PyObject_Realloc\n#else\n#define _pya_malloc malloc\n#define _pya_free free\n#define _pya_realloc realloc\n#endif\n\n/* Dimensions and strides */\n#define PyDimMem_NEW(size) ((intp *)_pya_malloc(size*sizeof(intp)))\n#define PyDimMem_FREE(ptr) _pya_free(ptr)\n#define PyDimMem_RENEW(ptr,size) ((intp *)_pya_realloc(ptr,size*sizeof(intp)))\n\n\n /* These must deal with unaligned and swapped data if necessary */\ntypedef PyObject * (PyArray_GetItemFunc) (void *, void *);\ntypedef int (PyArray_SetItemFunc)(PyObject *, void *, void *);\n\ntypedef void (PyArray_CopySwapNFunc)(void *, void *, intp, int, int);\ntypedef void (PyArray_CopySwapFunc)(void *, void *, int, int);\ntypedef Bool (PyArray_NonzeroFunc)(void *, void *);\n\n\n /* These assume aligned and notswapped data -- a buffer will be\n used before or contiguous data will be obtained\n */\ntypedef int (PyArray_CompareFunc)(const void *, const void *, void *);\ntypedef int (PyArray_ArgFunc)(void*, intp, intp*, void *);\ntypedef void (PyArray_DotFunc)(void *, intp, void *, intp, void *, intp,\n\t\t\t void *);\ntypedef void (PyArray_VectorUnaryFunc)(void *, void *, intp, void *, void *);\ntypedef int (PyArray_ScanFunc)(FILE *, void *, void *, void *);\ntypedef int (PyArray_FromStrFunc)(char *, void *, char **, void *);\n\ntypedef int (PyArray_FillFunc)(void *, intp, void *);\n\ntypedef int (PyArray_SortFunc)(void *, intp, void *);\ntypedef int (PyArray_ArgSortFunc)(void *, intp *, intp, void *);\n\ntypedef struct {\n intp *ptr;\n int len;\n} PyArray_Dims;\n\ntypedef struct {\n\t/* Functions to cast to all other standard types*/\n\tPyArray_VectorUnaryFunc *cast[PyArray_NTYPES];\n\n\t/* Functions to get and set items with standard\n\t Python types -- not array scalars */\n\tPyArray_GetItemFunc *getitem;\n\tPyArray_SetItemFunc *setitem;\n\n\t/* Copy and/or swap data. Memory areas may not overlap */\n\t/* Use memmove first if they might */\n\tPyArray_CopySwapNFunc *copyswapn;\n PyArray_CopySwapFunc *copyswap;\n\n\t/* Function to compare items */\n\tPyArray_CompareFunc *compare;\n\n\t/* Function to select largest */\n\tPyArray_ArgFunc *argmax;\n\n\t/* Function to compute dot product */\n\tPyArray_DotFunc\t*dotfunc;\n\n\t/* Function to scan an ASCII file and\n\t place a single value plus possible separator */\n\tPyArray_ScanFunc *scanfunc;\n\n\t/* Function to read a single value from a string */\n\t/* and adjust the pointer */\n\tPyArray_FromStrFunc *fromstr;\n\n\t/* Function to determine if data is zero or not */\n\tPyArray_NonzeroFunc *nonzero;\n\n\t/* Used for arange */\n\tPyArray_FillFunc *fill;\n\n\t/* Sorting functions */\n\tPyArray_SortFunc *sort[PyArray_NSORTS];\n\tPyArray_ArgSortFunc *argsort[PyArray_NSORTS];\n\n} PyArray_ArrFuncs;\n\n\ntypedef struct {\n\tPyObject_HEAD\n\tPyTypeObject *typeobj; /* the type object representing an\n\t\t\t\t intance of this type */\n\tchar kind; /* kind for this type */\n\tchar type; /* unique-character representing this type */\n\tchar byteorder; /* '>' (big), '<' (little), '|'\n\t\t\t\t (not-applicable), or '=' (native). */\n char hasobject; /* non-zero if it has object arrays in fields */\n\tint type_num; /* number representing this type */\n\tint elsize; /* element size for this type */\n\tint alignment; /* alignment needed for this type */\n\tstruct _arr_descr\t\t\t\t\t\\\n\t*subarray; /* Non-NULL if this type is\n\t\t\t\t is an array (C-contiguous)\n\t\t\t\t of some other type\n\t\t\t\t*/\n\tPyObject *fields; /* The fields dictionary for this type */\n\t /* For statically defined descr this\n\t\t\t\t is always Py_None */\n\n\tPyArray_ArrFuncs *f; /* a table of functions specific for each\n\t\t\t\t basic data descriptor */\n} PyArray_Descr;\n\ntypedef struct _arr_descr {\n\tPyArray_Descr *base;\n\tPyObject *shape; /* a tuple */\n} PyArray_ArrayDescr;\n\n\n/*\n The main array object structure. It is recommended to use the macros\n defined below (PyArray_DATA and friends) access fields here, instead\n of the members themselves.\n */\n\ntypedef struct PyArrayObject {\n\tPyObject_HEAD\n\tchar *data; /* pointer to raw data buffer */\n\tint nd; /* number of dimensions, also called ndim */\n\tintp *dimensions; /* size in each dimension */\n intp *strides; /* bytes to jump to get to the\n\t\t\t\t next element in each dimension */\n\tPyObject *base; /* This object should be decref'd\n\t\t\t\t upon deletion of array */\n\t /* For views it points to the original array */\n\t /* For creation from buffer object it points\n\t\t\t\t to an object that shold be decref'd on\n\t\t\t\t deletion */\n\t /* For UPDATEIFCOPY flag this is an array\n\t\t\t\t to-be-updated upon deletion of this one */\n\tPyArray_Descr *descr; /* Pointer to type structure */\n\tint flags; /* Flags describing array -- see below*/\n\tPyObject *weakreflist; /* For weakreferences */\n} PyArrayObject;\n\n#define fortran fortran_ /* For some compilers */\n\n/* Mirrors buffer object to ptr */\n\ntypedef struct {\n PyObject_HEAD\n PyObject *base;\n void *ptr;\n intp len;\n int flags;\n} PyArray_Chunk;\n\n/* Array flags */\n\n/* Means c-style contiguous (last index varies the fastest). The\n data elements right after each other. */\n#define CONTIGUOUS 0x0001\n/* set if array is a contiguous Fortran array: the first index\n varies the fastest in memory (strides array is reverse of\n C-contiguous array)*/\n#define FORTRAN 0x0002\n\n/*\n Note: all 0-d arrays are CONTIGUOUS and FORTRAN contiguous. If a\n 1-d array is CONTIGUOUS it is also FORTRAN contiguous\n*/\n\n/* If set, the array owns the data: it will be free'd when the array\n is deleted. */\n#define OWNDATA 0x0004\n#define OWN_DATA OWNDATA\n\n/* An array never has these three set; they're only used as parameter\n flags to the the various FromAny functions */\n/* Cause a cast to occur regardless of whether or not it is safe. */\n#define FORCECAST 0x0010\n/* Always copy the array. Returned arrays are always CONTIGUOUS, ALIGNED,\n and WRITEABLE. */\n#define ENSURECOPY 0x0020\n/* Make sure the returned array is an ndarray or a bigndarray */\n#define ENSUREARRAY 0x0040\n\n/* Array data is aligned on the appropiate memory address for the\n type stored (e.g., an array of doubles (8 bytes each) starts on\n a memory address that's a multiple of 8) */\n#define ALIGNED 0x0100\n/* Array data has the native endianness */\n#define NOTSWAPPED 0x0200\n/* Array data is writeable */\n#define WRITEABLE 0x0400\n/* If this flag is set, then base contains a pointer to an array of\n the same size that should be updated with the current contents of\n this array when this array is deallocated\n*/\n#define UPDATEIFCOPY 0x1000\n\n\n#define BEHAVED_FLAGS ALIGNED | WRITEABLE\n#define BEHAVED_NS_FLAGS ALIGNED | WRITEABLE | NOTSWAPPED\n#define CARRAY_FLAGS CONTIGUOUS | BEHAVED_FLAGS\n#define CARRAY_FLAGS_RO CONTIGUOUS | ALIGNED\n#define FARRAY_FLAGS FORTRAN | BEHAVED_FLAGS\n#define FARRAY_FLAGS_RO FORTRAN | ALIGNED\n#define DEFAULT_FLAGS CARRAY_FLAGS\n\n#define UPDATE_ALL_FLAGS CONTIGUOUS | FORTRAN | ALIGNED\n\n\n/* Size of internal buffers used for alignment */\n#define PyArray_BUFSIZE 10000\n#define PyArray_MIN_BUFSIZE 5\n#define PyArray_MAX_BUFSIZE 100000000\n\n/*\n * C API: consists of Macros and functions. The MACROS are defined here.\n */\n\n\n#define PyArray_CHKFLAGS(m, FLAGS) \\\n\t((((PyArrayObject *)(m))->flags & (FLAGS)) == (FLAGS))\n#define PyArray_ISCONTIGUOUS(m) PyArray_CHKFLAGS(m, CONTIGUOUS)\n#define PyArray_ISWRITEABLE(m) PyArray_CHKFLAGS(m, WRITEABLE)\n#define PyArray_ISALIGNED(m) PyArray_CHKFLAGS(m, ALIGNED)\n\n#ifndef MAX\n#define MAX(a,b) (((a)>(b))?(a):(b))\n#endif\n#ifndef MIN\n#define MIN(a,b) (((a)<(b))?(a):(b))\n#endif\n\n/* Useful if a and b have to be evaluated. */\n\n#define tMAX(a,b,typ) {typ _x_=(a); typ _y_=(b); _x_>_y_ ? _x_ : _y_}\n#define tMIN(a,b,typ) {typ _x_=(a); typ _y_=(b); _x_<_y_ ? _x_ : _y_}\n\n#if defined(ALLOW_THREADS)\n#define BEGIN_THREADS_DEF PyThreadState *_save;\n#define BEGIN_THREADS _save = PyEval_SaveThread();\n#define END_THREADS PyEval_RestoreThread(_save);\n#define ALLOW_C_API_DEF PyGILState_STATE __save__;\n#define ALLOW_C_API __save__ = PyGILState_Ensure();\n#define DISABLE_C_API PyGILState_Release(__save__);\n#else\n#define BEGIN_THREADS_DEF\n#define BEGIN_THREADS\n#define END_THREADS\n#define ALLOW_C_API_DEF\n#define\tALLOW_C_API\n#define\tDISABLE_C_API\n#endif\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\ntypedef struct {\n PyObject_HEAD\n\tint nd_m1; /* number of dimensions - 1 */\n intp\t\t index, size;\n\tintp coordinates[MAX_DIMS];/* N-dimensional loop */\n intp dims_m1[MAX_DIMS]; /* ao->dimensions - 1 */\n\tintp strides[MAX_DIMS]; /* ao->strides or fake */\n\tintp backstrides[MAX_DIMS];/* how far to jump back */\n\tintp factors[MAX_DIMS]; /* shape factors */\n\tPyArrayObject *ao;\n\tchar *dataptr; /* pointer to current item*/\n Bool contiguous;\n} PyArrayIterObject;\n\n\n/* Iterator API */\n#define PyArrayIter_Check(op) PyObject_TypeCheck(op, &PyArrayIter_Type)\n\n#define PyArray_ITER_RESET(it) {\t\t\t\t\t\\\n\tit->index = 0;\t\t\t\t\t\t \\\n\tit->dataptr = it->ao->data;\t\t\t\t\t\\\n\tmemset(it->coordinates, 0, (it->nd_m1+1)*sizeof(intp));\t\t\\\n}\n\n#define _PyArray_ITER_NEXT1(it) {\t\t\\\n\t\tit->dataptr += it->strides[0];\t\\\n\t\tit->coordinates[0]++;\t\t\\\n\t}\n\n#define _PyArray_ITER_NEXT2(it) {\t\t\t\t\t\\\n\t\tif (it->coordinates[1] < it->dims_m1[1]) {\t\t\\\n\t\t\tit->coordinates[1]++;\t\t\t\t\\\n\t\t\tit->dataptr += it->strides[1];\t\t\t\\\n\t\t}\t\t\t\t\t\t\t\\\n\t\telse {\t\t\t\t\t\t\t\\\n\t\t\tit->coordinates[1] = 0;\t\t\t\t\\\n\t\t\tit->coordinates[0]++;\t\t\t\t\\\n\t\t\tit->dataptr += it->strides[0] -\t\t\t\\\n\t\t\t\tit->backstrides[1];\t\t\t\\\n\t\t}\t\t\t\t\t\t\t\\\n\t}\n\n#define PyArray_ITER_NEXT(it) {\t\t\t\t\t\t\\\n\tit->index++;\t\t\t\t\t\t \\\n if (it->nd_m1 == 0) {\t\t\t\t\t\t\\\n\t\t_PyArray_ITER_NEXT1(it);\t\t\t\t\\\n\t}\t\t\t\t\t\t\t\t\\\n\telse if (it->contiguous) it->dataptr += it->ao->descr->elsize; \\\n\telse if (it->nd_m1 == 1) {\t\t\t\t\t\\\n\t\t_PyArray_ITER_NEXT2(it);\t\t\t\t\\\n\t}\t\t\t\t\t\t\t\t\\\n\telse {\t\t\t\t\t\t\t\t\\\n\t\tint _i_;\t\t\t\t\t\t\\\n\t\tfor (_i_ = it->nd_m1; _i_ >= 0; _i_--) {\t\t\\\n\t\t\tif (it->coordinates[_i_] <\t\t\t\\\n\t\t\t it->dims_m1[_i_]) {\t\t\t\t\\\n\t\t\t\tit->coordinates[_i_]++;\t\t\t\\\n\t\t\t\tit->dataptr += it->strides[_i_];\t\\\n\t\t\t\tbreak;\t\t\t\t\t\\\n\t\t\t}\t\t\t\t\t\t\\\n\t\t\telse {\t\t\t\t\t\t\\\n\t\t\t\tit->coordinates[_i_] = 0;\t\t\\\n\t\t\t\tit->dataptr -= it->backstrides[_i_];\t\\\n\t\t\t}\t\t\t\t\t\t\\\n\t\t}\t\t\t\t\t\t\t\\\n\t}\t\t\t\t\t\t\t\t\\\n}\n\n#define PyArray_ITER_GOTO(it, destination) {\t\t\t\t\\\n\t\tint _i_;\t\t\t\t\t\t\\\n\t\tit->index = 0;\t\t\t\t\t\t\\\n\t\tit->dataptr = it->ao->data;\t\t\t\t\\\n\t\tfor (_i_ = it->nd_m1; _i_>=0; _i_--) {\t\t\t\\\n\t\t\tit->dataptr += destination[_i_] *\t\t\\\n\t\t\t\tit->strides[_i_];\t\t\t\\\n\t\t\tit->coordinates[_i_] = destination[_i_];\t\\\n\t\t\tit->index += destination[_i_] *\t\t\t\\\n\t\t\t\t( _i_==it->nd_m1 ? 1 :\t\t\t\\\n\t\t\t\t it->dims_m1[i+1]+1) ;\t\t \\\n\t\t}\t\t\t\t\t\t\t\\\n\t}\n\n#define PyArray_ITER_GOTO1D(it, ind) { \\\n\t\tint _i_;\t\t\t\t\t\t\\\n\t\tintp _lind_ = (intp) (ind);\t\t\t\t\\\n\t\tit->index = _lind_;\t\t\t\t\t\\\n if (it->nd_m1 == 0) { \\\n it->dataptr = it->ao->data + (ind) * \\\n it->strides[0]; \\\n } \\\n else if (it->contiguous) \\\n\t\t\tit->dataptr = it->ao->data + (ind) *\t\t\\\n\t\t\t\tit->ao->descr->elsize;\t\t\t\\\n\t\telse {\t\t\t\t\t\t\t\\\n\t\t\tit->dataptr = it->ao->data;\t\t\t\\\n\t\t\tfor (_i_ = 0; _i_<=it->nd_m1; _i_++) {\t\t\\\n\t\t\t\tit->dataptr += (_lind_ / it->factors[_i_]) \\\n\t\t\t\t\t* it->strides[_i_];\t\t\\\n\t\t\t\t_lind_ %= it->factors[_i_];\t\t\\\n\t\t\t}\t\t\t\t\t\t\\\n\t\t}\t\t\t\t\t\t\t\\\n}\n\n#define PyArray_ITER_DATA(it) ((PyArrayIterObject *)it)->dataptr\n\n\n/*\n Any object passed to PyArray_Broadcast must be binary compatible with\n this structure.\n*/\n\ntypedef struct {\n\tPyObject_HEAD\n\n\tint numiter; /* number of iters */\n\tintp size; /* broadcasted size */\n\tintp index; /* current index */\n\tint nd; /* number of dims */\n\tintp dimensions[MAX_DIMS]; /* dimensions */\n\tPyArrayIterObject *iters[MAX_DIMS]; /* iterators */\n} PyArrayMultiIterObject;\n\n#define PyArray_MultiIter_RESET(multi) {\t\t\t \\\n\t\tint _mi_;\t\t\t\t\t \\\n\t\tPyArrayMultiIterObject *_mul_ = (multi);\t \\\n\t\t_mul_->index = 0;\t\t\t\t \\\n\t\tfor (_mi_ = 0; _mi_ < _mul_->numiter; _mi_++) {\t \\\n\t\t\tPyArray_ITER_RESET(_mul_->iters[_mi_]);\t \\\n\t\t}\t\t\t\t\t\t \\\n\t}\n\n#define PyArray_MultiIter_NEXT(multi) {\t\t\t\t \\\n\t\tint _mi_;\t\t\t\t\t \\\n\t\tPyArrayMultiIterObject *_mul_ = (multi);\t \\\n\t\t_mul_->index += 1;\t\t\t\t \\\n\t\tfor (_mi_=0; _mi_<_mul_->numiter; _mi_++) {\t \\\n\t\t\tPyArray_ITER_NEXT(_mul_->iters[_mi_]);\t \\\n\t\t}\t\t\t\t\t\t \\\n\t}\n\n#define PyArray_MultiIter_GOTO(multi, dest) {\t\t\t\t\\\n\t\tint _mi_;\t\t\t\t\t\t\\\n\t\tPyArrayMultiIterObject *_mul_ = (multi);\t\t\\\n\t\tfor (_mi_=0; _mi_<_mul_->numiter; _mi_++) {\t\t\\\n\t\t\tPyArray_ITER_GOTO(_mul_->iters[_mi_], dest);\t\\\n\t\t}\t\t\t\t\t\t\t\\\n\t\t_mul_->index = _mul_->iters[0]->index;\t\t\t\\\n\t}\n\n#define PyArray_MultiIter_GOTO1D(multi, ind) {\t\t\t\t\\\n\t\tint _mi_;\t\t\t\t\t\t\\\n\t\tPyArrayMultiIterObject *_mul_ = (multi);\t\t\\\n\t\tfor (_mi_=0; _mi_<_mul_->numiter; _mi_++) {\t\t\\\n\t\t\tPyArray_ITER_GOTO1D(_mul_->iters[_mi_], ind);\t\\\n\t\t}\t\t\t\t\t\t\t\\\n\t\t_mul_->index = _mul_->iters[0]->index;\t\t\t\\\n\t}\n\n#define PyArray_MultiIter_DATA(multi, i) \\\n\t((PyArrayMultiIterObject *)multi)->iters[i]->dataptr\n\n#define PyArray_MultiIter_SIZE(multi) \\\n\t((PyArrayMultiIterObject *)multi)->size;\n\n\n/* Store the information needed for fancy-indexing over an array */\n\ntypedef struct {\n\tPyObject_HEAD\n\t/* Multi-iterator portion --- needs to be present in this order to\n\t work with PyArray_Broadcast */\n\n\tint numiter; /* number of index-array\n\t\t\t\t\t\t\t iterators */\n\tintp size; /* size of broadcasted\n\t\t\t\t\t\t\t result */\n\tintp index; /* current index */\n\tint nd; /* number of dims */\n\tintp dimensions[MAX_DIMS]; /* dimensions */\n\tPyArrayIterObject *iters[MAX_DIMS]; /* index object\n\t\t\t\t\t\t\t iterators */\n\tPyArrayIterObject *ait; /* flat Iterator for\n\t\t\t\t\t\t\t underlying array */\n\n\t/* flat iterator for subspace (when numiter < nd) */\n\tPyArrayIterObject *subspace;\n\n\t/* if subspace iteration, then this is the array of\n\t axes in the underlying array represented by the\n\t index objects */\n\tint iteraxes[MAX_DIMS];\n\t/* if subspace iteration, the these are the coordinates\n\t to the start of the subspace.\n\t*/\n\tintp bscoord[MAX_DIMS];\n\n\tPyObject *indexobj; /* reference to\n\t\t\t\t\t\t\t creating obj */\n\tint view;\n\tint consec;\n\tchar *dataptr;\n\n} PyArrayMapIterObject;\n\n/* All sorts of useful ways to look into a PyArrayObject.\n These are the recommended over casting to PyArrayObject and accessing\n the members directly.\n */\n\n#define PyArray_NDIM(obj) (((PyArrayObject *)(obj))->nd)\n#define PyArray_ISONESEGMENT(m) (PyArray_NDIM(m) == 0 || PyArray_CHKFLAGS(m, CONTIGUOUS) || \\\n\t\t\t\t PyArray_CHKFLAGS(m, FORTRAN))\n#define PyArray_ISFORTRAN(m) (PyArray_CHKFLAGS(m, FORTRAN) && (PyArray_NDIM(m) > 1))\n#define FORTRAN_IF(m) ((PyArray_CHKFLAGS(m, FORTRAN) ? FORTRAN : 0))\n#define PyArray_DATA(obj) ((void *)(((PyArrayObject *)(obj))->data))\n#define PyArray_BYTES(obj) (((PyArrayObject *)(obj))->data)\n#define PyArray_DIMS(obj) (((PyArrayObject *)(obj))->dimensions)\n#define PyArray_STRIDES(obj) (((PyArrayObject *)(obj))->strides)\n#define PyArray_DIM(obj,n) (((PyArrayObject *)(obj))->dimensions[n])\n#define PyArray_STRIDE(obj,n) (((PyArrayObject *)(obj))->strides[n])\n#define PyArray_BASE(obj) (((PyArrayObject *)(obj))->base)\n#define PyArray_DESCR(obj) (((PyArrayObject *)(obj))->descr)\n#define PyArray_FLAGS(obj) (((PyArrayObject *)(obj))->flags)\n#define PyArray_ITEMSIZE(obj) (((PyArrayObject *)(obj))->descr->elsize)\n#define PyArray_TYPE(obj) (((PyArrayObject *)(obj))->descr->type_num)\n#define PyArray_GETITEM(obj,itemptr)\t\t\t\\\n\t((PyArrayObject *)(obj))->descr->getitem((char *)itemptr,\t\\\n\t\t\t\t\t\t (PyArrayObject *)obj);\n#define PyArray_SETITEM(obj,itemptr,v)\t\t\t\t\t\\\n\t(obj)->descr->setitem((PyObject *)v,(char *)(itemptr),\t\t\\\n\t\t\t (PyArrayObject *)(obj));\n\n\n#define PyTypeNum_ISBOOL(type) (type == PyArray_BOOL)\n#define PyTypeNum_ISUNSIGNED(type) ((type == PyArray_UBYTE) || \\\n\t\t\t\t (type == PyArray_USHORT) || \\\n\t\t\t\t (type == PyArray_UINT) ||\t\\\n\t\t\t\t (type == PyArray_ULONG) || \\\n\t\t\t\t (type == PyArray_ULONGLONG))\n\n#define PyTypeNum_ISSIGNED(type) ((type == PyArray_BYTE) ||\t\\\n\t\t\t (type == PyArray_SHORT) ||\t\\\n\t\t\t (type == PyArray_INT) ||\t\\\n\t\t\t (type == PyArray_LONG) ||\t\\\n\t\t\t (type == PyArray_LONGLONG))\n\n#define PyTypeNum_ISINTEGER(type) ((type >= PyArray_BYTE) &&\t\\\n\t\t\t\t(type <= PyArray_ULONGLONG))\n\n#define PyTypeNum_ISFLOAT(type) ((type >= PyArray_FLOAT) && \\\n\t\t\t (type <= PyArray_LONGDOUBLE))\n\n#define PyTypeNum_ISNUMBER(type) (type <= PyArray_CLONGDOUBLE)\n\n#define PyTypeNum_ISSTRING(type) ((type == PyArray_UCHAR) || \\\n\t\t\t (type == PyArray_UNICODE))\n\n#define PyTypeNum_ISCOMPLEX(type) ((type >= PyArray_CFLOAT) && \\\n\t\t\t\t(type <= PyArray_CLONGDOUBLE))\n\n#define PyTypeNum_ISPYTHON(type) ((type == PyArray_LONG) || \\\n\t\t\t\t (type == PyArray_DOUBLE) ||\t\\\n\t\t\t\t (type == PyArray_CDOUBLE) ||\t\\\n\t\t (type == PyArray_BOOL) || \\\n\t\t\t\t (type == PyArray_OBJECT ))\n\n#define PyTypeNum_ISFLEXIBLE(type) ((type>=PyArray_STRING) && \\\n\t\t\t\t (type<=PyArray_VOID))\n\n#define PyTypeNum_ISUSERDEF(type) ((type >= PyArray_USERDEF) && \\\n\t\t\t\t (type < PyArray_USERDEF+\\\n\t\t\t\t PyArray_NUMUSERTYPES))\n\n#define PyTypeNum_ISEXTENDED(type) (PyTypeNum_ISFLEXIBLE(type) || \\\n PyTypeNum_ISUSERDEF(type))\n\n#define PyTypeNum_ISOBJECT(type) ((type) == PyArray_OBJECT)\n\n#define _PyADt(o) ((PyArray_Descr *)o)->type_num\n#define PyDescr_ISBOOL(obj) PyTypeNum_ISBOOL(_PyADt(obj))\n#define PyDescr_ISUNSIGNED(obj) PyTypeNum_ISUNSIGNED(_PyADt(obj))\n#define PyDescr_ISSIGNED(obj) PyTypeNum_ISSIGNED(_PyADt(obj))\n#define PyDescr_ISINTEGER(obj) PyTypeNum_ISINTEGER(_PyADt(obj))\n#define PyDescr_ISFLOAT(obj) PyTypeNum_ISFLOAT(_PyADt(obj))\n#define PyDescr_ISNUMBER(obj) PyTypeNum_ISNUMBER(_PyADt(obj))\n#define PyDescr_ISSTRING(obj) PyTypeNum_ISSTRING(_PyADt(obj))\n#define PyDescr_ISCOMPLEX(obj) PyTypeNum_ISCOMPLEX(_PyADt(obj))\n#define PyDescr_ISPYTHON(obj) PyTypeNum_ISPYTHON(_PyADt(obj))\n#define PyDescr_ISFLEXIBLE(obj) PyTypeNum_ISFLEXIBLE(_PyADt(obj))\n#define PyDescr_ISUSERDEF(obj) PyTypeNum_ISUSERDEF(_PyADt(obj))\n#define PyDescr_ISEXTENDED(obj) PyTypeNum_ISEXTENDED(_PyADt(obj))\n#define PyDescr_ISOBJECT(obj) PyTypeNum_ISOBJECT(_PyADt(obj))\n#undef _PyAD\n\n#define PyArray_ISBOOL(obj) PyTypeNum_ISBOOL(PyArray_TYPE(obj))\n#define PyArray_ISUNSIGNED(obj) PyTypeNum_ISUNSIGNED(PyArray_TYPE(obj))\n#define PyArray_ISSIGNED(obj) PyTypeNum_ISSIGNED(PyArray_TYPE(obj))\n#define PyArray_ISINTEGER(obj) PyTypeNum_ISINTEGER(PyArray_TYPE(obj))\n#define PyArray_ISFLOAT(obj) PyTypeNum_ISFLOAT(PyArray_TYPE(obj))\n#define PyArray_ISNUMBER(obj) PyTypeNum_ISNUMBER(PyArray_TYPE(obj))\n#define PyArray_ISSTRING(obj) PyTypeNum_ISSTRING(PyArray_TYPE(obj))\n#define PyArray_ISCOMPLEX(obj) PyTypeNum_ISCOMPLEX(PyArray_TYPE(obj))\n#define PyArray_ISPYTHON(obj) PyTypeNum_ISPYTHON(PyArray_TYPE(obj))\n#define PyArray_ISFLEXIBLE(obj) PyTypeNum_ISFLEXIBLE(PyArray_TYPE(obj))\n#define PyArray_ISUSERDEF(obj) PyTypeNum_ISUSERDEF(PyArray_TYPE(obj))\n#define PyArray_ISEXTENDED(obj) PyTypeNum_ISEXTENDED(PyArray_TYPE(obj))\n#define PyArray_ISOBJECT(obj) PyTypeNum_ISOBJECT(PyArray_TYPE(obj))\n\n#define PyArray_LITTLE '<'\n#define PyArray_BIG '>'\n#define PyArray_NATIVE '='\n#define PyArray_SWAP 's'\n#define PyArray_IGNORE '|'\n\n#ifdef WORDS_BIGENDIAN\n#define PyArray_NATBYTE PyArray_BIG\n#define PyArray_OPPBYTE PyArray_LITTLE\n#else\n#define PyArray_NATBYTE PyArray_LITTLE\n#define PyArray_OPPBYTE PyArray_BIG\n#endif\n\n#define PyArray_ISNBO(arg) ((arg) != PyArray_OPPBYTE)\n#define PyArray_IsNativeByteOrder PyArray_ISNBO\n#define PyArray_ISNOTSWAPPED(m) PyArray_ISNBO(PyArray_DESCR(m)->byteorder)\n\n#define PyArray_FLAGSWAP(m, flags) (PyArray_CHKFLAGS(m, flags) &&\t\\\n\t\t\t\t PyArray_ISNOTSWAPPED(m))\n#define PyArray_ISCARRAY(m) PyArray_FLAGSWAP(m, CARRAY_FLAGS)\n#define PyArray_ISCARRAY_RO(m) PyArray_FLAGSWAP(m, CARRAY_FLAGS_RO)\n#define PyArray_ISFARRAY(m) PyArray_FLAGSWAP(m, FARRAY_FLAGS)\n#define PyArray_ISFARRAY_RO(m) PyArray_FLAGSWAP(m, FARRAY_FLAGS_RO)\n#define PyArray_ISBEHAVED(m) PyArray_FLAGSWAP(m, BEHAVED_FLAGS)\n#define PyArray_ISBEHAVED_RO(m) PyArray_FLAGSWAP(m, ALIGNED)\n\n\n\n/* This is the form of the struct that's returned pointed by the\n PyCObject attribute of an array __array_struct__. See\n http://numeric.scipy.org/array_interface.html for the full\n documentation. */\ntypedef struct {\n int version; /* contains the integer 2 as a sanity check */\n int nd; /* number of dimensions */\n char typekind; /* kind in array --- character code of typestr */\n int itemsize; /* size of each element */\n int flags; /* how should be data interpreted. Valid\n flags are CONTIGUOUS (1), FORTRAN (2),\n ALIGNED (0x100), NOTSWAPPED (0x200), and\n WRITEABLE (0x400)*/\n intp *shape; /* A length-nd array of shape information */\n intp *strides; /* A length-nd array of stride information */\n void *data; /* A pointer to the first element of the array */\n} PyArrayInterface;\n\n/* Includes the \"function\" C-API -- these are all stored in a\n list of pointers --- one for each file\n The two lists are concatenated into one in multiarray.\n\n They are available as import_array()\n*/\n\n\n#include \"__multiarray_api.h\"\n\n\n/* C-API that requries previous API to be defined */\n\n#define PyArray_DescrCheck(op) ((op)->ob_type == &PyArrayDescr_Type)\n\n#define PyArray_Check(op) ((op)->ob_type == &PyArray_Type || \\\n\t\t\t PyObject_TypeCheck((op), &PyBigArray_Type))\n#define PyBigArray_CheckExact(op) ((op)->ob_type == &PyBigArray_Type)\n#define PyArray_CheckExact(op) ((op)->ob_type == &PyArray_Type)\n\n#define PyArray_IsZeroDim(op) (PyArray_Check(op) && (PyArray_NDIM(op) == 0))\n#define PyArray_IsScalar(obj, cls)\t\t\t\t\\\n\t(PyObject_TypeCheck((obj), &Py##cls##ArrType_Type))\n#define PyArray_CheckScalar(m) (PyArray_IsScalar(m, Generic) || \\\n PyArray_IsZeroDim(m))\n#define PyArray_IsPythonScalar(obj) \\\n\t(PyInt_Check(obj) || PyFloat_Check(obj) || PyComplex_Check(obj) || \\\n\t PyLong_Check(obj) || PyBool_Check(obj) || PyString_Check(obj) || \\\n\t PyUnicode_Check(obj))\n#define PyArray_IsAnyScalar(obj)\t\t\t\t\t\\\n\t(PyArray_IsScalar(obj, Generic) || PyArray_IsPythonScalar(obj))\n#define PyArray_CheckAnyScalar(obj) (PyArray_IsPythonScalar(obj) || \\\n\t\t\t\t PyArray_CheckScalar(obj))\n\n#define PyArray_GETCONTIGUOUS(m) (PyArray_ISCONTIGUOUS(m) ? Py_INCREF(m), m : \\\n (PyArrayObject *)(PyArray_Copy(m)))\n\n#define PyArray_SIZE(m) PyArray_MultiplyList(PyArray_DIMS(m), PyArray_NDIM(m))\n#define PyArray_NBYTES(m) (PyArray_ITEMSIZE(m) * PyArray_SIZE(m))\n#define PyArray_FROM_O(m) PyArray_FromAny(m, NULL, 0, 0, 0, NULL)\n#define PyArray_FROM_OF(m,flags) PyArray_CheckFromAny(m, NULL, 0, 0, flags, NULL)\n#define PyArray_FROM_OT(m,type) PyArray_FromAny(m, PyArray_DescrFromType(type), \\\n 0, 0, 0, NULL);\n#define PyArray_FROM_OTF(m, type, flags) \\\n\tPyArray_FromAny(m, PyArray_DescrFromType(type), 0, 0, \\\n (((flags) & ENSURECOPY) ? \\\n ((flags) | DEFAULT_FLAGS) : (flags)), NULL)\n#define PyArray_FROMANY(m, type, min, max, flags) \\\n\tPyArray_FromAny(m, PyArray_DescrFromType(type), min, max, \\\n (((flags) & ENSURECOPY) ? \\\n (flags) | DEFAULT_FLAGS : (flags)), NULL)\n\n#define PyArray_FILLWBYTE(obj, val) memset(PyArray_DATA(obj), (val), PyArray_NBYTES(obj))\n\n#define REFCOUNT(obj) (((PyObject *)(obj))->ob_refcnt)\n#define MAX_ELSIZE 2*SIZEOF_LONGDOUBLE\n\n#define PyArray_ContiguousFromAny(op, type, min_depth, max_depth) \\\n PyArray_FromAny(op, PyArray_DescrFromType(type), min_depth, \\\n max_depth, DEFAULT_FLAGS, NULL)\n\n#define PyArray_EquivArrTypes(a1, a2)\t\t\t\t\t\\\n\tPyArray_EquivTypes(PyArray_DESCR(a1), PyArray_DESCR(a2))\n#define PyArray_EquivTypenums(typenum1, typenum2)\t\t\\\n\tPyArray_EquivTypes(PyArray_DescrFromType(typenum1),\t\\\n\t\t\t PyArray_DescrFromType(typenum2))\n\n#define PyArray_EquivByteorders(b1, b2) \\\n\t((b1 == b2) || (PyArray_ISNBO(b1) == PyArray_ISNBO(b2)))\n\n#define PyArray_SimpleNew(nd, dims, typenum) \\\n\tPyArray_New(&PyArray_Type, nd, dims, typenum, NULL, NULL, 0, 0, NULL)\n#define PyArray_SimpleNewFromData(nd, dims, typenum, data) \\\n PyArray_New(&PyArray_Type, nd, dims, typenum, NULL, data, 0, CARRAY_FLAGS, NULL)\n#define PyArray_SimpleNewFromDescr(nd, dims, descr) \\\n\tPyArray_NewFromDescr(&PyArray_Type, descr, nd, dims, NULL, NULL, 0, NULL)\n\n\n/* These might be faster without the dereferencing of obj\n going on inside -- of course an optimizing compiler should\n inline the constants inside a for loop making it a moot point\n*/\n\n#define PyArray_GETPTR1(obj, i) (PyArray_DATA(obj) +\t\t\\\n\t\t\t\t i*PyArray_STRIDE(obj, 0))\n\n#define PyArray_GETPTR2(obj, i, j) (PyArray_DATA(obj) +\t\t\\\n\t\t\t\t i*PyArray_STRIDE(obj, 0) +\t\\\n\t\t\t\t j*PyArray_STRIDE(obj, 1))\n\n#define PyArray_GETPTR3(obj, i, j, k) (PyArray_DATA(obj) +\t\t\\\n\t\t\t\t i*PyArray_STRIDE(obj, 0) +\t\\\n\t\t\t\t j*PyArray_STRIDE(obj, 1) +\t\\\n\t\t\t\t k*PyArray_STRIDE(obj, 2))\t\\\n\n#define PyArray_GETPTR4(obj, i, j, k, l) (PyArray_DATA(obj) +\t\t\\\n\t\t\t\t\t i*PyArray_STRIDE(obj, 0) +\t\\\n\t\t\t\t\t j*PyArray_STRIDE(obj, 1) +\t\\\n\t\t\t\t\t k*PyArray_STRIDE(obj, 2) +\t\\\n\t\t\t\t\t l*PyArray_STRIDE(obj, 3))\n\n#define PyArray_DESCR_REPLACE(descr) do {\t\\\n\t\tPyArray_Descr *_new_;\t\t\t\\\n\t\t_new_ = PyArray_DescrNew(descr);\t\\\n\t\tPy_XDECREF(descr);\t\t\t\\\n\t\tdescr = _new_;\t\t\t\t\\\n\t} while(0)\n\n/* Copy should always return contiguous array */\n#define PyArray_Copy(obj) PyArray_NewCopy(obj, 0)\n\n#define PyArray_FromObject(op, type, min_depth, max_depth)\t\t\\\n\tPyArray_FromAny(op, PyArray_DescrFromType(type), min_depth,\t\\\n max_depth, BEHAVED_FLAGS | ENSUREARRAY, NULL)\n\n#define PyArray_ContiguousFromObject(op, type, min_depth, max_depth)\t\\\n PyArray_FromAny(op, PyArray_DescrFromType(type), min_depth,\t\\\n max_depth, DEFAULT_FLAGS | ENSUREARRAY, NULL)\n\n#define PyArray_CopyFromObject(op, type, min_depth, max_depth)\t\t\\\n PyArray_FromAny(op, PyArray_DescrFromType(type), min_depth, \\\n max_depth, ENSURECOPY | DEFAULT_FLAGS | ENSUREARRAY, NULL)\n\n#define PyArray_Cast(mp, type_num) \\\n\tPyArray_CastToType(mp, PyArray_DescrFromType(type_num), 0)\n\n/* Compatibility with old Numeric stuff -- don't use in new code */\n\n#define PyArray_FromDimsAndData(nd, d, type, data) \\\n\tPyArray_FromDimsAndDataAndDescr(nd, d, PyArray_DescrFromType(type), \\\n\t\t\t\t\tdata)\n\n#define PyArray_UNSIGNED_TYPES\n#define PyArray_SBYTE PyArray_BYTE\n#define PyArray_CHAR PyArray_BYTE\n#define PyArray_CopyArray PyArray_CopyInto\n#define _PyArray_multiply_list PyArray_MultiplyIntList\n#define PyArray_ISSPACESAVER(m) FALSE\n#define PyScalarArray_Check PyArray_CheckScalar\n\n#ifdef PY_ARRAY_TYPES_PREFIX\n# undef CAT\n# undef CAT2\n# undef NS\n# undef longlong\n# undef ulonglong\n# undef Bool\n# undef longdouble\n# undef byte\n# undef ubyte\n# undef ushort\n# undef uint\n# undef ulong\n# undef cfloat\n# undef cdouble\n# undef clongdouble\n# undef Int8\n# undef UInt8\n# undef Int16\n# undef UInt16\n# undef Int32\n# undef UInt32\n# undef Int64\n# undef UInt64\n# undef Int128\n# undef UInt128\n# undef Int256\n# undef UInt256\n# undef Float16\n# undef Complex32\n# undef Float32\n# undef Complex64\n# undef Float64\n# undef Complex128\n# undef Float80\n# undef Complex160\n# undef Float96\n# undef Complex192\n# undef Float128\n# undef Complex256\n# undef intp\n# undef uintp\n#endif\n\n#ifdef __cplusplus\n}\n#endif\n\n#endif /* !Py_ARRAYOBJECT_H */\n", + "source_code_before": "/* This expects the following variables to be defined (besides\n the usual ones from pyconfig.h\n\n SIZEOF_LONG_DOUBLE -- sizeof(long double) or sizeof(double) if no\n long double is present on platform.\n CHAR_BIT -- number of bits in a char (usually 8)\n (should be in limits.h)\n*/\n\n#ifndef Py_ARRAYOBJECT_H\n#define Py_ARRAYOBJECT_H\n#ifdef __cplusplus\n#define CONFUSE_EMACS {\n#define CONFUSE_EMACS2 }\nextern \"C\" CONFUSE_EMACS\n#undef CONFUSE_EMACS\n#undef CONFUSE_EMACS2\n/* ... otherwise a semi-smart idententer (like emacs) tries to indent\n everything when you're typing */\n#endif\n#include \"config.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 longlong NS(longlong)\n# define ulonglong NS(ulonglong)\n# define Bool NS(Bool)\n# define longdouble NS(longdouble)\n# define byte NS(byte)\n# define ubyte NS(ubyte)\n# define ushort NS(ushort)\n# define uint NS(uint)\n# define ulong NS(ulong)\n# define cfloat NS(cfloat)\n# define cdouble NS(cdouble)\n# define clongdouble NS(clongdouble)\n# define Int8 NS(Int8)\n# define UInt8 NS(UInt8)\n# define Int16 NS(Int16)\n# define UInt16 NS(UInt16)\n# define Int32 NS(Int32)\n# define UInt32 NS(UInt32)\n# define Int64 NS(Int64)\n# define UInt64 NS(UInt64)\n# define Int128 NS(Int128)\n# define UInt128 NS(UInt128)\n# define Int256 NS(Int256)\n# define UInt256 NS(UInt256)\n# define Float16 NS(Float16)\n# define Complex32 NS(Complex32)\n# define Float32 NS(Float32)\n# define Complex64 NS(Complex64)\n# define Float64 NS(Float64)\n# define Complex128 NS(Complex128)\n# define Float80 NS(Float80)\n# define Complex160 NS(Complex160)\n# define Float96 NS(Float96)\n# define Complex192 NS(Complex192)\n# define Float128 NS(Float128)\n# define Complex256 NS(Complex256)\n# define intp NS(intp)\n# define uintp NS(uintp)\n#endif\n\n/* There are several places in the code where an array of dimensions is */\n/* allocated statically. This is the size of that static allocation. */\n/* The array creation itself could have arbitrary dimensions but\n * all the places where static allocation is used would need to\n * be changed to dynamic (including inside of structures)\n */\n\n#define MAX_DIMS 32\n\n/* Used for Converter Functions \"O&\" code in ParseTuple */\n#define PY_FAIL 0\n#define PY_SUCCEED 1\n\n\t/* Helpful to distinguish what is installed */\n#define NDARRAY_VERSION 0x00090404\n\n\t/* Some platforms don't define bool, long long, or long double.\n\t Handle that here.\n\t */\n\n#ifdef PY_LONG_LONG\ntypedef PY_LONG_LONG longlong;\ntypedef unsigned PY_LONG_LONG ulonglong;\n# ifdef _MSC_VER\n# define LONGLONG_FMT \"I64d\"\n# define ULONGLONG_FMT \"I64u\"\n# define LONGLONG_SUFFIX(x) (x##i64)\n# define ULONGLONG_SUFFIX(x) (x##Ui64)\n# else\n\t/* #define LONGLONG_FMT \"lld\" Another possible variant\n #define ULONGLONG_FMT \"llu\"\n\n\t #define LONGLONG_FMT \"qd\" -- BSD perhaps?\n\t #define ULONGLONG_FMT \"qu\"\n\t*/\n# define LONGLONG_FMT \"Ld\"\n# define ULONGLONG_FMT \"Lu\"\n# define LONGLONG_SUFFIX(x) (x##LL)\n# define ULONGLONG_SUFFIX(x) (x##ULL)\n# endif\n#else\ntypedef long longlong;\ntypedef unsigned long ulonglong;\n# define LONGLONG_SUFFIX(x) (x##L)\n# define ULONGLONG_SUFFIX(x) (x##UL)\n#endif\n\ntypedef unsigned char Bool;\n#ifndef FALSE\n#define FALSE 0\n#endif\n#ifndef TRUE\n#define TRUE 1\n#endif\n\n#if SIZEOF_LONG_DOUBLE==SIZEOF_DOUBLE\n\ttypedef double longdouble;\n #define LONGDOUBLE_FMT \"g\"\n#else\n\ttypedef long double longdouble;\n #define LONGDOUBLE_FMT \"Lg\"\n#endif\n\n#ifndef Py_USING_UNICODE\n#error Must use Python with unicode enabled. \n#endif\n\n\ntypedef signed char byte;\ntypedef unsigned char ubyte;\n#ifndef _BSD_SOURCE\ntypedef unsigned short ushort;\ntypedef unsigned int uint;\ntypedef unsigned long ulong;\n#endif\n\ntypedef struct { float real, imag; } cfloat;\ntypedef struct { double real, imag; } cdouble;\ntypedef struct {longdouble real, imag;} clongdouble;\n\nenum PyArray_TYPES { PyArray_BOOL=0,\n PyArray_BYTE, PyArray_UBYTE,\n\t\t PyArray_SHORT, PyArray_USHORT,\n\t\t PyArray_INT, PyArray_UINT,\n\t\t\tPyArray_LONG, PyArray_ULONG,\n PyArray_LONGLONG, PyArray_ULONGLONG,\n\t\t\tPyArray_FLOAT, PyArray_DOUBLE, PyArray_LONGDOUBLE,\n\t\t\tPyArray_CFLOAT, PyArray_CDOUBLE, PyArray_CLONGDOUBLE,\n\t\t\tPyArray_OBJECT=17,\n PyArray_STRING, PyArray_UNICODE,\n\t\t\tPyArray_VOID,\n\t\t\tPyArray_NTYPES,\n\t\t\tPyArray_NOTYPE,\n\t\t\tPyArray_USERDEF=256 /* leave room for characters */\n};\n\n\t/* basetype array priority */\n#define PyArray_PRIORITY 0.0\n#define PyArray_BIG_PRIORITY 0.1\n\t/* default subtype priority */\n#define PyArray_SUBTYPE_PRIORITY 1.0\n\n\t/* How many floating point types are there */\n#define PyArray_NUM_FLOATTYPE 3\n\n\n\t/* We need to match intp to a signed integer of the same size as\n\t a pointer variable. uintp to the equivalent unsigned integer\n\t*/\n\n\n\t/* These characters correspond to the array type and the\n\t struct module */\n\n\t/* except 'p' -- signed integer for pointer type */\n\nenum PyArray_TYPECHAR { PyArray_BOOLLTR = '?',\n\t\t\tPyArray_BYTELTR = 'b',\n\t\t\tPyArray_UBYTELTR = 'B',\n\t\t\tPyArray_SHORTLTR = 'h',\n\t\t\tPyArray_USHORTLTR = 'H',\n\t\t\tPyArray_INTLTR = 'i',\n\t\t\tPyArray_UINTLTR = 'I',\n\t\t\tPyArray_LONGLTR = 'l',\n\t\t\tPyArray_ULONGLTR = 'L',\n\t\t\tPyArray_LONGLONGLTR = 'q',\n\t\t\tPyArray_ULONGLONGLTR = 'Q',\n\t\t\tPyArray_FLOATLTR = 'f',\n\t\t\tPyArray_DOUBLELTR = 'd',\n\t\t\tPyArray_LONGDOUBLELTR = 'g',\n\t\t\tPyArray_CFLOATLTR = 'F',\n\t\t\tPyArray_CDOUBLELTR = 'D',\n\t\t\tPyArray_CLONGDOUBLELTR = 'G',\n\t\t\tPyArray_OBJECTLTR = 'O',\n\t\t\tPyArray_STRINGLTR = 'S',\n\t\t\tPyArray_STRINGLTR2 = 'a',\n\t\t\tPyArray_UNICODELTR = 'U',\n\t\t PyArray_VOIDLTR = 'V',\n\n\t\t\t/* No Descriptor, just a define -- this let's\n\t\t\t Python users specify an array of integers\n\t\t\t large enough to hold a pointer on the platform*/\n\t\t\tPyArray_INTPLTR = 'p',\n\t\t\tPyArray_UINTPLTR = 'P',\n\n\t\t\tPyArray_GENBOOLLTR ='b',\n\t\t\tPyArray_SIGNEDLTR = 'i',\n\t\t\tPyArray_UNSIGNEDLTR = 'u',\n\t\t\tPyArray_FLOATINGLTR = 'f',\n\t\t\tPyArray_COMPLEXLTR = 'c'\n};\n\ntypedef enum {\n\tPyArray_QUICKSORT=0,\n\tPyArray_HEAPSORT=1,\n\tPyArray_MERGESORT=2,\n\tPyArray_TIMSORT=3 /* the sort Python uses -- specialized */\n} PyArray_SORTKIND;\n#define PyArray_NSORTS PyArray_TIMSORT + 1\n\n\t/* Define bit-width array types and typedefs */\n\n#define MAX_INT8 127\n#define MIN_INT8 -128\n#define MAX_UINT8 255\n#define MAX_INT16 32767\n#define MIN_INT16 -32768\n#define MAX_UINT16 65535\n#define MAX_INT32 2147483647\n#define MIN_INT32 (-MAX_INT32 - 1)\n#define MAX_UINT32 4294967295U\n#define MAX_INT64 LONGLONG_SUFFIX(9223372036854775807)\n#define MIN_INT64 (-MAX_INT64 - LONGLONG_SUFFIX(1))\n#define MAX_UINT64 ULONGLONG_SUFFIX(18446744073709551615)\n#define MAX_INT128 LONGLONG_SUFFIX(85070591730234615865843651857942052864)\n#define MIN_INT128 (-MAX_INT128 - LONGLONG_SUFFIX(1))\n#define MAX_UINT128 ULONGLONG_SUFFIX(170141183460469231731687303715884105728)\n#define MAX_INT256 LONGLONG_SUFFIX(57896044618658097711785492504343953926634992332820282019728792003956564819967)\n#define MIN_INT256 (-MAX_INT256 - LONGLONG_SUFFIX(1))\n#define MAX_UINT256 ULONGLONG_SUFFIX(115792089237316195423570985008687907853269984665640564039457584007913129639935)\n\n\t/* Need to find the number of bits for each type and\n\t make definitions accordingly.\n\n\t C states that sizeof(char) == 1 by definition\n\n\t So, just using the sizeof keyword won't help.\n\n\t It also looks like Python itself uses sizeof(char) quite a\n\t bit, which by definition should be 1 all the time.\n\n\t Idea: Make Use of CHAR_BIT which should tell us how many\n\t BITS per CHARACTER\n\t*/\n\n\t/* Include platform definitions -- These are in the C89/90 standard */\n#include \n#define MAX_BYTE SCHAR_MAX\n#define MIN_BYTE SCHAR_MIN\n#define MAX_UBYTE UCHAR_MAX\n#define MAX_SHORT SHRT_MAX\n#define MIN_SHORT SHRT_MIN\n#define MAX_USHORT USHRT_MAX\n#define MAX_INT INT_MAX\n#ifndef INT_MIN\n#define INT_MIN (-INT_MAX - 1)\n#endif\n#define MIN_INT INT_MIN\n#define MAX_UINT UINT_MAX\n#define MAX_LONG LONG_MAX\n#define MIN_LONG LONG_MIN\n#define MAX_ULONG ULONG_MAX\n\n#define SIZEOF_LONGDOUBLE SIZEOF_LONG_DOUBLE\n#define SIZEOF_LONGLONG SIZEOF_LONG_LONG\n#define BITSOF_BOOL sizeof(Bool)*CHAR_BIT\n#define BITSOF_CHAR CHAR_BIT\n#define BITSOF_SHORT (SIZEOF_SHORT*CHAR_BIT)\n#define BITSOF_INT (SIZEOF_INT*CHAR_BIT)\n#define BITSOF_LONG (SIZEOF_LONG*CHAR_BIT)\n#define BITSOF_LONGLONG (SIZEOF_LONGLONG*CHAR_BIT)\n#define BITSOF_FLOAT (SIZEOF_FLOAT*CHAR_BIT)\n#define BITSOF_DOUBLE (SIZEOF_DOUBLE*CHAR_BIT)\n#define BITSOF_LONGDOUBLE (SIZEOF_LONGDOUBLE*CHAR_BIT)\n\n\n#if BITSOF_LONG == 8\n#define PyArray_INT8 PyArray_LONG\n#define PyArray_UINT8 PyArray_ULONG\n\ttypedef long Int8;\n\ttypedef unsigned long UInt8;\n#define STRBITSOF_LONG \"8\"\n#elif BITSOF_LONG == 16\n#define PyArray_INT16 PyArray_LONG\n#define PyArray_UINT16 PyArray_ULONG\n\ttypedef long Int16;\n\ttypedef unsigned long UInt16;\n#define STRBITSOF_LONG \"16\"\n#elif BITSOF_LONG == 32\n#define PyArray_INT32 PyArray_LONG\n#define PyArray_UINT32 PyArray_ULONG\n\ttypedef long Int32;\n\ttypedef unsigned long UInt32;\n\ttypedef unsigned long PyArray_UCS4;\n#define STRBITSOF_LONG \"32\"\n#elif BITSOF_LONG == 64\n#define PyArray_INT64 PyArray_LONG\n#define PyArray_UINT64 PyArray_ULONG\n\ttypedef long Int64;\n\ttypedef unsigned long UInt64;\n#define STRBITSOF_LONG \"64\"\n#elif BITSOF_LONG == 128\n#define PyArray_INT128 PyArray_LONG\n#define PyArray_UINT128 PyArray_ULONG\n\ttypedef long Int128;\n\ttypedef unsigned long UInt128;\n#define STRBITSOF_LONG \"128\"\n#endif\n\n#if BITSOF_LONGLONG == 8\n# ifndef PyArray_INT8\n# define PyArray_INT8 PyArray_LONGLONG\n# define PyArray_UINT8 PyArray_ULONGLONG\n\ttypedef longlong Int8;\n\ttypedef ulonglong UInt8;\n# endif\n# define MAX_LONGLONG MAX_INT8\n# define MIN_LONGLONG MIN_INT8\n# define MAX_ULONGLONG MAX_UINT8\n#define STRBITSOF_LONGLONG \"8\"\n#elif BITSOF_LONGLONG == 16\n# ifndef PyArray_INT16\n# define PyArray_INT16 PyArray_LONGLONG\n# define PyArray_UINT16 PyArray_ULONGLONG\n\ttypedef longlong Int16;\n\ttypedef ulonglong UInt16;\n# endif\n# define MAX_LONGLONG MAX_INT16\n# define MIN_LONGLONG MIN_INT16\n# define MAX_ULONGLONG MAX_UINT16\n#define STRBITSOF_LONGLONG \"16\"\n#elif BITSOF_LONGLONG == 32\n# ifndef PyArray_INT32\n# define PyArray_INT32 PyArray_LONGLONG\n# define PyArray_UINT32 PyArray_ULONGLONG\n\ttypedef longlong Int32;\n\ttypedef ulonglong UInt32;\n\ttypedef ulonglong PyArray_UCS4;\n# endif\n# define MAX_LONGLONG MAX_INT32\n# define MIN_LONGLONG MIN_INT32\n# define MAX_ULONGLONG MAX_UINT32\n#define STRBITSOF_LONGLONG \"32\"\n#elif BITSOF_LONGLONG == 64\n# ifndef PyArray_INT64\n# define PyArray_INT64 PyArray_LONGLONG\n# define PyArray_UINT64 PyArray_ULONGLONG\n\ttypedef longlong Int64;\n\ttypedef ulonglong UInt64;\n# endif\n# define MAX_LONGLONG MAX_INT64\n# define MIN_LONGLONG MIN_INT64\n# define MAX_ULONGLONG MAX_UINT64\n#define STRBITSOF_LONGLONG \"64\"\n#elif BITSOF_LONGLONG == 128\n# ifndef PyArray_INT128\n# define PyArray_INT128 PyArray_LONGLONG\n# define PyArray_UINT128 PyArray_ULONGLONG\n\ttypedef longlong Int128;\n\ttypedef ulonglong UInt128;\n# endif\n# define MAX_LONGLONG MAX_INT128\n# define MIN_LONGLONG MIN_INT128\n# define MAX_ULONGLONG MAX_UINT128\n#define STRBITSOF_LONGLONG \"128\"\n#elif BITSOF_LONGLONG == 256\n# define PyArray_INT256 PyArray_LONGLONG\n# define PyArray_UINT256 PyArray_ULONGLONG\n\ttypedef longlong Int256;\n\ttypedef ulonglong UInt256;\n# define MAX_LONGLONG MAX_INT256\n# define MIN_LONGLONG MIN_INT256\n# define MAX_ULONGLONG MAX_UINT256\n#define STRBITSOF_LONGLONG \"256\"\n#endif\n\n#if BITSOF_INT == 8\n#ifndef PyArray_INT8\n#define PyArray_INT8 PyArray_INT\n#define PyArray_UINT8 PyArray_UINT\n\ttypedef int Int8;\n\ttypedef unsigned int UInt8;\n#endif\n#define STRBITSOF_INT \"8\"\n#elif BITSOF_INT == 16\n#ifndef PyArray_INT16\n#define PyArray_INT16 PyArray_INT\n#define PyArray_UINT16 PyArray_UINT\n\ttypedef int Int16;\n\ttypedef unsigned int UInt16;\n#endif\n#define STRBITSOF_INT \"16\"\n#elif BITSOF_INT == 32\n#ifndef PyArray_INT32\n#define PyArray_INT32 PyArray_INT\n#define PyArray_UINT32 PyArray_UINT\n\ttypedef int Int32;\n\ttypedef unsigned int UInt32;\n\ttypedef unsigned int PyArray_UCS4;\n#endif\n#define STRBITSOF_INT \"32\"\n#elif BITSOF_INT == 64\n#ifndef PyArray_INT64\n#define PyArray_INT64 PyArray_INT\n#define PyArray_UINT64 PyArray_UINT\n\ttypedef int Int64;\n\ttypedef unsigned int UInt64;\n#endif\n#define STRBITSOF_INT \"64\"\n#elif BITSOF_INT == 128\n#ifndef PyArray_INT128\n#define PyArray_INT128 PyArray_INT\n#define PyArray_UINT128 PyArray_UINT\n\ttypedef int Int128;\n\ttypedef unsigned int UInt128;\n#endif\n#define STRBITSOF_INT \"128\"\n#endif\n\n#if BITSOF_SHORT == 8\n#ifndef PyArray_INT8\n#define PyArray_INT8 PyArray_SHORT\n#define PyArray_UINT8 PyArray_USHORT\n\ttypedef short Int8;\n\ttypedef unsigned short UInt8;\n#endif\n#define STRBITSOF_SHORT \"8\"\n#elif BITSOF_SHORT == 16\n#ifndef PyArray_INT16\n#define PyArray_INT16 PyArray_SHORT\n#define PyArray_UINT16 PyArray_USHORT\n\ttypedef short Int16;\n\ttypedef unsigned short UInt16;\n#endif\n#define STRBITSOF_SHORT \"16\"\n#elif BITSOF_SHORT == 32\n#ifndef PyArray_INT32\n#define PyArray_INT32 PyArray_SHORT\n#define PyArray_UINT32 PyArray_USHORT\n\ttypedef short Int32;\n\ttypedef unsigned short UInt32;\n\ttypedef unsigned short PyArray_UCS4;\n#endif\n#define STRBITSOF_SHORT \"32\"\n#elif BITSOF_SHORT == 64\n#ifndef PyArray_INT64\n#define PyArray_INT64 PyArray_SHORT\n#define PyArray_UINT64 PyArray_USHORT\n\ttypedef short Int64;\n\ttypedef unsigned short UInt64;\n#endif\n#define STRBITSOF_SHORT \"64\"\n#elif BITSOF_SHORT == 128\n#ifndef PyArray_INT128\n#define PyArray_INT128 PyArray_SHORT\n#define PyArray_UINT128 PyArray_USHORT\n\ttypedef short Int128;\n\ttypedef unsigned short UInt128;\n#endif\n#define STRBITSOF_SHORT \"128\"\n#endif\n\n\n#if BITSOF_CHAR == 8\n#ifndef PyArray_INT8\n#define PyArray_INT8 PyArray_BYTE\n#define PyArray_UINT8 PyArray_UBYTE\n\ttypedef signed char Int8;\n\ttypedef unsigned char UInt8;\n#endif\n#define STRBITSOF_CHAR \"8\"\n#elif BITSOF_CHAR == 16\n#ifndef PyArray_INT16\n#define PyArray_INT16 PyArray_BYTE\n#define PyArray_UINT16 PyArray_UBYTE\n\ttypedef signed char Int16;\n\ttypedef unsigned char UInt16;\n#endif\n#define STRBITSOF_CHAR \"16\"\n#elif BITSOF_CHAR == 32\n#ifndef PyArray_INT32\n#define PyArray_INT32 PyArray_BYTE\n#define PyArray_UINT32 PyArray_UBYTE\n\ttypedef signed char Int32;\n\ttypedef unsigned char UInt32;\n\ttypedef unsigned char PyArray_UCS4;\n#endif\n#define STRBITSOF_CHAR \"32\"\n#elif BITSOF_CHAR == 64\n#ifndef PyArray_INT64\n#define PyArray_INT64 PyArray_BYTE\n#define PyArray_UINT64 PyArray_UBYTE\n\ttypedef signed char Int64;\n\ttypedef unsigned char UInt64;\n#endif\n#define STRBITSOF_CHAR \"64\"\n#elif BITSOF_CHAR == 128\n#ifndef PyArray_INT128\n#define PyArray_INT128 PyArray_BYTE\n#define PyArray_UINT128 PyArray_UBYTE\n\ttypedef signed char Int128;\n\ttypedef unsigned char UInt128;\n#endif\n#define STRBITSOF_CHAR \"128\"\n#endif\n\n\n\n#if BITSOF_DOUBLE == 16\n#define STRBITSOF_DOUBLE \"16\"\n#define STRBITSOF_CDOUBLE \"32\"\n#ifndef PyArray_FLOAT16\n#define PyArray_FLOAT16 PyArray_DOUBLE\n#define PyArray_COMPLEX32 PyArray_CDOUBLE\n\ttypedef double Float16;\n\ttypedef cdouble Complex32;\n#endif\n#elif BITSOF_DOUBLE == 32\n#define STRBITSOF_DOUBLE \"32\"\n#define STRBITSOF_CDOUBLE \"64\"\n#ifndef PyArray_FLOAT32\n#define PyArray_FLOAT32 PyArray_DOUBLE\n#define PyArray_COMPLEX64 PyArray_CDOUBLE\n\ttypedef double Float32;\n\ttypedef cdouble Complex64;\n#endif\n#elif BITSOF_DOUBLE == 64\n#define STRBITSOF_DOUBLE \"64\"\n#define STRBITSOF_CDOUBLE \"128\"\n#ifndef PyArray_FLOAT64\n#define PyArray_FLOAT64 PyArray_DOUBLE\n#define PyArray_COMPLEX128 PyArray_CDOUBLE\n\ttypedef double Float64;\n\ttypedef cdouble Complex128;\n#endif\n#elif BITSOF_DOUBLE == 80\n#define STRBITSOF_DOUBLE \"80\"\n#define STRBITSOF_CDOUBLE \"160\"\n#ifndef PyArray_FLOAT80\n#define PyArray_FLOAT80 PyArray_DOUBLE\n#define PyArray_COMPLEX160 PyArray_CDOUBLE\n\ttypedef double Float80;\n\ttypedef cdouble Complex160;\n#endif\n#elif BITSOF_DOUBLE == 96\n#define STRBITSOF_DOUBLE \"96\"\n#define STRBITSOF_CDOUBLE \"192\"\n#ifndef PyArray_FLOAT96\n#define PyArray_FLOAT96 PyArray_DOUBLE\n#define PyArray_COMPLEX192 PyArray_CDOUBLE\n\ttypedef double Float96;\n\ttypedef cdouble Complex192;\n#endif\n#elif BITSOF_DOUBLE == 128\n#define STRBITSOF_DOUBLE \"128\"\n#define STRBITSOF_CDOUBLE \"256\"\n#ifndef PyArray_FLOAT128\n#define PyArray_FLOAT128 PyArray_DOUBLE\n#define PyArray_COMPLEX256 PyArray_CDOUBLE\n\ttypedef double Float128;\n\ttypedef cdouble Complex256;\n#endif\n#endif\n\n\n\n#if BITSOF_FLOAT == 16\n#define STRBITSOF_FLOAT \"16\"\n#define STRBITSOF_CFLOAT \"32\"\n#ifndef PyArray_FLOAT16\n#define PyArray_FLOAT16 PyArray_FLOAT\n#define PyArray_COMPLEX32 PyArray_CFLOAT\n\ttypedef float Float16;\n\ttypedef cfloat Complex32;\n#endif\n#elif BITSOF_FLOAT == 32\n#define STRBITSOF_FLOAT \"32\"\n#define STRBITSOF_CFLOAT \"64\"\n#ifndef PyArray_FLOAT32\n#define PyArray_FLOAT32 PyArray_FLOAT\n#define PyArray_COMPLEX64 PyArray_CFLOAT\n\ttypedef float Float32;\n\ttypedef cfloat Complex64;\n#endif\n#elif BITSOF_FLOAT == 64\n#define STRBITSOF_FLOAT \"64\"\n#define STRBITSOF_CFLOAT \"128\"\n#ifndef PyArray_FLOAT64\n#define PyArray_FLOAT64 PyArray_FLOAT\n#define PyArray_COMPLEX128 PyArray_CFLOAT\n\ttypedef float Float64;\n\ttypedef cfloat Complex128;\n#endif\n#elif BITSOF_FLOAT == 80\n#define STRBITSOF_FLOAT \"80\"\n#define STRBITSOF_CFLOAT \"160\"\n#ifndef PyArray_FLOAT80\n#define PyArray_FLOAT80 PyArray_FLOAT\n#define PyArray_COMPLEX160 PyArray_CFLOAT\n\ttypedef float Float80;\n\ttypedef cfloat Complex160;\n#endif\n#elif BITSOF_FLOAT == 96\n#define STRBITSOF_FLOAT \"96\"\n#define STRBITSOF_CFLOAT \"192\"\n#ifndef PyArray_FLOAT96\n#define PyArray_FLOAT96 PyArray_FLOAT\n#define PyArray_COMPLEX192 PyArray_CFLOAT\n\ttypedef float Float96;\n\ttypedef cfloat Complex192;\n#endif\n#elif BITSOF_FLOAT == 128\n#define STRBITSOF_FLOAT \"128\"\n#define STRBITSOF_CFLOAT \"256\"\n#ifndef PyArray_FLOAT128\n#define PyArray_FLOAT128 PyArray_FLOAT\n#define PyArray_COMPLEX256 PyArray_CFLOAT\n\ttypedef float Float128;\n\ttypedef cfloat Complex256;\n#endif\n#endif\n\n\n#if BITSOF_LONGDOUBLE == 16\n#define STRBITSOF_LONGDOUBLE \"16\"\n#define STRBITSOF_CLONGDOUBLE \"32\"\n#ifndef PyArray_FLOAT16\n#define PyArray_FLOAT16 PyArray_LONGDOUBLE\n#define PyArray_COMPLEX32 PyArray_CLONGDOUBLE\n\ttypedef longdouble Float16;\n\ttypedef clongdouble Complex32;\n#endif\n#elif BITSOF_LONGDOUBLE == 32\n#define STRBITSOF_LONGDOUBLE \"32\"\n#define STRBITSOF_CLONGDOUBLE \"64\"\n#ifndef PyArray_FLOAT32\n#define PyArray_FLOAT32 PyArray_LONGDOUBLE\n#define PyArray_COMPLEX64 PyArray_CLONGDOUBLE\n\ttypedef longdouble Float32;\n\ttypedef clongdouble Complex64;\n#endif\n#elif BITSOF_LONGDOUBLE == 64\n#define STRBITSOF_LONGDOUBLE \"64\"\n#define STRBITSOF_CLONGDOUBLE \"128\"\n#ifndef PyArray_FLOAT64\n#define PyArray_FLOAT64 PyArray_LONGDOUBLE\n#define PyArray_COMPLEX128 PyArray_CLONGDOUBLE\n\ttypedef longdouble Float64;\n\ttypedef clongdouble Complex128;\n#endif\n#elif BITSOF_LONGDOUBLE == 80\n#define STRBITSOF_LONGDOUBLE \"80\"\n#define STRBITSOF_CLONGDOUBLE \"160\"\n#ifndef PyArray_FLOAT80\n#define PyArray_FLOAT80 PyArray_LONGDOUBLE\n#define PyArray_COMPLEX160 PyArray_CLONGDOUBLE\n\ttypedef longdouble Float80;\n\ttypedef clongdouble Complex160;\n#endif\n#elif BITSOF_LONGDOUBLE == 96\n#define STRBITSOF_LONGDOUBLE \"96\"\n#define STRBITSOF_CLONGDOUBLE \"192\"\n#ifndef PyArray_FLOAT96\n#define PyArray_FLOAT96 PyArray_LONGDOUBLE\n#define PyArray_COMPLEX192 PyArray_CLONGDOUBLE\n\ttypedef longdouble Float96;\n\ttypedef clongdouble Complex192;\n#endif\n#elif BITSOF_LONGDOUBLE == 128\n#define STRBITSOF_LONGDOUBLE \"128\"\n#define STRBITSOF_CLONGDOUBLE \"256\"\n#ifndef PyArray_FLOAT128\n#define PyArray_FLOAT128 PyArray_LONGDOUBLE\n#define PyArray_COMPLEX256 PyArray_CLONGDOUBLE\n\ttypedef longdouble Float128;\n\ttypedef clongdouble Complex256;\n#endif\n#elif BITSOF_LONGDOUBLE == 256\n#define STRBITSOF_LONGDOUBLE \"256\"\n#define STRBITSOF_CLONGDOUBLE \"512\"\n#define PyArray_FLOAT256 PyArray_LONGDOUBLE\n#define PyArray_COMPLEX512 PyArray_CLONGDOUBLE\n\ttypedef longdouble Float256;\n\ttypedef clongdouble Complex512;\n#endif\n\n\n\t/* End of typedefs for numarray style bit-width names */\n\n/* This is to typedef Intp to the appropriate pointer size for this platform.\n * Py_intptr_t, Py_uintptr_t are defined in pyport.h. */\ntypedef Py_intptr_t intp;\ntypedef Py_uintptr_t uintp;\n#define SIZEOF_INTP SIZEOF_PY_INTPTR_T\n#define SIZEOF_UINTP SIZEOF_PY_INTPTR_T\n\n#define INTP_FMT \"d\"\n\n#if SIZEOF_PY_INTPTR_T == SIZEOF_INT\n\t#define PyArray_INTP PyArray_INT\n\t#define PyArray_UINTP PyArray_UINT\n #define PyIntpArrType_Type PyIntArrType_Type\n #define PyUIntpArrType_Type PyUIntArrType_Type\n\t#define MAX_INTP MAX_INT\n\t#define MIN_INTP MIN_INT\n\t#define MAX_UINTP MAX_UINT\n#elif SIZEOF_PY_INTPTR_T == SIZEOF_LONG\n\t#define PyArray_INTP PyArray_LONG\n\t#define PyArray_UINTP PyArray_ULONG\n #define PyIntpArrType_Type PyLongArrType_Type\n #define PyUIntpArrType_Type PyULongArrType_Type\n\t#define MAX_INTP MAX_LONG\n\t#define MIN_INTP MIN_LONG\n\t#define MAX_UINTP MAX_ULONG\n #undef INTP_FMT\n #define INTP_FMT \"ld\"\n#elif defined(PY_LONG_LONG) && (SIZEOF_PY_INTPTR_T == SIZEOF_LONG_LONG)\n\t#define PyArray_INTP PyArray_LONGLONG\n\t#define PyArray_UINTP PyArray_ULONGLONG\n #define PyIntpArrType_Type PyLongLongArrType_Type\n #define PyUIntpArrType_Type PyULongLongArrType_Type\n\t#define MAX_INTP MAX_LONGLONG\n\t#define MIN_INTP MIN_LONGLONG\n\t#define MAX_UINTP MAX_ULONGLONG\n #undef INTP_FMT\n #define INTP_FMT \"Ld\"\n#endif\n\n#define ERR(str) fprintf(stderr, #str); fflush(stderr);\n#define ERR2(str) fprintf(stderr, str); fflush(stderr);\n\n /* Macros to define how array, and dimension/strides data is\n allocated.\n */\n\n /* Data buffer */\n#define PyDataMem_NEW(size) ((char *)malloc(size))\n /* #define PyArrayMem_NEW(size) PyMem_NEW(char, size)*/\n#define PyDataMem_FREE(ptr) free(ptr)\n /* #define PyArrayMem_FREE(ptr) PyMem_Free(ptr) */\n#define PyDataMem_RENEW(ptr,size) ((char *)realloc(ptr,size))\n\n#define PyArray_USE_PYMEM 0\n\n#if PyArray_USE_PYMEM == 1\n#define _pya_malloc PyObject_Malloc\n#define _pya_free PyObject_Free\n#define _pya_realloc PyObject_Realloc\n#else\n#define _pya_malloc malloc\n#define _pya_free free\n#define _pya_realloc realloc\n#endif\n\n/* Dimensions and strides */\n#define PyDimMem_NEW(size) ((intp *)_pya_malloc(size*sizeof(intp)))\n#define PyDimMem_FREE(ptr) _pya_free(ptr)\n#define PyDimMem_RENEW(ptr,size) ((intp *)_pya_realloc(ptr,size*sizeof(intp)))\n\n\n /* These must deal with unaligned and swapped data if necessary */\ntypedef PyObject * (PyArray_GetItemFunc) (void *, void *);\ntypedef int (PyArray_SetItemFunc)(PyObject *, void *, void *);\n\ntypedef void (PyArray_CopySwapNFunc)(void *, void *, intp, int, int);\ntypedef void (PyArray_CopySwapFunc)(void *, void *, int, int);\ntypedef Bool (PyArray_NonzeroFunc)(void *, void *);\n\n\n /* These assume aligned and notswapped data -- a buffer will be\n used before or contiguous data will be obtained\n */\ntypedef int (PyArray_CompareFunc)(const void *, const void *, void *);\ntypedef int (PyArray_ArgFunc)(void*, intp, intp*, void *);\ntypedef void (PyArray_DotFunc)(void *, intp, void *, intp, void *, intp,\n\t\t\t void *);\ntypedef void (PyArray_VectorUnaryFunc)(void *, void *, intp, void *, void *);\ntypedef int (PyArray_ScanFunc)(FILE *, void *, void *, void *);\ntypedef int (PyArray_FromStrFunc)(char *, void *, char **, void *);\n\ntypedef int (PyArray_FillFunc)(void *, intp, void *);\n\ntypedef int (PyArray_SortFunc)(void *, intp, void *);\ntypedef int (PyArray_ArgSortFunc)(void *, intp *, intp, void *);\n\ntypedef struct {\n intp *ptr;\n int len;\n} PyArray_Dims;\n\ntypedef struct {\n\t/* Functions to cast to all other standard types*/\n\tPyArray_VectorUnaryFunc *cast[PyArray_NTYPES];\n\n\t/* Functions to get and set items with standard\n\t Python types -- not array scalars */\n\tPyArray_GetItemFunc *getitem;\n\tPyArray_SetItemFunc *setitem;\n\n\t/* Copy and/or swap data. Memory areas may not overlap */\n\t/* Use memmove first if they might */\n\tPyArray_CopySwapNFunc *copyswapn;\n PyArray_CopySwapFunc *copyswap;\n\n\t/* Function to compare items */\n\tPyArray_CompareFunc *compare;\n\n\t/* Function to select largest */\n\tPyArray_ArgFunc *argmax;\n\n\t/* Function to compute dot product */\n\tPyArray_DotFunc\t*dotfunc;\n\n\t/* Function to scan an ASCII file and\n\t place a single value plus possible separator */\n\tPyArray_ScanFunc *scanfunc;\n\n\t/* Function to read a single value from a string */\n\t/* and adjust the pointer */\n\tPyArray_FromStrFunc *fromstr;\n\n\t/* Function to determine if data is zero or not */\n\tPyArray_NonzeroFunc *nonzero;\n\n\t/* Used for arange */\n\tPyArray_FillFunc *fill;\n\n\t/* Sorting functions */\n\tPyArray_SortFunc *sort[PyArray_NSORTS];\n\tPyArray_ArgSortFunc *argsort[PyArray_NSORTS];\n\n} PyArray_ArrFuncs;\n\n\ntypedef struct {\n\tPyObject_HEAD\n\tPyTypeObject *typeobj; /* the type object representing an\n\t\t\t\t intance of this type */\n\tchar kind; /* kind for this type */\n\tchar type; /* unique-character representing this type */\n\tchar byteorder; /* '>' (big), '<' (little), '|'\n\t\t\t\t (not-applicable), or '=' (native). */\n char hasobject; /* non-zero if it has object arrays in fields */\n\tint type_num; /* number representing this type */\n\tint elsize; /* element size for this type */\n\tint alignment; /* alignment needed for this type */\n\tstruct _arr_descr\t\t\t\t\t\\\n\t*subarray; /* Non-NULL if this type is\n\t\t\t\t is an array (C-contiguous)\n\t\t\t\t of some other type\n\t\t\t\t*/\n\tPyObject *fields; /* The fields dictionary for this type */\n\t /* For statically defined descr this\n\t\t\t\t is always Py_None */\n\n\tPyArray_ArrFuncs *f; /* a table of functions specific for each\n\t\t\t\t basic data descriptor */\n} PyArray_Descr;\n\ntypedef struct _arr_descr {\n\tPyArray_Descr *base;\n\tPyObject *shape; /* a tuple */\n} PyArray_ArrayDescr;\n\n\n/*\n The main array object structure. It is recommended to use the macros\n defined below (PyArray_DATA and friends) access fields here, instead\n of the members themselves.\n */\n\ntypedef struct PyArrayObject {\n\tPyObject_HEAD\n\tchar *data; /* pointer to raw data buffer */\n\tint nd; /* number of dimensions, also called ndim */\n\tintp *dimensions; /* size in each dimension */\n intp *strides; /* bytes to jump to get to the\n\t\t\t\t next element in each dimension */\n\tPyObject *base; /* This object should be decref'd\n\t\t\t\t upon deletion of array */\n\t /* For views it points to the original array */\n\t /* For creation from buffer object it points\n\t\t\t\t to an object that shold be decref'd on\n\t\t\t\t deletion */\n\t /* For UPDATEIFCOPY flag this is an array\n\t\t\t\t to-be-updated upon deletion of this one */\n\tPyArray_Descr *descr; /* Pointer to type structure */\n\tint flags; /* Flags describing array -- see below*/\n\tPyObject *weakreflist; /* For weakreferences */\n} PyArrayObject;\n\n#define fortran fortran_ /* For some compilers */\n\n/* Mirrors buffer object to ptr */\n\ntypedef struct {\n PyObject_HEAD\n PyObject *base;\n void *ptr;\n intp len;\n int flags;\n} PyArray_Chunk;\n\n/* Array flags */\n\n/* Means c-style contiguous (last index varies the fastest). The\n data elements right after each other. */\n#define CONTIGUOUS 0x0001\n/* set if array is a contiguous Fortran array: the first index\n varies the fastest in memory (strides array is reverse of\n C-contiguous array)*/\n#define FORTRAN 0x0002\n\n/*\n Note: all 0-d arrays are CONTIGUOUS and FORTRAN contiguous. If a\n 1-d array is CONTIGUOUS it is also FORTRAN contiguous\n*/\n\n/* If set, the array owns the data: it will be free'd when the array\n is deleted. */\n#define OWNDATA 0x0004\n#define OWN_DATA OWNDATA\n\n/* An array never has these three set; they're only used as parameter\n flags to the the various FromAny functions */\n/* Cause a cast to occur regardless of whether or not it is safe. */\n#define FORCECAST 0x0010\n/* Always copy the array. Returned arrays are always CONTIGUOUS, ALIGNED,\n and WRITEABLE. */\n#define ENSURECOPY 0x0020\n/* Make sure the returned array is an ndarray or a bigndarray */\n#define ENSUREARRAY 0x0040\n\n/* Array data is aligned on the appropiate memory address for the\n type stored (e.g., an array of doubles (8 bytes each) starts on\n a memory address that's a multiple of 8) */\n#define ALIGNED 0x0100\n/* Array data has the native endianness */\n#define NOTSWAPPED 0x0200\n/* Array data is writeable */\n#define WRITEABLE 0x0400\n/* If this flag is set, then base contains a pointer to an array of\n the same size that should be updated with the current contents of\n this array when this array is deallocated\n*/\n#define UPDATEIFCOPY 0x1000\n\n\n#define BEHAVED_FLAGS ALIGNED | WRITEABLE\n#define BEHAVED_NS_FLAGS ALIGNED | WRITEABLE | NOTSWAPPED\n#define CARRAY_FLAGS CONTIGUOUS | BEHAVED_FLAGS\n#define CARRAY_FLAGS_RO CONTIGUOUS | ALIGNED\n#define FARRAY_FLAGS FORTRAN | BEHAVED_FLAGS\n#define FARRAY_FLAGS_RO FORTRAN | ALIGNED\n#define DEFAULT_FLAGS CARRAY_FLAGS\n\n#define UPDATE_ALL_FLAGS CONTIGUOUS | FORTRAN | ALIGNED\n\n\n/* Size of internal buffers used for alignment */\n#define PyArray_BUFSIZE 10000\n#define PyArray_MIN_BUFSIZE 5\n#define PyArray_MAX_BUFSIZE 100000000\n\n/*\n * C API: consists of Macros and functions. The MACROS are defined here.\n */\n\n\n#define PyArray_CHKFLAGS(m, FLAGS) \\\n\t((((PyArrayObject *)(m))->flags & (FLAGS)) == (FLAGS))\n#define PyArray_ISCONTIGUOUS(m) PyArray_CHKFLAGS(m, CONTIGUOUS)\n#define PyArray_ISWRITEABLE(m) PyArray_CHKFLAGS(m, WRITEABLE)\n#define PyArray_ISALIGNED(m) PyArray_CHKFLAGS(m, ALIGNED)\n\n#ifndef MAX\n#define MAX(a,b) (((a)>(b))?(a):(b))\n#endif\n#ifndef MIN\n#define MIN(a,b) (((a)<(b))?(a):(b))\n#endif\n\n/* Useful if a and b have to be evaluated. */\n\n#define tMAX(a,b,typ) {typ _x_=(a); typ _y_=(b); _x_>_y_ ? _x_ : _y_}\n#define tMIN(a,b,typ) {typ _x_=(a); typ _y_=(b); _x_<_y_ ? _x_ : _y_}\n\n#if defined(ALLOW_THREADS)\n#define BEGIN_THREADS_DEF PyThreadState *_save;\n#define BEGIN_THREADS _save = PyEval_SaveThread();\n#define END_THREADS PyEval_RestoreThread(_save);\n#define ALLOW_C_API_DEF PyGILState_STATE __save__;\n#define ALLOW_C_API __save__ = PyGILState_Ensure();\n#define DISABLE_C_API PyGILState_Release(__save__);\n#else\n#define BEGIN_THREADS_DEF\n#define BEGIN_THREADS\n#define END_THREADS\n#define ALLOW_C_API_DEF\n#define\tALLOW_C_API\n#define\tDISABLE_C_API\n#endif\n\ntypedef struct {\n PyObject_HEAD\n\tint nd_m1; /* number of dimensions - 1 */\n intp\t\t index, size;\n\tintp coordinates[MAX_DIMS];/* N-dimensional loop */\n intp dims_m1[MAX_DIMS]; /* ao->dimensions - 1 */\n\tintp strides[MAX_DIMS]; /* ao->strides or fake */\n\tintp backstrides[MAX_DIMS];/* how far to jump back */\n\tintp factors[MAX_DIMS]; /* shape factors */\n\tPyArrayObject *ao;\n\tchar *dataptr; /* pointer to current item*/\n Bool contiguous;\n} PyArrayIterObject;\n\n\n/* Iterator API */\n#define PyArrayIter_Check(op) PyObject_TypeCheck(op, &PyArrayIter_Type)\n\n#define PyArray_ITER_RESET(it) {\t\t\t\t\t\\\n\tit->index = 0;\t\t\t\t\t\t \\\n\tit->dataptr = it->ao->data;\t\t\t\t\t\\\n\tmemset(it->coordinates, 0, (it->nd_m1+1)*sizeof(intp));\t\t\\\n}\n\n#define _PyArray_ITER_NEXT1(it) {\t\t\\\n\t\tit->dataptr += it->strides[0];\t\\\n\t\tit->coordinates[0]++;\t\t\\\n\t}\n\n#define _PyArray_ITER_NEXT2(it) {\t\t\t\t\t\\\n\t\tif (it->coordinates[1] < it->dims_m1[1]) {\t\t\\\n\t\t\tit->coordinates[1]++;\t\t\t\t\\\n\t\t\tit->dataptr += it->strides[1];\t\t\t\\\n\t\t}\t\t\t\t\t\t\t\\\n\t\telse {\t\t\t\t\t\t\t\\\n\t\t\tit->coordinates[1] = 0;\t\t\t\t\\\n\t\t\tit->coordinates[0]++;\t\t\t\t\\\n\t\t\tit->dataptr += it->strides[0] -\t\t\t\\\n\t\t\t\tit->backstrides[1];\t\t\t\\\n\t\t}\t\t\t\t\t\t\t\\\n\t}\n\n#define PyArray_ITER_NEXT(it) {\t\t\t\t\t\t\\\n\tit->index++;\t\t\t\t\t\t \\\n if (it->nd_m1 == 0) {\t\t\t\t\t\t\\\n\t\t_PyArray_ITER_NEXT1(it);\t\t\t\t\\\n\t}\t\t\t\t\t\t\t\t\\\n\telse if (it->contiguous) it->dataptr += it->ao->descr->elsize; \\\n\telse if (it->nd_m1 == 1) {\t\t\t\t\t\\\n\t\t_PyArray_ITER_NEXT2(it);\t\t\t\t\\\n\t}\t\t\t\t\t\t\t\t\\\n\telse {\t\t\t\t\t\t\t\t\\\n\t\tint _i_;\t\t\t\t\t\t\\\n\t\tfor (_i_ = it->nd_m1; _i_ >= 0; _i_--) {\t\t\\\n\t\t\tif (it->coordinates[_i_] <\t\t\t\\\n\t\t\t it->dims_m1[_i_]) {\t\t\t\t\\\n\t\t\t\tit->coordinates[_i_]++;\t\t\t\\\n\t\t\t\tit->dataptr += it->strides[_i_];\t\\\n\t\t\t\tbreak;\t\t\t\t\t\\\n\t\t\t}\t\t\t\t\t\t\\\n\t\t\telse {\t\t\t\t\t\t\\\n\t\t\t\tit->coordinates[_i_] = 0;\t\t\\\n\t\t\t\tit->dataptr -= it->backstrides[_i_];\t\\\n\t\t\t}\t\t\t\t\t\t\\\n\t\t}\t\t\t\t\t\t\t\\\n\t}\t\t\t\t\t\t\t\t\\\n}\n\n#define PyArray_ITER_GOTO(it, destination) {\t\t\t\t\\\n\t\tint _i_;\t\t\t\t\t\t\\\n\t\tit->index = 0;\t\t\t\t\t\t\\\n\t\tit->dataptr = it->ao->data;\t\t\t\t\\\n\t\tfor (_i_ = it->nd_m1; _i_>=0; _i_--) {\t\t\t\\\n\t\t\tit->dataptr += destination[_i_] *\t\t\\\n\t\t\t\tit->strides[_i_];\t\t\t\\\n\t\t\tit->coordinates[_i_] = destination[_i_];\t\\\n\t\t\tit->index += destination[_i_] *\t\t\t\\\n\t\t\t\t( _i_==it->nd_m1 ? 1 :\t\t\t\\\n\t\t\t\t it->dims_m1[i+1]+1) ;\t\t \\\n\t\t}\t\t\t\t\t\t\t\\\n\t}\n\n#define PyArray_ITER_GOTO1D(it, ind) { \\\n\t\tint _i_;\t\t\t\t\t\t\\\n\t\tintp _lind_ = (intp) (ind);\t\t\t\t\\\n\t\tit->index = _lind_;\t\t\t\t\t\\\n if (it->nd_m1 == 0) { \\\n it->dataptr = it->ao->data + (ind) * \\\n it->strides[0]; \\\n } \\\n else if (it->contiguous) \\\n\t\t\tit->dataptr = it->ao->data + (ind) *\t\t\\\n\t\t\t\tit->ao->descr->elsize;\t\t\t\\\n\t\telse {\t\t\t\t\t\t\t\\\n\t\t\tit->dataptr = it->ao->data;\t\t\t\\\n\t\t\tfor (_i_ = 0; _i_<=it->nd_m1; _i_++) {\t\t\\\n\t\t\t\tit->dataptr += (_lind_ / it->factors[_i_]) \\\n\t\t\t\t\t* it->strides[_i_];\t\t\\\n\t\t\t\t_lind_ %= it->factors[_i_];\t\t\\\n\t\t\t}\t\t\t\t\t\t\\\n\t\t}\t\t\t\t\t\t\t\\\n}\n\n#define PyArray_ITER_DATA(it) ((PyArrayIterObject *)it)->dataptr\n\n\n/*\n Any object passed to PyArray_Broadcast must be binary compatible with\n this structure.\n*/\n\ntypedef struct {\n\tPyObject_HEAD\n\n\tint numiter; /* number of iters */\n\tintp size; /* broadcasted size */\n\tintp index; /* current index */\n\tint nd; /* number of dims */\n\tintp dimensions[MAX_DIMS]; /* dimensions */\n\tPyArrayIterObject *iters[MAX_DIMS]; /* iterators */\n} PyArrayMultiIterObject;\n\n#define PyArray_MultiIter_RESET(multi) {\t\t\t \\\n\t\tint _mi_;\t\t\t\t\t \\\n\t\tPyArrayMultiIterObject *_mul_ = (multi);\t \\\n\t\t_mul_->index = 0;\t\t\t\t \\\n\t\tfor (_mi_ = 0; _mi_ < _mul_->numiter; _mi_++) {\t \\\n\t\t\tPyArray_ITER_RESET(_mul_->iters[_mi_]);\t \\\n\t\t}\t\t\t\t\t\t \\\n\t}\n\n#define PyArray_MultiIter_NEXT(multi) {\t\t\t\t \\\n\t\tint _mi_;\t\t\t\t\t \\\n\t\tPyArrayMultiIterObject *_mul_ = (multi);\t \\\n\t\t_mul_->index += 1;\t\t\t\t \\\n\t\tfor (_mi_=0; _mi_<_mul_->numiter; _mi_++) {\t \\\n\t\t\tPyArray_ITER_NEXT(_mul_->iters[_mi_]);\t \\\n\t\t}\t\t\t\t\t\t \\\n\t}\n\n#define PyArray_MultiIter_GOTO(multi, dest) {\t\t\t\t\\\n\t\tint _mi_;\t\t\t\t\t\t\\\n\t\tPyArrayMultiIterObject *_mul_ = (multi);\t\t\\\n\t\tfor (_mi_=0; _mi_<_mul_->numiter; _mi_++) {\t\t\\\n\t\t\tPyArray_ITER_GOTO(_mul_->iters[_mi_], dest);\t\\\n\t\t}\t\t\t\t\t\t\t\\\n\t\t_mul_->index = _mul_->iters[0]->index;\t\t\t\\\n\t}\n\n#define PyArray_MultiIter_GOTO1D(multi, ind) {\t\t\t\t\\\n\t\tint _mi_;\t\t\t\t\t\t\\\n\t\tPyArrayMultiIterObject *_mul_ = (multi);\t\t\\\n\t\tfor (_mi_=0; _mi_<_mul_->numiter; _mi_++) {\t\t\\\n\t\t\tPyArray_ITER_GOTO1D(_mul_->iters[_mi_], ind);\t\\\n\t\t}\t\t\t\t\t\t\t\\\n\t\t_mul_->index = _mul_->iters[0]->index;\t\t\t\\\n\t}\n\n#define PyArray_MultiIter_DATA(multi, i) \\\n\t((PyArrayMultiIterObject *)multi)->iters[i]->dataptr\n\n#define PyArray_MultiIter_SIZE(multi) \\\n\t((PyArrayMultiIterObject *)multi)->size;\n\n\n/* Store the information needed for fancy-indexing over an array */\n\ntypedef struct {\n\tPyObject_HEAD\n\t/* Multi-iterator portion --- needs to be present in this order to\n\t work with PyArray_Broadcast */\n\n\tint numiter; /* number of index-array\n\t\t\t\t\t\t\t iterators */\n\tintp size; /* size of broadcasted\n\t\t\t\t\t\t\t result */\n\tintp index; /* current index */\n\tint nd; /* number of dims */\n\tintp dimensions[MAX_DIMS]; /* dimensions */\n\tPyArrayIterObject *iters[MAX_DIMS]; /* index object\n\t\t\t\t\t\t\t iterators */\n\tPyArrayIterObject *ait; /* flat Iterator for\n\t\t\t\t\t\t\t underlying array */\n\n\t/* flat iterator for subspace (when numiter < nd) */\n\tPyArrayIterObject *subspace;\n\n\t/* if subspace iteration, then this is the array of\n\t axes in the underlying array represented by the\n\t index objects */\n\tint iteraxes[MAX_DIMS];\n\t/* if subspace iteration, the these are the coordinates\n\t to the start of the subspace.\n\t*/\n\tintp bscoord[MAX_DIMS];\n\n\tPyObject *indexobj; /* reference to\n\t\t\t\t\t\t\t creating obj */\n\tint view;\n\tint consec;\n\tchar *dataptr;\n\n} PyArrayMapIterObject;\n\n/* All sorts of useful ways to look into a PyArrayObject.\n These are the recommended over casting to PyArrayObject and accessing\n the members directly.\n */\n\n#define PyArray_NDIM(obj) (((PyArrayObject *)(obj))->nd)\n#define PyArray_ISONESEGMENT(m) (PyArray_NDIM(m) == 0 || PyArray_CHKFLAGS(m, CONTIGUOUS) || \\\n\t\t\t\t PyArray_CHKFLAGS(m, FORTRAN))\n#define PyArray_ISFORTRAN(m) (PyArray_CHKFLAGS(m, FORTRAN) && (PyArray_NDIM(m) > 1))\n#define FORTRAN_IF(m) ((PyArray_CHKFLAGS(m, FORTRAN) ? FORTRAN : 0))\n#define PyArray_DATA(obj) ((void *)(((PyArrayObject *)(obj))->data))\n#define PyArray_BYTES(obj) (((PyArrayObject *)(obj))->data)\n#define PyArray_DIMS(obj) (((PyArrayObject *)(obj))->dimensions)\n#define PyArray_STRIDES(obj) (((PyArrayObject *)(obj))->strides)\n#define PyArray_DIM(obj,n) (((PyArrayObject *)(obj))->dimensions[n])\n#define PyArray_STRIDE(obj,n) (((PyArrayObject *)(obj))->strides[n])\n#define PyArray_BASE(obj) (((PyArrayObject *)(obj))->base)\n#define PyArray_DESCR(obj) (((PyArrayObject *)(obj))->descr)\n#define PyArray_FLAGS(obj) (((PyArrayObject *)(obj))->flags)\n#define PyArray_ITEMSIZE(obj) (((PyArrayObject *)(obj))->descr->elsize)\n#define PyArray_TYPE(obj) (((PyArrayObject *)(obj))->descr->type_num)\n#define PyArray_GETITEM(obj,itemptr)\t\t\t\\\n\t((PyArrayObject *)(obj))->descr->getitem((char *)itemptr,\t\\\n\t\t\t\t\t\t (PyArrayObject *)obj);\n#define PyArray_SETITEM(obj,itemptr,v)\t\t\t\t\t\\\n\t(obj)->descr->setitem((PyObject *)v,(char *)(itemptr),\t\t\\\n\t\t\t (PyArrayObject *)(obj));\n\n\n#define PyTypeNum_ISBOOL(type) (type == PyArray_BOOL)\n#define PyTypeNum_ISUNSIGNED(type) ((type == PyArray_UBYTE) || \\\n\t\t\t\t (type == PyArray_USHORT) || \\\n\t\t\t\t (type == PyArray_UINT) ||\t\\\n\t\t\t\t (type == PyArray_ULONG) || \\\n\t\t\t\t (type == PyArray_ULONGLONG))\n\n#define PyTypeNum_ISSIGNED(type) ((type == PyArray_BYTE) ||\t\\\n\t\t\t (type == PyArray_SHORT) ||\t\\\n\t\t\t (type == PyArray_INT) ||\t\\\n\t\t\t (type == PyArray_LONG) ||\t\\\n\t\t\t (type == PyArray_LONGLONG))\n\n#define PyTypeNum_ISINTEGER(type) ((type >= PyArray_BYTE) &&\t\\\n\t\t\t\t(type <= PyArray_ULONGLONG))\n\n#define PyTypeNum_ISFLOAT(type) ((type >= PyArray_FLOAT) && \\\n\t\t\t (type <= PyArray_LONGDOUBLE))\n\n#define PyTypeNum_ISNUMBER(type) (type <= PyArray_CLONGDOUBLE)\n\n#define PyTypeNum_ISSTRING(type) ((type == PyArray_UCHAR) || \\\n\t\t\t (type == PyArray_UNICODE))\n\n#define PyTypeNum_ISCOMPLEX(type) ((type >= PyArray_CFLOAT) && \\\n\t\t\t\t(type <= PyArray_CLONGDOUBLE))\n\n#define PyTypeNum_ISPYTHON(type) ((type == PyArray_LONG) || \\\n\t\t\t\t (type == PyArray_DOUBLE) ||\t\\\n\t\t\t\t (type == PyArray_CDOUBLE) ||\t\\\n\t\t (type == PyArray_BOOL) || \\\n\t\t\t\t (type == PyArray_OBJECT ))\n\n#define PyTypeNum_ISFLEXIBLE(type) ((type>=PyArray_STRING) && \\\n\t\t\t\t (type<=PyArray_VOID))\n\n#define PyTypeNum_ISUSERDEF(type) ((type >= PyArray_USERDEF) && \\\n\t\t\t\t (type < PyArray_USERDEF+\\\n\t\t\t\t PyArray_NUMUSERTYPES))\n\n#define PyTypeNum_ISEXTENDED(type) (PyTypeNum_ISFLEXIBLE(type) || \\\n PyTypeNum_ISUSERDEF(type))\n\n#define PyTypeNum_ISOBJECT(type) ((type) == PyArray_OBJECT)\n\n#define _PyADt(o) ((PyArray_Descr *)o)->type_num\n#define PyDescr_ISBOOL(obj) PyTypeNum_ISBOOL(_PyADt(obj))\n#define PyDescr_ISUNSIGNED(obj) PyTypeNum_ISUNSIGNED(_PyADt(obj))\n#define PyDescr_ISSIGNED(obj) PyTypeNum_ISSIGNED(_PyADt(obj))\n#define PyDescr_ISINTEGER(obj) PyTypeNum_ISINTEGER(_PyADt(obj))\n#define PyDescr_ISFLOAT(obj) PyTypeNum_ISFLOAT(_PyADt(obj))\n#define PyDescr_ISNUMBER(obj) PyTypeNum_ISNUMBER(_PyADt(obj))\n#define PyDescr_ISSTRING(obj) PyTypeNum_ISSTRING(_PyADt(obj))\n#define PyDescr_ISCOMPLEX(obj) PyTypeNum_ISCOMPLEX(_PyADt(obj))\n#define PyDescr_ISPYTHON(obj) PyTypeNum_ISPYTHON(_PyADt(obj))\n#define PyDescr_ISFLEXIBLE(obj) PyTypeNum_ISFLEXIBLE(_PyADt(obj))\n#define PyDescr_ISUSERDEF(obj) PyTypeNum_ISUSERDEF(_PyADt(obj))\n#define PyDescr_ISEXTENDED(obj) PyTypeNum_ISEXTENDED(_PyADt(obj))\n#define PyDescr_ISOBJECT(obj) PyTypeNum_ISOBJECT(_PyADt(obj))\n#undef _PyAD\n\n#define PyArray_ISBOOL(obj) PyTypeNum_ISBOOL(PyArray_TYPE(obj))\n#define PyArray_ISUNSIGNED(obj) PyTypeNum_ISUNSIGNED(PyArray_TYPE(obj))\n#define PyArray_ISSIGNED(obj) PyTypeNum_ISSIGNED(PyArray_TYPE(obj))\n#define PyArray_ISINTEGER(obj) PyTypeNum_ISINTEGER(PyArray_TYPE(obj))\n#define PyArray_ISFLOAT(obj) PyTypeNum_ISFLOAT(PyArray_TYPE(obj))\n#define PyArray_ISNUMBER(obj) PyTypeNum_ISNUMBER(PyArray_TYPE(obj))\n#define PyArray_ISSTRING(obj) PyTypeNum_ISSTRING(PyArray_TYPE(obj))\n#define PyArray_ISCOMPLEX(obj) PyTypeNum_ISCOMPLEX(PyArray_TYPE(obj))\n#define PyArray_ISPYTHON(obj) PyTypeNum_ISPYTHON(PyArray_TYPE(obj))\n#define PyArray_ISFLEXIBLE(obj) PyTypeNum_ISFLEXIBLE(PyArray_TYPE(obj))\n#define PyArray_ISUSERDEF(obj) PyTypeNum_ISUSERDEF(PyArray_TYPE(obj))\n#define PyArray_ISEXTENDED(obj) PyTypeNum_ISEXTENDED(PyArray_TYPE(obj))\n#define PyArray_ISOBJECT(obj) PyTypeNum_ISOBJECT(PyArray_TYPE(obj))\n\n#define PyArray_LITTLE '<'\n#define PyArray_BIG '>'\n#define PyArray_NATIVE '='\n#define PyArray_SWAP 's'\n#define PyArray_IGNORE '|'\n\n#ifdef WORDS_BIGENDIAN\n#define PyArray_NATBYTE PyArray_BIG\n#define PyArray_OPPBYTE PyArray_LITTLE\n#else\n#define PyArray_NATBYTE PyArray_LITTLE\n#define PyArray_OPPBYTE PyArray_BIG\n#endif\n\n#define PyArray_ISNBO(arg) ((arg) != PyArray_OPPBYTE)\n#define PyArray_IsNativeByteOrder PyArray_ISNBO\n#define PyArray_ISNOTSWAPPED(m) PyArray_ISNBO(PyArray_DESCR(m)->byteorder)\n\n#define PyArray_FLAGSWAP(m, flags) (PyArray_CHKFLAGS(m, flags) &&\t\\\n\t\t\t\t PyArray_ISNOTSWAPPED(m))\n#define PyArray_ISCARRAY(m) PyArray_FLAGSWAP(m, CARRAY_FLAGS)\n#define PyArray_ISCARRAY_RO(m) PyArray_FLAGSWAP(m, CARRAY_FLAGS_RO)\n#define PyArray_ISFARRAY(m) PyArray_FLAGSWAP(m, FARRAY_FLAGS)\n#define PyArray_ISFARRAY_RO(m) PyArray_FLAGSWAP(m, FARRAY_FLAGS_RO)\n#define PyArray_ISBEHAVED(m) PyArray_FLAGSWAP(m, BEHAVED_FLAGS)\n#define PyArray_ISBEHAVED_RO(m) PyArray_FLAGSWAP(m, ALIGNED)\n\n\n\n/* This is the form of the struct that's returned pointed by the\n PyCObject attribute of an array __array_struct__. See\n http://numeric.scipy.org/array_interface.html for the full\n documentation. */\ntypedef struct {\n int version; /* contains the integer 2 as a sanity check */\n int nd; /* number of dimensions */\n char typekind; /* kind in array --- character code of typestr */\n int itemsize; /* size of each element */\n int flags; /* how should be data interpreted. Valid\n flags are CONTIGUOUS (1), FORTRAN (2),\n ALIGNED (0x100), NOTSWAPPED (0x200), and\n WRITEABLE (0x400)*/\n intp *shape; /* A length-nd array of shape information */\n intp *strides; /* A length-nd array of stride information */\n void *data; /* A pointer to the first element of the array */\n} PyArrayInterface;\n\n/* Includes the \"function\" C-API -- these are all stored in a\n list of pointers --- one for each file\n The two lists are concatenated into one in multiarray.\n\n They are available as import_array()\n*/\n\n\n#include \"__multiarray_api.h\"\n\n\n/* C-API that requries previous API to be defined */\n\n#define PyArray_DescrCheck(op) ((op)->ob_type == &PyArrayDescr_Type)\n\n#define PyArray_Check(op) ((op)->ob_type == &PyArray_Type || \\\n\t\t\t PyObject_TypeCheck((op), &PyBigArray_Type))\n#define PyBigArray_CheckExact(op) ((op)->ob_type == &PyBigArray_Type)\n#define PyArray_CheckExact(op) ((op)->ob_type == &PyArray_Type)\n\n#define PyArray_IsZeroDim(op) (PyArray_Check(op) && (PyArray_NDIM(op) == 0))\n#define PyArray_IsScalar(obj, cls)\t\t\t\t\\\n\t(PyObject_TypeCheck((obj), &Py##cls##ArrType_Type))\n#define PyArray_CheckScalar(m) (PyArray_IsScalar(m, Generic) || \\\n PyArray_IsZeroDim(m))\n#define PyArray_IsPythonScalar(obj) \\\n\t(PyInt_Check(obj) || PyFloat_Check(obj) || PyComplex_Check(obj) || \\\n\t PyLong_Check(obj) || PyBool_Check(obj) || PyString_Check(obj) || \\\n\t PyUnicode_Check(obj))\n#define PyArray_IsAnyScalar(obj)\t\t\t\t\t\\\n\t(PyArray_IsScalar(obj, Generic) || PyArray_IsPythonScalar(obj))\n#define PyArray_CheckAnyScalar(obj) (PyArray_IsPythonScalar(obj) || \\\n\t\t\t\t PyArray_CheckScalar(obj))\n\n#define PyArray_GETCONTIGUOUS(m) (PyArray_ISCONTIGUOUS(m) ? Py_INCREF(m), m : \\\n (PyArrayObject *)(PyArray_Copy(m)))\n\n#define PyArray_SIZE(m) PyArray_MultiplyList(PyArray_DIMS(m), PyArray_NDIM(m))\n#define PyArray_NBYTES(m) (PyArray_ITEMSIZE(m) * PyArray_SIZE(m))\n#define PyArray_FROM_O(m) PyArray_FromAny(m, NULL, 0, 0, 0, NULL)\n#define PyArray_FROM_OF(m,flags) PyArray_CheckFromAny(m, NULL, 0, 0, flags, NULL)\n#define PyArray_FROM_OT(m,type) PyArray_FromAny(m, PyArray_DescrFromType(type), \\\n 0, 0, 0, NULL);\n#define PyArray_FROM_OTF(m, type, flags) \\\n\tPyArray_FromAny(m, PyArray_DescrFromType(type), 0, 0, \\\n (((flags) & ENSURECOPY) ? \\\n ((flags) | DEFAULT_FLAGS) : (flags)), NULL)\n#define PyArray_FROMANY(m, type, min, max, flags) \\\n\tPyArray_FromAny(m, PyArray_DescrFromType(type), min, max, \\\n (((flags) & ENSURECOPY) ? \\\n (flags) | DEFAULT_FLAGS : (flags)), NULL)\n\n#define PyArray_FILLWBYTE(obj, val) memset(PyArray_DATA(obj), (val), PyArray_NBYTES(obj))\n\n#define REFCOUNT(obj) (((PyObject *)(obj))->ob_refcnt)\n#define MAX_ELSIZE 2*SIZEOF_LONGDOUBLE\n\n#define PyArray_ContiguousFromAny(op, type, min_depth, max_depth) \\\n PyArray_FromAny(op, PyArray_DescrFromType(type), min_depth, \\\n max_depth, DEFAULT_FLAGS, NULL)\n\n#define PyArray_EquivArrTypes(a1, a2)\t\t\t\t\t\\\n\tPyArray_EquivTypes(PyArray_DESCR(a1), PyArray_DESCR(a2))\n#define PyArray_EquivTypenums(typenum1, typenum2)\t\t\\\n\tPyArray_EquivTypes(PyArray_DescrFromType(typenum1),\t\\\n\t\t\t PyArray_DescrFromType(typenum2))\n\n#define PyArray_EquivByteorders(b1, b2) \\\n\t((b1 == b2) || (PyArray_ISNBO(b1) == PyArray_ISNBO(b2)))\n\n#define PyArray_SimpleNew(nd, dims, typenum) \\\n\tPyArray_New(&PyArray_Type, nd, dims, typenum, NULL, NULL, 0, 0, NULL)\n#define PyArray_SimpleNewFromData(nd, dims, typenum, data) \\\n PyArray_New(&PyArray_Type, nd, dims, typenum, NULL, data, 0, CARRAY_FLAGS, NULL)\n#define PyArray_SimpleNewFromDescr(nd, dims, descr) \\\n\tPyArray_NewFromDescr(&PyArray_Type, descr, nd, dims, NULL, NULL, 0, NULL)\n\n\n/* These might be faster without the dereferencing of obj\n going on inside -- of course an optimizing compiler should\n inline the constants inside a for loop making it a moot point\n*/\n\n#define PyArray_GETPTR1(obj, i) (PyArray_DATA(obj) +\t\t\\\n\t\t\t\t i*PyArray_STRIDE(obj, 0))\n\n#define PyArray_GETPTR2(obj, i, j) (PyArray_DATA(obj) +\t\t\\\n\t\t\t\t i*PyArray_STRIDE(obj, 0) +\t\\\n\t\t\t\t j*PyArray_STRIDE(obj, 1))\n\n#define PyArray_GETPTR3(obj, i, j, k) (PyArray_DATA(obj) +\t\t\\\n\t\t\t\t i*PyArray_STRIDE(obj, 0) +\t\\\n\t\t\t\t j*PyArray_STRIDE(obj, 1) +\t\\\n\t\t\t\t k*PyArray_STRIDE(obj, 2))\t\\\n\n#define PyArray_GETPTR4(obj, i, j, k, l) (PyArray_DATA(obj) +\t\t\\\n\t\t\t\t\t i*PyArray_STRIDE(obj, 0) +\t\\\n\t\t\t\t\t j*PyArray_STRIDE(obj, 1) +\t\\\n\t\t\t\t\t k*PyArray_STRIDE(obj, 2) +\t\\\n\t\t\t\t\t l*PyArray_STRIDE(obj, 3))\n\n#define PyArray_DESCR_REPLACE(descr) do {\t\\\n\t\tPyArray_Descr *_new_;\t\t\t\\\n\t\t_new_ = PyArray_DescrNew(descr);\t\\\n\t\tPy_XDECREF(descr);\t\t\t\\\n\t\tdescr = _new_;\t\t\t\t\\\n\t} while(0)\n\n/* Copy should always return contiguous array */\n#define PyArray_Copy(obj) PyArray_NewCopy(obj, 0)\n\n#define PyArray_FromObject(op, type, min_depth, max_depth)\t\t\\\n\tPyArray_FromAny(op, PyArray_DescrFromType(type), min_depth,\t\\\n max_depth, BEHAVED_FLAGS | ENSUREARRAY, NULL)\n\n#define PyArray_ContiguousFromObject(op, type, min_depth, max_depth)\t\\\n PyArray_FromAny(op, PyArray_DescrFromType(type), min_depth,\t\\\n max_depth, DEFAULT_FLAGS | ENSUREARRAY, NULL)\n\n#define PyArray_CopyFromObject(op, type, min_depth, max_depth)\t\t\\\n PyArray_FromAny(op, PyArray_DescrFromType(type), min_depth, \\\n max_depth, ENSURECOPY | DEFAULT_FLAGS | ENSUREARRAY, NULL)\n\n#define PyArray_Cast(mp, type_num) \\\n\tPyArray_CastToType(mp, PyArray_DescrFromType(type_num), 0)\n\n/* Compatibility with old Numeric stuff -- don't use in new code */\n\n#define PyArray_FromDimsAndData(nd, d, type, data) \\\n\tPyArray_FromDimsAndDataAndDescr(nd, d, PyArray_DescrFromType(type), \\\n\t\t\t\t\tdata)\n\n#define PyArray_UNSIGNED_TYPES\n#define PyArray_SBYTE PyArray_BYTE\n#define PyArray_CHAR PyArray_BYTE\n#define PyArray_CopyArray PyArray_CopyInto\n#define _PyArray_multiply_list PyArray_MultiplyIntList\n#define PyArray_ISSPACESAVER(m) FALSE\n#define PyScalarArray_Check PyArray_CheckScalar\n\n#ifdef PY_ARRAY_TYPES_PREFIX\n# undef CAT\n# undef CAT2\n# undef NS\n# undef longlong\n# undef ulonglong\n# undef Bool\n# undef longdouble\n# undef byte\n# undef ubyte\n# undef ushort\n# undef uint\n# undef ulong\n# undef cfloat\n# undef cdouble\n# undef clongdouble\n# undef Int8\n# undef UInt8\n# undef Int16\n# undef UInt16\n# undef Int32\n# undef UInt32\n# undef Int64\n# undef UInt64\n# undef Int128\n# undef UInt128\n# undef Int256\n# undef UInt256\n# undef Float16\n# undef Complex32\n# undef Float32\n# undef Complex64\n# undef Float64\n# undef Complex128\n# undef Float80\n# undef Complex160\n# undef Float96\n# undef Complex192\n# undef Float128\n# undef Complex256\n# undef intp\n# undef uintp\n#endif\n\n#ifdef __cplusplus\n}\n#endif\n\n#endif /* !Py_ARRAYOBJECT_H */\n", + "methods": [], + "methods_before": [], + "changed_methods": [], + "nloc": 289, + "complexity": 0, + "token_count": 1354, + "diff_parsed": { + "added": [ + "#define NDARRAY_VERSION 0x00090405", + "", + "#define UFUNC_NOSCALAR 0", + "#define UFUNC_BOOL_SCALAR 1", + "#define UFUNC_INTPOS_SCALAR 2", + "#define UFUNC_INTNEG_SCALAR 3", + "#define UFUNC_FLOAT_SCALAR 4", + "#define UFUNC_COMPLEX_SCALAR 5", + "#define UFUNC_OBJECT_SCALAR 6", + "", + "" + ], + "deleted": [ + "#define NDARRAY_VERSION 0x00090404" + ] + } + } + ] + }, + { + "hash": "adcc8b80b9c60136aef3b37891219b6e504398fc", + "msg": "Fix typo.", + "author": { + "name": "Travis Oliphant", + "email": "oliphant@enthought.com" + }, + "committer": { + "name": "Travis Oliphant", + "email": "oliphant@enthought.com" + }, + "author_date": "2006-02-14T00:44:38+00:00", + "author_timezone": 0, + "committer_date": "2006-02-14T00:44:38+00:00", + "committer_timezone": 0, + "branches": [ + "main" + ], + "in_main_branch": true, + "merge": false, + "parents": [ + "3eae4c1ea4d1fb2f756f339221316feb91cbc778" + ], + "project_name": "repo_copy", + "project_path": "/tmp/tmpdjwupkfu/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/arraymethods.c", + "new_path": "numpy/core/src/arraymethods.c", + "filename": "arraymethods.c", + "extension": "c", + "change_type": "MODIFY", + "diff": "@@ -1532,7 +1532,7 @@ array_newbyteorder(PyArrayObject *self, PyObject *args)\n \n \tnew = PyArray_DescrNewByteorder(self->descr, endian);\n \tif (!new) return NULL;\n-\treturn PyArray_View(self, new, NULL));\n+\treturn PyArray_View(self, new, NULL);\n \n }\n \n", + "added_lines": 1, + "deleted_lines": 1, + "source_code": "\n/* Should only be used if x is known to be an nd-array */\n#define _ARET(x) PyArray_Return((PyArrayObject *)(x))\n\nstatic char doc_take[] = \"a.take(indices, axis=None). Selects the elements \"\\\n\t\"in indices from array a along the given axis.\";\n\nstatic PyObject *\narray_take(PyArrayObject *self, PyObject *args, PyObject *kwds) \n{\n\tint dimension=MAX_DIMS;\n\tPyObject *indices;\n\tstatic char *kwlist[] = {\"indices\", \"axis\", NULL};\n\t\n\tdimension=0;\n\tif (!PyArg_ParseTupleAndKeywords(args, kwds, \"O|O&\", kwlist, \n\t\t\t\t\t &indices, PyArray_AxisConverter,\n\t\t\t\t\t &dimension))\n\t\treturn NULL;\n\t\n\treturn _ARET(PyArray_Take(self, indices, dimension));\n}\n\nstatic char doc_fill[] = \"a.fill(value) places the scalar value at every\"\\\n\t\"position in the array.\";\n\nstatic PyObject *\narray_fill(PyArrayObject *self, PyObject *args)\n{\n\tPyObject *obj;\n\tif (!PyArg_ParseTuple(args, \"O\", &obj))\n\t\treturn NULL;\n\tif (PyArray_FillWithScalar(self, obj) < 0) return NULL;\n\tPy_INCREF(Py_None);\n\treturn Py_None;\n}\n\nstatic char doc_put[] = \"a.put(values, indices) sets a.flat[n] = v[n] \"\\\n\t\"for each n in indices. v can be scalar or shorter than indices, \"\\\n\t\"will repeat.\";\n\nstatic PyObject *\narray_put(PyArrayObject *self, PyObject *args, PyObject *kwds) \n{\n\tPyObject *indices, *values;\n\tstatic char *kwlist[] = {\"values\", \"indices\", NULL};\n\t\n\tif (!PyArg_ParseTupleAndKeywords(args, kwds, \"OO\", kwlist,\n\t\t\t\t\t &values, &indices))\n\t\treturn NULL;\n\treturn PyArray_Put(self, values, indices);\n}\n\nstatic char doc_putmask[] = \"a.putmask(values, mask) sets a.flat[n] = v[n] \"\\\n\t\"for each n where mask.flat[n] is TRUE. v can be scalar.\";\n\nstatic PyObject *\narray_putmask(PyArrayObject *self, PyObject *args, PyObject *kwds) \n{\n\tPyObject *mask, *values;\n\n\tstatic char *kwlist[] = {\"values\", \"mask\", NULL};\n\t\n\tif (!PyArg_ParseTupleAndKeywords(args, kwds, \"OO\", kwlist,\n\t\t\t\t\t &values, &mask))\n\t\treturn NULL;\n\treturn PyArray_PutMask(self, values, mask);\n}\n\n/* Used to reshape a Fortran Array */\nstatic void\n_reverse_shape(PyArray_Dims *newshape)\n{\n\tint i, n = newshape->len;\n\tintp *ptr = newshape->ptr;\n\tintp *eptr;\n\tintp tmp;\n\tint len = n >> 1;\n\n\teptr = ptr+n-1;\n\tfor(i=0; i) return a new view of array with same data. type can be either a new sub-type object or a data-descriptor object\";\n\nstatic PyObject *\narray_view(PyArrayObject *self, PyObject *args)\n{\n\tPyObject *otype=NULL;\n PyArray_Descr *type=NULL;\n\n\tif (!PyArg_ParseTuple(args, \"|O\", &otype)) return NULL;\n\n\tif (otype) {\n\t\tif (PyType_Check(otype) &&\t\t\t\t\\\n\t\t PyType_IsSubtype((PyTypeObject *)otype, \n\t\t\t\t &PyBigArray_Type)) {\n\t\t\treturn PyArray_View(self, NULL, \n (PyTypeObject *)otype);\n }\n\t\telse {\n\t\t\tif (PyArray_DescrConverter(otype, &type) == PY_FAIL) \n\t\t\t\treturn NULL;\n\t\t}\n\t}\n\treturn PyArray_View(self, type, NULL);\n}\n\nstatic char doc_argmax[] = \"a.argmax(axis=None)\";\n\nstatic PyObject *\narray_argmax(PyArrayObject *self, PyObject *args) \n{\n\tint axis=MAX_DIMS;\n\t\n\tif (!PyArg_ParseTuple(args, \"|O&\", PyArray_AxisConverter, \n\t\t\t &axis)) return NULL;\n\t\n\treturn _ARET(PyArray_ArgMax(self, axis));\n}\n\nstatic char doc_argmin[] = \"a.argmin(axis=None)\";\n\nstatic PyObject *\narray_argmin(PyArrayObject *self, PyObject *args) \n{\n\tint axis=MAX_DIMS;\n\t\n\tif (!PyArg_ParseTuple(args, \"|O&\", PyArray_AxisConverter, \n\t\t\t &axis)) return NULL;\n\t\n\treturn _ARET(PyArray_ArgMin(self, axis));\n}\n\nstatic char doc_max[] = \"a.max(axis=None)\";\n\nstatic PyObject *\narray_max(PyArrayObject *self, PyObject *args) \n{\n\tint axis=MAX_DIMS;\n\t\n\tif (!PyArg_ParseTuple(args, \"|O&\", PyArray_AxisConverter, \n\t\t\t &axis)) return NULL;\n\t\n\treturn PyArray_Max(self, axis);\n}\n\nstatic char doc_ptp[] = \"a.ptp(axis=None) a.max(axis)-a.min(axis)\";\n\nstatic PyObject *\narray_ptp(PyArrayObject *self, PyObject *args) \n{\n\tint axis=MAX_DIMS;\n\t\n\tif (!PyArg_ParseTuple(args, \"|O&\", PyArray_AxisConverter, \n\t\t\t &axis)) return NULL;\n\t\n\treturn PyArray_Ptp(self, axis);\n}\n\n\nstatic char doc_min[] = \"a.min(axis=None)\";\n\nstatic PyObject *\narray_min(PyArrayObject *self, PyObject *args) \n{\n\tint axis=MAX_DIMS;\n\t\n\tif (!PyArg_ParseTuple(args, \"|O&\", PyArray_AxisConverter, \n\t\t\t &axis)) return NULL;\n\t\n\treturn PyArray_Min(self, axis);\n}\n\n\nstatic char doc_swapaxes[] = \"a.swapaxes(axis1, axis2) returns new view with axes swapped.\";\n\nstatic PyObject *\narray_swapaxes(PyArrayObject *self, PyObject *args)\n{\n\tint axis1, axis2;\n\n\tif (!PyArg_ParseTuple(args, \"ii\", &axis1, &axis2)) return NULL;\n\n\treturn PyArray_SwapAxes(self, axis1, axis2);\n}\n\nstatic char doc_getfield[] = \"m.getfield(dtype, offset) returns a field \"\\\n\t\" of the given array as a certain type. A field is a view of \"\\\n\t\" the array's data with each itemsize determined by the given type\"\\\n\t\" and the offset into the current array.\";\n\n/* steals typed reference */\n/*OBJECT_API\n Get a subset of bytes from each element of the array\n*/\nstatic PyObject *\nPyArray_GetField(PyArrayObject *self, PyArray_Descr *typed, int offset)\n{\n\tPyObject *ret=NULL;\n\n\tif (offset < 0 || (offset + typed->elsize) > self->descr->elsize) {\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 self->descr->elsize-typed->elsize, offset);\n\t\tPy_DECREF(typed);\n\t\treturn NULL;\n\t}\n\tret = PyArray_NewFromDescr(self->ob_type, \n\t\t\t\t typed,\n\t\t\t\t self->nd, self->dimensions,\n\t\t\t\t self->strides, \n\t\t\t\t self->data + offset,\n\t\t\t\t self->flags, (PyObject *)self);\n\tif (ret == NULL) return NULL;\n\tPy_INCREF(self);\n\t((PyArrayObject *)ret)->base = (PyObject *)self; \n\n\tPyArray_UpdateFlags((PyArrayObject *)ret, UPDATE_ALL_FLAGS);\n\treturn ret;\n}\n\nstatic PyObject *\narray_getfield(PyArrayObject *self, PyObject *args, PyObject *kwds)\n{\n\n PyArray_Descr *dtype;\n\tint offset = 0;\n\tstatic char *kwlist[] = {\"dtype\", \"offset\", 0};\n\t\n\tif (!PyArg_ParseTupleAndKeywords(args, kwds, \"O&|i\", kwlist,\n\t\t\t\t\t PyArray_DescrConverter,\n\t\t\t\t\t &dtype, &offset)) return NULL;\n\t\n\treturn _ARET(PyArray_GetField(self, dtype, offset));\n}\n\n\nstatic char doc_setfield[] = \"m.setfield(value, dtype, offset) places val \"\\\n\t\"into field of the given array defined by the data type and offset.\";\n\n/*OBJECT_API\n Set a subset of bytes from each element of the array\n*/\nstatic int\nPyArray_SetField(PyArrayObject *self, PyArray_Descr *dtype,\n\t\t int offset, PyObject *val)\n{\n\tPyObject *ret=NULL;\n\tint retval = 0;\n \n\tif (offset < 0 || (offset + dtype->elsize) > self->descr->elsize) {\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 self->descr->elsize-dtype->elsize, offset);\n\t\tPy_DECREF(dtype);\n\t\treturn -1;\n\t}\n\tret = PyArray_NewFromDescr(self->ob_type, \n\t\t\t\t dtype, self->nd, self->dimensions,\n\t\t\t\t self->strides, self->data + offset,\n\t\t\t\t self->flags, (PyObject *)self);\n\tif (ret == NULL) return -1;\n\tPy_INCREF(self);\n\t((PyArrayObject *)ret)->base = (PyObject *)self;\n\n\tPyArray_UpdateFlags((PyArrayObject *)ret, UPDATE_ALL_FLAGS);\t\n\tretval = PyArray_CopyObject((PyArrayObject *)ret, val);\n\tPy_DECREF(ret);\n\treturn retval;\n}\n\nstatic PyObject *\narray_setfield(PyArrayObject *self, PyObject *args, PyObject *kwds)\n{\n PyArray_Descr *dtype;\n\tint offset = 0;\n\tPyObject *value;\n\tstatic char *kwlist[] = {\"value\", \"dtype\", \"offset\", 0};\n\t\n\tif (!PyArg_ParseTupleAndKeywords(args, kwds, \"OO&|i\", kwlist,\n\t\t\t\t\t &value, PyArray_DescrConverter,\n\t\t\t\t\t &dtype, &offset)) return NULL;\n\n\tif (PyArray_SetField(self, dtype, offset, value) < 0)\n\t\treturn NULL;\n\tPy_INCREF(Py_None);\n\treturn Py_None;\n}\n\n/* This doesn't change the descriptor just the actual data...\n */\n\n/*OBJECT_API*/\nstatic PyObject *\nPyArray_Byteswap(PyArrayObject *self, Bool inplace)\n{\n PyArrayObject *ret;\n\tintp size;\n\tPyArray_CopySwapNFunc *copyswapn;\n\tPyArray_CopySwapFunc *copyswap;\n\tPyArrayIterObject *it;\n\n\tif (inplace) {\n\t\tcopyswapn = self->descr->f->copyswapn;\n\t\t\n\t\tsize = PyArray_SIZE(self);\n\t\tif (PyArray_ISONESEGMENT(self)) {\n\t\t\tcopyswapn(self->data, NULL, size, 1, \n\t\t\t\t self->descr->elsize);\n\t\t}\n\t\telse { /* Use iterator */\n\t\t\t\n\t\t\tit = (PyArrayIterObject *)\\\n\t\t\t\tPyArray_IterNew((PyObject *)self);\n\t\t\tcopyswap = self->descr->f->copyswap;\n\t\t\twhile (it->index < it->size) {\n\t\t\t\tcopyswap(it->dataptr, NULL, 1, \n\t\t\t\t\t self->descr->elsize);\n\t\t\t\tPyArray_ITER_NEXT(it);\n\t\t\t}\n\t\t\tPy_DECREF(it);\n\t\t}\n\t\t\n\t\tPy_INCREF(self);\n\t\treturn (PyObject *)self;\n\t}\n\telse {\n\t\tif ((ret = (PyArrayObject *)PyArray_NewCopy(self,-1)) == NULL) \n\t\t\treturn NULL;\n\t\t\n\t\tsize = PyArray_SIZE(self);\n\n\t\t/* now ret has the same dtypedescr as self (including\n\t\t byteorder)\n\t\t*/\n\n\t\tret->descr->f->copyswapn(ret->data, NULL, size, 1, \n\t\t\t\t\t ret->descr->elsize);\n\n\t\treturn (PyObject *)ret;\n\t}\n}\n\nstatic char doc_byteswap[] = \"m.byteswap(False) Swap the bytes in\"\\\n\t\" the array. Return the byteswapped array. If the first argument\"\\\n\t\" is TRUE, byteswap in-place and return a reference to self.\";\n\nstatic PyObject *\narray_byteswap(PyArrayObject *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\treturn PyArray_Byteswap(self, inplace);\n}\n\nstatic char doc_tolist[] = \"m.tolist().\t Copy the data portion of the array\"\\\n\t\" to a hierarchical python list and return that list.\";\n\nstatic PyObject *\narray_tolist(PyArrayObject *self, PyObject *args) \n{\n if (!PyArg_ParseTuple(args, \"\")) return NULL;\n if (self->nd <= 0) {\n PyErr_SetString(PyExc_ValueError, \n\t\t\t\t\"can't convert a 0-d array to a list\");\n return NULL;\n }\n\t\n return PyArray_ToList(self);\n}\n\nstatic char doc_tostring[] = \"m.tostring() Construct a Python string \"\\\n \"containing the raw bytes in the array\";\n\nstatic PyObject *\narray_tostring(PyArrayObject *self, PyObject *args)\n{\n if (!PyArg_ParseTuple(args, \"\")) return NULL;\n return PyArray_ToString(self);\n}\n\nstatic char doc_tofile[] = \"m.tofile(fid, sep=\"\") write the data to a file.\";\n\nstatic PyObject *\narray_tofile(PyArrayObject *self, PyObject *args, PyObject *kwds)\n{\n\tint ret;\n PyObject *file;\n\tFILE *fd;\n char *sep=\"\";\n\tchar *format=\"\";\n\tchar *mode=\"\";\n\tstatic char *kwlist[] = {\"file\", \"sep\", \"format\", NULL};\n \n\tif (!PyArg_ParseTupleAndKeywords(args, kwds, \"O|ss\", kwlist, \n &file, &sep, &format)) return NULL;\n\n\tif (PyString_Check(file)) {\n\t\tif (sep == \"\") mode=\"wb\";\n\t\telse mode=\"w\";\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\tfd = PyFile_AsFile(file);\n\tif (fd == NULL) {\n\t\tPyErr_SetString(PyExc_IOError, \"first argument must be a \" \\\n\t\t\t\t\"string or open file\");\n\t\tPy_DECREF(file);\n\t\treturn NULL;\n\t}\n\tret = PyArray_ToFile(self, fd, sep, format);\n\tPy_DECREF(file);\n\tif (ret < 0) return NULL;\n Py_INCREF(Py_None);\n return Py_None;\n}\n\nstatic char doc_toscalar[] = \"m.item(). Copy the first data point of \"\\\n\t\"the array to a standard Python scalar and return it.\";\n\nstatic PyObject *\narray_toscalar(PyArrayObject *self, PyObject *args) {\n if (!PyArg_ParseTuple(args, \"\")) return NULL;\n\tif (self->nd == 0 || PyArray_SIZE(self) == 1) \n\t\treturn self->descr->f->getitem(self->data, self);\n\telse {\n\t\tPyErr_SetString(PyExc_ValueError, \"can only convert an\"\t\\\n\t\t\t\t\" array of size 1 to Python scalar.\");\n\t\treturn NULL;\n\t}\n}\n\nstatic char doc_cast[] = \"m.astype(t).\tCast array m to type t.\t \\n\\n\"\\\n\t\"t can be either a string representing a typecode, or a python type\"\\\n\t\" object of type int, float, or complex.\";\n\nstatic PyObject *\narray_cast(PyArrayObject *self, PyObject *args) \n{\n\tPyArray_Descr *descr=NULL;\n\tPyObject *obj;\n\t\n if (!PyArg_ParseTuple(args, \"O&\", PyArray_DescrConverter,\n\t\t\t &descr)) return NULL;\n\t\n\tif (descr == self->descr) {\n\t\tobj = _ARET(PyArray_NewCopy(self,0));\n\t\tPy_XDECREF(descr);\n\t\treturn obj;\n\t}\n\treturn _ARET(PyArray_CastToType(self, descr, 0));\n}\t \n\n/* default sub-type implementation */\n\nstatic char doc_wraparray[] = \"m.__array_wrap__(obj) returns an object of \"\\\n\t\"type m from the ndarray object obj\";\n\nstatic PyObject *\narray_wraparray(PyArrayObject *self, PyObject *args)\n{\n\tPyObject *arr;\n\tPyObject *ret;\n\t\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}\t\n\n\tPy_INCREF(PyArray_DESCR(arr));\n\tret = PyArray_NewFromDescr(self->ob_type, \n\t\t\t\t PyArray_DESCR(arr),\n\t\t\t\t PyArray_NDIM(arr),\n\t\t\t\t PyArray_DIMS(arr), \n\t\t\t\t PyArray_STRIDES(arr), PyArray_DATA(arr),\n\t\t\t\t PyArray_FLAGS(arr), (PyObject *)self);\n\tif (ret == NULL) return NULL;\n\tPy_INCREF(arr);\n\tPyArray_BASE(ret) = arr;\n\treturn ret;\n}\n\n/* NO-OP --- just so all subclasses will have one by default. */\nstatic PyObject *\narray_finalize(PyArrayObject *self, PyObject *args)\n{\n\tPy_INCREF(Py_None);\n\treturn Py_None;\n}\n\n\nstatic char doc_array_getarray[] = \"m.__array__(|dtype) just returns either a new reference to self if dtype is not given or a new array of provided data type if dtype is different from the current dtype of the array.\";\n\nstatic PyObject *\narray_getarray(PyArrayObject *self, PyObject *args) \n{\n\tPyArray_Descr *newtype=NULL;\n\tPyObject *ret;\n\t\n\tif (!PyArg_ParseTuple(args, \"|O&\", PyArray_DescrConverter,\n\t\t\t &newtype)) return NULL;\n\t\n\t/* convert to PyArray_Type or PyBigArray_Type */\n\tif (!PyArray_CheckExact(self) || !PyBigArray_CheckExact(self)) {\n\t\tPyObject *new;\n\t\tPyTypeObject *subtype = &PyArray_Type;\n\n\t\tif (!PyType_IsSubtype(self->ob_type, &PyArray_Type)) {\n\t\t\tsubtype = &PyBigArray_Type;\n\t\t}\n\t\t\n\t\tPy_INCREF(PyArray_DESCR(self));\n\t\tnew = PyArray_NewFromDescr(subtype, \n\t\t\t\t\t PyArray_DESCR(self),\n\t\t\t\t\t PyArray_NDIM(self),\n\t\t\t\t\t PyArray_DIMS(self), \n\t\t\t\t\t PyArray_STRIDES(self), \n\t\t\t\t\t PyArray_DATA(self),\n\t\t\t\t\t PyArray_FLAGS(self), NULL);\n\t\tif (new == NULL) return NULL;\n\t\tPy_INCREF(self);\n\t\tPyArray_BASE(new) = (PyObject *)self;\n\t\tself = (PyArrayObject *)new;\n\t}\n\telse {\n\t\tPy_INCREF(self);\n\t}\n\t\t\n\tif ((newtype == NULL) || \\\n\t PyArray_EquivTypes(self->descr, newtype)) {\n\t\treturn (PyObject *)self;\n\t}\n\telse {\n\t\tret = PyArray_CastToType(self, newtype, 0);\n\t\tPy_DECREF(self);\n\t\treturn ret;\n\t}\n}\n\nstatic char doc_copy[] = \"m.copy(|fortran). Return a copy of the array.\\n\"\\\n\t\"If fortran == 0 then the result is contiguous (default). \\n\"\\\n\t\"If fortran > 0 then the result has fortran data order. \\n\"\\\n\t\"If fortran < 0 then the result has fortran data order only if m\\n\"\n\t\" is already in fortran order.\";\n\nstatic PyObject *\narray_copy(PyArrayObject *self, PyObject *args) \n{\n\tint fortran=0;\n if (!PyArg_ParseTuple(args, \"|i\", &fortran)) return NULL;\n\t\n return PyArray_NewCopy(self, fortran);\n}\n\nstatic char doc_resize[] = \"self.resize(new_shape). \"\\\n\t\"Change size and shape of self inplace.\\n\"\\\n\t\"\\n Array must own its own memory and not be referenced by other \" \\\n\t\"arrays\\n Returns None.\";\n\nstatic PyObject *\narray_resize(PyArrayObject *self, PyObject *args) \n{\n PyArray_Dims newshape;\n PyObject *ret;\n\tint n;\n\t\n\tn = PyTuple_Size(args);\n\tif (n <= 1) {\n\t\tif (!PyArg_ParseTuple(args, \"O&\", PyArray_IntpConverter, \n\t\t\t\t &newshape)) return NULL;\n\t}\n else {\n\t\tif (!PyArray_IntpConverter(args, &newshape)) {\n\t\t\tif (!PyErr_Occurred()) {\n\t\t\t\tPyErr_SetString(PyExc_TypeError, \n\t\t\t\t\t\t\"invalid shape\");\n\t\t\t} \n\t\t\treturn NULL;\t\t\t\n\t\t}\n\t}\n\tret = PyArray_Resize(self, &newshape);\n PyDimMem_FREE(newshape.ptr);\n if (ret == NULL) return NULL;\n\tPy_DECREF(ret);\n\tPy_INCREF(Py_None);\n\treturn Py_None;\n}\n\nstatic char doc_repeat[] = \"a.repeat(repeats=, axis=None)\\n\"\\\n\t\"\\n\"\\\n\t\" Copy elements of a, repeats times. The repeats argument must\\n\"\\\n\t\" be a sequence of length a.shape[axis] or a scalar.\";\n\nstatic PyObject *\narray_repeat(PyArrayObject *self, PyObject *args, PyObject *kwds) {\n\tPyObject *repeats;\n\tint axis=MAX_DIMS;\n\tstatic char *kwlist[] = {\"repeats\", \"axis\", NULL};\n\t\n\tif (!PyArg_ParseTupleAndKeywords(args, kwds, \"O|O&\", kwlist, \n\t\t\t\t\t &repeats, PyArray_AxisConverter,\n\t\t\t\t\t &axis)) return NULL;\n\t\n\treturn _ARET(PyArray_Repeat(self, repeats, axis));\n}\n\nstatic char doc_choose[] = \"a.choose(b0, b1, ..., bn)\\n\"\\\n\t\"\\n\"\\\n\t\"Return an array with elements chosen from 'a' at the positions\\n\"\\\n \"of the given arrays b_i. The array 'a' should be an integer array\\n\"\\\n \"with entries from 0 to n+1, and the b_i arrays should have the same\\n\"\\\n \"shape as 'a'.\";\n\nstatic PyObject *\narray_choose(PyArrayObject *self, PyObject *args) \n{\n\tPyObject *choices;\n\tint n;\n\t\n\tn = PyTuple_Size(args);\n\tif (n <= 1) {\n\t\tif (!PyArg_ParseTuple(args, \"O\", &choices))\n\t\t\treturn NULL;\n\t}\n else {\n\t\tchoices = args;\n\t}\n\t\n\treturn _ARET(PyArray_Choose(self, choices));\n}\n\nstatic char doc_sort[] = \"a.sort(axis=-1,kind='quicksort') sorts in place along axis. Return is None and kind can be 'quicksort', 'mergesort', or 'heapsort'\";\n\nstatic PyObject *\narray_sort(PyArrayObject *self, PyObject *args, PyObject *kwds) \n{\n\tint axis=-1;\n\tint val;\n\tPyArray_SORTKIND which=PyArray_QUICKSORT;\n\tstatic char *kwlist[] = {\"axis\", \"kind\", NULL};\n\t\n\tif (!PyArg_ParseTupleAndKeywords(args, kwds, \"|iO&\", kwlist, &axis,\n\t\t\t\t\t PyArray_SortkindConverter, &which))\n\t\treturn NULL;\n\t\n\tval = PyArray_Sort(self, axis, which);\n\tif (val < 0) return NULL;\n\tPy_INCREF(Py_None);\n\treturn Py_None;\n}\n\nstatic char doc_argsort[] = \"a.argsort(axis=-1,kind='quicksort')\\n\"\\\n\t\" Return the indexes into a that would sort it along the\"\\\n\t\" given axis; kind can be 'quicksort', 'mergesort', or 'heapsort'\";\n\nstatic PyObject *\narray_argsort(PyArrayObject *self, PyObject *args, PyObject *kwds) \n{\n\tint axis=-1;\n\tPyArray_SORTKIND which=PyArray_QUICKSORT;\n\tstatic char *kwlist[] = {\"axis\", \"kind\", NULL};\n\t\n\tif (!PyArg_ParseTupleAndKeywords(args, kwds, \"|iO&\", kwlist, &axis,\n\t\t\t\t\t PyArray_SortkindConverter, &which))\n\t\treturn NULL;\n\t\n\treturn _ARET(PyArray_ArgSort(self, axis, which));\n}\n\nstatic char doc_searchsorted[] = \"a.searchsorted(v)\\n\"\\\n\t\" Assuming that a is a 1-D array, in ascending order and\\n\"\\\n\t\" represents bin boundaries, then a.searchsorted(values) gives an\\n\"\\\n\t\" array of bin numbers, giving the bin into which each value would\\n\"\\\n\t\" be placed. This method is helpful for histograming. \\n\"\\\n\t\" Note: No warning is given if the boundaries, in a, are not \\n\"\\\n\t\" in ascending order.\";\n\nstatic PyObject *\narray_searchsorted(PyArrayObject *self, PyObject *args) \n{\n\tPyObject *values;\n\t\n\tif (!PyArg_ParseTuple(args, \"O\", &values)) return NULL;\n\t\n\treturn _ARET(PyArray_SearchSorted(self, values));\n}\n\nstatic char doc_deepcopy[] = \"Used if copy.deepcopy is called on an array.\";\n\nstatic PyObject *\narray_deepcopy(PyArrayObject *self, PyObject *args) \n{\n PyObject* visit;\n PyObject **optr;\n PyArrayIterObject *it;\n PyObject *copy, *ret, *deepcopy, *temp, *res;\n\n if (!PyArg_ParseTuple(args, \"O\", &visit)) return NULL;\n ret = PyArray_Copy(self);\n if (PyArray_ISOBJECT(self)) {\n copy = PyImport_ImportModule(\"copy\");\n if (copy == NULL) return NULL;\n deepcopy = PyObject_GetAttrString(copy, \"deepcopy\");\n Py_DECREF(copy);\n if (deepcopy == NULL) return NULL;\n it = (PyArrayIterObject *)PyArray_IterNew((PyObject *)self);\n if (it == NULL) {Py_DECREF(deepcopy); return NULL;}\n optr = (PyObject **)PyArray_DATA(ret);\n while(it->index < it->size) {\n temp = *((PyObject **)it->dataptr);\n Py_INCREF(temp);\n /* call deepcopy on this argument */\n res = PyObject_CallFunctionObjArgs(deepcopy, \n temp, visit, NULL);\n Py_DECREF(temp);\n Py_DECREF(*optr);\n *optr++ = res;\n PyArray_ITER_NEXT(it);\n }\n Py_DECREF(deepcopy);\n Py_DECREF(it);\n }\n return _ARET(ret);\n}\n\n/* Convert Object Array to flat list and pickle the flat list string */\nstatic PyObject *\n_getobject_pkl(PyArrayObject *self)\n{\n\tPyObject *theobject;\n\tPyArrayIterObject *iter=NULL;\n\tPyObject *list;\n\n\t\n\titer = (PyArrayIterObject *)PyArray_IterNew((PyObject *)self);\n\tif (iter == NULL) return NULL;\n\tlist = PyList_New(iter->size);\n\tif (list == NULL) {Py_DECREF(iter); return NULL;}\n\twhile (iter->index < iter->size) {\n\t\ttheobject = *((PyObject **)iter->dataptr);\n\t\tPy_INCREF(theobject);\n\t\tPyList_SET_ITEM(list, (int) iter->index, theobject);\n\t\tPyArray_ITER_NEXT(iter);\n\t}\n\tPy_DECREF(iter);\n\treturn list;\n}\n\nstatic int\n_setobject_pkl(PyArrayObject *self, PyObject *list)\n{\n\tPyObject *theobject;\n\tPyArrayIterObject *iter=NULL;\n\tint size;\n\n\tsize = self->descr->elsize;\n\t\n\titer = (PyArrayIterObject *)PyArray_IterNew((PyObject *)self);\n\tif (iter == NULL) return -1;\n\twhile(iter->index < iter->size) {\n\t\ttheobject = PyList_GET_ITEM(list, (int) iter->index);\n\t\tPy_INCREF(theobject);\n\t\t*((PyObject **)iter->dataptr) = theobject;\n\t\tPyArray_ITER_NEXT(iter);\n\t}\n\tPy_XDECREF(iter);\n\treturn 0;\n}\n\nstatic char doc_reduce[] = \"a.__reduce__() for pickling.\";\n\nstatic PyObject *\narray_reduce(PyArrayObject *self, PyObject *args)\n{\n\tPyObject *ret=NULL, *state=NULL, *obj=NULL, *mod=NULL;\n\tPyObject *mybool, *thestr=NULL;\n\tPyArray_Descr *descr;\n\n\t/* Return a tuple of (callable object, arguments, object's state) */\n\t/* We will put everything in the object's state, so that on UnPickle\n\t it can use the string object as memory without a copy */\n\n\tret = PyTuple_New(3);\n\tif (ret == NULL) return NULL;\n\tmod = PyImport_ImportModule(\"numpy.core._internal\");\n\tif (mod == NULL) {Py_DECREF(ret); return NULL;}\n\tobj = PyObject_GetAttrString(mod, \"_reconstruct\");\n\tPy_DECREF(mod);\n\tPyTuple_SET_ITEM(ret, 0, obj);\n\tPyTuple_SET_ITEM(ret, 1, \n\t\t\t Py_BuildValue(\"ONN\",\n\t\t\t\t (PyObject *)self->ob_type,\n\t\t\t\t Py_BuildValue(\"(N)\",\n\t\t\t\t\t\t PyInt_FromLong(0)),\n\t\t\t\t PyObject_GetAttrString((PyObject *)(self->descr),\n\t\t\t\t\t\t\t \"char\")));\n\t\n\t/* Now fill in object's state. This is a tuple with \n\t 4 arguments\n\n\t 1) a Tuple giving the shape\n\t 2) a PyArray_Descr Object (with correct bytorder set)\n\t 3) a Bool stating if Fortran or not\n\t 4) a binary string with the data (or a list for Object arrays)\n\n\t Notice because Python does not describe a mechanism to write \n\t raw data to the pickle, this performs a copy to a string first\n\t*/\n\n\tstate = PyTuple_New(4);\n\tif (state == NULL) {\n\t\tPy_DECREF(ret); return NULL;\n\t}\n\tPyTuple_SET_ITEM(state, 0, PyObject_GetAttrString((PyObject *)self, \n\t\t\t\t\t\t\t \"shape\"));\n\tdescr = self->descr;\n\tPy_INCREF(descr);\n\tPyTuple_SET_ITEM(state, 1, (PyObject *)descr);\n\tmybool = (PyArray_ISFORTRAN(self) ? Py_True : Py_False);\n\tPy_INCREF(mybool);\n\tPyTuple_SET_ITEM(state, 2, mybool);\n\tif (PyArray_ISOBJECT(self)) {\n\t\tthestr = _getobject_pkl(self);\n\t}\n\telse {\n thestr = PyArray_ToString(self);\n\t}\n\tif (thestr == NULL) {\n\t\tPy_DECREF(ret);\n\t\tPy_DECREF(state);\n\t\treturn NULL;\n\t}\n\tPyTuple_SET_ITEM(state, 3, thestr);\n\tPyTuple_SET_ITEM(ret, 2, state);\n\treturn ret;\n}\n\nstatic char doc_setstate[] = \"a.__setstate__(tuple) for unpickling.\";\n\n/*\n\t 1) a Tuple giving the shape\n\t 2) a PyArray_Descr Object\n\t 3) a Bool stating if Fortran or not\n\t 4) a binary string with the data (or a list if Object array) \n*/\n\nstatic intp _array_fill_strides(intp *, intp *, int, intp, int, int *);\n\nstatic int _IsAligned(PyArrayObject *); \n\nstatic PyArray_Descr * _array_typedescr_fromstr(char *);\n\nstatic PyObject *\narray_setstate(PyArrayObject *self, PyObject *args)\n{\n\tPyObject *shape;\n\tPyArray_Descr *typecode;\n\tlong fortran;\n\tPyObject *rawdata;\n\tchar *datastr;\n\tint len;\n\tintp dimensions[MAX_DIMS];\n\tint nd;\n\t\n\t/* This will free any memory associated with a and\n\t use the string in setstate as the (writeable) memory.\n\t*/\n\tif (!PyArg_ParseTuple(args, \"(O!O!iO)\", &PyTuple_Type,\n\t\t\t &shape, &PyArrayDescr_Type, &typecode, \n\t\t\t &fortran, &rawdata))\n\t\treturn NULL;\n\n\tPy_XDECREF(self->descr);\n\tself->descr = typecode;\n\tPy_INCREF(typecode);\n\tnd = PyArray_IntpFromSequence(shape, dimensions, MAX_DIMS);\n\tif (typecode->type_num == PyArray_OBJECT) {\n\t\tif (!PyList_Check(rawdata)) {\n\t\t\tPyErr_SetString(PyExc_TypeError, \n\t\t\t\t\t\"object pickle not returning list\");\n\t\t\treturn NULL;\n\t\t}\n\t}\n\telse {\n\t\tif (!PyString_Check(rawdata)) {\n\t\t\tPyErr_SetString(PyExc_TypeError, \n\t\t\t\t\t\"pickle not returning string\");\n\t\t\treturn NULL;\n\t\t}\n\n\t\tif (PyString_AsStringAndSize(rawdata, &datastr, &len))\n\t\t\treturn NULL;\n\n\t\tif ((len != (self->descr->elsize *\t\t\t\\\n\t\t\t (int) PyArray_MultiplyList(dimensions, nd)))) {\n\t\t\tPyErr_SetString(PyExc_ValueError, \n\t\t\t\t\t\"buffer size does not\"\t\\\n\t\t\t\t\t\" match array size\");\n\t\t\treturn NULL;\n\t\t}\n\t}\n\n if ((self->flags & OWN_DATA)) {\n\t\tif (self->data != NULL)\n\t\t\tPyDataMem_FREE(self->data);\n\t\tself->flags &= ~OWN_DATA;\n }\n\tPy_XDECREF(self->base);\n\n\tself->flags &= ~UPDATEIFCOPY;\n\n if (self->dimensions != NULL) {\n PyDimMem_FREE(self->dimensions); \n\t\tself->dimensions = NULL;\n\t}\n\n\tself->flags = DEFAULT_FLAGS;\n\n\tself->nd = nd;\n\n\tif (nd > 0) {\n\t\tself->dimensions = PyDimMem_NEW(nd * 2);\n\t\tself->strides = self->dimensions + nd;\n\t\tmemcpy(self->dimensions, dimensions, sizeof(intp)*nd);\n\t\t(void) _array_fill_strides(self->strides, dimensions, nd,\n\t\t\t\t\t self->descr->elsize, fortran, \n\t\t\t\t\t &(self->flags));\n\t}\n\n\tif (typecode->type_num != PyArray_OBJECT) {\n\t\tself->data = datastr;\n\t\tif (!_IsAligned(self)) {\n\t\t\tintp num = PyArray_NBYTES(self);\n\t\t\tself->data = PyDataMem_NEW(num);\n\t\t\tif (self->data == NULL) {\n\t\t\t\tself->nd = 0;\n\t\t\t\tPyDimMem_FREE(self->dimensions);\n\t\t\t\treturn PyErr_NoMemory();\n\t\t\t}\n\t\t\tmemcpy(self->data, datastr, num);\n\t\t\tself->flags |= OWN_DATA;\n\t\t\tself->base = NULL;\n\t\t}\n\t\telse {\n\t\t\tself->base = rawdata;\n\t\t\tPy_INCREF(self->base);\n\t\t}\n\t}\n\telse {\n\t\tself->data = PyDataMem_NEW(PyArray_NBYTES(self));\n\t\tif (self->data == NULL) { \n\t\t\tself->nd = 0;\n\t\t\tself->data = PyDataMem_NEW(self->descr->elsize);\n\t\t\tif (self->dimensions) PyDimMem_FREE(self->dimensions);\n\t\t\treturn PyErr_NoMemory();\n\t\t}\n\t\tself->flags |= OWN_DATA;\n\t\tself->base = NULL;\n\t\tif (_setobject_pkl(self, rawdata) < 0) \n\t\t\treturn NULL;\n\t}\n\n\tPyArray_UpdateFlags(self, UPDATE_ALL_FLAGS);\n\t\n\tPy_INCREF(Py_None);\n\treturn Py_None;\t\n}\n\n/*OBJECT_API*/\nstatic int\nPyArray_Dump(PyObject *self, PyObject *file, int protocol)\n{\n\tPyObject *cpick=NULL;\n\tPyObject *ret;\n\tif (protocol < 0) protocol = 2;\n\n\tcpick = PyImport_ImportModule(\"cPickle\");\n\tif (cpick==NULL) return -1;\n\n\tif PyString_Check(file) {\n\t\tfile = PyFile_FromString(PyString_AS_STRING(file), \"wb\");\n\t\tif (file==NULL) return -1;\n\t}\n\telse Py_INCREF(file);\n\tret = PyObject_CallMethod(cpick, \"dump\", \"OOi\", self, \n\t\t\t\t file, protocol);\n\tPy_XDECREF(ret);\n\tPy_DECREF(file);\n\tPy_DECREF(cpick);\n\tif (PyErr_Occurred()) return -1;\n\treturn 0;\n}\n\n/*OBJECT_API*/\nstatic PyObject *\nPyArray_Dumps(PyObject *self, int protocol)\n{\n\tPyObject *cpick=NULL;\n\tPyObject *ret;\n\tif (protocol < 0) protocol = 2;\n\n\tcpick = PyImport_ImportModule(\"cPickle\");\n\tif (cpick==NULL) return NULL;\n\tret = PyObject_CallMethod(cpick, \"dumps\", \"Oi\", self, protocol);\n\tPy_DECREF(cpick);\n\treturn ret;\n}\n\n\nstatic char doc_dump[] = \"m.dump(file)\";\n\nstatic PyObject *\narray_dump(PyArrayObject *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((PyObject *)self, file, 2);\n\tif (ret < 0) return NULL;\n\tPy_INCREF(Py_None);\n\treturn Py_None;\n}\n\nstatic char doc_dumps[] = \"m.dumps()\";\n\nstatic PyObject *\narray_dumps(PyArrayObject *self, PyObject *args)\n{\n\tif (!PyArg_ParseTuple(args, \"\"))\n\t\treturn NULL;\n\treturn PyArray_Dumps((PyObject *)self, 2);\n}\n\n\nstatic char doc_transpose[] = \"m.transpose()\";\n\nstatic PyObject *\narray_transpose(PyArrayObject *self, PyObject *args) \n{\n\tPyObject *shape=Py_None;\n\tint n;\n\tPyArray_Dims permute;\n\tPyObject *ret;\n\n\tn = PyTuple_Size(args);\n\tif (n > 1) shape = args;\n\telse if (n == 1) shape = PyTuple_GET_ITEM(args, 0);\n\t\n\tif (shape == Py_None)\n\t\tret = PyArray_Transpose(self, NULL);\n\telse {\n\t\tif (!PyArray_IntpConverter(shape, &permute)) return NULL;\n\t\tret = PyArray_Transpose(self, &permute);\n\t\tPyDimMem_FREE(permute.ptr);\n\t}\n\t\n\treturn _ARET(ret);\n}\n\nstatic char doc_mean[] = \"a.mean(axis=None, dtype=None)\\n\\n\"\\\n \"Average the array over the given axis. If the axis is None, average\\n\"\\\n \"over all dimensions of the array.\\n\"\\\n \"\\n\"\\\n \"If an integer axis is given, this equals:\\n\"\\\n \" a.sum(axis, dtype) * 1.0 / len(a)\\n\"\\\n \"\\n\"\\\n \"If axis is None, this equals:\\n\"\\\n \" a.sum(axis, dtype) * 1.0 / product(a.shape)\\n\"\\\n \"\\n\"\\\n \"The optional dtype argument is the data type for intermediate\\n\"\\\n \"calculations in the sum.\";\n\n#define _CHKTYPENUM(typ) ((typ) ? (typ)->type_num : PyArray_NOTYPE)\n\nstatic PyObject *\narray_mean(PyArrayObject *self, PyObject *args, PyObject *kwds) \n{\n\tint axis=MAX_DIMS;\n\tPyArray_Descr *dtype=NULL;\n\tstatic char *kwlist[] = {\"axis\", \"dtype\", NULL};\n\t\n\tif (!PyArg_ParseTupleAndKeywords(args, kwds, \"|O&O&\", kwlist,\n\t\t\t\t\t PyArray_AxisConverter, \n\t\t\t\t\t &axis, PyArray_DescrConverter2,\n\t\t\t\t\t &dtype)) return NULL;\n\n\treturn PyArray_Mean(self, axis, _CHKTYPENUM(dtype));\n}\n\nstatic char doc_sum[] = \"a.sum(axis=None, dtype=None)\\n\\n\"\\\n \"Sum the array over the given axis. If the axis is None, sum over all\\n\"\\\n \"dimensions of the array.\\n\"\\\n \"\\n\"\\\n \"The optional dtype argument is the data type for the returned value\\n\"\\\n \"and intermediate calculations. The default is to upcast (promote)\\n\"\\\n \"smaller integer types to the platform-dependent int. For example, on\\n\"\\\n \"32-bit platforms:\\n\"\\\n \"\\n\"\\\n \" a.dtype default sum() dtype\\n\"\\\n \" ---------------------------------------------------\\n\"\\\n \" bool, int8, int16, int32 int32\\n\"\\\n \"\\n\"\\\n \"Examples:\\n\"\\\n \"\\n\"\\\n \">>> array([0.5, 1.5]).sum()\\n\"\\\n \"2.0\\n\"\\\n \">>> array([0.5, 1.5]).sum(dtype=int32)\\n\"\\\n \"1\\n\"\\\n \">>> array([[0, 1], [0, 5]]).sum()\\n\"\\\n \"array([0, 6])\\n\"\\\n \">>> array([[0, 1], [0, 5]]).sum(axis=1)\\n\"\\\n \"array([1, 5])\";\n\nstatic PyObject *\narray_sum(PyArrayObject *self, PyObject *args, PyObject *kwds) \n{\n\tint axis=MAX_DIMS;\n\tPyArray_Descr *dtype=NULL;\n\tstatic char *kwlist[] = {\"axis\", \"dtype\", NULL};\n\n\tif (!PyArg_ParseTupleAndKeywords(args, kwds, \"|O&O&\", kwlist, \n\t\t\t\t\t PyArray_AxisConverter, \n\t\t\t\t\t &axis, PyArray_DescrConverter2,\n\t\t\t\t\t &dtype)) return NULL;\n\t\n\treturn PyArray_Sum(self, axis, _CHKTYPENUM(dtype));\n}\n\n\nstatic char doc_cumsum[] = \"a.cumsum(axis=None, dtype=None)\";\n\nstatic PyObject *\narray_cumsum(PyArrayObject *self, PyObject *args, PyObject *kwds) \n{\n\tint axis=MAX_DIMS;\n\tPyArray_Descr *dtype=NULL;\n\tstatic char *kwlist[] = {\"axis\", \"dtype\", NULL};\n\t\n\tif (!PyArg_ParseTupleAndKeywords(args, kwds, \"|O&O&\", kwlist, \n\t\t\t\t\t PyArray_AxisConverter, \n\t\t\t\t\t &axis, PyArray_DescrConverter2,\n\t\t\t\t\t &dtype)) return NULL;\n\t\n\treturn PyArray_CumSum(self, axis, _CHKTYPENUM(dtype));\n}\n\nstatic char doc_prod[] = \"a.prod(axis=None, dtype=None)\";\n\nstatic PyObject *\narray_prod(PyArrayObject *self, PyObject *args, PyObject *kwds) \n{\n\tint axis=MAX_DIMS;\n\tPyArray_Descr *dtype=NULL;\n\tstatic char *kwlist[] = {\"axis\", \"dtype\", NULL};\n\t\n\tif (!PyArg_ParseTupleAndKeywords(args, kwds, \"|O&O&\", kwlist, \n\t\t\t\t\t PyArray_AxisConverter, \n\t\t\t\t\t &axis, PyArray_DescrConverter2,\n\t\t\t\t\t &dtype)) return NULL;\n\t\n\treturn PyArray_Prod(self, axis, _CHKTYPENUM(dtype));\n}\n\n\nstatic char doc_cumprod[] = \"a.cumprod(axis=None, dtype=None)\";\n\nstatic PyObject *\narray_cumprod(PyArrayObject *self, PyObject *args, PyObject *kwds) \n{\n\tint axis=MAX_DIMS;\n\tPyArray_Descr *dtype=NULL;\n\tstatic char *kwlist[] = {\"axis\", \"dtype\", NULL};\n\t\n\tif (!PyArg_ParseTupleAndKeywords(args, kwds, \"|O&O&\", kwlist, \n\t\t\t\t\t PyArray_AxisConverter, \n\t\t\t\t\t &axis, PyArray_DescrConverter2,\n\t\t\t\t\t &dtype)) return NULL;\n\t\n\treturn PyArray_CumProd(self, axis, _CHKTYPENUM(dtype));\n}\n\n\nstatic char doc_any[] = \"a.any(axis=None)\";\n\nstatic PyObject *\narray_any(PyArrayObject *self, PyObject *args) \n{\n\tint axis=MAX_DIMS;\n\t\n\tif (!PyArg_ParseTuple(args, \"|O&\", PyArray_AxisConverter, \n\t\t\t &axis)) return NULL;\n\t\n\treturn PyArray_Any(self, axis);\n}\n\nstatic char doc_all[] = \"a.all(axis=None)\";\n\nstatic PyObject *\narray_all(PyArrayObject *self, PyObject *args) \n{\n\tint axis=MAX_DIMS;\n\t\n\tif (!PyArg_ParseTuple(args, \"|O&\", PyArray_AxisConverter, \n\t\t\t &axis)) return NULL;\n\t\n\treturn PyArray_All(self, axis);\n}\n\nstatic char doc_stddev[] = \"a.std(axis=None, dtype=None)\";\n\nstatic PyObject *\narray_stddev(PyArrayObject *self, PyObject *args, PyObject *kwds) \n{\n\tint axis=MAX_DIMS;\n\tPyArray_Descr *dtype=NULL;\n\tstatic char *kwlist[] = {\"axis\", \"dtype\", NULL};\n\t\n\tif (!PyArg_ParseTupleAndKeywords(args, kwds, \"|O&O&\", kwlist, \n\t\t\t\t\t PyArray_AxisConverter, \n\t\t\t\t\t &axis, PyArray_DescrConverter2,\n\t\t\t\t\t &dtype)) return NULL;\n\t\n\treturn PyArray_Std(self, axis, _CHKTYPENUM(dtype), 0);\n}\n\nstatic char doc_variance[] = \"a.var(axis=None, dtype=None)\";\n\nstatic PyObject *\narray_variance(PyArrayObject *self, PyObject *args, PyObject *kwds) \n{\n\tint axis=MAX_DIMS;\n\tPyArray_Descr *dtype=NULL;\n\tstatic char *kwlist[] = {\"axis\", \"dtype\", NULL};\n\t\n\tif (!PyArg_ParseTupleAndKeywords(args, kwds, \"|O&O&\", kwlist, \n\t\t\t\t\t PyArray_AxisConverter, \n\t\t\t\t\t &axis, PyArray_DescrConverter2,\n\t\t\t\t\t &dtype)) return NULL;\n\t\n\treturn PyArray_Std(self, axis, _CHKTYPENUM(dtype), 1);\n}\n\nstatic char doc_compress[] = \"a.compress(condition=, axis=None)\";\n\nstatic PyObject *\narray_compress(PyArrayObject *self, PyObject *args, PyObject *kwds) \n{\n\tint axis=MAX_DIMS;\n\tPyObject *condition;\t\n\tstatic char *kwlist[] = {\"condition\", \"axis\", NULL};\n\t\n\tif (!PyArg_ParseTupleAndKeywords(args, kwds, \"O|O&\", kwlist, \n\t\t\t\t\t &condition, PyArray_AxisConverter,\n\t\t\t\t\t &axis)) return NULL;\n\n\treturn _ARET(PyArray_Compress(self, condition, axis));\n}\n\nstatic char doc_nonzero[] = \"a.nonzero() return a tuple of indices referencing\"\\\n\t\"the elements of a that are nonzero.\";\n\nstatic PyObject *\narray_nonzero(PyArrayObject *self, PyObject *args)\n{\n\tif (!PyArg_ParseTuple(args, \"\")) return NULL;\n\n\treturn _ARET(PyArray_Nonzero(self));\n}\n\n\nstatic char doc_trace[] = \"a.trace(offset=0, axis1=0, axis2=1, dtype=None) \\n\"\\\n\t\"return the sum along the offset diagonal of the arrays indicated\\n\" \\\n\t\"axis1 and axis2.\";\n\nstatic PyObject *\narray_trace(PyArrayObject *self, PyObject *args, PyObject *kwds) \n{\n\tint axis1=0, axis2=1, offset=0;\n\tPyArray_Descr *dtype=NULL;\n\tstatic char *kwlist[] = {\"offset\", \"axis1\", \"axis2\", \"dtype\", NULL};\n\t\n\tif (!PyArg_ParseTupleAndKeywords(args, kwds, \"|iiiO&\", kwlist, \n\t\t\t\t\t &offset, &axis1, &axis2,\n\t\t\t\t\t PyArray_DescrConverter2, &dtype))\n\t\treturn NULL;\n\t\n\treturn _ARET(PyArray_Trace(self, offset, axis1, axis2, \n\t\t\t\t _CHKTYPENUM(dtype)));\n}\n\n#undef _CHKTYPENUM\n\n\nstatic char doc_clip[] = \"a.clip(min=, max=)\";\n\nstatic PyObject *\narray_clip(PyArrayObject *self, PyObject *args, PyObject *kwds) \n{\n\tPyObject *min, *max;\n\tstatic char *kwlist[] = {\"min\", \"max\", NULL};\n\n\tif (!PyArg_ParseTupleAndKeywords(args, kwds, \"OO\", kwlist,\n\t\t\t\t\t &min, &max)) \n\t\treturn NULL;\n\t\n\treturn _ARET(PyArray_Clip(self, min, max));\n}\n\nstatic char doc_conj[] = \"a.conj()\";\n\nstatic char doc_conjugate[] = \"a.conjugate()\";\n\nstatic PyObject *\narray_conjugate(PyArrayObject *self, PyObject *args) \n{\n\n\tif (!PyArg_ParseTuple(args, \"\")) return NULL;\n\t\n\treturn PyArray_Conjugate(self);\n}\n\n\nstatic char doc_diagonal[] = \"a.diagonal(offset=0, axis1=0, axis2=1)\";\n\nstatic PyObject *\narray_diagonal(PyArrayObject *self, PyObject *args, PyObject *kwds) \n{\n\tint axis1=0, axis2=1, offset=0;\n\tstatic char *kwlist[] = {\"offset\", \"axis1\", \"axis2\", NULL};\n\t\n\tif (!PyArg_ParseTupleAndKeywords(args, kwds, \"|iii\", kwlist, \n\t\t\t\t\t &offset, &axis1, &axis2))\n\t\treturn NULL;\n\t\n\treturn _ARET(PyArray_Diagonal(self, offset, axis1, axis2));\n}\n\nstatic char doc_flatten[] = \"a.flatten([fortran]) return a 1-d array (always copy)\";\n\nstatic PyObject *\narray_flatten(PyArrayObject *self, PyObject *args)\n{\n\tint fortran=0;\n\n\tif (!PyArg_ParseTuple(args, \"|i\", &fortran)) return NULL;\n \n\treturn PyArray_Flatten(self, (int) fortran);\n}\n\nstatic char doc_ravel[] = \"a.ravel([fortran]) return a 1-d array (copy only if needed)\";\n\nstatic PyObject *\narray_ravel(PyArrayObject *self, PyObject *args)\n{\n\tint fortran=0;\n\n\tif (!PyArg_ParseTuple(args, \"|i\", &fortran)) return NULL;\n\n\treturn PyArray_Ravel(self, fortran);\n}\n\n\n\nstatic char doc_setflags[] = \"a.setflags(write=None, align=None, uic=None)\";\n\nstatic int _IsAligned(PyArrayObject *);\nstatic Bool _IsWriteable(PyArrayObject *);\n\nstatic PyObject *\narray_setflags(PyArrayObject *self, PyObject *args, PyObject *kwds)\n{\n\tstatic char *kwlist[] = {\"write\", \"align\", \"uic\", NULL};\n\tPyObject *write=Py_None;\n\tPyObject *align=Py_None;\n\tPyObject *uic=Py_None;\n\tint flagback = self->flags;\n\t\t\n\tif (!PyArg_ParseTupleAndKeywords(args, kwds, \"|OOO\", kwlist,\n\t\t\t\t\t &write, &align, &uic))\n\t\treturn NULL;\n\n\tif (align != Py_None) {\n\t\tif (PyObject_Not(align)) self->flags &= ~ALIGNED;\n\t\telse if (_IsAligned(self)) self->flags |= ALIGNED;\n\t\telse {\n\t\t\tPyErr_SetString(PyExc_ValueError, \n\t\t\t\t\t\"cannot set aligned flag of mis-\"\\\n\t\t\t\t\t\"aligned array to True\");\n\t\t\treturn NULL;\n\t\t}\n\t}\n\t\n\tif (uic != Py_None) {\n if (PyObject_IsTrue(uic)) {\n\t\t\tself->flags = flagback;\n PyErr_SetString(PyExc_ValueError, \n \"cannot set UPDATEIFCOPY\" \\\n \"flag to True\");\n return NULL;\n }\n else {\n self->flags &= ~UPDATEIFCOPY;\n Py_DECREF(self->base);\n self->base = NULL;\n }\n }\n \n if (write != Py_None) {\n if (PyObject_IsTrue(write)) \n\t\t\tif (_IsWriteable(self)) {\n\t\t\t\tself->flags |= WRITEABLE;\n\t\t\t}\n\t\t\telse {\n\t\t\t\tself->flags = flagback;\n\t\t\t\tPyErr_SetString(PyExc_ValueError, \n\t\t\t\t\t\t\"cannot set WRITEABLE \"\t\\\n\t\t\t\t\t\t\"flag to True of this \"\t\\\n\t\t\t\t\t\t\"array\");\t\t\\\n\t\t\t\treturn NULL;\n\t\t\t}\n else\n self->flags &= ~WRITEABLE;\n }\n \n Py_INCREF(Py_None);\n return Py_None;\n}\n\nstatic char doc_newbyteorder[] = \"a.newbyteorder() is equivalent\\n\" \\\n\t\" to a.view(a.dtype.newbytorder())\\n\";\n\nstatic PyObject *\narray_newbyteorder(PyArrayObject *self, PyObject *args) \n{\n\tchar endian = PyArray_SWAP;\n\tPyArray_Descr *new;\n\t\n\tif (!PyArg_ParseTuple(args, \"|O&\", PyArray_ByteorderConverter,\n\t\t\t &endian)) return NULL;\n\n\tnew = PyArray_DescrNewByteorder(self->descr, endian);\n\tif (!new) return NULL;\n\treturn PyArray_View(self, new, NULL);\n\n}\n\nstatic PyMethodDef array_methods[] = {\n {\"tolist\",\t (PyCFunction)array_tolist,\t1, doc_tolist},\n {\"item\", (PyCFunction)array_toscalar, METH_VARARGS, doc_toscalar},\n\t{\"tofile\", (PyCFunction)array_tofile, \n METH_VARARGS | METH_KEYWORDS, doc_tofile},\n {\"tostring\", (PyCFunction)array_tostring, METH_VARARGS, doc_tostring},\n {\"byteswap\", (PyCFunction)array_byteswap,\t1, doc_byteswap},\n {\"astype\", (PyCFunction)array_cast, 1, doc_cast},\n\t{\"getfield\", (PyCFunction)array_getfield, \n\t METH_VARARGS | METH_KEYWORDS, doc_getfield},\n\t{\"setfield\", (PyCFunction)array_setfield, \n\t METH_VARARGS | METH_KEYWORDS, doc_setfield},\n {\"copy\", (PyCFunction)array_copy, 1, doc_copy}, \n {\"resize\", (PyCFunction)array_resize, 1, doc_resize}, \n\n\t/* for subtypes */\n\t{\"__array__\", (PyCFunction)array_getarray, 1, doc_array_getarray},\n\t{\"__array_wrap__\", (PyCFunction)array_wraparray, 1, doc_wraparray},\n\t/* default version so it is found... -- only used for subclasses */\n\t{\"__array_finalize__\", (PyCFunction)array_finalize, 1, NULL},\n\t\n\t\n\t/* for the copy module */\n {\"__copy__\", (PyCFunction)array_copy, 1, doc_copy},\t \n {\"__deepcopy__\", (PyCFunction)array_deepcopy, 1, doc_deepcopy}, \n\t\n /* for Pickling */\n {\"__reduce__\", (PyCFunction) array_reduce, 1, doc_reduce},\t\n\t{\"__setstate__\", (PyCFunction) array_setstate, 1, doc_setstate},\n\t{\"dumps\", (PyCFunction) array_dumps, 1, doc_dumps},\n\t{\"dump\", (PyCFunction) array_dump, 1, doc_dump},\n\n\t/* Extended methods added 2005 */\n\t{\"fill\", (PyCFunction)array_fill,\n\t METH_VARARGS, doc_fill},\n\t{\"transpose\",\t(PyCFunction)array_transpose, \n\t METH_VARARGS, doc_transpose},\n\t{\"take\",\t(PyCFunction)array_take, \n\t METH_VARARGS|METH_KEYWORDS, doc_take},\n\t{\"put\",\t(PyCFunction)array_put, \n\t METH_VARARGS|METH_KEYWORDS, doc_put},\n\t{\"putmask\",\t(PyCFunction)array_putmask, \n\t METH_VARARGS|METH_KEYWORDS, doc_putmask},\n\t{\"repeat\",\t(PyCFunction)array_repeat, \n\t METH_VARARGS|METH_KEYWORDS, doc_repeat},\n\t{\"choose\",\t(PyCFunction)array_choose, \n\t METH_VARARGS, doc_choose},\t\n\t{\"sort\",\t(PyCFunction)array_sort, \n\t METH_VARARGS|METH_KEYWORDS, doc_sort},\n\t{\"argsort\",\t(PyCFunction)array_argsort, \n\t METH_VARARGS|METH_KEYWORDS, doc_argsort},\n\t{\"searchsorted\", (PyCFunction)array_searchsorted, \n\t METH_VARARGS, doc_searchsorted},\t\n\t{\"argmax\",\t(PyCFunction)array_argmax, \n\t METH_VARARGS, doc_argmax},\n\t{\"argmin\", (PyCFunction)array_argmin,\n\t METH_VARARGS, doc_argmin},\n\t{\"reshape\",\t(PyCFunction)array_reshape, \n\t METH_VARARGS, doc_reshape},\n\t{\"squeeze\",\t(PyCFunction)array_squeeze,\n\t METH_VARARGS, doc_squeeze},\n\t{\"view\", (PyCFunction)array_view, \n\t METH_VARARGS, doc_view},\n\t{\"swapaxes\", (PyCFunction)array_swapaxes,\n\t METH_VARARGS, doc_swapaxes},\n\t{\"max\", (PyCFunction)array_max,\n\t METH_VARARGS, doc_max},\n\t{\"min\", (PyCFunction)array_min,\n\t METH_VARARGS, doc_min},\n\t{\"ptp\", (PyCFunction)array_ptp,\n\t METH_VARARGS, doc_ptp},\n\t{\"mean\", (PyCFunction)array_mean,\n\t METH_VARARGS|METH_KEYWORDS, doc_mean},\n\t{\"trace\", (PyCFunction)array_trace,\n\t METH_VARARGS|METH_KEYWORDS, doc_trace},\n\t{\"diagonal\", (PyCFunction)array_diagonal,\n\t METH_VARARGS|METH_KEYWORDS, doc_diagonal},\n\t{\"clip\", (PyCFunction)array_clip,\n\t METH_VARARGS|METH_KEYWORDS, doc_clip},\n\t{\"conj\", (PyCFunction)array_conjugate,\n\t METH_VARARGS, doc_conj},\n\t{\"conjugate\", (PyCFunction)array_conjugate,\n\t METH_VARARGS, doc_conjugate},\n\t{\"nonzero\", (PyCFunction)array_nonzero,\n\t METH_VARARGS, doc_nonzero},\n\t{\"std\", (PyCFunction)array_stddev,\n\t METH_VARARGS|METH_KEYWORDS, doc_stddev},\n\t{\"var\", (PyCFunction)array_variance,\n\t METH_VARARGS|METH_KEYWORDS, doc_variance},\n\t{\"sum\", (PyCFunction)array_sum,\n\t METH_VARARGS|METH_KEYWORDS, doc_sum},\n\t{\"cumsum\", (PyCFunction)array_cumsum,\n\t METH_VARARGS|METH_KEYWORDS, doc_cumsum},\n\t{\"prod\", (PyCFunction)array_prod,\n\t METH_VARARGS|METH_KEYWORDS, doc_prod},\n\t{\"cumprod\", (PyCFunction)array_cumprod,\n\t METH_VARARGS|METH_KEYWORDS, doc_cumprod},\n\t{\"all\", (PyCFunction)array_all,\n\t METH_VARARGS, doc_all},\n\t{\"any\", (PyCFunction)array_any,\n\t METH_VARARGS, doc_any},\n\t{\"compress\", (PyCFunction)array_compress,\n\t METH_VARARGS|METH_KEYWORDS, doc_compress},\n\t{\"flatten\", (PyCFunction)array_flatten,\n\t METH_VARARGS, doc_flatten},\n\t{\"ravel\", (PyCFunction)array_ravel,\n\t METH_VARARGS, doc_ravel},\n\t{\"setflags\", (PyCFunction)array_setflags,\n\t METH_VARARGS|METH_KEYWORDS, doc_setflags},\n\t{\"newbyteorder\", (PyCFunction)array_newbyteorder,\n\t METH_VARARGS, doc_newbyteorder},\n {NULL,\t\tNULL}\t\t/* sentinel */\n};\n\n#undef _ARET\n\n\n", + "source_code_before": "\n/* Should only be used if x is known to be an nd-array */\n#define _ARET(x) PyArray_Return((PyArrayObject *)(x))\n\nstatic char doc_take[] = \"a.take(indices, axis=None). Selects the elements \"\\\n\t\"in indices from array a along the given axis.\";\n\nstatic PyObject *\narray_take(PyArrayObject *self, PyObject *args, PyObject *kwds) \n{\n\tint dimension=MAX_DIMS;\n\tPyObject *indices;\n\tstatic char *kwlist[] = {\"indices\", \"axis\", NULL};\n\t\n\tdimension=0;\n\tif (!PyArg_ParseTupleAndKeywords(args, kwds, \"O|O&\", kwlist, \n\t\t\t\t\t &indices, PyArray_AxisConverter,\n\t\t\t\t\t &dimension))\n\t\treturn NULL;\n\t\n\treturn _ARET(PyArray_Take(self, indices, dimension));\n}\n\nstatic char doc_fill[] = \"a.fill(value) places the scalar value at every\"\\\n\t\"position in the array.\";\n\nstatic PyObject *\narray_fill(PyArrayObject *self, PyObject *args)\n{\n\tPyObject *obj;\n\tif (!PyArg_ParseTuple(args, \"O\", &obj))\n\t\treturn NULL;\n\tif (PyArray_FillWithScalar(self, obj) < 0) return NULL;\n\tPy_INCREF(Py_None);\n\treturn Py_None;\n}\n\nstatic char doc_put[] = \"a.put(values, indices) sets a.flat[n] = v[n] \"\\\n\t\"for each n in indices. v can be scalar or shorter than indices, \"\\\n\t\"will repeat.\";\n\nstatic PyObject *\narray_put(PyArrayObject *self, PyObject *args, PyObject *kwds) \n{\n\tPyObject *indices, *values;\n\tstatic char *kwlist[] = {\"values\", \"indices\", NULL};\n\t\n\tif (!PyArg_ParseTupleAndKeywords(args, kwds, \"OO\", kwlist,\n\t\t\t\t\t &values, &indices))\n\t\treturn NULL;\n\treturn PyArray_Put(self, values, indices);\n}\n\nstatic char doc_putmask[] = \"a.putmask(values, mask) sets a.flat[n] = v[n] \"\\\n\t\"for each n where mask.flat[n] is TRUE. v can be scalar.\";\n\nstatic PyObject *\narray_putmask(PyArrayObject *self, PyObject *args, PyObject *kwds) \n{\n\tPyObject *mask, *values;\n\n\tstatic char *kwlist[] = {\"values\", \"mask\", NULL};\n\t\n\tif (!PyArg_ParseTupleAndKeywords(args, kwds, \"OO\", kwlist,\n\t\t\t\t\t &values, &mask))\n\t\treturn NULL;\n\treturn PyArray_PutMask(self, values, mask);\n}\n\n/* Used to reshape a Fortran Array */\nstatic void\n_reverse_shape(PyArray_Dims *newshape)\n{\n\tint i, n = newshape->len;\n\tintp *ptr = newshape->ptr;\n\tintp *eptr;\n\tintp tmp;\n\tint len = n >> 1;\n\n\teptr = ptr+n-1;\n\tfor(i=0; i) return a new view of array with same data. type can be either a new sub-type object or a data-descriptor object\";\n\nstatic PyObject *\narray_view(PyArrayObject *self, PyObject *args)\n{\n\tPyObject *otype=NULL;\n PyArray_Descr *type=NULL;\n\n\tif (!PyArg_ParseTuple(args, \"|O\", &otype)) return NULL;\n\n\tif (otype) {\n\t\tif (PyType_Check(otype) &&\t\t\t\t\\\n\t\t PyType_IsSubtype((PyTypeObject *)otype, \n\t\t\t\t &PyBigArray_Type)) {\n\t\t\treturn PyArray_View(self, NULL, \n (PyTypeObject *)otype);\n }\n\t\telse {\n\t\t\tif (PyArray_DescrConverter(otype, &type) == PY_FAIL) \n\t\t\t\treturn NULL;\n\t\t}\n\t}\n\treturn PyArray_View(self, type, NULL);\n}\n\nstatic char doc_argmax[] = \"a.argmax(axis=None)\";\n\nstatic PyObject *\narray_argmax(PyArrayObject *self, PyObject *args) \n{\n\tint axis=MAX_DIMS;\n\t\n\tif (!PyArg_ParseTuple(args, \"|O&\", PyArray_AxisConverter, \n\t\t\t &axis)) return NULL;\n\t\n\treturn _ARET(PyArray_ArgMax(self, axis));\n}\n\nstatic char doc_argmin[] = \"a.argmin(axis=None)\";\n\nstatic PyObject *\narray_argmin(PyArrayObject *self, PyObject *args) \n{\n\tint axis=MAX_DIMS;\n\t\n\tif (!PyArg_ParseTuple(args, \"|O&\", PyArray_AxisConverter, \n\t\t\t &axis)) return NULL;\n\t\n\treturn _ARET(PyArray_ArgMin(self, axis));\n}\n\nstatic char doc_max[] = \"a.max(axis=None)\";\n\nstatic PyObject *\narray_max(PyArrayObject *self, PyObject *args) \n{\n\tint axis=MAX_DIMS;\n\t\n\tif (!PyArg_ParseTuple(args, \"|O&\", PyArray_AxisConverter, \n\t\t\t &axis)) return NULL;\n\t\n\treturn PyArray_Max(self, axis);\n}\n\nstatic char doc_ptp[] = \"a.ptp(axis=None) a.max(axis)-a.min(axis)\";\n\nstatic PyObject *\narray_ptp(PyArrayObject *self, PyObject *args) \n{\n\tint axis=MAX_DIMS;\n\t\n\tif (!PyArg_ParseTuple(args, \"|O&\", PyArray_AxisConverter, \n\t\t\t &axis)) return NULL;\n\t\n\treturn PyArray_Ptp(self, axis);\n}\n\n\nstatic char doc_min[] = \"a.min(axis=None)\";\n\nstatic PyObject *\narray_min(PyArrayObject *self, PyObject *args) \n{\n\tint axis=MAX_DIMS;\n\t\n\tif (!PyArg_ParseTuple(args, \"|O&\", PyArray_AxisConverter, \n\t\t\t &axis)) return NULL;\n\t\n\treturn PyArray_Min(self, axis);\n}\n\n\nstatic char doc_swapaxes[] = \"a.swapaxes(axis1, axis2) returns new view with axes swapped.\";\n\nstatic PyObject *\narray_swapaxes(PyArrayObject *self, PyObject *args)\n{\n\tint axis1, axis2;\n\n\tif (!PyArg_ParseTuple(args, \"ii\", &axis1, &axis2)) return NULL;\n\n\treturn PyArray_SwapAxes(self, axis1, axis2);\n}\n\nstatic char doc_getfield[] = \"m.getfield(dtype, offset) returns a field \"\\\n\t\" of the given array as a certain type. A field is a view of \"\\\n\t\" the array's data with each itemsize determined by the given type\"\\\n\t\" and the offset into the current array.\";\n\n/* steals typed reference */\n/*OBJECT_API\n Get a subset of bytes from each element of the array\n*/\nstatic PyObject *\nPyArray_GetField(PyArrayObject *self, PyArray_Descr *typed, int offset)\n{\n\tPyObject *ret=NULL;\n\n\tif (offset < 0 || (offset + typed->elsize) > self->descr->elsize) {\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 self->descr->elsize-typed->elsize, offset);\n\t\tPy_DECREF(typed);\n\t\treturn NULL;\n\t}\n\tret = PyArray_NewFromDescr(self->ob_type, \n\t\t\t\t typed,\n\t\t\t\t self->nd, self->dimensions,\n\t\t\t\t self->strides, \n\t\t\t\t self->data + offset,\n\t\t\t\t self->flags, (PyObject *)self);\n\tif (ret == NULL) return NULL;\n\tPy_INCREF(self);\n\t((PyArrayObject *)ret)->base = (PyObject *)self; \n\n\tPyArray_UpdateFlags((PyArrayObject *)ret, UPDATE_ALL_FLAGS);\n\treturn ret;\n}\n\nstatic PyObject *\narray_getfield(PyArrayObject *self, PyObject *args, PyObject *kwds)\n{\n\n PyArray_Descr *dtype;\n\tint offset = 0;\n\tstatic char *kwlist[] = {\"dtype\", \"offset\", 0};\n\t\n\tif (!PyArg_ParseTupleAndKeywords(args, kwds, \"O&|i\", kwlist,\n\t\t\t\t\t PyArray_DescrConverter,\n\t\t\t\t\t &dtype, &offset)) return NULL;\n\t\n\treturn _ARET(PyArray_GetField(self, dtype, offset));\n}\n\n\nstatic char doc_setfield[] = \"m.setfield(value, dtype, offset) places val \"\\\n\t\"into field of the given array defined by the data type and offset.\";\n\n/*OBJECT_API\n Set a subset of bytes from each element of the array\n*/\nstatic int\nPyArray_SetField(PyArrayObject *self, PyArray_Descr *dtype,\n\t\t int offset, PyObject *val)\n{\n\tPyObject *ret=NULL;\n\tint retval = 0;\n \n\tif (offset < 0 || (offset + dtype->elsize) > self->descr->elsize) {\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 self->descr->elsize-dtype->elsize, offset);\n\t\tPy_DECREF(dtype);\n\t\treturn -1;\n\t}\n\tret = PyArray_NewFromDescr(self->ob_type, \n\t\t\t\t dtype, self->nd, self->dimensions,\n\t\t\t\t self->strides, self->data + offset,\n\t\t\t\t self->flags, (PyObject *)self);\n\tif (ret == NULL) return -1;\n\tPy_INCREF(self);\n\t((PyArrayObject *)ret)->base = (PyObject *)self;\n\n\tPyArray_UpdateFlags((PyArrayObject *)ret, UPDATE_ALL_FLAGS);\t\n\tretval = PyArray_CopyObject((PyArrayObject *)ret, val);\n\tPy_DECREF(ret);\n\treturn retval;\n}\n\nstatic PyObject *\narray_setfield(PyArrayObject *self, PyObject *args, PyObject *kwds)\n{\n PyArray_Descr *dtype;\n\tint offset = 0;\n\tPyObject *value;\n\tstatic char *kwlist[] = {\"value\", \"dtype\", \"offset\", 0};\n\t\n\tif (!PyArg_ParseTupleAndKeywords(args, kwds, \"OO&|i\", kwlist,\n\t\t\t\t\t &value, PyArray_DescrConverter,\n\t\t\t\t\t &dtype, &offset)) return NULL;\n\n\tif (PyArray_SetField(self, dtype, offset, value) < 0)\n\t\treturn NULL;\n\tPy_INCREF(Py_None);\n\treturn Py_None;\n}\n\n/* This doesn't change the descriptor just the actual data...\n */\n\n/*OBJECT_API*/\nstatic PyObject *\nPyArray_Byteswap(PyArrayObject *self, Bool inplace)\n{\n PyArrayObject *ret;\n\tintp size;\n\tPyArray_CopySwapNFunc *copyswapn;\n\tPyArray_CopySwapFunc *copyswap;\n\tPyArrayIterObject *it;\n\n\tif (inplace) {\n\t\tcopyswapn = self->descr->f->copyswapn;\n\t\t\n\t\tsize = PyArray_SIZE(self);\n\t\tif (PyArray_ISONESEGMENT(self)) {\n\t\t\tcopyswapn(self->data, NULL, size, 1, \n\t\t\t\t self->descr->elsize);\n\t\t}\n\t\telse { /* Use iterator */\n\t\t\t\n\t\t\tit = (PyArrayIterObject *)\\\n\t\t\t\tPyArray_IterNew((PyObject *)self);\n\t\t\tcopyswap = self->descr->f->copyswap;\n\t\t\twhile (it->index < it->size) {\n\t\t\t\tcopyswap(it->dataptr, NULL, 1, \n\t\t\t\t\t self->descr->elsize);\n\t\t\t\tPyArray_ITER_NEXT(it);\n\t\t\t}\n\t\t\tPy_DECREF(it);\n\t\t}\n\t\t\n\t\tPy_INCREF(self);\n\t\treturn (PyObject *)self;\n\t}\n\telse {\n\t\tif ((ret = (PyArrayObject *)PyArray_NewCopy(self,-1)) == NULL) \n\t\t\treturn NULL;\n\t\t\n\t\tsize = PyArray_SIZE(self);\n\n\t\t/* now ret has the same dtypedescr as self (including\n\t\t byteorder)\n\t\t*/\n\n\t\tret->descr->f->copyswapn(ret->data, NULL, size, 1, \n\t\t\t\t\t ret->descr->elsize);\n\n\t\treturn (PyObject *)ret;\n\t}\n}\n\nstatic char doc_byteswap[] = \"m.byteswap(False) Swap the bytes in\"\\\n\t\" the array. Return the byteswapped array. If the first argument\"\\\n\t\" is TRUE, byteswap in-place and return a reference to self.\";\n\nstatic PyObject *\narray_byteswap(PyArrayObject *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\treturn PyArray_Byteswap(self, inplace);\n}\n\nstatic char doc_tolist[] = \"m.tolist().\t Copy the data portion of the array\"\\\n\t\" to a hierarchical python list and return that list.\";\n\nstatic PyObject *\narray_tolist(PyArrayObject *self, PyObject *args) \n{\n if (!PyArg_ParseTuple(args, \"\")) return NULL;\n if (self->nd <= 0) {\n PyErr_SetString(PyExc_ValueError, \n\t\t\t\t\"can't convert a 0-d array to a list\");\n return NULL;\n }\n\t\n return PyArray_ToList(self);\n}\n\nstatic char doc_tostring[] = \"m.tostring() Construct a Python string \"\\\n \"containing the raw bytes in the array\";\n\nstatic PyObject *\narray_tostring(PyArrayObject *self, PyObject *args)\n{\n if (!PyArg_ParseTuple(args, \"\")) return NULL;\n return PyArray_ToString(self);\n}\n\nstatic char doc_tofile[] = \"m.tofile(fid, sep=\"\") write the data to a file.\";\n\nstatic PyObject *\narray_tofile(PyArrayObject *self, PyObject *args, PyObject *kwds)\n{\n\tint ret;\n PyObject *file;\n\tFILE *fd;\n char *sep=\"\";\n\tchar *format=\"\";\n\tchar *mode=\"\";\n\tstatic char *kwlist[] = {\"file\", \"sep\", \"format\", NULL};\n \n\tif (!PyArg_ParseTupleAndKeywords(args, kwds, \"O|ss\", kwlist, \n &file, &sep, &format)) return NULL;\n\n\tif (PyString_Check(file)) {\n\t\tif (sep == \"\") mode=\"wb\";\n\t\telse mode=\"w\";\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\tfd = PyFile_AsFile(file);\n\tif (fd == NULL) {\n\t\tPyErr_SetString(PyExc_IOError, \"first argument must be a \" \\\n\t\t\t\t\"string or open file\");\n\t\tPy_DECREF(file);\n\t\treturn NULL;\n\t}\n\tret = PyArray_ToFile(self, fd, sep, format);\n\tPy_DECREF(file);\n\tif (ret < 0) return NULL;\n Py_INCREF(Py_None);\n return Py_None;\n}\n\nstatic char doc_toscalar[] = \"m.item(). Copy the first data point of \"\\\n\t\"the array to a standard Python scalar and return it.\";\n\nstatic PyObject *\narray_toscalar(PyArrayObject *self, PyObject *args) {\n if (!PyArg_ParseTuple(args, \"\")) return NULL;\n\tif (self->nd == 0 || PyArray_SIZE(self) == 1) \n\t\treturn self->descr->f->getitem(self->data, self);\n\telse {\n\t\tPyErr_SetString(PyExc_ValueError, \"can only convert an\"\t\\\n\t\t\t\t\" array of size 1 to Python scalar.\");\n\t\treturn NULL;\n\t}\n}\n\nstatic char doc_cast[] = \"m.astype(t).\tCast array m to type t.\t \\n\\n\"\\\n\t\"t can be either a string representing a typecode, or a python type\"\\\n\t\" object of type int, float, or complex.\";\n\nstatic PyObject *\narray_cast(PyArrayObject *self, PyObject *args) \n{\n\tPyArray_Descr *descr=NULL;\n\tPyObject *obj;\n\t\n if (!PyArg_ParseTuple(args, \"O&\", PyArray_DescrConverter,\n\t\t\t &descr)) return NULL;\n\t\n\tif (descr == self->descr) {\n\t\tobj = _ARET(PyArray_NewCopy(self,0));\n\t\tPy_XDECREF(descr);\n\t\treturn obj;\n\t}\n\treturn _ARET(PyArray_CastToType(self, descr, 0));\n}\t \n\n/* default sub-type implementation */\n\nstatic char doc_wraparray[] = \"m.__array_wrap__(obj) returns an object of \"\\\n\t\"type m from the ndarray object obj\";\n\nstatic PyObject *\narray_wraparray(PyArrayObject *self, PyObject *args)\n{\n\tPyObject *arr;\n\tPyObject *ret;\n\t\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}\t\n\n\tPy_INCREF(PyArray_DESCR(arr));\n\tret = PyArray_NewFromDescr(self->ob_type, \n\t\t\t\t PyArray_DESCR(arr),\n\t\t\t\t PyArray_NDIM(arr),\n\t\t\t\t PyArray_DIMS(arr), \n\t\t\t\t PyArray_STRIDES(arr), PyArray_DATA(arr),\n\t\t\t\t PyArray_FLAGS(arr), (PyObject *)self);\n\tif (ret == NULL) return NULL;\n\tPy_INCREF(arr);\n\tPyArray_BASE(ret) = arr;\n\treturn ret;\n}\n\n/* NO-OP --- just so all subclasses will have one by default. */\nstatic PyObject *\narray_finalize(PyArrayObject *self, PyObject *args)\n{\n\tPy_INCREF(Py_None);\n\treturn Py_None;\n}\n\n\nstatic char doc_array_getarray[] = \"m.__array__(|dtype) just returns either a new reference to self if dtype is not given or a new array of provided data type if dtype is different from the current dtype of the array.\";\n\nstatic PyObject *\narray_getarray(PyArrayObject *self, PyObject *args) \n{\n\tPyArray_Descr *newtype=NULL;\n\tPyObject *ret;\n\t\n\tif (!PyArg_ParseTuple(args, \"|O&\", PyArray_DescrConverter,\n\t\t\t &newtype)) return NULL;\n\t\n\t/* convert to PyArray_Type or PyBigArray_Type */\n\tif (!PyArray_CheckExact(self) || !PyBigArray_CheckExact(self)) {\n\t\tPyObject *new;\n\t\tPyTypeObject *subtype = &PyArray_Type;\n\n\t\tif (!PyType_IsSubtype(self->ob_type, &PyArray_Type)) {\n\t\t\tsubtype = &PyBigArray_Type;\n\t\t}\n\t\t\n\t\tPy_INCREF(PyArray_DESCR(self));\n\t\tnew = PyArray_NewFromDescr(subtype, \n\t\t\t\t\t PyArray_DESCR(self),\n\t\t\t\t\t PyArray_NDIM(self),\n\t\t\t\t\t PyArray_DIMS(self), \n\t\t\t\t\t PyArray_STRIDES(self), \n\t\t\t\t\t PyArray_DATA(self),\n\t\t\t\t\t PyArray_FLAGS(self), NULL);\n\t\tif (new == NULL) return NULL;\n\t\tPy_INCREF(self);\n\t\tPyArray_BASE(new) = (PyObject *)self;\n\t\tself = (PyArrayObject *)new;\n\t}\n\telse {\n\t\tPy_INCREF(self);\n\t}\n\t\t\n\tif ((newtype == NULL) || \\\n\t PyArray_EquivTypes(self->descr, newtype)) {\n\t\treturn (PyObject *)self;\n\t}\n\telse {\n\t\tret = PyArray_CastToType(self, newtype, 0);\n\t\tPy_DECREF(self);\n\t\treturn ret;\n\t}\n}\n\nstatic char doc_copy[] = \"m.copy(|fortran). Return a copy of the array.\\n\"\\\n\t\"If fortran == 0 then the result is contiguous (default). \\n\"\\\n\t\"If fortran > 0 then the result has fortran data order. \\n\"\\\n\t\"If fortran < 0 then the result has fortran data order only if m\\n\"\n\t\" is already in fortran order.\";\n\nstatic PyObject *\narray_copy(PyArrayObject *self, PyObject *args) \n{\n\tint fortran=0;\n if (!PyArg_ParseTuple(args, \"|i\", &fortran)) return NULL;\n\t\n return PyArray_NewCopy(self, fortran);\n}\n\nstatic char doc_resize[] = \"self.resize(new_shape). \"\\\n\t\"Change size and shape of self inplace.\\n\"\\\n\t\"\\n Array must own its own memory and not be referenced by other \" \\\n\t\"arrays\\n Returns None.\";\n\nstatic PyObject *\narray_resize(PyArrayObject *self, PyObject *args) \n{\n PyArray_Dims newshape;\n PyObject *ret;\n\tint n;\n\t\n\tn = PyTuple_Size(args);\n\tif (n <= 1) {\n\t\tif (!PyArg_ParseTuple(args, \"O&\", PyArray_IntpConverter, \n\t\t\t\t &newshape)) return NULL;\n\t}\n else {\n\t\tif (!PyArray_IntpConverter(args, &newshape)) {\n\t\t\tif (!PyErr_Occurred()) {\n\t\t\t\tPyErr_SetString(PyExc_TypeError, \n\t\t\t\t\t\t\"invalid shape\");\n\t\t\t} \n\t\t\treturn NULL;\t\t\t\n\t\t}\n\t}\n\tret = PyArray_Resize(self, &newshape);\n PyDimMem_FREE(newshape.ptr);\n if (ret == NULL) return NULL;\n\tPy_DECREF(ret);\n\tPy_INCREF(Py_None);\n\treturn Py_None;\n}\n\nstatic char doc_repeat[] = \"a.repeat(repeats=, axis=None)\\n\"\\\n\t\"\\n\"\\\n\t\" Copy elements of a, repeats times. The repeats argument must\\n\"\\\n\t\" be a sequence of length a.shape[axis] or a scalar.\";\n\nstatic PyObject *\narray_repeat(PyArrayObject *self, PyObject *args, PyObject *kwds) {\n\tPyObject *repeats;\n\tint axis=MAX_DIMS;\n\tstatic char *kwlist[] = {\"repeats\", \"axis\", NULL};\n\t\n\tif (!PyArg_ParseTupleAndKeywords(args, kwds, \"O|O&\", kwlist, \n\t\t\t\t\t &repeats, PyArray_AxisConverter,\n\t\t\t\t\t &axis)) return NULL;\n\t\n\treturn _ARET(PyArray_Repeat(self, repeats, axis));\n}\n\nstatic char doc_choose[] = \"a.choose(b0, b1, ..., bn)\\n\"\\\n\t\"\\n\"\\\n\t\"Return an array with elements chosen from 'a' at the positions\\n\"\\\n \"of the given arrays b_i. The array 'a' should be an integer array\\n\"\\\n \"with entries from 0 to n+1, and the b_i arrays should have the same\\n\"\\\n \"shape as 'a'.\";\n\nstatic PyObject *\narray_choose(PyArrayObject *self, PyObject *args) \n{\n\tPyObject *choices;\n\tint n;\n\t\n\tn = PyTuple_Size(args);\n\tif (n <= 1) {\n\t\tif (!PyArg_ParseTuple(args, \"O\", &choices))\n\t\t\treturn NULL;\n\t}\n else {\n\t\tchoices = args;\n\t}\n\t\n\treturn _ARET(PyArray_Choose(self, choices));\n}\n\nstatic char doc_sort[] = \"a.sort(axis=-1,kind='quicksort') sorts in place along axis. Return is None and kind can be 'quicksort', 'mergesort', or 'heapsort'\";\n\nstatic PyObject *\narray_sort(PyArrayObject *self, PyObject *args, PyObject *kwds) \n{\n\tint axis=-1;\n\tint val;\n\tPyArray_SORTKIND which=PyArray_QUICKSORT;\n\tstatic char *kwlist[] = {\"axis\", \"kind\", NULL};\n\t\n\tif (!PyArg_ParseTupleAndKeywords(args, kwds, \"|iO&\", kwlist, &axis,\n\t\t\t\t\t PyArray_SortkindConverter, &which))\n\t\treturn NULL;\n\t\n\tval = PyArray_Sort(self, axis, which);\n\tif (val < 0) return NULL;\n\tPy_INCREF(Py_None);\n\treturn Py_None;\n}\n\nstatic char doc_argsort[] = \"a.argsort(axis=-1,kind='quicksort')\\n\"\\\n\t\" Return the indexes into a that would sort it along the\"\\\n\t\" given axis; kind can be 'quicksort', 'mergesort', or 'heapsort'\";\n\nstatic PyObject *\narray_argsort(PyArrayObject *self, PyObject *args, PyObject *kwds) \n{\n\tint axis=-1;\n\tPyArray_SORTKIND which=PyArray_QUICKSORT;\n\tstatic char *kwlist[] = {\"axis\", \"kind\", NULL};\n\t\n\tif (!PyArg_ParseTupleAndKeywords(args, kwds, \"|iO&\", kwlist, &axis,\n\t\t\t\t\t PyArray_SortkindConverter, &which))\n\t\treturn NULL;\n\t\n\treturn _ARET(PyArray_ArgSort(self, axis, which));\n}\n\nstatic char doc_searchsorted[] = \"a.searchsorted(v)\\n\"\\\n\t\" Assuming that a is a 1-D array, in ascending order and\\n\"\\\n\t\" represents bin boundaries, then a.searchsorted(values) gives an\\n\"\\\n\t\" array of bin numbers, giving the bin into which each value would\\n\"\\\n\t\" be placed. This method is helpful for histograming. \\n\"\\\n\t\" Note: No warning is given if the boundaries, in a, are not \\n\"\\\n\t\" in ascending order.\";\n\nstatic PyObject *\narray_searchsorted(PyArrayObject *self, PyObject *args) \n{\n\tPyObject *values;\n\t\n\tif (!PyArg_ParseTuple(args, \"O\", &values)) return NULL;\n\t\n\treturn _ARET(PyArray_SearchSorted(self, values));\n}\n\nstatic char doc_deepcopy[] = \"Used if copy.deepcopy is called on an array.\";\n\nstatic PyObject *\narray_deepcopy(PyArrayObject *self, PyObject *args) \n{\n PyObject* visit;\n PyObject **optr;\n PyArrayIterObject *it;\n PyObject *copy, *ret, *deepcopy, *temp, *res;\n\n if (!PyArg_ParseTuple(args, \"O\", &visit)) return NULL;\n ret = PyArray_Copy(self);\n if (PyArray_ISOBJECT(self)) {\n copy = PyImport_ImportModule(\"copy\");\n if (copy == NULL) return NULL;\n deepcopy = PyObject_GetAttrString(copy, \"deepcopy\");\n Py_DECREF(copy);\n if (deepcopy == NULL) return NULL;\n it = (PyArrayIterObject *)PyArray_IterNew((PyObject *)self);\n if (it == NULL) {Py_DECREF(deepcopy); return NULL;}\n optr = (PyObject **)PyArray_DATA(ret);\n while(it->index < it->size) {\n temp = *((PyObject **)it->dataptr);\n Py_INCREF(temp);\n /* call deepcopy on this argument */\n res = PyObject_CallFunctionObjArgs(deepcopy, \n temp, visit, NULL);\n Py_DECREF(temp);\n Py_DECREF(*optr);\n *optr++ = res;\n PyArray_ITER_NEXT(it);\n }\n Py_DECREF(deepcopy);\n Py_DECREF(it);\n }\n return _ARET(ret);\n}\n\n/* Convert Object Array to flat list and pickle the flat list string */\nstatic PyObject *\n_getobject_pkl(PyArrayObject *self)\n{\n\tPyObject *theobject;\n\tPyArrayIterObject *iter=NULL;\n\tPyObject *list;\n\n\t\n\titer = (PyArrayIterObject *)PyArray_IterNew((PyObject *)self);\n\tif (iter == NULL) return NULL;\n\tlist = PyList_New(iter->size);\n\tif (list == NULL) {Py_DECREF(iter); return NULL;}\n\twhile (iter->index < iter->size) {\n\t\ttheobject = *((PyObject **)iter->dataptr);\n\t\tPy_INCREF(theobject);\n\t\tPyList_SET_ITEM(list, (int) iter->index, theobject);\n\t\tPyArray_ITER_NEXT(iter);\n\t}\n\tPy_DECREF(iter);\n\treturn list;\n}\n\nstatic int\n_setobject_pkl(PyArrayObject *self, PyObject *list)\n{\n\tPyObject *theobject;\n\tPyArrayIterObject *iter=NULL;\n\tint size;\n\n\tsize = self->descr->elsize;\n\t\n\titer = (PyArrayIterObject *)PyArray_IterNew((PyObject *)self);\n\tif (iter == NULL) return -1;\n\twhile(iter->index < iter->size) {\n\t\ttheobject = PyList_GET_ITEM(list, (int) iter->index);\n\t\tPy_INCREF(theobject);\n\t\t*((PyObject **)iter->dataptr) = theobject;\n\t\tPyArray_ITER_NEXT(iter);\n\t}\n\tPy_XDECREF(iter);\n\treturn 0;\n}\n\nstatic char doc_reduce[] = \"a.__reduce__() for pickling.\";\n\nstatic PyObject *\narray_reduce(PyArrayObject *self, PyObject *args)\n{\n\tPyObject *ret=NULL, *state=NULL, *obj=NULL, *mod=NULL;\n\tPyObject *mybool, *thestr=NULL;\n\tPyArray_Descr *descr;\n\n\t/* Return a tuple of (callable object, arguments, object's state) */\n\t/* We will put everything in the object's state, so that on UnPickle\n\t it can use the string object as memory without a copy */\n\n\tret = PyTuple_New(3);\n\tif (ret == NULL) return NULL;\n\tmod = PyImport_ImportModule(\"numpy.core._internal\");\n\tif (mod == NULL) {Py_DECREF(ret); return NULL;}\n\tobj = PyObject_GetAttrString(mod, \"_reconstruct\");\n\tPy_DECREF(mod);\n\tPyTuple_SET_ITEM(ret, 0, obj);\n\tPyTuple_SET_ITEM(ret, 1, \n\t\t\t Py_BuildValue(\"ONN\",\n\t\t\t\t (PyObject *)self->ob_type,\n\t\t\t\t Py_BuildValue(\"(N)\",\n\t\t\t\t\t\t PyInt_FromLong(0)),\n\t\t\t\t PyObject_GetAttrString((PyObject *)(self->descr),\n\t\t\t\t\t\t\t \"char\")));\n\t\n\t/* Now fill in object's state. This is a tuple with \n\t 4 arguments\n\n\t 1) a Tuple giving the shape\n\t 2) a PyArray_Descr Object (with correct bytorder set)\n\t 3) a Bool stating if Fortran or not\n\t 4) a binary string with the data (or a list for Object arrays)\n\n\t Notice because Python does not describe a mechanism to write \n\t raw data to the pickle, this performs a copy to a string first\n\t*/\n\n\tstate = PyTuple_New(4);\n\tif (state == NULL) {\n\t\tPy_DECREF(ret); return NULL;\n\t}\n\tPyTuple_SET_ITEM(state, 0, PyObject_GetAttrString((PyObject *)self, \n\t\t\t\t\t\t\t \"shape\"));\n\tdescr = self->descr;\n\tPy_INCREF(descr);\n\tPyTuple_SET_ITEM(state, 1, (PyObject *)descr);\n\tmybool = (PyArray_ISFORTRAN(self) ? Py_True : Py_False);\n\tPy_INCREF(mybool);\n\tPyTuple_SET_ITEM(state, 2, mybool);\n\tif (PyArray_ISOBJECT(self)) {\n\t\tthestr = _getobject_pkl(self);\n\t}\n\telse {\n thestr = PyArray_ToString(self);\n\t}\n\tif (thestr == NULL) {\n\t\tPy_DECREF(ret);\n\t\tPy_DECREF(state);\n\t\treturn NULL;\n\t}\n\tPyTuple_SET_ITEM(state, 3, thestr);\n\tPyTuple_SET_ITEM(ret, 2, state);\n\treturn ret;\n}\n\nstatic char doc_setstate[] = \"a.__setstate__(tuple) for unpickling.\";\n\n/*\n\t 1) a Tuple giving the shape\n\t 2) a PyArray_Descr Object\n\t 3) a Bool stating if Fortran or not\n\t 4) a binary string with the data (or a list if Object array) \n*/\n\nstatic intp _array_fill_strides(intp *, intp *, int, intp, int, int *);\n\nstatic int _IsAligned(PyArrayObject *); \n\nstatic PyArray_Descr * _array_typedescr_fromstr(char *);\n\nstatic PyObject *\narray_setstate(PyArrayObject *self, PyObject *args)\n{\n\tPyObject *shape;\n\tPyArray_Descr *typecode;\n\tlong fortran;\n\tPyObject *rawdata;\n\tchar *datastr;\n\tint len;\n\tintp dimensions[MAX_DIMS];\n\tint nd;\n\t\n\t/* This will free any memory associated with a and\n\t use the string in setstate as the (writeable) memory.\n\t*/\n\tif (!PyArg_ParseTuple(args, \"(O!O!iO)\", &PyTuple_Type,\n\t\t\t &shape, &PyArrayDescr_Type, &typecode, \n\t\t\t &fortran, &rawdata))\n\t\treturn NULL;\n\n\tPy_XDECREF(self->descr);\n\tself->descr = typecode;\n\tPy_INCREF(typecode);\n\tnd = PyArray_IntpFromSequence(shape, dimensions, MAX_DIMS);\n\tif (typecode->type_num == PyArray_OBJECT) {\n\t\tif (!PyList_Check(rawdata)) {\n\t\t\tPyErr_SetString(PyExc_TypeError, \n\t\t\t\t\t\"object pickle not returning list\");\n\t\t\treturn NULL;\n\t\t}\n\t}\n\telse {\n\t\tif (!PyString_Check(rawdata)) {\n\t\t\tPyErr_SetString(PyExc_TypeError, \n\t\t\t\t\t\"pickle not returning string\");\n\t\t\treturn NULL;\n\t\t}\n\n\t\tif (PyString_AsStringAndSize(rawdata, &datastr, &len))\n\t\t\treturn NULL;\n\n\t\tif ((len != (self->descr->elsize *\t\t\t\\\n\t\t\t (int) PyArray_MultiplyList(dimensions, nd)))) {\n\t\t\tPyErr_SetString(PyExc_ValueError, \n\t\t\t\t\t\"buffer size does not\"\t\\\n\t\t\t\t\t\" match array size\");\n\t\t\treturn NULL;\n\t\t}\n\t}\n\n if ((self->flags & OWN_DATA)) {\n\t\tif (self->data != NULL)\n\t\t\tPyDataMem_FREE(self->data);\n\t\tself->flags &= ~OWN_DATA;\n }\n\tPy_XDECREF(self->base);\n\n\tself->flags &= ~UPDATEIFCOPY;\n\n if (self->dimensions != NULL) {\n PyDimMem_FREE(self->dimensions); \n\t\tself->dimensions = NULL;\n\t}\n\n\tself->flags = DEFAULT_FLAGS;\n\n\tself->nd = nd;\n\n\tif (nd > 0) {\n\t\tself->dimensions = PyDimMem_NEW(nd * 2);\n\t\tself->strides = self->dimensions + nd;\n\t\tmemcpy(self->dimensions, dimensions, sizeof(intp)*nd);\n\t\t(void) _array_fill_strides(self->strides, dimensions, nd,\n\t\t\t\t\t self->descr->elsize, fortran, \n\t\t\t\t\t &(self->flags));\n\t}\n\n\tif (typecode->type_num != PyArray_OBJECT) {\n\t\tself->data = datastr;\n\t\tif (!_IsAligned(self)) {\n\t\t\tintp num = PyArray_NBYTES(self);\n\t\t\tself->data = PyDataMem_NEW(num);\n\t\t\tif (self->data == NULL) {\n\t\t\t\tself->nd = 0;\n\t\t\t\tPyDimMem_FREE(self->dimensions);\n\t\t\t\treturn PyErr_NoMemory();\n\t\t\t}\n\t\t\tmemcpy(self->data, datastr, num);\n\t\t\tself->flags |= OWN_DATA;\n\t\t\tself->base = NULL;\n\t\t}\n\t\telse {\n\t\t\tself->base = rawdata;\n\t\t\tPy_INCREF(self->base);\n\t\t}\n\t}\n\telse {\n\t\tself->data = PyDataMem_NEW(PyArray_NBYTES(self));\n\t\tif (self->data == NULL) { \n\t\t\tself->nd = 0;\n\t\t\tself->data = PyDataMem_NEW(self->descr->elsize);\n\t\t\tif (self->dimensions) PyDimMem_FREE(self->dimensions);\n\t\t\treturn PyErr_NoMemory();\n\t\t}\n\t\tself->flags |= OWN_DATA;\n\t\tself->base = NULL;\n\t\tif (_setobject_pkl(self, rawdata) < 0) \n\t\t\treturn NULL;\n\t}\n\n\tPyArray_UpdateFlags(self, UPDATE_ALL_FLAGS);\n\t\n\tPy_INCREF(Py_None);\n\treturn Py_None;\t\n}\n\n/*OBJECT_API*/\nstatic int\nPyArray_Dump(PyObject *self, PyObject *file, int protocol)\n{\n\tPyObject *cpick=NULL;\n\tPyObject *ret;\n\tif (protocol < 0) protocol = 2;\n\n\tcpick = PyImport_ImportModule(\"cPickle\");\n\tif (cpick==NULL) return -1;\n\n\tif PyString_Check(file) {\n\t\tfile = PyFile_FromString(PyString_AS_STRING(file), \"wb\");\n\t\tif (file==NULL) return -1;\n\t}\n\telse Py_INCREF(file);\n\tret = PyObject_CallMethod(cpick, \"dump\", \"OOi\", self, \n\t\t\t\t file, protocol);\n\tPy_XDECREF(ret);\n\tPy_DECREF(file);\n\tPy_DECREF(cpick);\n\tif (PyErr_Occurred()) return -1;\n\treturn 0;\n}\n\n/*OBJECT_API*/\nstatic PyObject *\nPyArray_Dumps(PyObject *self, int protocol)\n{\n\tPyObject *cpick=NULL;\n\tPyObject *ret;\n\tif (protocol < 0) protocol = 2;\n\n\tcpick = PyImport_ImportModule(\"cPickle\");\n\tif (cpick==NULL) return NULL;\n\tret = PyObject_CallMethod(cpick, \"dumps\", \"Oi\", self, protocol);\n\tPy_DECREF(cpick);\n\treturn ret;\n}\n\n\nstatic char doc_dump[] = \"m.dump(file)\";\n\nstatic PyObject *\narray_dump(PyArrayObject *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((PyObject *)self, file, 2);\n\tif (ret < 0) return NULL;\n\tPy_INCREF(Py_None);\n\treturn Py_None;\n}\n\nstatic char doc_dumps[] = \"m.dumps()\";\n\nstatic PyObject *\narray_dumps(PyArrayObject *self, PyObject *args)\n{\n\tif (!PyArg_ParseTuple(args, \"\"))\n\t\treturn NULL;\n\treturn PyArray_Dumps((PyObject *)self, 2);\n}\n\n\nstatic char doc_transpose[] = \"m.transpose()\";\n\nstatic PyObject *\narray_transpose(PyArrayObject *self, PyObject *args) \n{\n\tPyObject *shape=Py_None;\n\tint n;\n\tPyArray_Dims permute;\n\tPyObject *ret;\n\n\tn = PyTuple_Size(args);\n\tif (n > 1) shape = args;\n\telse if (n == 1) shape = PyTuple_GET_ITEM(args, 0);\n\t\n\tif (shape == Py_None)\n\t\tret = PyArray_Transpose(self, NULL);\n\telse {\n\t\tif (!PyArray_IntpConverter(shape, &permute)) return NULL;\n\t\tret = PyArray_Transpose(self, &permute);\n\t\tPyDimMem_FREE(permute.ptr);\n\t}\n\t\n\treturn _ARET(ret);\n}\n\nstatic char doc_mean[] = \"a.mean(axis=None, dtype=None)\\n\\n\"\\\n \"Average the array over the given axis. If the axis is None, average\\n\"\\\n \"over all dimensions of the array.\\n\"\\\n \"\\n\"\\\n \"If an integer axis is given, this equals:\\n\"\\\n \" a.sum(axis, dtype) * 1.0 / len(a)\\n\"\\\n \"\\n\"\\\n \"If axis is None, this equals:\\n\"\\\n \" a.sum(axis, dtype) * 1.0 / product(a.shape)\\n\"\\\n \"\\n\"\\\n \"The optional dtype argument is the data type for intermediate\\n\"\\\n \"calculations in the sum.\";\n\n#define _CHKTYPENUM(typ) ((typ) ? (typ)->type_num : PyArray_NOTYPE)\n\nstatic PyObject *\narray_mean(PyArrayObject *self, PyObject *args, PyObject *kwds) \n{\n\tint axis=MAX_DIMS;\n\tPyArray_Descr *dtype=NULL;\n\tstatic char *kwlist[] = {\"axis\", \"dtype\", NULL};\n\t\n\tif (!PyArg_ParseTupleAndKeywords(args, kwds, \"|O&O&\", kwlist,\n\t\t\t\t\t PyArray_AxisConverter, \n\t\t\t\t\t &axis, PyArray_DescrConverter2,\n\t\t\t\t\t &dtype)) return NULL;\n\n\treturn PyArray_Mean(self, axis, _CHKTYPENUM(dtype));\n}\n\nstatic char doc_sum[] = \"a.sum(axis=None, dtype=None)\\n\\n\"\\\n \"Sum the array over the given axis. If the axis is None, sum over all\\n\"\\\n \"dimensions of the array.\\n\"\\\n \"\\n\"\\\n \"The optional dtype argument is the data type for the returned value\\n\"\\\n \"and intermediate calculations. The default is to upcast (promote)\\n\"\\\n \"smaller integer types to the platform-dependent int. For example, on\\n\"\\\n \"32-bit platforms:\\n\"\\\n \"\\n\"\\\n \" a.dtype default sum() dtype\\n\"\\\n \" ---------------------------------------------------\\n\"\\\n \" bool, int8, int16, int32 int32\\n\"\\\n \"\\n\"\\\n \"Examples:\\n\"\\\n \"\\n\"\\\n \">>> array([0.5, 1.5]).sum()\\n\"\\\n \"2.0\\n\"\\\n \">>> array([0.5, 1.5]).sum(dtype=int32)\\n\"\\\n \"1\\n\"\\\n \">>> array([[0, 1], [0, 5]]).sum()\\n\"\\\n \"array([0, 6])\\n\"\\\n \">>> array([[0, 1], [0, 5]]).sum(axis=1)\\n\"\\\n \"array([1, 5])\";\n\nstatic PyObject *\narray_sum(PyArrayObject *self, PyObject *args, PyObject *kwds) \n{\n\tint axis=MAX_DIMS;\n\tPyArray_Descr *dtype=NULL;\n\tstatic char *kwlist[] = {\"axis\", \"dtype\", NULL};\n\n\tif (!PyArg_ParseTupleAndKeywords(args, kwds, \"|O&O&\", kwlist, \n\t\t\t\t\t PyArray_AxisConverter, \n\t\t\t\t\t &axis, PyArray_DescrConverter2,\n\t\t\t\t\t &dtype)) return NULL;\n\t\n\treturn PyArray_Sum(self, axis, _CHKTYPENUM(dtype));\n}\n\n\nstatic char doc_cumsum[] = \"a.cumsum(axis=None, dtype=None)\";\n\nstatic PyObject *\narray_cumsum(PyArrayObject *self, PyObject *args, PyObject *kwds) \n{\n\tint axis=MAX_DIMS;\n\tPyArray_Descr *dtype=NULL;\n\tstatic char *kwlist[] = {\"axis\", \"dtype\", NULL};\n\t\n\tif (!PyArg_ParseTupleAndKeywords(args, kwds, \"|O&O&\", kwlist, \n\t\t\t\t\t PyArray_AxisConverter, \n\t\t\t\t\t &axis, PyArray_DescrConverter2,\n\t\t\t\t\t &dtype)) return NULL;\n\t\n\treturn PyArray_CumSum(self, axis, _CHKTYPENUM(dtype));\n}\n\nstatic char doc_prod[] = \"a.prod(axis=None, dtype=None)\";\n\nstatic PyObject *\narray_prod(PyArrayObject *self, PyObject *args, PyObject *kwds) \n{\n\tint axis=MAX_DIMS;\n\tPyArray_Descr *dtype=NULL;\n\tstatic char *kwlist[] = {\"axis\", \"dtype\", NULL};\n\t\n\tif (!PyArg_ParseTupleAndKeywords(args, kwds, \"|O&O&\", kwlist, \n\t\t\t\t\t PyArray_AxisConverter, \n\t\t\t\t\t &axis, PyArray_DescrConverter2,\n\t\t\t\t\t &dtype)) return NULL;\n\t\n\treturn PyArray_Prod(self, axis, _CHKTYPENUM(dtype));\n}\n\n\nstatic char doc_cumprod[] = \"a.cumprod(axis=None, dtype=None)\";\n\nstatic PyObject *\narray_cumprod(PyArrayObject *self, PyObject *args, PyObject *kwds) \n{\n\tint axis=MAX_DIMS;\n\tPyArray_Descr *dtype=NULL;\n\tstatic char *kwlist[] = {\"axis\", \"dtype\", NULL};\n\t\n\tif (!PyArg_ParseTupleAndKeywords(args, kwds, \"|O&O&\", kwlist, \n\t\t\t\t\t PyArray_AxisConverter, \n\t\t\t\t\t &axis, PyArray_DescrConverter2,\n\t\t\t\t\t &dtype)) return NULL;\n\t\n\treturn PyArray_CumProd(self, axis, _CHKTYPENUM(dtype));\n}\n\n\nstatic char doc_any[] = \"a.any(axis=None)\";\n\nstatic PyObject *\narray_any(PyArrayObject *self, PyObject *args) \n{\n\tint axis=MAX_DIMS;\n\t\n\tif (!PyArg_ParseTuple(args, \"|O&\", PyArray_AxisConverter, \n\t\t\t &axis)) return NULL;\n\t\n\treturn PyArray_Any(self, axis);\n}\n\nstatic char doc_all[] = \"a.all(axis=None)\";\n\nstatic PyObject *\narray_all(PyArrayObject *self, PyObject *args) \n{\n\tint axis=MAX_DIMS;\n\t\n\tif (!PyArg_ParseTuple(args, \"|O&\", PyArray_AxisConverter, \n\t\t\t &axis)) return NULL;\n\t\n\treturn PyArray_All(self, axis);\n}\n\nstatic char doc_stddev[] = \"a.std(axis=None, dtype=None)\";\n\nstatic PyObject *\narray_stddev(PyArrayObject *self, PyObject *args, PyObject *kwds) \n{\n\tint axis=MAX_DIMS;\n\tPyArray_Descr *dtype=NULL;\n\tstatic char *kwlist[] = {\"axis\", \"dtype\", NULL};\n\t\n\tif (!PyArg_ParseTupleAndKeywords(args, kwds, \"|O&O&\", kwlist, \n\t\t\t\t\t PyArray_AxisConverter, \n\t\t\t\t\t &axis, PyArray_DescrConverter2,\n\t\t\t\t\t &dtype)) return NULL;\n\t\n\treturn PyArray_Std(self, axis, _CHKTYPENUM(dtype), 0);\n}\n\nstatic char doc_variance[] = \"a.var(axis=None, dtype=None)\";\n\nstatic PyObject *\narray_variance(PyArrayObject *self, PyObject *args, PyObject *kwds) \n{\n\tint axis=MAX_DIMS;\n\tPyArray_Descr *dtype=NULL;\n\tstatic char *kwlist[] = {\"axis\", \"dtype\", NULL};\n\t\n\tif (!PyArg_ParseTupleAndKeywords(args, kwds, \"|O&O&\", kwlist, \n\t\t\t\t\t PyArray_AxisConverter, \n\t\t\t\t\t &axis, PyArray_DescrConverter2,\n\t\t\t\t\t &dtype)) return NULL;\n\t\n\treturn PyArray_Std(self, axis, _CHKTYPENUM(dtype), 1);\n}\n\nstatic char doc_compress[] = \"a.compress(condition=, axis=None)\";\n\nstatic PyObject *\narray_compress(PyArrayObject *self, PyObject *args, PyObject *kwds) \n{\n\tint axis=MAX_DIMS;\n\tPyObject *condition;\t\n\tstatic char *kwlist[] = {\"condition\", \"axis\", NULL};\n\t\n\tif (!PyArg_ParseTupleAndKeywords(args, kwds, \"O|O&\", kwlist, \n\t\t\t\t\t &condition, PyArray_AxisConverter,\n\t\t\t\t\t &axis)) return NULL;\n\n\treturn _ARET(PyArray_Compress(self, condition, axis));\n}\n\nstatic char doc_nonzero[] = \"a.nonzero() return a tuple of indices referencing\"\\\n\t\"the elements of a that are nonzero.\";\n\nstatic PyObject *\narray_nonzero(PyArrayObject *self, PyObject *args)\n{\n\tif (!PyArg_ParseTuple(args, \"\")) return NULL;\n\n\treturn _ARET(PyArray_Nonzero(self));\n}\n\n\nstatic char doc_trace[] = \"a.trace(offset=0, axis1=0, axis2=1, dtype=None) \\n\"\\\n\t\"return the sum along the offset diagonal of the arrays indicated\\n\" \\\n\t\"axis1 and axis2.\";\n\nstatic PyObject *\narray_trace(PyArrayObject *self, PyObject *args, PyObject *kwds) \n{\n\tint axis1=0, axis2=1, offset=0;\n\tPyArray_Descr *dtype=NULL;\n\tstatic char *kwlist[] = {\"offset\", \"axis1\", \"axis2\", \"dtype\", NULL};\n\t\n\tif (!PyArg_ParseTupleAndKeywords(args, kwds, \"|iiiO&\", kwlist, \n\t\t\t\t\t &offset, &axis1, &axis2,\n\t\t\t\t\t PyArray_DescrConverter2, &dtype))\n\t\treturn NULL;\n\t\n\treturn _ARET(PyArray_Trace(self, offset, axis1, axis2, \n\t\t\t\t _CHKTYPENUM(dtype)));\n}\n\n#undef _CHKTYPENUM\n\n\nstatic char doc_clip[] = \"a.clip(min=, max=)\";\n\nstatic PyObject *\narray_clip(PyArrayObject *self, PyObject *args, PyObject *kwds) \n{\n\tPyObject *min, *max;\n\tstatic char *kwlist[] = {\"min\", \"max\", NULL};\n\n\tif (!PyArg_ParseTupleAndKeywords(args, kwds, \"OO\", kwlist,\n\t\t\t\t\t &min, &max)) \n\t\treturn NULL;\n\t\n\treturn _ARET(PyArray_Clip(self, min, max));\n}\n\nstatic char doc_conj[] = \"a.conj()\";\n\nstatic char doc_conjugate[] = \"a.conjugate()\";\n\nstatic PyObject *\narray_conjugate(PyArrayObject *self, PyObject *args) \n{\n\n\tif (!PyArg_ParseTuple(args, \"\")) return NULL;\n\t\n\treturn PyArray_Conjugate(self);\n}\n\n\nstatic char doc_diagonal[] = \"a.diagonal(offset=0, axis1=0, axis2=1)\";\n\nstatic PyObject *\narray_diagonal(PyArrayObject *self, PyObject *args, PyObject *kwds) \n{\n\tint axis1=0, axis2=1, offset=0;\n\tstatic char *kwlist[] = {\"offset\", \"axis1\", \"axis2\", NULL};\n\t\n\tif (!PyArg_ParseTupleAndKeywords(args, kwds, \"|iii\", kwlist, \n\t\t\t\t\t &offset, &axis1, &axis2))\n\t\treturn NULL;\n\t\n\treturn _ARET(PyArray_Diagonal(self, offset, axis1, axis2));\n}\n\nstatic char doc_flatten[] = \"a.flatten([fortran]) return a 1-d array (always copy)\";\n\nstatic PyObject *\narray_flatten(PyArrayObject *self, PyObject *args)\n{\n\tint fortran=0;\n\n\tif (!PyArg_ParseTuple(args, \"|i\", &fortran)) return NULL;\n \n\treturn PyArray_Flatten(self, (int) fortran);\n}\n\nstatic char doc_ravel[] = \"a.ravel([fortran]) return a 1-d array (copy only if needed)\";\n\nstatic PyObject *\narray_ravel(PyArrayObject *self, PyObject *args)\n{\n\tint fortran=0;\n\n\tif (!PyArg_ParseTuple(args, \"|i\", &fortran)) return NULL;\n\n\treturn PyArray_Ravel(self, fortran);\n}\n\n\n\nstatic char doc_setflags[] = \"a.setflags(write=None, align=None, uic=None)\";\n\nstatic int _IsAligned(PyArrayObject *);\nstatic Bool _IsWriteable(PyArrayObject *);\n\nstatic PyObject *\narray_setflags(PyArrayObject *self, PyObject *args, PyObject *kwds)\n{\n\tstatic char *kwlist[] = {\"write\", \"align\", \"uic\", NULL};\n\tPyObject *write=Py_None;\n\tPyObject *align=Py_None;\n\tPyObject *uic=Py_None;\n\tint flagback = self->flags;\n\t\t\n\tif (!PyArg_ParseTupleAndKeywords(args, kwds, \"|OOO\", kwlist,\n\t\t\t\t\t &write, &align, &uic))\n\t\treturn NULL;\n\n\tif (align != Py_None) {\n\t\tif (PyObject_Not(align)) self->flags &= ~ALIGNED;\n\t\telse if (_IsAligned(self)) self->flags |= ALIGNED;\n\t\telse {\n\t\t\tPyErr_SetString(PyExc_ValueError, \n\t\t\t\t\t\"cannot set aligned flag of mis-\"\\\n\t\t\t\t\t\"aligned array to True\");\n\t\t\treturn NULL;\n\t\t}\n\t}\n\t\n\tif (uic != Py_None) {\n if (PyObject_IsTrue(uic)) {\n\t\t\tself->flags = flagback;\n PyErr_SetString(PyExc_ValueError, \n \"cannot set UPDATEIFCOPY\" \\\n \"flag to True\");\n return NULL;\n }\n else {\n self->flags &= ~UPDATEIFCOPY;\n Py_DECREF(self->base);\n self->base = NULL;\n }\n }\n \n if (write != Py_None) {\n if (PyObject_IsTrue(write)) \n\t\t\tif (_IsWriteable(self)) {\n\t\t\t\tself->flags |= WRITEABLE;\n\t\t\t}\n\t\t\telse {\n\t\t\t\tself->flags = flagback;\n\t\t\t\tPyErr_SetString(PyExc_ValueError, \n\t\t\t\t\t\t\"cannot set WRITEABLE \"\t\\\n\t\t\t\t\t\t\"flag to True of this \"\t\\\n\t\t\t\t\t\t\"array\");\t\t\\\n\t\t\t\treturn NULL;\n\t\t\t}\n else\n self->flags &= ~WRITEABLE;\n }\n \n Py_INCREF(Py_None);\n return Py_None;\n}\n\nstatic char doc_newbyteorder[] = \"a.newbyteorder() is equivalent\\n\" \\\n\t\" to a.view(a.dtype.newbytorder())\\n\";\n\nstatic PyObject *\narray_newbyteorder(PyArrayObject *self, PyObject *args) \n{\n\tchar endian = PyArray_SWAP;\n\tPyArray_Descr *new;\n\t\n\tif (!PyArg_ParseTuple(args, \"|O&\", PyArray_ByteorderConverter,\n\t\t\t &endian)) return NULL;\n\n\tnew = PyArray_DescrNewByteorder(self->descr, endian);\n\tif (!new) return NULL;\n\treturn PyArray_View(self, new, NULL));\n\n}\n\nstatic PyMethodDef array_methods[] = {\n {\"tolist\",\t (PyCFunction)array_tolist,\t1, doc_tolist},\n {\"item\", (PyCFunction)array_toscalar, METH_VARARGS, doc_toscalar},\n\t{\"tofile\", (PyCFunction)array_tofile, \n METH_VARARGS | METH_KEYWORDS, doc_tofile},\n {\"tostring\", (PyCFunction)array_tostring, METH_VARARGS, doc_tostring},\n {\"byteswap\", (PyCFunction)array_byteswap,\t1, doc_byteswap},\n {\"astype\", (PyCFunction)array_cast, 1, doc_cast},\n\t{\"getfield\", (PyCFunction)array_getfield, \n\t METH_VARARGS | METH_KEYWORDS, doc_getfield},\n\t{\"setfield\", (PyCFunction)array_setfield, \n\t METH_VARARGS | METH_KEYWORDS, doc_setfield},\n {\"copy\", (PyCFunction)array_copy, 1, doc_copy}, \n {\"resize\", (PyCFunction)array_resize, 1, doc_resize}, \n\n\t/* for subtypes */\n\t{\"__array__\", (PyCFunction)array_getarray, 1, doc_array_getarray},\n\t{\"__array_wrap__\", (PyCFunction)array_wraparray, 1, doc_wraparray},\n\t/* default version so it is found... -- only used for subclasses */\n\t{\"__array_finalize__\", (PyCFunction)array_finalize, 1, NULL},\n\t\n\t\n\t/* for the copy module */\n {\"__copy__\", (PyCFunction)array_copy, 1, doc_copy},\t \n {\"__deepcopy__\", (PyCFunction)array_deepcopy, 1, doc_deepcopy}, \n\t\n /* for Pickling */\n {\"__reduce__\", (PyCFunction) array_reduce, 1, doc_reduce},\t\n\t{\"__setstate__\", (PyCFunction) array_setstate, 1, doc_setstate},\n\t{\"dumps\", (PyCFunction) array_dumps, 1, doc_dumps},\n\t{\"dump\", (PyCFunction) array_dump, 1, doc_dump},\n\n\t/* Extended methods added 2005 */\n\t{\"fill\", (PyCFunction)array_fill,\n\t METH_VARARGS, doc_fill},\n\t{\"transpose\",\t(PyCFunction)array_transpose, \n\t METH_VARARGS, doc_transpose},\n\t{\"take\",\t(PyCFunction)array_take, \n\t METH_VARARGS|METH_KEYWORDS, doc_take},\n\t{\"put\",\t(PyCFunction)array_put, \n\t METH_VARARGS|METH_KEYWORDS, doc_put},\n\t{\"putmask\",\t(PyCFunction)array_putmask, \n\t METH_VARARGS|METH_KEYWORDS, doc_putmask},\n\t{\"repeat\",\t(PyCFunction)array_repeat, \n\t METH_VARARGS|METH_KEYWORDS, doc_repeat},\n\t{\"choose\",\t(PyCFunction)array_choose, \n\t METH_VARARGS, doc_choose},\t\n\t{\"sort\",\t(PyCFunction)array_sort, \n\t METH_VARARGS|METH_KEYWORDS, doc_sort},\n\t{\"argsort\",\t(PyCFunction)array_argsort, \n\t METH_VARARGS|METH_KEYWORDS, doc_argsort},\n\t{\"searchsorted\", (PyCFunction)array_searchsorted, \n\t METH_VARARGS, doc_searchsorted},\t\n\t{\"argmax\",\t(PyCFunction)array_argmax, \n\t METH_VARARGS, doc_argmax},\n\t{\"argmin\", (PyCFunction)array_argmin,\n\t METH_VARARGS, doc_argmin},\n\t{\"reshape\",\t(PyCFunction)array_reshape, \n\t METH_VARARGS, doc_reshape},\n\t{\"squeeze\",\t(PyCFunction)array_squeeze,\n\t METH_VARARGS, doc_squeeze},\n\t{\"view\", (PyCFunction)array_view, \n\t METH_VARARGS, doc_view},\n\t{\"swapaxes\", (PyCFunction)array_swapaxes,\n\t METH_VARARGS, doc_swapaxes},\n\t{\"max\", (PyCFunction)array_max,\n\t METH_VARARGS, doc_max},\n\t{\"min\", (PyCFunction)array_min,\n\t METH_VARARGS, doc_min},\n\t{\"ptp\", (PyCFunction)array_ptp,\n\t METH_VARARGS, doc_ptp},\n\t{\"mean\", (PyCFunction)array_mean,\n\t METH_VARARGS|METH_KEYWORDS, doc_mean},\n\t{\"trace\", (PyCFunction)array_trace,\n\t METH_VARARGS|METH_KEYWORDS, doc_trace},\n\t{\"diagonal\", (PyCFunction)array_diagonal,\n\t METH_VARARGS|METH_KEYWORDS, doc_diagonal},\n\t{\"clip\", (PyCFunction)array_clip,\n\t METH_VARARGS|METH_KEYWORDS, doc_clip},\n\t{\"conj\", (PyCFunction)array_conjugate,\n\t METH_VARARGS, doc_conj},\n\t{\"conjugate\", (PyCFunction)array_conjugate,\n\t METH_VARARGS, doc_conjugate},\n\t{\"nonzero\", (PyCFunction)array_nonzero,\n\t METH_VARARGS, doc_nonzero},\n\t{\"std\", (PyCFunction)array_stddev,\n\t METH_VARARGS|METH_KEYWORDS, doc_stddev},\n\t{\"var\", (PyCFunction)array_variance,\n\t METH_VARARGS|METH_KEYWORDS, doc_variance},\n\t{\"sum\", (PyCFunction)array_sum,\n\t METH_VARARGS|METH_KEYWORDS, doc_sum},\n\t{\"cumsum\", (PyCFunction)array_cumsum,\n\t METH_VARARGS|METH_KEYWORDS, doc_cumsum},\n\t{\"prod\", (PyCFunction)array_prod,\n\t METH_VARARGS|METH_KEYWORDS, doc_prod},\n\t{\"cumprod\", (PyCFunction)array_cumprod,\n\t METH_VARARGS|METH_KEYWORDS, doc_cumprod},\n\t{\"all\", (PyCFunction)array_all,\n\t METH_VARARGS, doc_all},\n\t{\"any\", (PyCFunction)array_any,\n\t METH_VARARGS, doc_any},\n\t{\"compress\", (PyCFunction)array_compress,\n\t METH_VARARGS|METH_KEYWORDS, doc_compress},\n\t{\"flatten\", (PyCFunction)array_flatten,\n\t METH_VARARGS, doc_flatten},\n\t{\"ravel\", (PyCFunction)array_ravel,\n\t METH_VARARGS, doc_ravel},\n\t{\"setflags\", (PyCFunction)array_setflags,\n\t METH_VARARGS|METH_KEYWORDS, doc_setflags},\n\t{\"newbyteorder\", (PyCFunction)array_newbyteorder,\n\t METH_VARARGS, doc_newbyteorder},\n {NULL,\t\tNULL}\t\t/* sentinel */\n};\n\n#undef _ARET\n\n\n", + "methods": [ + { + "name": "array_take", + "long_name": "array_take( PyArrayObject * self , PyObject * args , PyObject * kwds)", + "filename": "arraymethods.c", + "nloc": 12, + "complexity": 2, + "token_count": 82, + "parameters": [ + "self", + "args", + "kwds" + ], + "start_line": 9, + "end_line": 22, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 14, + "top_nesting_level": 0 + }, + { + "name": "array_fill", + "long_name": "array_fill( PyArrayObject * self , PyObject * args)", + "filename": "arraymethods.c", + "nloc": 9, + "complexity": 3, + "token_count": 54, + "parameters": [ + "self", + "args" + ], + "start_line": 28, + "end_line": 36, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 9, + "top_nesting_level": 0 + }, + { + "name": "array_put", + "long_name": "array_put( PyArrayObject * self , PyObject * args , PyObject * kwds)", + "filename": "arraymethods.c", + "nloc": 9, + "complexity": 2, + "token_count": 71, + "parameters": [ + "self", + "args", + "kwds" + ], + "start_line": 43, + "end_line": 52, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 10, + "top_nesting_level": 0 + }, + { + "name": "array_putmask", + "long_name": "array_putmask( PyArrayObject * self , PyObject * args , PyObject * kwds)", + "filename": "arraymethods.c", + "nloc": 9, + "complexity": 2, + "token_count": 71, + "parameters": [ + "self", + "args", + "kwds" + ], + "start_line": 58, + "end_line": 68, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 11, + "top_nesting_level": 0 + }, + { + "name": "_reverse_shape", + "long_name": "_reverse_shape( PyArray_Dims * newshape)", + "filename": "arraymethods.c", + "nloc": 14, + "complexity": 2, + "token_count": 81, + "parameters": [ + "newshape" + ], + "start_line": 72, + "end_line": 86, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 15, + "top_nesting_level": 0 + }, + { + "name": "array_reshape", + "long_name": "array_reshape( PyArrayObject * self , PyObject * args)", + "filename": "arraymethods.c", + "nloc": 50, + "complexity": 13, + "token_count": 299, + "parameters": [ + "self", + "args" + ], + "start_line": 94, + "end_line": 147, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 54, + "top_nesting_level": 0 + }, + { + "name": "array_squeeze", + "long_name": "array_squeeze( PyArrayObject * self , PyObject * args)", + "filename": "arraymethods.c", + "nloc": 5, + "complexity": 2, + "token_count": 34, + "parameters": [ + "self", + "args" + ], + "start_line": 152, + "end_line": 156, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 5, + "top_nesting_level": 0 + }, + { + "name": "array_view", + "long_name": "array_view( PyArrayObject * self , PyObject * args)", + "filename": "arraymethods.c", + "nloc": 19, + "complexity": 6, + "token_count": 110, + "parameters": [ + "self", + "args" + ], + "start_line": 161, + "end_line": 181, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 21, + "top_nesting_level": 0 + }, + { + "name": "array_argmax", + "long_name": "array_argmax( PyArrayObject * self , PyObject * args)", + "filename": "arraymethods.c", + "nloc": 7, + "complexity": 2, + "token_count": 46, + "parameters": [ + "self", + "args" + ], + "start_line": 186, + "end_line": 194, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 9, + "top_nesting_level": 0 + }, + { + "name": "array_argmin", + "long_name": "array_argmin( PyArrayObject * self , PyObject * args)", + "filename": "arraymethods.c", + "nloc": 7, + "complexity": 2, + "token_count": 46, + "parameters": [ + "self", + "args" + ], + "start_line": 199, + "end_line": 207, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 9, + "top_nesting_level": 0 + }, + { + "name": "array_max", + "long_name": "array_max( PyArrayObject * self , PyObject * args)", + "filename": "arraymethods.c", + "nloc": 7, + "complexity": 2, + "token_count": 43, + "parameters": [ + "self", + "args" + ], + "start_line": 212, + "end_line": 220, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 9, + "top_nesting_level": 0 + }, + { + "name": "array_ptp", + "long_name": "array_ptp( PyArrayObject * self , PyObject * args)", + "filename": "arraymethods.c", + "nloc": 7, + "complexity": 2, + "token_count": 43, + "parameters": [ + "self", + "args" + ], + "start_line": 225, + "end_line": 233, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 9, + "top_nesting_level": 0 + }, + { + "name": "array_min", + "long_name": "array_min( PyArrayObject * self , PyObject * args)", + "filename": "arraymethods.c", + "nloc": 7, + "complexity": 2, + "token_count": 43, + "parameters": [ + "self", + "args" + ], + "start_line": 239, + "end_line": 247, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 9, + "top_nesting_level": 0 + }, + { + "name": "array_swapaxes", + "long_name": "array_swapaxes( PyArrayObject * self , PyObject * args)", + "filename": "arraymethods.c", + "nloc": 6, + "complexity": 2, + "token_count": 46, + "parameters": [ + "self", + "args" + ], + "start_line": 253, + "end_line": 260, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 8, + "top_nesting_level": 0 + }, + { + "name": "PyArray_GetField", + "long_name": "PyArray_GetField( PyArrayObject * self , PyArray_Descr * typed , int offset)", + "filename": "arraymethods.c", + "nloc": 23, + "complexity": 4, + "token_count": 155, + "parameters": [ + "self", + "typed", + "offset" + ], + "start_line": 272, + "end_line": 296, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 25, + "top_nesting_level": 0 + }, + { + "name": "array_getfield", + "long_name": "array_getfield( PyArrayObject * self , PyObject * args , PyObject * kwds)", + "filename": "arraymethods.c", + "nloc": 10, + "complexity": 2, + "token_count": 78, + "parameters": [ + "self", + "args", + "kwds" + ], + "start_line": 299, + "end_line": 311, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 13, + "top_nesting_level": 0 + }, + { + "name": "PyArray_SetField", + "long_name": "PyArray_SetField( PyArrayObject * self , PyArray_Descr * dtype , int offset , PyObject * val)", + "filename": "arraymethods.c", + "nloc": 25, + "complexity": 4, + "token_count": 184, + "parameters": [ + "self", + "dtype", + "offset", + "val" + ], + "start_line": 321, + "end_line": 347, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 27, + "top_nesting_level": 0 + }, + { + "name": "array_setfield", + "long_name": "array_setfield( PyArrayObject * self , PyObject * args , PyObject * kwds)", + "filename": "arraymethods.c", + "nloc": 14, + "complexity": 3, + "token_count": 100, + "parameters": [ + "self", + "args", + "kwds" + ], + "start_line": 350, + "end_line": 365, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 16, + "top_nesting_level": 0 + }, + { + "name": "PyArray_Byteswap", + "long_name": "PyArray_Byteswap( PyArrayObject * self , Bool inplace)", + "filename": "arraymethods.c", + "nloc": 37, + "complexity": 5, + "token_count": 226, + "parameters": [ + "self", + "inplace" + ], + "start_line": 372, + "end_line": 419, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 48, + "top_nesting_level": 0 + }, + { + "name": "array_byteswap", + "long_name": "array_byteswap( PyArrayObject * self , PyObject * args)", + "filename": "arraymethods.c", + "nloc": 7, + "complexity": 2, + "token_count": 43, + "parameters": [ + "self", + "args" + ], + "start_line": 426, + "end_line": 434, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 9, + "top_nesting_level": 0 + }, + { + "name": "array_tolist", + "long_name": "array_tolist( PyArrayObject * self , PyObject * args)", + "filename": "arraymethods.c", + "nloc": 10, + "complexity": 3, + "token_count": 51, + "parameters": [ + "self", + "args" + ], + "start_line": 440, + "end_line": 450, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 11, + "top_nesting_level": 0 + }, + { + "name": "array_tostring", + "long_name": "array_tostring( PyArrayObject * self , PyObject * args)", + "filename": "arraymethods.c", + "nloc": 5, + "complexity": 2, + "token_count": 31, + "parameters": [ + "self", + "args" + ], + "start_line": 456, + "end_line": 460, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 5, + "top_nesting_level": 0 + }, + { + "name": "array_tofile", + "long_name": "array_tofile( PyArrayObject * self , PyObject * args , PyObject * kwds)", + "filename": "arraymethods.c", + "nloc": 33, + "complexity": 7, + "token_count": 208, + "parameters": [ + "self", + "args", + "kwds" + ], + "start_line": 465, + "end_line": 499, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 35, + "top_nesting_level": 0 + }, + { + "name": "array_toscalar", + "long_name": "array_toscalar( PyArrayObject * self , PyObject * args)", + "filename": "arraymethods.c", + "nloc": 10, + "complexity": 4, + "token_count": 71, + "parameters": [ + "self", + "args" + ], + "start_line": 505, + "end_line": 514, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 10, + "top_nesting_level": 0 + }, + { + "name": "array_cast", + "long_name": "array_cast( PyArrayObject * self , PyObject * args)", + "filename": "arraymethods.c", + "nloc": 13, + "complexity": 3, + "token_count": 83, + "parameters": [ + "self", + "args" + ], + "start_line": 521, + "end_line": 535, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 15, + "top_nesting_level": 0 + }, + { + "name": "array_wraparray", + "long_name": "array_wraparray( PyArrayObject * self , PyObject * args)", + "filename": "arraymethods.c", + "nloc": 27, + "complexity": 4, + "token_count": 147, + "parameters": [ + "self", + "args" + ], + "start_line": 543, + "end_line": 571, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 29, + "top_nesting_level": 0 + }, + { + "name": "array_finalize", + "long_name": "array_finalize( PyArrayObject * self , PyObject * args)", + "filename": "arraymethods.c", + "nloc": 5, + "complexity": 1, + "token_count": 20, + "parameters": [ + "self", + "args" + ], + "start_line": 575, + "end_line": 579, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 5, + "top_nesting_level": 0 + }, + { + "name": "array_getarray", + "long_name": "array_getarray( PyArrayObject * self , PyObject * args)", + "filename": "arraymethods.c", + "nloc": 38, + "complexity": 8, + "token_count": 224, + "parameters": [ + "self", + "args" + ], + "start_line": 585, + "end_line": 628, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 44, + "top_nesting_level": 0 + }, + { + "name": "array_copy", + "long_name": "array_copy( PyArrayObject * self , PyObject * args)", + "filename": "arraymethods.c", + "nloc": 6, + "complexity": 2, + "token_count": 41, + "parameters": [ + "self", + "args" + ], + "start_line": 637, + "end_line": 643, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 7, + "top_nesting_level": 0 + }, + { + "name": "array_resize", + "long_name": "array_resize( PyArrayObject * self , PyObject * args)", + "filename": "arraymethods.c", + "nloc": 26, + "complexity": 6, + "token_count": 129, + "parameters": [ + "self", + "args" + ], + "start_line": 651, + "end_line": 677, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 27, + "top_nesting_level": 0 + }, + { + "name": "array_repeat", + "long_name": "array_repeat( PyArrayObject * self , PyObject * args , PyObject * kwds)", + "filename": "arraymethods.c", + "nloc": 9, + "complexity": 2, + "token_count": 78, + "parameters": [ + "self", + "args", + "kwds" + ], + "start_line": 685, + "end_line": 695, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 11, + "top_nesting_level": 0 + }, + { + "name": "array_choose", + "long_name": "array_choose( PyArrayObject * self , PyObject * args)", + "filename": "arraymethods.c", + "nloc": 14, + "complexity": 3, + "token_count": 68, + "parameters": [ + "self", + "args" + ], + "start_line": 705, + "end_line": 720, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 16, + "top_nesting_level": 0 + }, + { + "name": "array_sort", + "long_name": "array_sort( PyArrayObject * self , PyObject * args , PyObject * kwds)", + "filename": "arraymethods.c", + "nloc": 14, + "complexity": 3, + "token_count": 98, + "parameters": [ + "self", + "args", + "kwds" + ], + "start_line": 725, + "end_line": 740, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 16, + "top_nesting_level": 0 + }, + { + "name": "array_argsort", + "long_name": "array_argsort( PyArrayObject * self , PyObject * args , PyObject * kwds)", + "filename": "arraymethods.c", + "nloc": 10, + "complexity": 2, + "token_count": 80, + "parameters": [ + "self", + "args", + "kwds" + ], + "start_line": 747, + "end_line": 758, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 12, + "top_nesting_level": 0 + }, + { + "name": "array_searchsorted", + "long_name": "array_searchsorted( PyArrayObject * self , PyObject * args)", + "filename": "arraymethods.c", + "nloc": 6, + "complexity": 2, + "token_count": 43, + "parameters": [ + "self", + "args" + ], + "start_line": 769, + "end_line": 776, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 8, + "top_nesting_level": 0 + }, + { + "name": "array_deepcopy", + "long_name": "array_deepcopy( PyArrayObject * self , PyObject * args)", + "filename": "arraymethods.c", + "nloc": 32, + "complexity": 7, + "token_count": 234, + "parameters": [ + "self", + "args" + ], + "start_line": 781, + "end_line": 814, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 34, + "top_nesting_level": 0 + }, + { + "name": "_getobject_pkl", + "long_name": "_getobject_pkl( PyArrayObject * self)", + "filename": "arraymethods.c", + "nloc": 18, + "complexity": 4, + "token_count": 128, + "parameters": [ + "self" + ], + "start_line": 818, + "end_line": 837, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 20, + "top_nesting_level": 0 + }, + { + "name": "_setobject_pkl", + "long_name": "_setobject_pkl( PyArrayObject * self , PyObject * list)", + "filename": "arraymethods.c", + "nloc": 17, + "complexity": 3, + "token_count": 115, + "parameters": [ + "self", + "list" + ], + "start_line": 840, + "end_line": 858, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 19, + "top_nesting_level": 0 + }, + { + "name": "array_reduce", + "long_name": "array_reduce( PyArrayObject * self , PyObject * args)", + "filename": "arraymethods.c", + "nloc": 46, + "complexity": 7, + "token_count": 313, + "parameters": [ + "self", + "args" + ], + "start_line": 863, + "end_line": 926, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 64, + "top_nesting_level": 0 + }, + { + "name": "array_setstate", + "long_name": "array_setstate( PyArrayObject * self , PyObject * args)", + "filename": "arraymethods.c", + "nloc": 98, + "complexity": 17, + "token_count": 579, + "parameters": [ + "self", + "args" + ], + "start_line": 944, + "end_line": 1057, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 114, + "top_nesting_level": 0 + }, + { + "name": "PyArray_Dump", + "long_name": "PyArray_Dump( PyObject * self , PyObject * file , int protocol)", + "filename": "arraymethods.c", + "nloc": 20, + "complexity": 6, + "token_count": 132, + "parameters": [ + "self", + "file", + "protocol" + ], + "start_line": 1061, + "end_line": 1082, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 22, + "top_nesting_level": 0 + }, + { + "name": "PyArray_Dumps", + "long_name": "PyArray_Dumps( PyObject * self , int protocol)", + "filename": "arraymethods.c", + "nloc": 11, + "complexity": 3, + "token_count": 70, + "parameters": [ + "self", + "protocol" + ], + "start_line": 1086, + "end_line": 1097, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 12, + "top_nesting_level": 0 + }, + { + "name": "array_dump", + "long_name": "array_dump( PyArrayObject * self , PyObject * args)", + "filename": "arraymethods.c", + "nloc": 11, + "complexity": 3, + "token_count": 69, + "parameters": [ + "self", + "args" + ], + "start_line": 1103, + "end_line": 1114, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 12, + "top_nesting_level": 0 + }, + { + "name": "array_dumps", + "long_name": "array_dumps( PyArrayObject * self , PyObject * args)", + "filename": "arraymethods.c", + "nloc": 6, + "complexity": 2, + "token_count": 37, + "parameters": [ + "self", + "args" + ], + "start_line": 1119, + "end_line": 1124, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 6, + "top_nesting_level": 0 + }, + { + "name": "array_transpose", + "long_name": "array_transpose( PyArrayObject * self , PyObject * args)", + "filename": "arraymethods.c", + "nloc": 18, + "complexity": 5, + "token_count": 116, + "parameters": [ + "self", + "args" + ], + "start_line": 1130, + "end_line": 1150, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 21, + "top_nesting_level": 0 + }, + { + "name": "array_mean", + "long_name": "array_mean( PyArrayObject * self , PyObject * args , PyObject * kwds)", + "filename": "arraymethods.c", + "nloc": 11, + "complexity": 2, + "token_count": 82, + "parameters": [ + "self", + "args", + "kwds" + ], + "start_line": 1168, + "end_line": 1180, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 13, + "top_nesting_level": 0 + }, + { + "name": "array_sum", + "long_name": "array_sum( PyArrayObject * self , PyObject * args , PyObject * kwds)", + "filename": "arraymethods.c", + "nloc": 11, + "complexity": 2, + "token_count": 82, + "parameters": [ + "self", + "args", + "kwds" + ], + "start_line": 1207, + "end_line": 1219, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 13, + "top_nesting_level": 0 + }, + { + "name": "array_cumsum", + "long_name": "array_cumsum( PyArrayObject * self , PyObject * args , PyObject * kwds)", + "filename": "arraymethods.c", + "nloc": 11, + "complexity": 2, + "token_count": 82, + "parameters": [ + "self", + "args", + "kwds" + ], + "start_line": 1225, + "end_line": 1237, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 13, + "top_nesting_level": 0 + }, + { + "name": "array_prod", + "long_name": "array_prod( PyArrayObject * self , PyObject * args , PyObject * kwds)", + "filename": "arraymethods.c", + "nloc": 11, + "complexity": 2, + "token_count": 82, + "parameters": [ + "self", + "args", + "kwds" + ], + "start_line": 1242, + "end_line": 1254, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 13, + "top_nesting_level": 0 + }, + { + "name": "array_cumprod", + "long_name": "array_cumprod( PyArrayObject * self , PyObject * args , PyObject * kwds)", + "filename": "arraymethods.c", + "nloc": 11, + "complexity": 2, + "token_count": 82, + "parameters": [ + "self", + "args", + "kwds" + ], + "start_line": 1260, + "end_line": 1272, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 13, + "top_nesting_level": 0 + }, + { + "name": "array_any", + "long_name": "array_any( PyArrayObject * self , PyObject * args)", + "filename": "arraymethods.c", + "nloc": 7, + "complexity": 2, + "token_count": 43, + "parameters": [ + "self", + "args" + ], + "start_line": 1278, + "end_line": 1286, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 9, + "top_nesting_level": 0 + }, + { + "name": "array_all", + "long_name": "array_all( PyArrayObject * self , PyObject * args)", + "filename": "arraymethods.c", + "nloc": 7, + "complexity": 2, + "token_count": 43, + "parameters": [ + "self", + "args" + ], + "start_line": 1291, + "end_line": 1299, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 9, + "top_nesting_level": 0 + }, + { + "name": "array_stddev", + "long_name": "array_stddev( PyArrayObject * self , PyObject * args , PyObject * kwds)", + "filename": "arraymethods.c", + "nloc": 11, + "complexity": 2, + "token_count": 84, + "parameters": [ + "self", + "args", + "kwds" + ], + "start_line": 1304, + "end_line": 1316, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 13, + "top_nesting_level": 0 + }, + { + "name": "array_variance", + "long_name": "array_variance( PyArrayObject * self , PyObject * args , PyObject * kwds)", + "filename": "arraymethods.c", + "nloc": 11, + "complexity": 2, + "token_count": 84, + "parameters": [ + "self", + "args", + "kwds" + ], + "start_line": 1321, + "end_line": 1333, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 13, + "top_nesting_level": 0 + }, + { + "name": "array_compress", + "long_name": "array_compress( PyArrayObject * self , PyObject * args , PyObject * kwds)", + "filename": "arraymethods.c", + "nloc": 10, + "complexity": 2, + "token_count": 78, + "parameters": [ + "self", + "args", + "kwds" + ], + "start_line": 1338, + "end_line": 1349, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 12, + "top_nesting_level": 0 + }, + { + "name": "array_nonzero", + "long_name": "array_nonzero( PyArrayObject * self , PyObject * args)", + "filename": "arraymethods.c", + "nloc": 5, + "complexity": 2, + "token_count": 34, + "parameters": [ + "self", + "args" + ], + "start_line": 1355, + "end_line": 1360, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 6, + "top_nesting_level": 0 + }, + { + "name": "array_trace", + "long_name": "array_trace( PyArrayObject * self , PyObject * args , PyObject * kwds)", + "filename": "arraymethods.c", + "nloc": 12, + "complexity": 2, + "token_count": 105, + "parameters": [ + "self", + "args", + "kwds" + ], + "start_line": 1368, + "end_line": 1381, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 14, + "top_nesting_level": 0 + }, + { + "name": "array_clip", + "long_name": "array_clip( PyArrayObject * self , PyObject * args , PyObject * kwds)", + "filename": "arraymethods.c", + "nloc": 9, + "complexity": 2, + "token_count": 74, + "parameters": [ + "self", + "args", + "kwds" + ], + "start_line": 1389, + "end_line": 1399, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 11, + "top_nesting_level": 0 + }, + { + "name": "array_conjugate", + "long_name": "array_conjugate( PyArrayObject * self , PyObject * args)", + "filename": "arraymethods.c", + "nloc": 5, + "complexity": 2, + "token_count": 31, + "parameters": [ + "self", + "args" + ], + "start_line": 1406, + "end_line": 1412, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 7, + "top_nesting_level": 0 + }, + { + "name": "array_diagonal", + "long_name": "array_diagonal( PyArrayObject * self , PyObject * args , PyObject * kwds)", + "filename": "arraymethods.c", + "nloc": 9, + "complexity": 2, + "token_count": 87, + "parameters": [ + "self", + "args", + "kwds" + ], + "start_line": 1418, + "end_line": 1428, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 11, + "top_nesting_level": 0 + }, + { + "name": "array_flatten", + "long_name": "array_flatten( PyArrayObject * self , PyObject * args)", + "filename": "arraymethods.c", + "nloc": 6, + "complexity": 2, + "token_count": 44, + "parameters": [ + "self", + "args" + ], + "start_line": 1433, + "end_line": 1440, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 8, + "top_nesting_level": 0 + }, + { + "name": "array_ravel", + "long_name": "array_ravel( PyArrayObject * self , PyObject * args)", + "filename": "arraymethods.c", + "nloc": 6, + "complexity": 2, + "token_count": 41, + "parameters": [ + "self", + "args" + ], + "start_line": 1445, + "end_line": 1452, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 8, + "top_nesting_level": 0 + }, + { + "name": "array_setflags", + "long_name": "array_setflags( PyArrayObject * self , PyObject * args , PyObject * kwds)", + "filename": "arraymethods.c", + "nloc": 53, + "complexity": 10, + "token_count": 260, + "parameters": [ + "self", + "args", + "kwds" + ], + "start_line": 1462, + "end_line": 1519, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 58, + "top_nesting_level": 0 + }, + { + "name": "array_newbyteorder", + "long_name": "array_newbyteorder( PyArrayObject * self , PyObject * args)", + "filename": "arraymethods.c", + "nloc": 10, + "complexity": 3, + "token_count": 68, + "parameters": [ + "self", + "args" + ], + "start_line": 1525, + "end_line": 1537, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 13, + "top_nesting_level": 0 + } + ], + "methods_before": [ + { + "name": "array_take", + "long_name": "array_take( PyArrayObject * self , PyObject * args , PyObject * kwds)", + "filename": "arraymethods.c", + "nloc": 12, + "complexity": 2, + "token_count": 82, + "parameters": [ + "self", + "args", + "kwds" + ], + "start_line": 9, + "end_line": 22, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 14, + "top_nesting_level": 0 + }, + { + "name": "array_fill", + "long_name": "array_fill( PyArrayObject * self , PyObject * args)", + "filename": "arraymethods.c", + "nloc": 9, + "complexity": 3, + "token_count": 54, + "parameters": [ + "self", + "args" + ], + "start_line": 28, + "end_line": 36, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 9, + "top_nesting_level": 0 + }, + { + "name": "array_put", + "long_name": "array_put( PyArrayObject * self , PyObject * args , PyObject * kwds)", + "filename": "arraymethods.c", + "nloc": 9, + "complexity": 2, + "token_count": 71, + "parameters": [ + "self", + "args", + "kwds" + ], + "start_line": 43, + "end_line": 52, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 10, + "top_nesting_level": 0 + }, + { + "name": "array_putmask", + "long_name": "array_putmask( PyArrayObject * self , PyObject * args , PyObject * kwds)", + "filename": "arraymethods.c", + "nloc": 9, + "complexity": 2, + "token_count": 71, + "parameters": [ + "self", + "args", + "kwds" + ], + "start_line": 58, + "end_line": 68, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 11, + "top_nesting_level": 0 + }, + { + "name": "_reverse_shape", + "long_name": "_reverse_shape( PyArray_Dims * newshape)", + "filename": "arraymethods.c", + "nloc": 14, + "complexity": 2, + "token_count": 81, + "parameters": [ + "newshape" + ], + "start_line": 72, + "end_line": 86, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 15, + "top_nesting_level": 0 + }, + { + "name": "array_reshape", + "long_name": "array_reshape( PyArrayObject * self , PyObject * args)", + "filename": "arraymethods.c", + "nloc": 50, + "complexity": 13, + "token_count": 299, + "parameters": [ + "self", + "args" + ], + "start_line": 94, + "end_line": 147, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 54, + "top_nesting_level": 0 + }, + { + "name": "array_squeeze", + "long_name": "array_squeeze( PyArrayObject * self , PyObject * args)", + "filename": "arraymethods.c", + "nloc": 5, + "complexity": 2, + "token_count": 34, + "parameters": [ + "self", + "args" + ], + "start_line": 152, + "end_line": 156, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 5, + "top_nesting_level": 0 + }, + { + "name": "array_view", + "long_name": "array_view( PyArrayObject * self , PyObject * args)", + "filename": "arraymethods.c", + "nloc": 19, + "complexity": 6, + "token_count": 110, + "parameters": [ + "self", + "args" + ], + "start_line": 161, + "end_line": 181, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 21, + "top_nesting_level": 0 + }, + { + "name": "array_argmax", + "long_name": "array_argmax( PyArrayObject * self , PyObject * args)", + "filename": "arraymethods.c", + "nloc": 7, + "complexity": 2, + "token_count": 46, + "parameters": [ + "self", + "args" + ], + "start_line": 186, + "end_line": 194, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 9, + "top_nesting_level": 0 + }, + { + "name": "array_argmin", + "long_name": "array_argmin( PyArrayObject * self , PyObject * args)", + "filename": "arraymethods.c", + "nloc": 7, + "complexity": 2, + "token_count": 46, + "parameters": [ + "self", + "args" + ], + "start_line": 199, + "end_line": 207, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 9, + "top_nesting_level": 0 + }, + { + "name": "array_max", + "long_name": "array_max( PyArrayObject * self , PyObject * args)", + "filename": "arraymethods.c", + "nloc": 7, + "complexity": 2, + "token_count": 43, + "parameters": [ + "self", + "args" + ], + "start_line": 212, + "end_line": 220, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 9, + "top_nesting_level": 0 + }, + { + "name": "array_ptp", + "long_name": "array_ptp( PyArrayObject * self , PyObject * args)", + "filename": "arraymethods.c", + "nloc": 7, + "complexity": 2, + "token_count": 43, + "parameters": [ + "self", + "args" + ], + "start_line": 225, + "end_line": 233, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 9, + "top_nesting_level": 0 + }, + { + "name": "array_min", + "long_name": "array_min( PyArrayObject * self , PyObject * args)", + "filename": "arraymethods.c", + "nloc": 7, + "complexity": 2, + "token_count": 43, + "parameters": [ + "self", + "args" + ], + "start_line": 239, + "end_line": 247, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 9, + "top_nesting_level": 0 + }, + { + "name": "array_swapaxes", + "long_name": "array_swapaxes( PyArrayObject * self , PyObject * args)", + "filename": "arraymethods.c", + "nloc": 6, + "complexity": 2, + "token_count": 46, + "parameters": [ + "self", + "args" + ], + "start_line": 253, + "end_line": 260, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 8, + "top_nesting_level": 0 + }, + { + "name": "PyArray_GetField", + "long_name": "PyArray_GetField( PyArrayObject * self , PyArray_Descr * typed , int offset)", + "filename": "arraymethods.c", + "nloc": 23, + "complexity": 4, + "token_count": 155, + "parameters": [ + "self", + "typed", + "offset" + ], + "start_line": 272, + "end_line": 296, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 25, + "top_nesting_level": 0 + }, + { + "name": "array_getfield", + "long_name": "array_getfield( PyArrayObject * self , PyObject * args , PyObject * kwds)", + "filename": "arraymethods.c", + "nloc": 10, + "complexity": 2, + "token_count": 78, + "parameters": [ + "self", + "args", + "kwds" + ], + "start_line": 299, + "end_line": 311, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 13, + "top_nesting_level": 0 + }, + { + "name": "PyArray_SetField", + "long_name": "PyArray_SetField( PyArrayObject * self , PyArray_Descr * dtype , int offset , PyObject * val)", + "filename": "arraymethods.c", + "nloc": 25, + "complexity": 4, + "token_count": 184, + "parameters": [ + "self", + "dtype", + "offset", + "val" + ], + "start_line": 321, + "end_line": 347, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 27, + "top_nesting_level": 0 + }, + { + "name": "array_setfield", + "long_name": "array_setfield( PyArrayObject * self , PyObject * args , PyObject * kwds)", + "filename": "arraymethods.c", + "nloc": 14, + "complexity": 3, + "token_count": 100, + "parameters": [ + "self", + "args", + "kwds" + ], + "start_line": 350, + "end_line": 365, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 16, + "top_nesting_level": 0 + }, + { + "name": "PyArray_Byteswap", + "long_name": "PyArray_Byteswap( PyArrayObject * self , Bool inplace)", + "filename": "arraymethods.c", + "nloc": 37, + "complexity": 5, + "token_count": 226, + "parameters": [ + "self", + "inplace" + ], + "start_line": 372, + "end_line": 419, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 48, + "top_nesting_level": 0 + }, + { + "name": "array_byteswap", + "long_name": "array_byteswap( PyArrayObject * self , PyObject * args)", + "filename": "arraymethods.c", + "nloc": 7, + "complexity": 2, + "token_count": 43, + "parameters": [ + "self", + "args" + ], + "start_line": 426, + "end_line": 434, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 9, + "top_nesting_level": 0 + }, + { + "name": "array_tolist", + "long_name": "array_tolist( PyArrayObject * self , PyObject * args)", + "filename": "arraymethods.c", + "nloc": 10, + "complexity": 3, + "token_count": 51, + "parameters": [ + "self", + "args" + ], + "start_line": 440, + "end_line": 450, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 11, + "top_nesting_level": 0 + }, + { + "name": "array_tostring", + "long_name": "array_tostring( PyArrayObject * self , PyObject * args)", + "filename": "arraymethods.c", + "nloc": 5, + "complexity": 2, + "token_count": 31, + "parameters": [ + "self", + "args" + ], + "start_line": 456, + "end_line": 460, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 5, + "top_nesting_level": 0 + }, + { + "name": "array_tofile", + "long_name": "array_tofile( PyArrayObject * self , PyObject * args , PyObject * kwds)", + "filename": "arraymethods.c", + "nloc": 33, + "complexity": 7, + "token_count": 208, + "parameters": [ + "self", + "args", + "kwds" + ], + "start_line": 465, + "end_line": 499, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 35, + "top_nesting_level": 0 + }, + { + "name": "array_toscalar", + "long_name": "array_toscalar( PyArrayObject * self , PyObject * args)", + "filename": "arraymethods.c", + "nloc": 10, + "complexity": 4, + "token_count": 71, + "parameters": [ + "self", + "args" + ], + "start_line": 505, + "end_line": 514, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 10, + "top_nesting_level": 0 + }, + { + "name": "array_cast", + "long_name": "array_cast( PyArrayObject * self , PyObject * args)", + "filename": "arraymethods.c", + "nloc": 13, + "complexity": 3, + "token_count": 83, + "parameters": [ + "self", + "args" + ], + "start_line": 521, + "end_line": 535, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 15, + "top_nesting_level": 0 + }, + { + "name": "array_wraparray", + "long_name": "array_wraparray( PyArrayObject * self , PyObject * args)", + "filename": "arraymethods.c", + "nloc": 27, + "complexity": 4, + "token_count": 147, + "parameters": [ + "self", + "args" + ], + "start_line": 543, + "end_line": 571, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 29, + "top_nesting_level": 0 + }, + { + "name": "array_finalize", + "long_name": "array_finalize( PyArrayObject * self , PyObject * args)", + "filename": "arraymethods.c", + "nloc": 5, + "complexity": 1, + "token_count": 20, + "parameters": [ + "self", + "args" + ], + "start_line": 575, + "end_line": 579, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 5, + "top_nesting_level": 0 + }, + { + "name": "array_getarray", + "long_name": "array_getarray( PyArrayObject * self , PyObject * args)", + "filename": "arraymethods.c", + "nloc": 38, + "complexity": 8, + "token_count": 224, + "parameters": [ + "self", + "args" + ], + "start_line": 585, + "end_line": 628, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 44, + "top_nesting_level": 0 + }, + { + "name": "array_copy", + "long_name": "array_copy( PyArrayObject * self , PyObject * args)", + "filename": "arraymethods.c", + "nloc": 6, + "complexity": 2, + "token_count": 41, + "parameters": [ + "self", + "args" + ], + "start_line": 637, + "end_line": 643, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 7, + "top_nesting_level": 0 + }, + { + "name": "array_resize", + "long_name": "array_resize( PyArrayObject * self , PyObject * args)", + "filename": "arraymethods.c", + "nloc": 26, + "complexity": 6, + "token_count": 129, + "parameters": [ + "self", + "args" + ], + "start_line": 651, + "end_line": 677, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 27, + "top_nesting_level": 0 + }, + { + "name": "array_repeat", + "long_name": "array_repeat( PyArrayObject * self , PyObject * args , PyObject * kwds)", + "filename": "arraymethods.c", + "nloc": 9, + "complexity": 2, + "token_count": 78, + "parameters": [ + "self", + "args", + "kwds" + ], + "start_line": 685, + "end_line": 695, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 11, + "top_nesting_level": 0 + }, + { + "name": "array_choose", + "long_name": "array_choose( PyArrayObject * self , PyObject * args)", + "filename": "arraymethods.c", + "nloc": 14, + "complexity": 3, + "token_count": 68, + "parameters": [ + "self", + "args" + ], + "start_line": 705, + "end_line": 720, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 16, + "top_nesting_level": 0 + }, + { + "name": "array_sort", + "long_name": "array_sort( PyArrayObject * self , PyObject * args , PyObject * kwds)", + "filename": "arraymethods.c", + "nloc": 14, + "complexity": 3, + "token_count": 98, + "parameters": [ + "self", + "args", + "kwds" + ], + "start_line": 725, + "end_line": 740, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 16, + "top_nesting_level": 0 + }, + { + "name": "array_argsort", + "long_name": "array_argsort( PyArrayObject * self , PyObject * args , PyObject * kwds)", + "filename": "arraymethods.c", + "nloc": 10, + "complexity": 2, + "token_count": 80, + "parameters": [ + "self", + "args", + "kwds" + ], + "start_line": 747, + "end_line": 758, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 12, + "top_nesting_level": 0 + }, + { + "name": "array_searchsorted", + "long_name": "array_searchsorted( PyArrayObject * self , PyObject * args)", + "filename": "arraymethods.c", + "nloc": 6, + "complexity": 2, + "token_count": 43, + "parameters": [ + "self", + "args" + ], + "start_line": 769, + "end_line": 776, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 8, + "top_nesting_level": 0 + }, + { + "name": "array_deepcopy", + "long_name": "array_deepcopy( PyArrayObject * self , PyObject * args)", + "filename": "arraymethods.c", + "nloc": 32, + "complexity": 7, + "token_count": 234, + "parameters": [ + "self", + "args" + ], + "start_line": 781, + "end_line": 814, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 34, + "top_nesting_level": 0 + }, + { + "name": "_getobject_pkl", + "long_name": "_getobject_pkl( PyArrayObject * self)", + "filename": "arraymethods.c", + "nloc": 18, + "complexity": 4, + "token_count": 128, + "parameters": [ + "self" + ], + "start_line": 818, + "end_line": 837, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 20, + "top_nesting_level": 0 + }, + { + "name": "_setobject_pkl", + "long_name": "_setobject_pkl( PyArrayObject * self , PyObject * list)", + "filename": "arraymethods.c", + "nloc": 17, + "complexity": 3, + "token_count": 115, + "parameters": [ + "self", + "list" + ], + "start_line": 840, + "end_line": 858, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 19, + "top_nesting_level": 0 + }, + { + "name": "array_reduce", + "long_name": "array_reduce( PyArrayObject * self , PyObject * args)", + "filename": "arraymethods.c", + "nloc": 46, + "complexity": 7, + "token_count": 313, + "parameters": [ + "self", + "args" + ], + "start_line": 863, + "end_line": 926, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 64, + "top_nesting_level": 0 + }, + { + "name": "array_setstate", + "long_name": "array_setstate( PyArrayObject * self , PyObject * args)", + "filename": "arraymethods.c", + "nloc": 98, + "complexity": 17, + "token_count": 579, + "parameters": [ + "self", + "args" + ], + "start_line": 944, + "end_line": 1057, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 114, + "top_nesting_level": 0 + }, + { + "name": "PyArray_Dump", + "long_name": "PyArray_Dump( PyObject * self , PyObject * file , int protocol)", + "filename": "arraymethods.c", + "nloc": 20, + "complexity": 6, + "token_count": 132, + "parameters": [ + "self", + "file", + "protocol" + ], + "start_line": 1061, + "end_line": 1082, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 22, + "top_nesting_level": 0 + }, + { + "name": "PyArray_Dumps", + "long_name": "PyArray_Dumps( PyObject * self , int protocol)", + "filename": "arraymethods.c", + "nloc": 11, + "complexity": 3, + "token_count": 70, + "parameters": [ + "self", + "protocol" + ], + "start_line": 1086, + "end_line": 1097, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 12, + "top_nesting_level": 0 + }, + { + "name": "array_dump", + "long_name": "array_dump( PyArrayObject * self , PyObject * args)", + "filename": "arraymethods.c", + "nloc": 11, + "complexity": 3, + "token_count": 69, + "parameters": [ + "self", + "args" + ], + "start_line": 1103, + "end_line": 1114, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 12, + "top_nesting_level": 0 + }, + { + "name": "array_dumps", + "long_name": "array_dumps( PyArrayObject * self , PyObject * args)", + "filename": "arraymethods.c", + "nloc": 6, + "complexity": 2, + "token_count": 37, + "parameters": [ + "self", + "args" + ], + "start_line": 1119, + "end_line": 1124, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 6, + "top_nesting_level": 0 + }, + { + "name": "array_transpose", + "long_name": "array_transpose( PyArrayObject * self , PyObject * args)", + "filename": "arraymethods.c", + "nloc": 18, + "complexity": 5, + "token_count": 116, + "parameters": [ + "self", + "args" + ], + "start_line": 1130, + "end_line": 1150, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 21, + "top_nesting_level": 0 + }, + { + "name": "array_mean", + "long_name": "array_mean( PyArrayObject * self , PyObject * args , PyObject * kwds)", + "filename": "arraymethods.c", + "nloc": 11, + "complexity": 2, + "token_count": 82, + "parameters": [ + "self", + "args", + "kwds" + ], + "start_line": 1168, + "end_line": 1180, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 13, + "top_nesting_level": 0 + }, + { + "name": "array_sum", + "long_name": "array_sum( PyArrayObject * self , PyObject * args , PyObject * kwds)", + "filename": "arraymethods.c", + "nloc": 11, + "complexity": 2, + "token_count": 82, + "parameters": [ + "self", + "args", + "kwds" + ], + "start_line": 1207, + "end_line": 1219, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 13, + "top_nesting_level": 0 + }, + { + "name": "array_cumsum", + "long_name": "array_cumsum( PyArrayObject * self , PyObject * args , PyObject * kwds)", + "filename": "arraymethods.c", + "nloc": 11, + "complexity": 2, + "token_count": 82, + "parameters": [ + "self", + "args", + "kwds" + ], + "start_line": 1225, + "end_line": 1237, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 13, + "top_nesting_level": 0 + }, + { + "name": "array_prod", + "long_name": "array_prod( PyArrayObject * self , PyObject * args , PyObject * kwds)", + "filename": "arraymethods.c", + "nloc": 11, + "complexity": 2, + "token_count": 82, + "parameters": [ + "self", + "args", + "kwds" + ], + "start_line": 1242, + "end_line": 1254, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 13, + "top_nesting_level": 0 + }, + { + "name": "array_cumprod", + "long_name": "array_cumprod( PyArrayObject * self , PyObject * args , PyObject * kwds)", + "filename": "arraymethods.c", + "nloc": 11, + "complexity": 2, + "token_count": 82, + "parameters": [ + "self", + "args", + "kwds" + ], + "start_line": 1260, + "end_line": 1272, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 13, + "top_nesting_level": 0 + }, + { + "name": "array_any", + "long_name": "array_any( PyArrayObject * self , PyObject * args)", + "filename": "arraymethods.c", + "nloc": 7, + "complexity": 2, + "token_count": 43, + "parameters": [ + "self", + "args" + ], + "start_line": 1278, + "end_line": 1286, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 9, + "top_nesting_level": 0 + }, + { + "name": "array_all", + "long_name": "array_all( PyArrayObject * self , PyObject * args)", + "filename": "arraymethods.c", + "nloc": 7, + "complexity": 2, + "token_count": 43, + "parameters": [ + "self", + "args" + ], + "start_line": 1291, + "end_line": 1299, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 9, + "top_nesting_level": 0 + }, + { + "name": "array_stddev", + "long_name": "array_stddev( PyArrayObject * self , PyObject * args , PyObject * kwds)", + "filename": "arraymethods.c", + "nloc": 11, + "complexity": 2, + "token_count": 84, + "parameters": [ + "self", + "args", + "kwds" + ], + "start_line": 1304, + "end_line": 1316, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 13, + "top_nesting_level": 0 + }, + { + "name": "array_variance", + "long_name": "array_variance( PyArrayObject * self , PyObject * args , PyObject * kwds)", + "filename": "arraymethods.c", + "nloc": 11, + "complexity": 2, + "token_count": 84, + "parameters": [ + "self", + "args", + "kwds" + ], + "start_line": 1321, + "end_line": 1333, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 13, + "top_nesting_level": 0 + }, + { + "name": "array_compress", + "long_name": "array_compress( PyArrayObject * self , PyObject * args , PyObject * kwds)", + "filename": "arraymethods.c", + "nloc": 10, + "complexity": 2, + "token_count": 78, + "parameters": [ + "self", + "args", + "kwds" + ], + "start_line": 1338, + "end_line": 1349, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 12, + "top_nesting_level": 0 + }, + { + "name": "array_nonzero", + "long_name": "array_nonzero( PyArrayObject * self , PyObject * args)", + "filename": "arraymethods.c", + "nloc": 5, + "complexity": 2, + "token_count": 34, + "parameters": [ + "self", + "args" + ], + "start_line": 1355, + "end_line": 1360, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 6, + "top_nesting_level": 0 + }, + { + "name": "array_trace", + "long_name": "array_trace( PyArrayObject * self , PyObject * args , PyObject * kwds)", + "filename": "arraymethods.c", + "nloc": 12, + "complexity": 2, + "token_count": 105, + "parameters": [ + "self", + "args", + "kwds" + ], + "start_line": 1368, + "end_line": 1381, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 14, + "top_nesting_level": 0 + }, + { + "name": "array_clip", + "long_name": "array_clip( PyArrayObject * self , PyObject * args , PyObject * kwds)", + "filename": "arraymethods.c", + "nloc": 9, + "complexity": 2, + "token_count": 74, + "parameters": [ + "self", + "args", + "kwds" + ], + "start_line": 1389, + "end_line": 1399, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 11, + "top_nesting_level": 0 + }, + { + "name": "array_conjugate", + "long_name": "array_conjugate( PyArrayObject * self , PyObject * args)", + "filename": "arraymethods.c", + "nloc": 5, + "complexity": 2, + "token_count": 31, + "parameters": [ + "self", + "args" + ], + "start_line": 1406, + "end_line": 1412, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 7, + "top_nesting_level": 0 + }, + { + "name": "array_diagonal", + "long_name": "array_diagonal( PyArrayObject * self , PyObject * args , PyObject * kwds)", + "filename": "arraymethods.c", + "nloc": 9, + "complexity": 2, + "token_count": 87, + "parameters": [ + "self", + "args", + "kwds" + ], + "start_line": 1418, + "end_line": 1428, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 11, + "top_nesting_level": 0 + }, + { + "name": "array_flatten", + "long_name": "array_flatten( PyArrayObject * self , PyObject * args)", + "filename": "arraymethods.c", + "nloc": 6, + "complexity": 2, + "token_count": 44, + "parameters": [ + "self", + "args" + ], + "start_line": 1433, + "end_line": 1440, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 8, + "top_nesting_level": 0 + }, + { + "name": "array_ravel", + "long_name": "array_ravel( PyArrayObject * self , PyObject * args)", + "filename": "arraymethods.c", + "nloc": 6, + "complexity": 2, + "token_count": 41, + "parameters": [ + "self", + "args" + ], + "start_line": 1445, + "end_line": 1452, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 8, + "top_nesting_level": 0 + }, + { + "name": "array_setflags", + "long_name": "array_setflags( PyArrayObject * self , PyObject * args , PyObject * kwds)", + "filename": "arraymethods.c", + "nloc": 53, + "complexity": 10, + "token_count": 260, + "parameters": [ + "self", + "args", + "kwds" + ], + "start_line": 1462, + "end_line": 1519, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 58, + "top_nesting_level": 0 + }, + { + "name": "array_newbyteorder", + "long_name": "array_newbyteorder( PyArrayObject * self , PyObject * args)", + "filename": "arraymethods.c", + "nloc": 10, + "complexity": 3, + "token_count": 69, + "parameters": [ + "self", + "args" + ], + "start_line": 1525, + "end_line": 1537, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 13, + "top_nesting_level": 0 + } + ], + "changed_methods": [ + { + "name": "array_newbyteorder", + "long_name": "array_newbyteorder( PyArrayObject * self , PyObject * args)", + "filename": "arraymethods.c", + "nloc": 10, + "complexity": 3, + "token_count": 68, + "parameters": [ + "self", + "args" + ], + "start_line": 1525, + "end_line": 1537, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 13, + "top_nesting_level": 0 + } + ], + "nloc": 1311, + "complexity": 220, + "token_count": 8164, + "diff_parsed": { + "added": [ + "\treturn PyArray_View(self, new, NULL);" + ], + "deleted": [ + "\treturn PyArray_View(self, new, NULL));" + ] + } + } + ] + }, + { + "hash": "3faeb7eb7d496991eaa55996c6a9ada2248a2b29", + "msg": "Fix segfault and move PyArray_Put fix from newunicode branch.", + "author": { + "name": "Travis Oliphant", + "email": "oliphant@enthought.com" + }, + "committer": { + "name": "Travis Oliphant", + "email": "oliphant@enthought.com" + }, + "author_date": "2006-02-14T04:56:47+00:00", + "author_timezone": 0, + "committer_date": "2006-02-14T04:56:47+00:00", + "committer_timezone": 0, + "branches": [ + "main" + ], + "in_main_branch": true, + "merge": true, + "parents": [ + "adcc8b80b9c60136aef3b37891219b6e504398fc", + "7e34c2e10baa325f2ca22a12e655b1729ae59785" + ], + "project_name": "repo_copy", + "project_path": "/tmp/tmpdjwupkfu/repo_copy", + "deletions": 4, + "insertions": 4, + "lines": 8, + "files": 1, + "dmm_unit_size": null, + "dmm_unit_complexity": null, + "dmm_unit_interfacing": null + }, + { + "hash": "263df7516f66a53dd9a93f6cd08ce98e30ad0eca", + "msg": "Make Getptr function and macros return void *", + "author": { + "name": "Travis Oliphant", + "email": "oliphant@enthought.com" + }, + "committer": { + "name": "Travis Oliphant", + "email": "oliphant@enthought.com" + }, + "author_date": "2006-02-14T22:15:05+00:00", + "author_timezone": 0, + "committer_date": "2006-02-14T22:15:05+00:00", + "committer_timezone": 0, + "branches": [ + "main" + ], + "in_main_branch": true, + "merge": false, + "parents": [ + "3faeb7eb7d496991eaa55996c6a9ada2248a2b29" + ], + "project_name": "repo_copy", + "project_path": "/tmp/tmpdjwupkfu/repo_copy", + "deletions": 6, + "insertions": 6, + "lines": 12, + "files": 2, + "dmm_unit_size": null, + "dmm_unit_complexity": null, + "dmm_unit_interfacing": null, + "modified_files": [ + { + "old_path": "numpy/core/include/numpy/arrayobject.h", + "new_path": "numpy/core/include/numpy/arrayobject.h", + "filename": "arrayobject.h", + "extension": "h", + "change_type": "MODIFY", + "diff": "@@ -1465,19 +1465,19 @@ typedef struct {\n inline the constants inside a for loop making it a moot point\n */\n \n-#define PyArray_GETPTR1(obj, i) (PyArray_DATA(obj) +\t\t\\\n+#define PyArray_GETPTR1(obj, i) (void *)(PyArray_BYTES(obj) +\t\t\\\n \t\t\t\t i*PyArray_STRIDE(obj, 0))\n \n-#define PyArray_GETPTR2(obj, i, j) (PyArray_DATA(obj) +\t\t\\\n+#define PyArray_GETPTR2(obj, i, j) (void *)(PyArray_BYTES(obj) +\t\t\\\n \t\t\t\t i*PyArray_STRIDE(obj, 0) +\t\\\n \t\t\t\t j*PyArray_STRIDE(obj, 1))\n \n-#define PyArray_GETPTR3(obj, i, j, k) (PyArray_DATA(obj) +\t\t\\\n+#define PyArray_GETPTR3(obj, i, j, k) (void *)(PyArray_BYTES(obj) +\t\t\\\n \t\t\t\t i*PyArray_STRIDE(obj, 0) +\t\\\n \t\t\t\t j*PyArray_STRIDE(obj, 1) +\t\\\n \t\t\t\t k*PyArray_STRIDE(obj, 2))\t\\\n \n-#define PyArray_GETPTR4(obj, i, j, k, l) (PyArray_DATA(obj) +\t\t\\\n+#define PyArray_GETPTR4(obj, i, j, k, l) (void *)(PyArray_BYTES(obj) +\t\t\\\n \t\t\t\t\t i*PyArray_STRIDE(obj, 0) +\t\\\n \t\t\t\t\t j*PyArray_STRIDE(obj, 1) +\t\\\n \t\t\t\t\t k*PyArray_STRIDE(obj, 2) +\t\\\n", + "added_lines": 4, + "deleted_lines": 4, + "source_code": "/* This expects the following variables to be defined (besides\n the usual ones from pyconfig.h\n\n SIZEOF_LONG_DOUBLE -- sizeof(long double) or sizeof(double) if no\n long double is present on platform.\n CHAR_BIT -- number of bits in a char (usually 8)\n (should be in limits.h)\n*/\n\n#ifndef Py_ARRAYOBJECT_H\n#define Py_ARRAYOBJECT_H\n#ifdef __cplusplus\n#define CONFUSE_EMACS {\n#define CONFUSE_EMACS2 }\nextern \"C\" CONFUSE_EMACS\n#undef CONFUSE_EMACS\n#undef CONFUSE_EMACS2\n/* ... otherwise a semi-smart idententer (like emacs) tries to indent\n everything when you're typing */\n#endif\n#include \"config.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 longlong NS(longlong)\n# define ulonglong NS(ulonglong)\n# define Bool NS(Bool)\n# define longdouble NS(longdouble)\n# define byte NS(byte)\n# define ubyte NS(ubyte)\n# define ushort NS(ushort)\n# define uint NS(uint)\n# define ulong NS(ulong)\n# define cfloat NS(cfloat)\n# define cdouble NS(cdouble)\n# define clongdouble NS(clongdouble)\n# define Int8 NS(Int8)\n# define UInt8 NS(UInt8)\n# define Int16 NS(Int16)\n# define UInt16 NS(UInt16)\n# define Int32 NS(Int32)\n# define UInt32 NS(UInt32)\n# define Int64 NS(Int64)\n# define UInt64 NS(UInt64)\n# define Int128 NS(Int128)\n# define UInt128 NS(UInt128)\n# define Int256 NS(Int256)\n# define UInt256 NS(UInt256)\n# define Float16 NS(Float16)\n# define Complex32 NS(Complex32)\n# define Float32 NS(Float32)\n# define Complex64 NS(Complex64)\n# define Float64 NS(Float64)\n# define Complex128 NS(Complex128)\n# define Float80 NS(Float80)\n# define Complex160 NS(Complex160)\n# define Float96 NS(Float96)\n# define Complex192 NS(Complex192)\n# define Float128 NS(Float128)\n# define Complex256 NS(Complex256)\n# define intp NS(intp)\n# define uintp NS(uintp)\n#endif\n\n/* There are several places in the code where an array of dimensions is */\n/* allocated statically. This is the size of that static allocation. */\n/* The array creation itself could have arbitrary dimensions but\n * all the places where static allocation is used would need to\n * be changed to dynamic (including inside of structures)\n */\n\n#define MAX_DIMS 32\n\n/* Used for Converter Functions \"O&\" code in ParseTuple */\n#define PY_FAIL 0\n#define PY_SUCCEED 1\n\n\t/* Helpful to distinguish what is installed */\n#define NDARRAY_VERSION 0x00090405\n\n\t/* Some platforms don't define bool, long long, or long double.\n\t Handle that here.\n\t */\n\n#ifdef PY_LONG_LONG\ntypedef PY_LONG_LONG longlong;\ntypedef unsigned PY_LONG_LONG ulonglong;\n# ifdef _MSC_VER\n# define LONGLONG_FMT \"I64d\"\n# define ULONGLONG_FMT \"I64u\"\n# define LONGLONG_SUFFIX(x) (x##i64)\n# define ULONGLONG_SUFFIX(x) (x##Ui64)\n# else\n\t/* #define LONGLONG_FMT \"lld\" Another possible variant\n #define ULONGLONG_FMT \"llu\"\n\n\t #define LONGLONG_FMT \"qd\" -- BSD perhaps?\n\t #define ULONGLONG_FMT \"qu\"\n\t*/\n# define LONGLONG_FMT \"Ld\"\n# define ULONGLONG_FMT \"Lu\"\n# define LONGLONG_SUFFIX(x) (x##LL)\n# define ULONGLONG_SUFFIX(x) (x##ULL)\n# endif\n#else\ntypedef long longlong;\ntypedef unsigned long ulonglong;\n# define LONGLONG_SUFFIX(x) (x##L)\n# define ULONGLONG_SUFFIX(x) (x##UL)\n#endif\n\ntypedef unsigned char Bool;\n#ifndef FALSE\n#define FALSE 0\n#endif\n#ifndef TRUE\n#define TRUE 1\n#endif\n\n#if SIZEOF_LONG_DOUBLE==SIZEOF_DOUBLE\n\ttypedef double longdouble;\n #define LONGDOUBLE_FMT \"g\"\n#else\n\ttypedef long double longdouble;\n #define LONGDOUBLE_FMT \"Lg\"\n#endif\n\n#ifndef Py_USING_UNICODE\n#error Must use Python with unicode enabled. \n#endif\n\n\ntypedef signed char byte;\ntypedef unsigned char ubyte;\n#ifndef _BSD_SOURCE\ntypedef unsigned short ushort;\ntypedef unsigned int uint;\ntypedef unsigned long ulong;\n#endif\n\ntypedef struct { float real, imag; } cfloat;\ntypedef struct { double real, imag; } cdouble;\ntypedef struct {longdouble real, imag;} clongdouble;\n\nenum PyArray_TYPES { PyArray_BOOL=0,\n PyArray_BYTE, PyArray_UBYTE,\n\t\t PyArray_SHORT, PyArray_USHORT,\n\t\t PyArray_INT, PyArray_UINT,\n\t\t\tPyArray_LONG, PyArray_ULONG,\n PyArray_LONGLONG, PyArray_ULONGLONG,\n\t\t\tPyArray_FLOAT, PyArray_DOUBLE, PyArray_LONGDOUBLE,\n\t\t\tPyArray_CFLOAT, PyArray_CDOUBLE, PyArray_CLONGDOUBLE,\n\t\t\tPyArray_OBJECT=17,\n PyArray_STRING, PyArray_UNICODE,\n\t\t\tPyArray_VOID,\n\t\t\tPyArray_NTYPES,\n\t\t\tPyArray_NOTYPE,\n\t\t\tPyArray_USERDEF=256 /* leave room for characters */\n};\n\n\t/* basetype array priority */\n#define PyArray_PRIORITY 0.0\n#define PyArray_BIG_PRIORITY 0.1\n\t/* default subtype priority */\n#define PyArray_SUBTYPE_PRIORITY 1.0\n\n\t/* How many floating point types are there */\n#define PyArray_NUM_FLOATTYPE 3\n\n\n\t/* We need to match intp to a signed integer of the same size as\n\t a pointer variable. uintp to the equivalent unsigned integer\n\t*/\n\n\n\t/* These characters correspond to the array type and the\n\t struct module */\n\n\t/* except 'p' -- signed integer for pointer type */\n\nenum PyArray_TYPECHAR { PyArray_BOOLLTR = '?',\n\t\t\tPyArray_BYTELTR = 'b',\n\t\t\tPyArray_UBYTELTR = 'B',\n\t\t\tPyArray_SHORTLTR = 'h',\n\t\t\tPyArray_USHORTLTR = 'H',\n\t\t\tPyArray_INTLTR = 'i',\n\t\t\tPyArray_UINTLTR = 'I',\n\t\t\tPyArray_LONGLTR = 'l',\n\t\t\tPyArray_ULONGLTR = 'L',\n\t\t\tPyArray_LONGLONGLTR = 'q',\n\t\t\tPyArray_ULONGLONGLTR = 'Q',\n\t\t\tPyArray_FLOATLTR = 'f',\n\t\t\tPyArray_DOUBLELTR = 'd',\n\t\t\tPyArray_LONGDOUBLELTR = 'g',\n\t\t\tPyArray_CFLOATLTR = 'F',\n\t\t\tPyArray_CDOUBLELTR = 'D',\n\t\t\tPyArray_CLONGDOUBLELTR = 'G',\n\t\t\tPyArray_OBJECTLTR = 'O',\n\t\t\tPyArray_STRINGLTR = 'S',\n\t\t\tPyArray_STRINGLTR2 = 'a',\n\t\t\tPyArray_UNICODELTR = 'U',\n\t\t PyArray_VOIDLTR = 'V',\n\n\t\t\t/* No Descriptor, just a define -- this let's\n\t\t\t Python users specify an array of integers\n\t\t\t large enough to hold a pointer on the platform*/\n\t\t\tPyArray_INTPLTR = 'p',\n\t\t\tPyArray_UINTPLTR = 'P',\n\n\t\t\tPyArray_GENBOOLLTR ='b',\n\t\t\tPyArray_SIGNEDLTR = 'i',\n\t\t\tPyArray_UNSIGNEDLTR = 'u',\n\t\t\tPyArray_FLOATINGLTR = 'f',\n\t\t\tPyArray_COMPLEXLTR = 'c'\n};\n\ntypedef enum {\n\tPyArray_QUICKSORT=0,\n\tPyArray_HEAPSORT=1,\n\tPyArray_MERGESORT=2,\n\tPyArray_TIMSORT=3 /* the sort Python uses -- specialized */\n} PyArray_SORTKIND;\n#define PyArray_NSORTS PyArray_TIMSORT + 1\n\n\t/* Define bit-width array types and typedefs */\n\n#define MAX_INT8 127\n#define MIN_INT8 -128\n#define MAX_UINT8 255\n#define MAX_INT16 32767\n#define MIN_INT16 -32768\n#define MAX_UINT16 65535\n#define MAX_INT32 2147483647\n#define MIN_INT32 (-MAX_INT32 - 1)\n#define MAX_UINT32 4294967295U\n#define MAX_INT64 LONGLONG_SUFFIX(9223372036854775807)\n#define MIN_INT64 (-MAX_INT64 - LONGLONG_SUFFIX(1))\n#define MAX_UINT64 ULONGLONG_SUFFIX(18446744073709551615)\n#define MAX_INT128 LONGLONG_SUFFIX(85070591730234615865843651857942052864)\n#define MIN_INT128 (-MAX_INT128 - LONGLONG_SUFFIX(1))\n#define MAX_UINT128 ULONGLONG_SUFFIX(170141183460469231731687303715884105728)\n#define MAX_INT256 LONGLONG_SUFFIX(57896044618658097711785492504343953926634992332820282019728792003956564819967)\n#define MIN_INT256 (-MAX_INT256 - LONGLONG_SUFFIX(1))\n#define MAX_UINT256 ULONGLONG_SUFFIX(115792089237316195423570985008687907853269984665640564039457584007913129639935)\n\n\t/* Need to find the number of bits for each type and\n\t make definitions accordingly.\n\n\t C states that sizeof(char) == 1 by definition\n\n\t So, just using the sizeof keyword won't help.\n\n\t It also looks like Python itself uses sizeof(char) quite a\n\t bit, which by definition should be 1 all the time.\n\n\t Idea: Make Use of CHAR_BIT which should tell us how many\n\t BITS per CHARACTER\n\t*/\n\n\t/* Include platform definitions -- These are in the C89/90 standard */\n#include \n#define MAX_BYTE SCHAR_MAX\n#define MIN_BYTE SCHAR_MIN\n#define MAX_UBYTE UCHAR_MAX\n#define MAX_SHORT SHRT_MAX\n#define MIN_SHORT SHRT_MIN\n#define MAX_USHORT USHRT_MAX\n#define MAX_INT INT_MAX\n#ifndef INT_MIN\n#define INT_MIN (-INT_MAX - 1)\n#endif\n#define MIN_INT INT_MIN\n#define MAX_UINT UINT_MAX\n#define MAX_LONG LONG_MAX\n#define MIN_LONG LONG_MIN\n#define MAX_ULONG ULONG_MAX\n\n#define SIZEOF_LONGDOUBLE SIZEOF_LONG_DOUBLE\n#define SIZEOF_LONGLONG SIZEOF_LONG_LONG\n#define BITSOF_BOOL sizeof(Bool)*CHAR_BIT\n#define BITSOF_CHAR CHAR_BIT\n#define BITSOF_SHORT (SIZEOF_SHORT*CHAR_BIT)\n#define BITSOF_INT (SIZEOF_INT*CHAR_BIT)\n#define BITSOF_LONG (SIZEOF_LONG*CHAR_BIT)\n#define BITSOF_LONGLONG (SIZEOF_LONGLONG*CHAR_BIT)\n#define BITSOF_FLOAT (SIZEOF_FLOAT*CHAR_BIT)\n#define BITSOF_DOUBLE (SIZEOF_DOUBLE*CHAR_BIT)\n#define BITSOF_LONGDOUBLE (SIZEOF_LONGDOUBLE*CHAR_BIT)\n\n\n#if BITSOF_LONG == 8\n#define PyArray_INT8 PyArray_LONG\n#define PyArray_UINT8 PyArray_ULONG\n\ttypedef long Int8;\n\ttypedef unsigned long UInt8;\n#define STRBITSOF_LONG \"8\"\n#elif BITSOF_LONG == 16\n#define PyArray_INT16 PyArray_LONG\n#define PyArray_UINT16 PyArray_ULONG\n\ttypedef long Int16;\n\ttypedef unsigned long UInt16;\n#define STRBITSOF_LONG \"16\"\n#elif BITSOF_LONG == 32\n#define PyArray_INT32 PyArray_LONG\n#define PyArray_UINT32 PyArray_ULONG\n\ttypedef long Int32;\n\ttypedef unsigned long UInt32;\n\ttypedef unsigned long PyArray_UCS4;\n#define STRBITSOF_LONG \"32\"\n#elif BITSOF_LONG == 64\n#define PyArray_INT64 PyArray_LONG\n#define PyArray_UINT64 PyArray_ULONG\n\ttypedef long Int64;\n\ttypedef unsigned long UInt64;\n#define STRBITSOF_LONG \"64\"\n#elif BITSOF_LONG == 128\n#define PyArray_INT128 PyArray_LONG\n#define PyArray_UINT128 PyArray_ULONG\n\ttypedef long Int128;\n\ttypedef unsigned long UInt128;\n#define STRBITSOF_LONG \"128\"\n#endif\n\n#if BITSOF_LONGLONG == 8\n# ifndef PyArray_INT8\n# define PyArray_INT8 PyArray_LONGLONG\n# define PyArray_UINT8 PyArray_ULONGLONG\n\ttypedef longlong Int8;\n\ttypedef ulonglong UInt8;\n# endif\n# define MAX_LONGLONG MAX_INT8\n# define MIN_LONGLONG MIN_INT8\n# define MAX_ULONGLONG MAX_UINT8\n#define STRBITSOF_LONGLONG \"8\"\n#elif BITSOF_LONGLONG == 16\n# ifndef PyArray_INT16\n# define PyArray_INT16 PyArray_LONGLONG\n# define PyArray_UINT16 PyArray_ULONGLONG\n\ttypedef longlong Int16;\n\ttypedef ulonglong UInt16;\n# endif\n# define MAX_LONGLONG MAX_INT16\n# define MIN_LONGLONG MIN_INT16\n# define MAX_ULONGLONG MAX_UINT16\n#define STRBITSOF_LONGLONG \"16\"\n#elif BITSOF_LONGLONG == 32\n# ifndef PyArray_INT32\n# define PyArray_INT32 PyArray_LONGLONG\n# define PyArray_UINT32 PyArray_ULONGLONG\n\ttypedef longlong Int32;\n\ttypedef ulonglong UInt32;\n\ttypedef ulonglong PyArray_UCS4;\n# endif\n# define MAX_LONGLONG MAX_INT32\n# define MIN_LONGLONG MIN_INT32\n# define MAX_ULONGLONG MAX_UINT32\n#define STRBITSOF_LONGLONG \"32\"\n#elif BITSOF_LONGLONG == 64\n# ifndef PyArray_INT64\n# define PyArray_INT64 PyArray_LONGLONG\n# define PyArray_UINT64 PyArray_ULONGLONG\n\ttypedef longlong Int64;\n\ttypedef ulonglong UInt64;\n# endif\n# define MAX_LONGLONG MAX_INT64\n# define MIN_LONGLONG MIN_INT64\n# define MAX_ULONGLONG MAX_UINT64\n#define STRBITSOF_LONGLONG \"64\"\n#elif BITSOF_LONGLONG == 128\n# ifndef PyArray_INT128\n# define PyArray_INT128 PyArray_LONGLONG\n# define PyArray_UINT128 PyArray_ULONGLONG\n\ttypedef longlong Int128;\n\ttypedef ulonglong UInt128;\n# endif\n# define MAX_LONGLONG MAX_INT128\n# define MIN_LONGLONG MIN_INT128\n# define MAX_ULONGLONG MAX_UINT128\n#define STRBITSOF_LONGLONG \"128\"\n#elif BITSOF_LONGLONG == 256\n# define PyArray_INT256 PyArray_LONGLONG\n# define PyArray_UINT256 PyArray_ULONGLONG\n\ttypedef longlong Int256;\n\ttypedef ulonglong UInt256;\n# define MAX_LONGLONG MAX_INT256\n# define MIN_LONGLONG MIN_INT256\n# define MAX_ULONGLONG MAX_UINT256\n#define STRBITSOF_LONGLONG \"256\"\n#endif\n\n#if BITSOF_INT == 8\n#ifndef PyArray_INT8\n#define PyArray_INT8 PyArray_INT\n#define PyArray_UINT8 PyArray_UINT\n\ttypedef int Int8;\n\ttypedef unsigned int UInt8;\n#endif\n#define STRBITSOF_INT \"8\"\n#elif BITSOF_INT == 16\n#ifndef PyArray_INT16\n#define PyArray_INT16 PyArray_INT\n#define PyArray_UINT16 PyArray_UINT\n\ttypedef int Int16;\n\ttypedef unsigned int UInt16;\n#endif\n#define STRBITSOF_INT \"16\"\n#elif BITSOF_INT == 32\n#ifndef PyArray_INT32\n#define PyArray_INT32 PyArray_INT\n#define PyArray_UINT32 PyArray_UINT\n\ttypedef int Int32;\n\ttypedef unsigned int UInt32;\n\ttypedef unsigned int PyArray_UCS4;\n#endif\n#define STRBITSOF_INT \"32\"\n#elif BITSOF_INT == 64\n#ifndef PyArray_INT64\n#define PyArray_INT64 PyArray_INT\n#define PyArray_UINT64 PyArray_UINT\n\ttypedef int Int64;\n\ttypedef unsigned int UInt64;\n#endif\n#define STRBITSOF_INT \"64\"\n#elif BITSOF_INT == 128\n#ifndef PyArray_INT128\n#define PyArray_INT128 PyArray_INT\n#define PyArray_UINT128 PyArray_UINT\n\ttypedef int Int128;\n\ttypedef unsigned int UInt128;\n#endif\n#define STRBITSOF_INT \"128\"\n#endif\n\n#if BITSOF_SHORT == 8\n#ifndef PyArray_INT8\n#define PyArray_INT8 PyArray_SHORT\n#define PyArray_UINT8 PyArray_USHORT\n\ttypedef short Int8;\n\ttypedef unsigned short UInt8;\n#endif\n#define STRBITSOF_SHORT \"8\"\n#elif BITSOF_SHORT == 16\n#ifndef PyArray_INT16\n#define PyArray_INT16 PyArray_SHORT\n#define PyArray_UINT16 PyArray_USHORT\n\ttypedef short Int16;\n\ttypedef unsigned short UInt16;\n#endif\n#define STRBITSOF_SHORT \"16\"\n#elif BITSOF_SHORT == 32\n#ifndef PyArray_INT32\n#define PyArray_INT32 PyArray_SHORT\n#define PyArray_UINT32 PyArray_USHORT\n\ttypedef short Int32;\n\ttypedef unsigned short UInt32;\n\ttypedef unsigned short PyArray_UCS4;\n#endif\n#define STRBITSOF_SHORT \"32\"\n#elif BITSOF_SHORT == 64\n#ifndef PyArray_INT64\n#define PyArray_INT64 PyArray_SHORT\n#define PyArray_UINT64 PyArray_USHORT\n\ttypedef short Int64;\n\ttypedef unsigned short UInt64;\n#endif\n#define STRBITSOF_SHORT \"64\"\n#elif BITSOF_SHORT == 128\n#ifndef PyArray_INT128\n#define PyArray_INT128 PyArray_SHORT\n#define PyArray_UINT128 PyArray_USHORT\n\ttypedef short Int128;\n\ttypedef unsigned short UInt128;\n#endif\n#define STRBITSOF_SHORT \"128\"\n#endif\n\n\n#if BITSOF_CHAR == 8\n#ifndef PyArray_INT8\n#define PyArray_INT8 PyArray_BYTE\n#define PyArray_UINT8 PyArray_UBYTE\n\ttypedef signed char Int8;\n\ttypedef unsigned char UInt8;\n#endif\n#define STRBITSOF_CHAR \"8\"\n#elif BITSOF_CHAR == 16\n#ifndef PyArray_INT16\n#define PyArray_INT16 PyArray_BYTE\n#define PyArray_UINT16 PyArray_UBYTE\n\ttypedef signed char Int16;\n\ttypedef unsigned char UInt16;\n#endif\n#define STRBITSOF_CHAR \"16\"\n#elif BITSOF_CHAR == 32\n#ifndef PyArray_INT32\n#define PyArray_INT32 PyArray_BYTE\n#define PyArray_UINT32 PyArray_UBYTE\n\ttypedef signed char Int32;\n\ttypedef unsigned char UInt32;\n\ttypedef unsigned char PyArray_UCS4;\n#endif\n#define STRBITSOF_CHAR \"32\"\n#elif BITSOF_CHAR == 64\n#ifndef PyArray_INT64\n#define PyArray_INT64 PyArray_BYTE\n#define PyArray_UINT64 PyArray_UBYTE\n\ttypedef signed char Int64;\n\ttypedef unsigned char UInt64;\n#endif\n#define STRBITSOF_CHAR \"64\"\n#elif BITSOF_CHAR == 128\n#ifndef PyArray_INT128\n#define PyArray_INT128 PyArray_BYTE\n#define PyArray_UINT128 PyArray_UBYTE\n\ttypedef signed char Int128;\n\ttypedef unsigned char UInt128;\n#endif\n#define STRBITSOF_CHAR \"128\"\n#endif\n\n\n\n#if BITSOF_DOUBLE == 16\n#define STRBITSOF_DOUBLE \"16\"\n#define STRBITSOF_CDOUBLE \"32\"\n#ifndef PyArray_FLOAT16\n#define PyArray_FLOAT16 PyArray_DOUBLE\n#define PyArray_COMPLEX32 PyArray_CDOUBLE\n\ttypedef double Float16;\n\ttypedef cdouble Complex32;\n#endif\n#elif BITSOF_DOUBLE == 32\n#define STRBITSOF_DOUBLE \"32\"\n#define STRBITSOF_CDOUBLE \"64\"\n#ifndef PyArray_FLOAT32\n#define PyArray_FLOAT32 PyArray_DOUBLE\n#define PyArray_COMPLEX64 PyArray_CDOUBLE\n\ttypedef double Float32;\n\ttypedef cdouble Complex64;\n#endif\n#elif BITSOF_DOUBLE == 64\n#define STRBITSOF_DOUBLE \"64\"\n#define STRBITSOF_CDOUBLE \"128\"\n#ifndef PyArray_FLOAT64\n#define PyArray_FLOAT64 PyArray_DOUBLE\n#define PyArray_COMPLEX128 PyArray_CDOUBLE\n\ttypedef double Float64;\n\ttypedef cdouble Complex128;\n#endif\n#elif BITSOF_DOUBLE == 80\n#define STRBITSOF_DOUBLE \"80\"\n#define STRBITSOF_CDOUBLE \"160\"\n#ifndef PyArray_FLOAT80\n#define PyArray_FLOAT80 PyArray_DOUBLE\n#define PyArray_COMPLEX160 PyArray_CDOUBLE\n\ttypedef double Float80;\n\ttypedef cdouble Complex160;\n#endif\n#elif BITSOF_DOUBLE == 96\n#define STRBITSOF_DOUBLE \"96\"\n#define STRBITSOF_CDOUBLE \"192\"\n#ifndef PyArray_FLOAT96\n#define PyArray_FLOAT96 PyArray_DOUBLE\n#define PyArray_COMPLEX192 PyArray_CDOUBLE\n\ttypedef double Float96;\n\ttypedef cdouble Complex192;\n#endif\n#elif BITSOF_DOUBLE == 128\n#define STRBITSOF_DOUBLE \"128\"\n#define STRBITSOF_CDOUBLE \"256\"\n#ifndef PyArray_FLOAT128\n#define PyArray_FLOAT128 PyArray_DOUBLE\n#define PyArray_COMPLEX256 PyArray_CDOUBLE\n\ttypedef double Float128;\n\ttypedef cdouble Complex256;\n#endif\n#endif\n\n\n\n#if BITSOF_FLOAT == 16\n#define STRBITSOF_FLOAT \"16\"\n#define STRBITSOF_CFLOAT \"32\"\n#ifndef PyArray_FLOAT16\n#define PyArray_FLOAT16 PyArray_FLOAT\n#define PyArray_COMPLEX32 PyArray_CFLOAT\n\ttypedef float Float16;\n\ttypedef cfloat Complex32;\n#endif\n#elif BITSOF_FLOAT == 32\n#define STRBITSOF_FLOAT \"32\"\n#define STRBITSOF_CFLOAT \"64\"\n#ifndef PyArray_FLOAT32\n#define PyArray_FLOAT32 PyArray_FLOAT\n#define PyArray_COMPLEX64 PyArray_CFLOAT\n\ttypedef float Float32;\n\ttypedef cfloat Complex64;\n#endif\n#elif BITSOF_FLOAT == 64\n#define STRBITSOF_FLOAT \"64\"\n#define STRBITSOF_CFLOAT \"128\"\n#ifndef PyArray_FLOAT64\n#define PyArray_FLOAT64 PyArray_FLOAT\n#define PyArray_COMPLEX128 PyArray_CFLOAT\n\ttypedef float Float64;\n\ttypedef cfloat Complex128;\n#endif\n#elif BITSOF_FLOAT == 80\n#define STRBITSOF_FLOAT \"80\"\n#define STRBITSOF_CFLOAT \"160\"\n#ifndef PyArray_FLOAT80\n#define PyArray_FLOAT80 PyArray_FLOAT\n#define PyArray_COMPLEX160 PyArray_CFLOAT\n\ttypedef float Float80;\n\ttypedef cfloat Complex160;\n#endif\n#elif BITSOF_FLOAT == 96\n#define STRBITSOF_FLOAT \"96\"\n#define STRBITSOF_CFLOAT \"192\"\n#ifndef PyArray_FLOAT96\n#define PyArray_FLOAT96 PyArray_FLOAT\n#define PyArray_COMPLEX192 PyArray_CFLOAT\n\ttypedef float Float96;\n\ttypedef cfloat Complex192;\n#endif\n#elif BITSOF_FLOAT == 128\n#define STRBITSOF_FLOAT \"128\"\n#define STRBITSOF_CFLOAT \"256\"\n#ifndef PyArray_FLOAT128\n#define PyArray_FLOAT128 PyArray_FLOAT\n#define PyArray_COMPLEX256 PyArray_CFLOAT\n\ttypedef float Float128;\n\ttypedef cfloat Complex256;\n#endif\n#endif\n\n\n#if BITSOF_LONGDOUBLE == 16\n#define STRBITSOF_LONGDOUBLE \"16\"\n#define STRBITSOF_CLONGDOUBLE \"32\"\n#ifndef PyArray_FLOAT16\n#define PyArray_FLOAT16 PyArray_LONGDOUBLE\n#define PyArray_COMPLEX32 PyArray_CLONGDOUBLE\n\ttypedef longdouble Float16;\n\ttypedef clongdouble Complex32;\n#endif\n#elif BITSOF_LONGDOUBLE == 32\n#define STRBITSOF_LONGDOUBLE \"32\"\n#define STRBITSOF_CLONGDOUBLE \"64\"\n#ifndef PyArray_FLOAT32\n#define PyArray_FLOAT32 PyArray_LONGDOUBLE\n#define PyArray_COMPLEX64 PyArray_CLONGDOUBLE\n\ttypedef longdouble Float32;\n\ttypedef clongdouble Complex64;\n#endif\n#elif BITSOF_LONGDOUBLE == 64\n#define STRBITSOF_LONGDOUBLE \"64\"\n#define STRBITSOF_CLONGDOUBLE \"128\"\n#ifndef PyArray_FLOAT64\n#define PyArray_FLOAT64 PyArray_LONGDOUBLE\n#define PyArray_COMPLEX128 PyArray_CLONGDOUBLE\n\ttypedef longdouble Float64;\n\ttypedef clongdouble Complex128;\n#endif\n#elif BITSOF_LONGDOUBLE == 80\n#define STRBITSOF_LONGDOUBLE \"80\"\n#define STRBITSOF_CLONGDOUBLE \"160\"\n#ifndef PyArray_FLOAT80\n#define PyArray_FLOAT80 PyArray_LONGDOUBLE\n#define PyArray_COMPLEX160 PyArray_CLONGDOUBLE\n\ttypedef longdouble Float80;\n\ttypedef clongdouble Complex160;\n#endif\n#elif BITSOF_LONGDOUBLE == 96\n#define STRBITSOF_LONGDOUBLE \"96\"\n#define STRBITSOF_CLONGDOUBLE \"192\"\n#ifndef PyArray_FLOAT96\n#define PyArray_FLOAT96 PyArray_LONGDOUBLE\n#define PyArray_COMPLEX192 PyArray_CLONGDOUBLE\n\ttypedef longdouble Float96;\n\ttypedef clongdouble Complex192;\n#endif\n#elif BITSOF_LONGDOUBLE == 128\n#define STRBITSOF_LONGDOUBLE \"128\"\n#define STRBITSOF_CLONGDOUBLE \"256\"\n#ifndef PyArray_FLOAT128\n#define PyArray_FLOAT128 PyArray_LONGDOUBLE\n#define PyArray_COMPLEX256 PyArray_CLONGDOUBLE\n\ttypedef longdouble Float128;\n\ttypedef clongdouble Complex256;\n#endif\n#elif BITSOF_LONGDOUBLE == 256\n#define STRBITSOF_LONGDOUBLE \"256\"\n#define STRBITSOF_CLONGDOUBLE \"512\"\n#define PyArray_FLOAT256 PyArray_LONGDOUBLE\n#define PyArray_COMPLEX512 PyArray_CLONGDOUBLE\n\ttypedef longdouble Float256;\n\ttypedef clongdouble Complex512;\n#endif\n\n\n\t/* End of typedefs for numarray style bit-width names */\n\n/* This is to typedef Intp to the appropriate pointer size for this platform.\n * Py_intptr_t, Py_uintptr_t are defined in pyport.h. */\ntypedef Py_intptr_t intp;\ntypedef Py_uintptr_t uintp;\n#define SIZEOF_INTP SIZEOF_PY_INTPTR_T\n#define SIZEOF_UINTP SIZEOF_PY_INTPTR_T\n\n#define INTP_FMT \"d\"\n\n#if SIZEOF_PY_INTPTR_T == SIZEOF_INT\n\t#define PyArray_INTP PyArray_INT\n\t#define PyArray_UINTP PyArray_UINT\n #define PyIntpArrType_Type PyIntArrType_Type\n #define PyUIntpArrType_Type PyUIntArrType_Type\n\t#define MAX_INTP MAX_INT\n\t#define MIN_INTP MIN_INT\n\t#define MAX_UINTP MAX_UINT\n#elif SIZEOF_PY_INTPTR_T == SIZEOF_LONG\n\t#define PyArray_INTP PyArray_LONG\n\t#define PyArray_UINTP PyArray_ULONG\n #define PyIntpArrType_Type PyLongArrType_Type\n #define PyUIntpArrType_Type PyULongArrType_Type\n\t#define MAX_INTP MAX_LONG\n\t#define MIN_INTP MIN_LONG\n\t#define MAX_UINTP MAX_ULONG\n #undef INTP_FMT\n #define INTP_FMT \"ld\"\n#elif defined(PY_LONG_LONG) && (SIZEOF_PY_INTPTR_T == SIZEOF_LONG_LONG)\n\t#define PyArray_INTP PyArray_LONGLONG\n\t#define PyArray_UINTP PyArray_ULONGLONG\n #define PyIntpArrType_Type PyLongLongArrType_Type\n #define PyUIntpArrType_Type PyULongLongArrType_Type\n\t#define MAX_INTP MAX_LONGLONG\n\t#define MIN_INTP MIN_LONGLONG\n\t#define MAX_UINTP MAX_ULONGLONG\n #undef INTP_FMT\n #define INTP_FMT \"Ld\"\n#endif\n\n#define ERR(str) fprintf(stderr, #str); fflush(stderr);\n#define ERR2(str) fprintf(stderr, str); fflush(stderr);\n\n /* Macros to define how array, and dimension/strides data is\n allocated.\n */\n\n /* Data buffer */\n#define PyDataMem_NEW(size) ((char *)malloc(size))\n /* #define PyArrayMem_NEW(size) PyMem_NEW(char, size)*/\n#define PyDataMem_FREE(ptr) free(ptr)\n /* #define PyArrayMem_FREE(ptr) PyMem_Free(ptr) */\n#define PyDataMem_RENEW(ptr,size) ((char *)realloc(ptr,size))\n\n#define PyArray_USE_PYMEM 0\n\n#if PyArray_USE_PYMEM == 1\n#define _pya_malloc PyObject_Malloc\n#define _pya_free PyObject_Free\n#define _pya_realloc PyObject_Realloc\n#else\n#define _pya_malloc malloc\n#define _pya_free free\n#define _pya_realloc realloc\n#endif\n\n/* Dimensions and strides */\n#define PyDimMem_NEW(size) ((intp *)_pya_malloc(size*sizeof(intp)))\n#define PyDimMem_FREE(ptr) _pya_free(ptr)\n#define PyDimMem_RENEW(ptr,size) ((intp *)_pya_realloc(ptr,size*sizeof(intp)))\n\n\n /* These must deal with unaligned and swapped data if necessary */\ntypedef PyObject * (PyArray_GetItemFunc) (void *, void *);\ntypedef int (PyArray_SetItemFunc)(PyObject *, void *, void *);\n\ntypedef void (PyArray_CopySwapNFunc)(void *, void *, intp, int, int);\ntypedef void (PyArray_CopySwapFunc)(void *, void *, int, int);\ntypedef Bool (PyArray_NonzeroFunc)(void *, void *);\n\n\n /* These assume aligned and notswapped data -- a buffer will be\n used before or contiguous data will be obtained\n */\ntypedef int (PyArray_CompareFunc)(const void *, const void *, void *);\ntypedef int (PyArray_ArgFunc)(void*, intp, intp*, void *);\ntypedef void (PyArray_DotFunc)(void *, intp, void *, intp, void *, intp,\n\t\t\t void *);\ntypedef void (PyArray_VectorUnaryFunc)(void *, void *, intp, void *, void *);\ntypedef int (PyArray_ScanFunc)(FILE *, void *, void *, void *);\ntypedef int (PyArray_FromStrFunc)(char *, void *, char **, void *);\n\ntypedef int (PyArray_FillFunc)(void *, intp, void *);\n\ntypedef int (PyArray_SortFunc)(void *, intp, void *);\ntypedef int (PyArray_ArgSortFunc)(void *, intp *, intp, void *);\n\ntypedef struct {\n intp *ptr;\n int len;\n} PyArray_Dims;\n\ntypedef struct {\n\t/* Functions to cast to all other standard types*/\n\tPyArray_VectorUnaryFunc *cast[PyArray_NTYPES];\n\n\t/* Functions to get and set items with standard\n\t Python types -- not array scalars */\n\tPyArray_GetItemFunc *getitem;\n\tPyArray_SetItemFunc *setitem;\n\n\t/* Copy and/or swap data. Memory areas may not overlap */\n\t/* Use memmove first if they might */\n\tPyArray_CopySwapNFunc *copyswapn;\n PyArray_CopySwapFunc *copyswap;\n\n\t/* Function to compare items */\n\tPyArray_CompareFunc *compare;\n\n\t/* Function to select largest */\n\tPyArray_ArgFunc *argmax;\n\n\t/* Function to compute dot product */\n\tPyArray_DotFunc\t*dotfunc;\n\n\t/* Function to scan an ASCII file and\n\t place a single value plus possible separator */\n\tPyArray_ScanFunc *scanfunc;\n\n\t/* Function to read a single value from a string */\n\t/* and adjust the pointer */\n\tPyArray_FromStrFunc *fromstr;\n\n\t/* Function to determine if data is zero or not */\n\tPyArray_NonzeroFunc *nonzero;\n\n\t/* Used for arange */\n\tPyArray_FillFunc *fill;\n\n\t/* Sorting functions */\n\tPyArray_SortFunc *sort[PyArray_NSORTS];\n\tPyArray_ArgSortFunc *argsort[PyArray_NSORTS];\n\n} PyArray_ArrFuncs;\n\n\ntypedef struct {\n\tPyObject_HEAD\n\tPyTypeObject *typeobj; /* the type object representing an\n\t\t\t\t intance of this type */\n\tchar kind; /* kind for this type */\n\tchar type; /* unique-character representing this type */\n\tchar byteorder; /* '>' (big), '<' (little), '|'\n\t\t\t\t (not-applicable), or '=' (native). */\n char hasobject; /* non-zero if it has object arrays in fields */\n\tint type_num; /* number representing this type */\n\tint elsize; /* element size for this type */\n\tint alignment; /* alignment needed for this type */\n\tstruct _arr_descr\t\t\t\t\t\\\n\t*subarray; /* Non-NULL if this type is\n\t\t\t\t is an array (C-contiguous)\n\t\t\t\t of some other type\n\t\t\t\t*/\n\tPyObject *fields; /* The fields dictionary for this type */\n\t /* For statically defined descr this\n\t\t\t\t is always Py_None */\n\n\tPyArray_ArrFuncs *f; /* a table of functions specific for each\n\t\t\t\t basic data descriptor */\n} PyArray_Descr;\n\ntypedef struct _arr_descr {\n\tPyArray_Descr *base;\n\tPyObject *shape; /* a tuple */\n} PyArray_ArrayDescr;\n\n\n/*\n The main array object structure. It is recommended to use the macros\n defined below (PyArray_DATA and friends) access fields here, instead\n of the members themselves.\n */\n\ntypedef struct PyArrayObject {\n\tPyObject_HEAD\n\tchar *data; /* pointer to raw data buffer */\n\tint nd; /* number of dimensions, also called ndim */\n\tintp *dimensions; /* size in each dimension */\n intp *strides; /* bytes to jump to get to the\n\t\t\t\t next element in each dimension */\n\tPyObject *base; /* This object should be decref'd\n\t\t\t\t upon deletion of array */\n\t /* For views it points to the original array */\n\t /* For creation from buffer object it points\n\t\t\t\t to an object that shold be decref'd on\n\t\t\t\t deletion */\n\t /* For UPDATEIFCOPY flag this is an array\n\t\t\t\t to-be-updated upon deletion of this one */\n\tPyArray_Descr *descr; /* Pointer to type structure */\n\tint flags; /* Flags describing array -- see below*/\n\tPyObject *weakreflist; /* For weakreferences */\n} PyArrayObject;\n\n#define fortran fortran_ /* For some compilers */\n\n/* Mirrors buffer object to ptr */\n\ntypedef struct {\n PyObject_HEAD\n PyObject *base;\n void *ptr;\n intp len;\n int flags;\n} PyArray_Chunk;\n\n/* Array flags */\n\n/* Means c-style contiguous (last index varies the fastest). The\n data elements right after each other. */\n#define CONTIGUOUS 0x0001\n/* set if array is a contiguous Fortran array: the first index\n varies the fastest in memory (strides array is reverse of\n C-contiguous array)*/\n#define FORTRAN 0x0002\n\n/*\n Note: all 0-d arrays are CONTIGUOUS and FORTRAN contiguous. If a\n 1-d array is CONTIGUOUS it is also FORTRAN contiguous\n*/\n\n/* If set, the array owns the data: it will be free'd when the array\n is deleted. */\n#define OWNDATA 0x0004\n#define OWN_DATA OWNDATA\n\n/* An array never has these three set; they're only used as parameter\n flags to the the various FromAny functions */\n/* Cause a cast to occur regardless of whether or not it is safe. */\n#define FORCECAST 0x0010\n/* Always copy the array. Returned arrays are always CONTIGUOUS, ALIGNED,\n and WRITEABLE. */\n#define ENSURECOPY 0x0020\n/* Make sure the returned array is an ndarray or a bigndarray */\n#define ENSUREARRAY 0x0040\n\n/* Array data is aligned on the appropiate memory address for the\n type stored (e.g., an array of doubles (8 bytes each) starts on\n a memory address that's a multiple of 8) */\n#define ALIGNED 0x0100\n/* Array data has the native endianness */\n#define NOTSWAPPED 0x0200\n/* Array data is writeable */\n#define WRITEABLE 0x0400\n/* If this flag is set, then base contains a pointer to an array of\n the same size that should be updated with the current contents of\n this array when this array is deallocated\n*/\n#define UPDATEIFCOPY 0x1000\n\n\n#define BEHAVED_FLAGS ALIGNED | WRITEABLE\n#define BEHAVED_NS_FLAGS ALIGNED | WRITEABLE | NOTSWAPPED\n#define CARRAY_FLAGS CONTIGUOUS | BEHAVED_FLAGS\n#define CARRAY_FLAGS_RO CONTIGUOUS | ALIGNED\n#define FARRAY_FLAGS FORTRAN | BEHAVED_FLAGS\n#define FARRAY_FLAGS_RO FORTRAN | ALIGNED\n#define DEFAULT_FLAGS CARRAY_FLAGS\n\n#define UPDATE_ALL_FLAGS CONTIGUOUS | FORTRAN | ALIGNED\n\n\n/* Size of internal buffers used for alignment */\n#define PyArray_BUFSIZE 10000\n#define PyArray_MIN_BUFSIZE 5\n#define PyArray_MAX_BUFSIZE 100000000\n\n/*\n * C API: consists of Macros and functions. The MACROS are defined here.\n */\n\n\n#define PyArray_CHKFLAGS(m, FLAGS) \\\n\t((((PyArrayObject *)(m))->flags & (FLAGS)) == (FLAGS))\n#define PyArray_ISCONTIGUOUS(m) PyArray_CHKFLAGS(m, CONTIGUOUS)\n#define PyArray_ISWRITEABLE(m) PyArray_CHKFLAGS(m, WRITEABLE)\n#define PyArray_ISALIGNED(m) PyArray_CHKFLAGS(m, ALIGNED)\n\n#ifndef MAX\n#define MAX(a,b) (((a)>(b))?(a):(b))\n#endif\n#ifndef MIN\n#define MIN(a,b) (((a)<(b))?(a):(b))\n#endif\n\n/* Useful if a and b have to be evaluated. */\n\n#define tMAX(a,b,typ) {typ _x_=(a); typ _y_=(b); _x_>_y_ ? _x_ : _y_}\n#define tMIN(a,b,typ) {typ _x_=(a); typ _y_=(b); _x_<_y_ ? _x_ : _y_}\n\n#if defined(ALLOW_THREADS)\n#define BEGIN_THREADS_DEF PyThreadState *_save;\n#define BEGIN_THREADS _save = PyEval_SaveThread();\n#define END_THREADS PyEval_RestoreThread(_save);\n#define ALLOW_C_API_DEF PyGILState_STATE __save__;\n#define ALLOW_C_API __save__ = PyGILState_Ensure();\n#define DISABLE_C_API PyGILState_Release(__save__);\n#else\n#define BEGIN_THREADS_DEF\n#define BEGIN_THREADS\n#define END_THREADS\n#define ALLOW_C_API_DEF\n#define\tALLOW_C_API\n#define\tDISABLE_C_API\n#endif\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\ntypedef struct {\n PyObject_HEAD\n\tint nd_m1; /* number of dimensions - 1 */\n intp\t\t index, size;\n\tintp coordinates[MAX_DIMS];/* N-dimensional loop */\n intp dims_m1[MAX_DIMS]; /* ao->dimensions - 1 */\n\tintp strides[MAX_DIMS]; /* ao->strides or fake */\n\tintp backstrides[MAX_DIMS];/* how far to jump back */\n\tintp factors[MAX_DIMS]; /* shape factors */\n\tPyArrayObject *ao;\n\tchar *dataptr; /* pointer to current item*/\n Bool contiguous;\n} PyArrayIterObject;\n\n\n/* Iterator API */\n#define PyArrayIter_Check(op) PyObject_TypeCheck(op, &PyArrayIter_Type)\n\n#define PyArray_ITER_RESET(it) {\t\t\t\t\t\\\n\tit->index = 0;\t\t\t\t\t\t \\\n\tit->dataptr = it->ao->data;\t\t\t\t\t\\\n\tmemset(it->coordinates, 0, (it->nd_m1+1)*sizeof(intp));\t\t\\\n}\n\n#define _PyArray_ITER_NEXT1(it) {\t\t\\\n\t\tit->dataptr += it->strides[0];\t\\\n\t\tit->coordinates[0]++;\t\t\\\n\t}\n\n#define _PyArray_ITER_NEXT2(it) {\t\t\t\t\t\\\n\t\tif (it->coordinates[1] < it->dims_m1[1]) {\t\t\\\n\t\t\tit->coordinates[1]++;\t\t\t\t\\\n\t\t\tit->dataptr += it->strides[1];\t\t\t\\\n\t\t}\t\t\t\t\t\t\t\\\n\t\telse {\t\t\t\t\t\t\t\\\n\t\t\tit->coordinates[1] = 0;\t\t\t\t\\\n\t\t\tit->coordinates[0]++;\t\t\t\t\\\n\t\t\tit->dataptr += it->strides[0] -\t\t\t\\\n\t\t\t\tit->backstrides[1];\t\t\t\\\n\t\t}\t\t\t\t\t\t\t\\\n\t}\n\n#define PyArray_ITER_NEXT(it) {\t\t\t\t\t\t\\\n\tit->index++;\t\t\t\t\t\t \\\n if (it->nd_m1 == 0) {\t\t\t\t\t\t\\\n\t\t_PyArray_ITER_NEXT1(it);\t\t\t\t\\\n\t}\t\t\t\t\t\t\t\t\\\n\telse if (it->contiguous) it->dataptr += it->ao->descr->elsize; \\\n\telse if (it->nd_m1 == 1) {\t\t\t\t\t\\\n\t\t_PyArray_ITER_NEXT2(it);\t\t\t\t\\\n\t}\t\t\t\t\t\t\t\t\\\n\telse {\t\t\t\t\t\t\t\t\\\n\t\tint _i_;\t\t\t\t\t\t\\\n\t\tfor (_i_ = it->nd_m1; _i_ >= 0; _i_--) {\t\t\\\n\t\t\tif (it->coordinates[_i_] <\t\t\t\\\n\t\t\t it->dims_m1[_i_]) {\t\t\t\t\\\n\t\t\t\tit->coordinates[_i_]++;\t\t\t\\\n\t\t\t\tit->dataptr += it->strides[_i_];\t\\\n\t\t\t\tbreak;\t\t\t\t\t\\\n\t\t\t}\t\t\t\t\t\t\\\n\t\t\telse {\t\t\t\t\t\t\\\n\t\t\t\tit->coordinates[_i_] = 0;\t\t\\\n\t\t\t\tit->dataptr -= it->backstrides[_i_];\t\\\n\t\t\t}\t\t\t\t\t\t\\\n\t\t}\t\t\t\t\t\t\t\\\n\t}\t\t\t\t\t\t\t\t\\\n}\n\n#define PyArray_ITER_GOTO(it, destination) {\t\t\t\t\\\n\t\tint _i_;\t\t\t\t\t\t\\\n\t\tit->index = 0;\t\t\t\t\t\t\\\n\t\tit->dataptr = it->ao->data;\t\t\t\t\\\n\t\tfor (_i_ = it->nd_m1; _i_>=0; _i_--) {\t\t\t\\\n\t\t\tit->dataptr += destination[_i_] *\t\t\\\n\t\t\t\tit->strides[_i_];\t\t\t\\\n\t\t\tit->coordinates[_i_] = destination[_i_];\t\\\n\t\t\tit->index += destination[_i_] *\t\t\t\\\n\t\t\t\t( _i_==it->nd_m1 ? 1 :\t\t\t\\\n\t\t\t\t it->dims_m1[i+1]+1) ;\t\t \\\n\t\t}\t\t\t\t\t\t\t\\\n\t}\n\n#define PyArray_ITER_GOTO1D(it, ind) { \\\n\t\tint _i_;\t\t\t\t\t\t\\\n\t\tintp _lind_ = (intp) (ind);\t\t\t\t\\\n\t\tit->index = _lind_;\t\t\t\t\t\\\n if (it->nd_m1 == 0) { \\\n it->dataptr = it->ao->data + (ind) * \\\n it->strides[0]; \\\n } \\\n else if (it->contiguous) \\\n\t\t\tit->dataptr = it->ao->data + (ind) *\t\t\\\n\t\t\t\tit->ao->descr->elsize;\t\t\t\\\n\t\telse {\t\t\t\t\t\t\t\\\n\t\t\tit->dataptr = it->ao->data;\t\t\t\\\n\t\t\tfor (_i_ = 0; _i_<=it->nd_m1; _i_++) {\t\t\\\n\t\t\t\tit->dataptr += (_lind_ / it->factors[_i_]) \\\n\t\t\t\t\t* it->strides[_i_];\t\t\\\n\t\t\t\t_lind_ %= it->factors[_i_];\t\t\\\n\t\t\t}\t\t\t\t\t\t\\\n\t\t}\t\t\t\t\t\t\t\\\n}\n\n#define PyArray_ITER_DATA(it) ((PyArrayIterObject *)it)->dataptr\n\n\n/*\n Any object passed to PyArray_Broadcast must be binary compatible with\n this structure.\n*/\n\ntypedef struct {\n\tPyObject_HEAD\n\n\tint numiter; /* number of iters */\n\tintp size; /* broadcasted size */\n\tintp index; /* current index */\n\tint nd; /* number of dims */\n\tintp dimensions[MAX_DIMS]; /* dimensions */\n\tPyArrayIterObject *iters[MAX_DIMS]; /* iterators */\n} PyArrayMultiIterObject;\n\n#define PyArray_MultiIter_RESET(multi) {\t\t\t \\\n\t\tint _mi_;\t\t\t\t\t \\\n\t\tPyArrayMultiIterObject *_mul_ = (multi);\t \\\n\t\t_mul_->index = 0;\t\t\t\t \\\n\t\tfor (_mi_ = 0; _mi_ < _mul_->numiter; _mi_++) {\t \\\n\t\t\tPyArray_ITER_RESET(_mul_->iters[_mi_]);\t \\\n\t\t}\t\t\t\t\t\t \\\n\t}\n\n#define PyArray_MultiIter_NEXT(multi) {\t\t\t\t \\\n\t\tint _mi_;\t\t\t\t\t \\\n\t\tPyArrayMultiIterObject *_mul_ = (multi);\t \\\n\t\t_mul_->index += 1;\t\t\t\t \\\n\t\tfor (_mi_=0; _mi_<_mul_->numiter; _mi_++) {\t \\\n\t\t\tPyArray_ITER_NEXT(_mul_->iters[_mi_]);\t \\\n\t\t}\t\t\t\t\t\t \\\n\t}\n\n#define PyArray_MultiIter_GOTO(multi, dest) {\t\t\t\t\\\n\t\tint _mi_;\t\t\t\t\t\t\\\n\t\tPyArrayMultiIterObject *_mul_ = (multi);\t\t\\\n\t\tfor (_mi_=0; _mi_<_mul_->numiter; _mi_++) {\t\t\\\n\t\t\tPyArray_ITER_GOTO(_mul_->iters[_mi_], dest);\t\\\n\t\t}\t\t\t\t\t\t\t\\\n\t\t_mul_->index = _mul_->iters[0]->index;\t\t\t\\\n\t}\n\n#define PyArray_MultiIter_GOTO1D(multi, ind) {\t\t\t\t\\\n\t\tint _mi_;\t\t\t\t\t\t\\\n\t\tPyArrayMultiIterObject *_mul_ = (multi);\t\t\\\n\t\tfor (_mi_=0; _mi_<_mul_->numiter; _mi_++) {\t\t\\\n\t\t\tPyArray_ITER_GOTO1D(_mul_->iters[_mi_], ind);\t\\\n\t\t}\t\t\t\t\t\t\t\\\n\t\t_mul_->index = _mul_->iters[0]->index;\t\t\t\\\n\t}\n\n#define PyArray_MultiIter_DATA(multi, i) \\\n\t((PyArrayMultiIterObject *)multi)->iters[i]->dataptr\n\n#define PyArray_MultiIter_SIZE(multi) \\\n\t((PyArrayMultiIterObject *)multi)->size;\n\n\n/* Store the information needed for fancy-indexing over an array */\n\ntypedef struct {\n\tPyObject_HEAD\n\t/* Multi-iterator portion --- needs to be present in this order to\n\t work with PyArray_Broadcast */\n\n\tint numiter; /* number of index-array\n\t\t\t\t\t\t\t iterators */\n\tintp size; /* size of broadcasted\n\t\t\t\t\t\t\t result */\n\tintp index; /* current index */\n\tint nd; /* number of dims */\n\tintp dimensions[MAX_DIMS]; /* dimensions */\n\tPyArrayIterObject *iters[MAX_DIMS]; /* index object\n\t\t\t\t\t\t\t iterators */\n\tPyArrayIterObject *ait; /* flat Iterator for\n\t\t\t\t\t\t\t underlying array */\n\n\t/* flat iterator for subspace (when numiter < nd) */\n\tPyArrayIterObject *subspace;\n\n\t/* if subspace iteration, then this is the array of\n\t axes in the underlying array represented by the\n\t index objects */\n\tint iteraxes[MAX_DIMS];\n\t/* if subspace iteration, the these are the coordinates\n\t to the start of the subspace.\n\t*/\n\tintp bscoord[MAX_DIMS];\n\n\tPyObject *indexobj; /* reference to\n\t\t\t\t\t\t\t creating obj */\n\tint view;\n\tint consec;\n\tchar *dataptr;\n\n} PyArrayMapIterObject;\n\n/* All sorts of useful ways to look into a PyArrayObject.\n These are the recommended over casting to PyArrayObject and accessing\n the members directly.\n */\n\n#define PyArray_NDIM(obj) (((PyArrayObject *)(obj))->nd)\n#define PyArray_ISONESEGMENT(m) (PyArray_NDIM(m) == 0 || PyArray_CHKFLAGS(m, CONTIGUOUS) || \\\n\t\t\t\t PyArray_CHKFLAGS(m, FORTRAN))\n#define PyArray_ISFORTRAN(m) (PyArray_CHKFLAGS(m, FORTRAN) && (PyArray_NDIM(m) > 1))\n#define FORTRAN_IF(m) ((PyArray_CHKFLAGS(m, FORTRAN) ? FORTRAN : 0))\n#define PyArray_DATA(obj) ((void *)(((PyArrayObject *)(obj))->data))\n#define PyArray_BYTES(obj) (((PyArrayObject *)(obj))->data)\n#define PyArray_DIMS(obj) (((PyArrayObject *)(obj))->dimensions)\n#define PyArray_STRIDES(obj) (((PyArrayObject *)(obj))->strides)\n#define PyArray_DIM(obj,n) (((PyArrayObject *)(obj))->dimensions[n])\n#define PyArray_STRIDE(obj,n) (((PyArrayObject *)(obj))->strides[n])\n#define PyArray_BASE(obj) (((PyArrayObject *)(obj))->base)\n#define PyArray_DESCR(obj) (((PyArrayObject *)(obj))->descr)\n#define PyArray_FLAGS(obj) (((PyArrayObject *)(obj))->flags)\n#define PyArray_ITEMSIZE(obj) (((PyArrayObject *)(obj))->descr->elsize)\n#define PyArray_TYPE(obj) (((PyArrayObject *)(obj))->descr->type_num)\n#define PyArray_GETITEM(obj,itemptr)\t\t\t\\\n\t((PyArrayObject *)(obj))->descr->getitem((char *)itemptr,\t\\\n\t\t\t\t\t\t (PyArrayObject *)obj);\n#define PyArray_SETITEM(obj,itemptr,v)\t\t\t\t\t\\\n\t(obj)->descr->setitem((PyObject *)v,(char *)(itemptr),\t\t\\\n\t\t\t (PyArrayObject *)(obj));\n\n\n#define PyTypeNum_ISBOOL(type) (type == PyArray_BOOL)\n#define PyTypeNum_ISUNSIGNED(type) ((type == PyArray_UBYTE) || \\\n\t\t\t\t (type == PyArray_USHORT) || \\\n\t\t\t\t (type == PyArray_UINT) ||\t\\\n\t\t\t\t (type == PyArray_ULONG) || \\\n\t\t\t\t (type == PyArray_ULONGLONG))\n\n#define PyTypeNum_ISSIGNED(type) ((type == PyArray_BYTE) ||\t\\\n\t\t\t (type == PyArray_SHORT) ||\t\\\n\t\t\t (type == PyArray_INT) ||\t\\\n\t\t\t (type == PyArray_LONG) ||\t\\\n\t\t\t (type == PyArray_LONGLONG))\n\n#define PyTypeNum_ISINTEGER(type) ((type >= PyArray_BYTE) &&\t\\\n\t\t\t\t(type <= PyArray_ULONGLONG))\n\n#define PyTypeNum_ISFLOAT(type) ((type >= PyArray_FLOAT) && \\\n\t\t\t (type <= PyArray_LONGDOUBLE))\n\n#define PyTypeNum_ISNUMBER(type) (type <= PyArray_CLONGDOUBLE)\n\n#define PyTypeNum_ISSTRING(type) ((type == PyArray_UCHAR) || \\\n\t\t\t (type == PyArray_UNICODE))\n\n#define PyTypeNum_ISCOMPLEX(type) ((type >= PyArray_CFLOAT) && \\\n\t\t\t\t(type <= PyArray_CLONGDOUBLE))\n\n#define PyTypeNum_ISPYTHON(type) ((type == PyArray_LONG) || \\\n\t\t\t\t (type == PyArray_DOUBLE) ||\t\\\n\t\t\t\t (type == PyArray_CDOUBLE) ||\t\\\n\t\t (type == PyArray_BOOL) || \\\n\t\t\t\t (type == PyArray_OBJECT ))\n\n#define PyTypeNum_ISFLEXIBLE(type) ((type>=PyArray_STRING) && \\\n\t\t\t\t (type<=PyArray_VOID))\n\n#define PyTypeNum_ISUSERDEF(type) ((type >= PyArray_USERDEF) && \\\n\t\t\t\t (type < PyArray_USERDEF+\\\n\t\t\t\t PyArray_NUMUSERTYPES))\n\n#define PyTypeNum_ISEXTENDED(type) (PyTypeNum_ISFLEXIBLE(type) || \\\n PyTypeNum_ISUSERDEF(type))\n\n#define PyTypeNum_ISOBJECT(type) ((type) == PyArray_OBJECT)\n\n#define _PyADt(o) ((PyArray_Descr *)o)->type_num\n#define PyDescr_ISBOOL(obj) PyTypeNum_ISBOOL(_PyADt(obj))\n#define PyDescr_ISUNSIGNED(obj) PyTypeNum_ISUNSIGNED(_PyADt(obj))\n#define PyDescr_ISSIGNED(obj) PyTypeNum_ISSIGNED(_PyADt(obj))\n#define PyDescr_ISINTEGER(obj) PyTypeNum_ISINTEGER(_PyADt(obj))\n#define PyDescr_ISFLOAT(obj) PyTypeNum_ISFLOAT(_PyADt(obj))\n#define PyDescr_ISNUMBER(obj) PyTypeNum_ISNUMBER(_PyADt(obj))\n#define PyDescr_ISSTRING(obj) PyTypeNum_ISSTRING(_PyADt(obj))\n#define PyDescr_ISCOMPLEX(obj) PyTypeNum_ISCOMPLEX(_PyADt(obj))\n#define PyDescr_ISPYTHON(obj) PyTypeNum_ISPYTHON(_PyADt(obj))\n#define PyDescr_ISFLEXIBLE(obj) PyTypeNum_ISFLEXIBLE(_PyADt(obj))\n#define PyDescr_ISUSERDEF(obj) PyTypeNum_ISUSERDEF(_PyADt(obj))\n#define PyDescr_ISEXTENDED(obj) PyTypeNum_ISEXTENDED(_PyADt(obj))\n#define PyDescr_ISOBJECT(obj) PyTypeNum_ISOBJECT(_PyADt(obj))\n#undef _PyAD\n\n#define PyArray_ISBOOL(obj) PyTypeNum_ISBOOL(PyArray_TYPE(obj))\n#define PyArray_ISUNSIGNED(obj) PyTypeNum_ISUNSIGNED(PyArray_TYPE(obj))\n#define PyArray_ISSIGNED(obj) PyTypeNum_ISSIGNED(PyArray_TYPE(obj))\n#define PyArray_ISINTEGER(obj) PyTypeNum_ISINTEGER(PyArray_TYPE(obj))\n#define PyArray_ISFLOAT(obj) PyTypeNum_ISFLOAT(PyArray_TYPE(obj))\n#define PyArray_ISNUMBER(obj) PyTypeNum_ISNUMBER(PyArray_TYPE(obj))\n#define PyArray_ISSTRING(obj) PyTypeNum_ISSTRING(PyArray_TYPE(obj))\n#define PyArray_ISCOMPLEX(obj) PyTypeNum_ISCOMPLEX(PyArray_TYPE(obj))\n#define PyArray_ISPYTHON(obj) PyTypeNum_ISPYTHON(PyArray_TYPE(obj))\n#define PyArray_ISFLEXIBLE(obj) PyTypeNum_ISFLEXIBLE(PyArray_TYPE(obj))\n#define PyArray_ISUSERDEF(obj) PyTypeNum_ISUSERDEF(PyArray_TYPE(obj))\n#define PyArray_ISEXTENDED(obj) PyTypeNum_ISEXTENDED(PyArray_TYPE(obj))\n#define PyArray_ISOBJECT(obj) PyTypeNum_ISOBJECT(PyArray_TYPE(obj))\n\n#define PyArray_LITTLE '<'\n#define PyArray_BIG '>'\n#define PyArray_NATIVE '='\n#define PyArray_SWAP 's'\n#define PyArray_IGNORE '|'\n\n#ifdef WORDS_BIGENDIAN\n#define PyArray_NATBYTE PyArray_BIG\n#define PyArray_OPPBYTE PyArray_LITTLE\n#else\n#define PyArray_NATBYTE PyArray_LITTLE\n#define PyArray_OPPBYTE PyArray_BIG\n#endif\n\n#define PyArray_ISNBO(arg) ((arg) != PyArray_OPPBYTE)\n#define PyArray_IsNativeByteOrder PyArray_ISNBO\n#define PyArray_ISNOTSWAPPED(m) PyArray_ISNBO(PyArray_DESCR(m)->byteorder)\n\n#define PyArray_FLAGSWAP(m, flags) (PyArray_CHKFLAGS(m, flags) &&\t\\\n\t\t\t\t PyArray_ISNOTSWAPPED(m))\n#define PyArray_ISCARRAY(m) PyArray_FLAGSWAP(m, CARRAY_FLAGS)\n#define PyArray_ISCARRAY_RO(m) PyArray_FLAGSWAP(m, CARRAY_FLAGS_RO)\n#define PyArray_ISFARRAY(m) PyArray_FLAGSWAP(m, FARRAY_FLAGS)\n#define PyArray_ISFARRAY_RO(m) PyArray_FLAGSWAP(m, FARRAY_FLAGS_RO)\n#define PyArray_ISBEHAVED(m) PyArray_FLAGSWAP(m, BEHAVED_FLAGS)\n#define PyArray_ISBEHAVED_RO(m) PyArray_FLAGSWAP(m, ALIGNED)\n\n\n\n/* This is the form of the struct that's returned pointed by the\n PyCObject attribute of an array __array_struct__. See\n http://numeric.scipy.org/array_interface.html for the full\n documentation. */\ntypedef struct {\n int version; /* contains the integer 2 as a sanity check */\n int nd; /* number of dimensions */\n char typekind; /* kind in array --- character code of typestr */\n int itemsize; /* size of each element */\n int flags; /* how should be data interpreted. Valid\n flags are CONTIGUOUS (1), FORTRAN (2),\n ALIGNED (0x100), NOTSWAPPED (0x200), and\n WRITEABLE (0x400)*/\n intp *shape; /* A length-nd array of shape information */\n intp *strides; /* A length-nd array of stride information */\n void *data; /* A pointer to the first element of the array */\n} PyArrayInterface;\n\n/* Includes the \"function\" C-API -- these are all stored in a\n list of pointers --- one for each file\n The two lists are concatenated into one in multiarray.\n\n They are available as import_array()\n*/\n\n\n#include \"__multiarray_api.h\"\n\n\n/* C-API that requries previous API to be defined */\n\n#define PyArray_DescrCheck(op) ((op)->ob_type == &PyArrayDescr_Type)\n\n#define PyArray_Check(op) ((op)->ob_type == &PyArray_Type || \\\n\t\t\t PyObject_TypeCheck((op), &PyBigArray_Type))\n#define PyBigArray_CheckExact(op) ((op)->ob_type == &PyBigArray_Type)\n#define PyArray_CheckExact(op) ((op)->ob_type == &PyArray_Type)\n\n#define PyArray_IsZeroDim(op) (PyArray_Check(op) && (PyArray_NDIM(op) == 0))\n#define PyArray_IsScalar(obj, cls)\t\t\t\t\\\n\t(PyObject_TypeCheck((obj), &Py##cls##ArrType_Type))\n#define PyArray_CheckScalar(m) (PyArray_IsScalar(m, Generic) || \\\n PyArray_IsZeroDim(m))\n#define PyArray_IsPythonScalar(obj) \\\n\t(PyInt_Check(obj) || PyFloat_Check(obj) || PyComplex_Check(obj) || \\\n\t PyLong_Check(obj) || PyBool_Check(obj) || PyString_Check(obj) || \\\n\t PyUnicode_Check(obj))\n#define PyArray_IsAnyScalar(obj)\t\t\t\t\t\\\n\t(PyArray_IsScalar(obj, Generic) || PyArray_IsPythonScalar(obj))\n#define PyArray_CheckAnyScalar(obj) (PyArray_IsPythonScalar(obj) || \\\n\t\t\t\t PyArray_CheckScalar(obj))\n\n#define PyArray_GETCONTIGUOUS(m) (PyArray_ISCONTIGUOUS(m) ? Py_INCREF(m), m : \\\n (PyArrayObject *)(PyArray_Copy(m)))\n\n#define PyArray_SIZE(m) PyArray_MultiplyList(PyArray_DIMS(m), PyArray_NDIM(m))\n#define PyArray_NBYTES(m) (PyArray_ITEMSIZE(m) * PyArray_SIZE(m))\n#define PyArray_FROM_O(m) PyArray_FromAny(m, NULL, 0, 0, 0, NULL)\n#define PyArray_FROM_OF(m,flags) PyArray_CheckFromAny(m, NULL, 0, 0, flags, NULL)\n#define PyArray_FROM_OT(m,type) PyArray_FromAny(m, PyArray_DescrFromType(type), \\\n 0, 0, 0, NULL);\n#define PyArray_FROM_OTF(m, type, flags) \\\n\tPyArray_FromAny(m, PyArray_DescrFromType(type), 0, 0, \\\n (((flags) & ENSURECOPY) ? \\\n ((flags) | DEFAULT_FLAGS) : (flags)), NULL)\n#define PyArray_FROMANY(m, type, min, max, flags) \\\n\tPyArray_FromAny(m, PyArray_DescrFromType(type), min, max, \\\n (((flags) & ENSURECOPY) ? \\\n (flags) | DEFAULT_FLAGS : (flags)), NULL)\n\n#define PyArray_FILLWBYTE(obj, val) memset(PyArray_DATA(obj), (val), PyArray_NBYTES(obj))\n\n#define REFCOUNT(obj) (((PyObject *)(obj))->ob_refcnt)\n#define MAX_ELSIZE 2*SIZEOF_LONGDOUBLE\n\n#define PyArray_ContiguousFromAny(op, type, min_depth, max_depth) \\\n PyArray_FromAny(op, PyArray_DescrFromType(type), min_depth, \\\n max_depth, DEFAULT_FLAGS, NULL)\n\n#define PyArray_EquivArrTypes(a1, a2)\t\t\t\t\t\\\n\tPyArray_EquivTypes(PyArray_DESCR(a1), PyArray_DESCR(a2))\n#define PyArray_EquivTypenums(typenum1, typenum2)\t\t\\\n\tPyArray_EquivTypes(PyArray_DescrFromType(typenum1),\t\\\n\t\t\t PyArray_DescrFromType(typenum2))\n\n#define PyArray_EquivByteorders(b1, b2) \\\n\t((b1 == b2) || (PyArray_ISNBO(b1) == PyArray_ISNBO(b2)))\n\n#define PyArray_SimpleNew(nd, dims, typenum) \\\n\tPyArray_New(&PyArray_Type, nd, dims, typenum, NULL, NULL, 0, 0, NULL)\n#define PyArray_SimpleNewFromData(nd, dims, typenum, data) \\\n PyArray_New(&PyArray_Type, nd, dims, typenum, NULL, data, 0, CARRAY_FLAGS, NULL)\n#define PyArray_SimpleNewFromDescr(nd, dims, descr) \\\n\tPyArray_NewFromDescr(&PyArray_Type, descr, nd, dims, NULL, NULL, 0, NULL)\n\n\n/* These might be faster without the dereferencing of obj\n going on inside -- of course an optimizing compiler should\n inline the constants inside a for loop making it a moot point\n*/\n\n#define PyArray_GETPTR1(obj, i) (void *)(PyArray_BYTES(obj) +\t\t\\\n\t\t\t\t i*PyArray_STRIDE(obj, 0))\n\n#define PyArray_GETPTR2(obj, i, j) (void *)(PyArray_BYTES(obj) +\t\t\\\n\t\t\t\t i*PyArray_STRIDE(obj, 0) +\t\\\n\t\t\t\t j*PyArray_STRIDE(obj, 1))\n\n#define PyArray_GETPTR3(obj, i, j, k) (void *)(PyArray_BYTES(obj) +\t\t\\\n\t\t\t\t i*PyArray_STRIDE(obj, 0) +\t\\\n\t\t\t\t j*PyArray_STRIDE(obj, 1) +\t\\\n\t\t\t\t k*PyArray_STRIDE(obj, 2))\t\\\n\n#define PyArray_GETPTR4(obj, i, j, k, l) (void *)(PyArray_BYTES(obj) +\t\t\\\n\t\t\t\t\t i*PyArray_STRIDE(obj, 0) +\t\\\n\t\t\t\t\t j*PyArray_STRIDE(obj, 1) +\t\\\n\t\t\t\t\t k*PyArray_STRIDE(obj, 2) +\t\\\n\t\t\t\t\t l*PyArray_STRIDE(obj, 3))\n\n#define PyArray_DESCR_REPLACE(descr) do {\t\\\n\t\tPyArray_Descr *_new_;\t\t\t\\\n\t\t_new_ = PyArray_DescrNew(descr);\t\\\n\t\tPy_XDECREF(descr);\t\t\t\\\n\t\tdescr = _new_;\t\t\t\t\\\n\t} while(0)\n\n/* Copy should always return contiguous array */\n#define PyArray_Copy(obj) PyArray_NewCopy(obj, 0)\n\n#define PyArray_FromObject(op, type, min_depth, max_depth)\t\t\\\n\tPyArray_FromAny(op, PyArray_DescrFromType(type), min_depth,\t\\\n max_depth, BEHAVED_FLAGS | ENSUREARRAY, NULL)\n\n#define PyArray_ContiguousFromObject(op, type, min_depth, max_depth)\t\\\n PyArray_FromAny(op, PyArray_DescrFromType(type), min_depth,\t\\\n max_depth, DEFAULT_FLAGS | ENSUREARRAY, NULL)\n\n#define PyArray_CopyFromObject(op, type, min_depth, max_depth)\t\t\\\n PyArray_FromAny(op, PyArray_DescrFromType(type), min_depth, \\\n max_depth, ENSURECOPY | DEFAULT_FLAGS | ENSUREARRAY, NULL)\n\n#define PyArray_Cast(mp, type_num) \\\n\tPyArray_CastToType(mp, PyArray_DescrFromType(type_num), 0)\n\n/* Compatibility with old Numeric stuff -- don't use in new code */\n\n#define PyArray_FromDimsAndData(nd, d, type, data) \\\n\tPyArray_FromDimsAndDataAndDescr(nd, d, PyArray_DescrFromType(type), \\\n\t\t\t\t\tdata)\n\n#define PyArray_UNSIGNED_TYPES\n#define PyArray_SBYTE PyArray_BYTE\n#define PyArray_CHAR PyArray_BYTE\n#define PyArray_CopyArray PyArray_CopyInto\n#define _PyArray_multiply_list PyArray_MultiplyIntList\n#define PyArray_ISSPACESAVER(m) FALSE\n#define PyScalarArray_Check PyArray_CheckScalar\n\n#ifdef PY_ARRAY_TYPES_PREFIX\n# undef CAT\n# undef CAT2\n# undef NS\n# undef longlong\n# undef ulonglong\n# undef Bool\n# undef longdouble\n# undef byte\n# undef ubyte\n# undef ushort\n# undef uint\n# undef ulong\n# undef cfloat\n# undef cdouble\n# undef clongdouble\n# undef Int8\n# undef UInt8\n# undef Int16\n# undef UInt16\n# undef Int32\n# undef UInt32\n# undef Int64\n# undef UInt64\n# undef Int128\n# undef UInt128\n# undef Int256\n# undef UInt256\n# undef Float16\n# undef Complex32\n# undef Float32\n# undef Complex64\n# undef Float64\n# undef Complex128\n# undef Float80\n# undef Complex160\n# undef Float96\n# undef Complex192\n# undef Float128\n# undef Complex256\n# undef intp\n# undef uintp\n#endif\n\n#ifdef __cplusplus\n}\n#endif\n\n#endif /* !Py_ARRAYOBJECT_H */\n", + "source_code_before": "/* This expects the following variables to be defined (besides\n the usual ones from pyconfig.h\n\n SIZEOF_LONG_DOUBLE -- sizeof(long double) or sizeof(double) if no\n long double is present on platform.\n CHAR_BIT -- number of bits in a char (usually 8)\n (should be in limits.h)\n*/\n\n#ifndef Py_ARRAYOBJECT_H\n#define Py_ARRAYOBJECT_H\n#ifdef __cplusplus\n#define CONFUSE_EMACS {\n#define CONFUSE_EMACS2 }\nextern \"C\" CONFUSE_EMACS\n#undef CONFUSE_EMACS\n#undef CONFUSE_EMACS2\n/* ... otherwise a semi-smart idententer (like emacs) tries to indent\n everything when you're typing */\n#endif\n#include \"config.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 longlong NS(longlong)\n# define ulonglong NS(ulonglong)\n# define Bool NS(Bool)\n# define longdouble NS(longdouble)\n# define byte NS(byte)\n# define ubyte NS(ubyte)\n# define ushort NS(ushort)\n# define uint NS(uint)\n# define ulong NS(ulong)\n# define cfloat NS(cfloat)\n# define cdouble NS(cdouble)\n# define clongdouble NS(clongdouble)\n# define Int8 NS(Int8)\n# define UInt8 NS(UInt8)\n# define Int16 NS(Int16)\n# define UInt16 NS(UInt16)\n# define Int32 NS(Int32)\n# define UInt32 NS(UInt32)\n# define Int64 NS(Int64)\n# define UInt64 NS(UInt64)\n# define Int128 NS(Int128)\n# define UInt128 NS(UInt128)\n# define Int256 NS(Int256)\n# define UInt256 NS(UInt256)\n# define Float16 NS(Float16)\n# define Complex32 NS(Complex32)\n# define Float32 NS(Float32)\n# define Complex64 NS(Complex64)\n# define Float64 NS(Float64)\n# define Complex128 NS(Complex128)\n# define Float80 NS(Float80)\n# define Complex160 NS(Complex160)\n# define Float96 NS(Float96)\n# define Complex192 NS(Complex192)\n# define Float128 NS(Float128)\n# define Complex256 NS(Complex256)\n# define intp NS(intp)\n# define uintp NS(uintp)\n#endif\n\n/* There are several places in the code where an array of dimensions is */\n/* allocated statically. This is the size of that static allocation. */\n/* The array creation itself could have arbitrary dimensions but\n * all the places where static allocation is used would need to\n * be changed to dynamic (including inside of structures)\n */\n\n#define MAX_DIMS 32\n\n/* Used for Converter Functions \"O&\" code in ParseTuple */\n#define PY_FAIL 0\n#define PY_SUCCEED 1\n\n\t/* Helpful to distinguish what is installed */\n#define NDARRAY_VERSION 0x00090405\n\n\t/* Some platforms don't define bool, long long, or long double.\n\t Handle that here.\n\t */\n\n#ifdef PY_LONG_LONG\ntypedef PY_LONG_LONG longlong;\ntypedef unsigned PY_LONG_LONG ulonglong;\n# ifdef _MSC_VER\n# define LONGLONG_FMT \"I64d\"\n# define ULONGLONG_FMT \"I64u\"\n# define LONGLONG_SUFFIX(x) (x##i64)\n# define ULONGLONG_SUFFIX(x) (x##Ui64)\n# else\n\t/* #define LONGLONG_FMT \"lld\" Another possible variant\n #define ULONGLONG_FMT \"llu\"\n\n\t #define LONGLONG_FMT \"qd\" -- BSD perhaps?\n\t #define ULONGLONG_FMT \"qu\"\n\t*/\n# define LONGLONG_FMT \"Ld\"\n# define ULONGLONG_FMT \"Lu\"\n# define LONGLONG_SUFFIX(x) (x##LL)\n# define ULONGLONG_SUFFIX(x) (x##ULL)\n# endif\n#else\ntypedef long longlong;\ntypedef unsigned long ulonglong;\n# define LONGLONG_SUFFIX(x) (x##L)\n# define ULONGLONG_SUFFIX(x) (x##UL)\n#endif\n\ntypedef unsigned char Bool;\n#ifndef FALSE\n#define FALSE 0\n#endif\n#ifndef TRUE\n#define TRUE 1\n#endif\n\n#if SIZEOF_LONG_DOUBLE==SIZEOF_DOUBLE\n\ttypedef double longdouble;\n #define LONGDOUBLE_FMT \"g\"\n#else\n\ttypedef long double longdouble;\n #define LONGDOUBLE_FMT \"Lg\"\n#endif\n\n#ifndef Py_USING_UNICODE\n#error Must use Python with unicode enabled. \n#endif\n\n\ntypedef signed char byte;\ntypedef unsigned char ubyte;\n#ifndef _BSD_SOURCE\ntypedef unsigned short ushort;\ntypedef unsigned int uint;\ntypedef unsigned long ulong;\n#endif\n\ntypedef struct { float real, imag; } cfloat;\ntypedef struct { double real, imag; } cdouble;\ntypedef struct {longdouble real, imag;} clongdouble;\n\nenum PyArray_TYPES { PyArray_BOOL=0,\n PyArray_BYTE, PyArray_UBYTE,\n\t\t PyArray_SHORT, PyArray_USHORT,\n\t\t PyArray_INT, PyArray_UINT,\n\t\t\tPyArray_LONG, PyArray_ULONG,\n PyArray_LONGLONG, PyArray_ULONGLONG,\n\t\t\tPyArray_FLOAT, PyArray_DOUBLE, PyArray_LONGDOUBLE,\n\t\t\tPyArray_CFLOAT, PyArray_CDOUBLE, PyArray_CLONGDOUBLE,\n\t\t\tPyArray_OBJECT=17,\n PyArray_STRING, PyArray_UNICODE,\n\t\t\tPyArray_VOID,\n\t\t\tPyArray_NTYPES,\n\t\t\tPyArray_NOTYPE,\n\t\t\tPyArray_USERDEF=256 /* leave room for characters */\n};\n\n\t/* basetype array priority */\n#define PyArray_PRIORITY 0.0\n#define PyArray_BIG_PRIORITY 0.1\n\t/* default subtype priority */\n#define PyArray_SUBTYPE_PRIORITY 1.0\n\n\t/* How many floating point types are there */\n#define PyArray_NUM_FLOATTYPE 3\n\n\n\t/* We need to match intp to a signed integer of the same size as\n\t a pointer variable. uintp to the equivalent unsigned integer\n\t*/\n\n\n\t/* These characters correspond to the array type and the\n\t struct module */\n\n\t/* except 'p' -- signed integer for pointer type */\n\nenum PyArray_TYPECHAR { PyArray_BOOLLTR = '?',\n\t\t\tPyArray_BYTELTR = 'b',\n\t\t\tPyArray_UBYTELTR = 'B',\n\t\t\tPyArray_SHORTLTR = 'h',\n\t\t\tPyArray_USHORTLTR = 'H',\n\t\t\tPyArray_INTLTR = 'i',\n\t\t\tPyArray_UINTLTR = 'I',\n\t\t\tPyArray_LONGLTR = 'l',\n\t\t\tPyArray_ULONGLTR = 'L',\n\t\t\tPyArray_LONGLONGLTR = 'q',\n\t\t\tPyArray_ULONGLONGLTR = 'Q',\n\t\t\tPyArray_FLOATLTR = 'f',\n\t\t\tPyArray_DOUBLELTR = 'd',\n\t\t\tPyArray_LONGDOUBLELTR = 'g',\n\t\t\tPyArray_CFLOATLTR = 'F',\n\t\t\tPyArray_CDOUBLELTR = 'D',\n\t\t\tPyArray_CLONGDOUBLELTR = 'G',\n\t\t\tPyArray_OBJECTLTR = 'O',\n\t\t\tPyArray_STRINGLTR = 'S',\n\t\t\tPyArray_STRINGLTR2 = 'a',\n\t\t\tPyArray_UNICODELTR = 'U',\n\t\t PyArray_VOIDLTR = 'V',\n\n\t\t\t/* No Descriptor, just a define -- this let's\n\t\t\t Python users specify an array of integers\n\t\t\t large enough to hold a pointer on the platform*/\n\t\t\tPyArray_INTPLTR = 'p',\n\t\t\tPyArray_UINTPLTR = 'P',\n\n\t\t\tPyArray_GENBOOLLTR ='b',\n\t\t\tPyArray_SIGNEDLTR = 'i',\n\t\t\tPyArray_UNSIGNEDLTR = 'u',\n\t\t\tPyArray_FLOATINGLTR = 'f',\n\t\t\tPyArray_COMPLEXLTR = 'c'\n};\n\ntypedef enum {\n\tPyArray_QUICKSORT=0,\n\tPyArray_HEAPSORT=1,\n\tPyArray_MERGESORT=2,\n\tPyArray_TIMSORT=3 /* the sort Python uses -- specialized */\n} PyArray_SORTKIND;\n#define PyArray_NSORTS PyArray_TIMSORT + 1\n\n\t/* Define bit-width array types and typedefs */\n\n#define MAX_INT8 127\n#define MIN_INT8 -128\n#define MAX_UINT8 255\n#define MAX_INT16 32767\n#define MIN_INT16 -32768\n#define MAX_UINT16 65535\n#define MAX_INT32 2147483647\n#define MIN_INT32 (-MAX_INT32 - 1)\n#define MAX_UINT32 4294967295U\n#define MAX_INT64 LONGLONG_SUFFIX(9223372036854775807)\n#define MIN_INT64 (-MAX_INT64 - LONGLONG_SUFFIX(1))\n#define MAX_UINT64 ULONGLONG_SUFFIX(18446744073709551615)\n#define MAX_INT128 LONGLONG_SUFFIX(85070591730234615865843651857942052864)\n#define MIN_INT128 (-MAX_INT128 - LONGLONG_SUFFIX(1))\n#define MAX_UINT128 ULONGLONG_SUFFIX(170141183460469231731687303715884105728)\n#define MAX_INT256 LONGLONG_SUFFIX(57896044618658097711785492504343953926634992332820282019728792003956564819967)\n#define MIN_INT256 (-MAX_INT256 - LONGLONG_SUFFIX(1))\n#define MAX_UINT256 ULONGLONG_SUFFIX(115792089237316195423570985008687907853269984665640564039457584007913129639935)\n\n\t/* Need to find the number of bits for each type and\n\t make definitions accordingly.\n\n\t C states that sizeof(char) == 1 by definition\n\n\t So, just using the sizeof keyword won't help.\n\n\t It also looks like Python itself uses sizeof(char) quite a\n\t bit, which by definition should be 1 all the time.\n\n\t Idea: Make Use of CHAR_BIT which should tell us how many\n\t BITS per CHARACTER\n\t*/\n\n\t/* Include platform definitions -- These are in the C89/90 standard */\n#include \n#define MAX_BYTE SCHAR_MAX\n#define MIN_BYTE SCHAR_MIN\n#define MAX_UBYTE UCHAR_MAX\n#define MAX_SHORT SHRT_MAX\n#define MIN_SHORT SHRT_MIN\n#define MAX_USHORT USHRT_MAX\n#define MAX_INT INT_MAX\n#ifndef INT_MIN\n#define INT_MIN (-INT_MAX - 1)\n#endif\n#define MIN_INT INT_MIN\n#define MAX_UINT UINT_MAX\n#define MAX_LONG LONG_MAX\n#define MIN_LONG LONG_MIN\n#define MAX_ULONG ULONG_MAX\n\n#define SIZEOF_LONGDOUBLE SIZEOF_LONG_DOUBLE\n#define SIZEOF_LONGLONG SIZEOF_LONG_LONG\n#define BITSOF_BOOL sizeof(Bool)*CHAR_BIT\n#define BITSOF_CHAR CHAR_BIT\n#define BITSOF_SHORT (SIZEOF_SHORT*CHAR_BIT)\n#define BITSOF_INT (SIZEOF_INT*CHAR_BIT)\n#define BITSOF_LONG (SIZEOF_LONG*CHAR_BIT)\n#define BITSOF_LONGLONG (SIZEOF_LONGLONG*CHAR_BIT)\n#define BITSOF_FLOAT (SIZEOF_FLOAT*CHAR_BIT)\n#define BITSOF_DOUBLE (SIZEOF_DOUBLE*CHAR_BIT)\n#define BITSOF_LONGDOUBLE (SIZEOF_LONGDOUBLE*CHAR_BIT)\n\n\n#if BITSOF_LONG == 8\n#define PyArray_INT8 PyArray_LONG\n#define PyArray_UINT8 PyArray_ULONG\n\ttypedef long Int8;\n\ttypedef unsigned long UInt8;\n#define STRBITSOF_LONG \"8\"\n#elif BITSOF_LONG == 16\n#define PyArray_INT16 PyArray_LONG\n#define PyArray_UINT16 PyArray_ULONG\n\ttypedef long Int16;\n\ttypedef unsigned long UInt16;\n#define STRBITSOF_LONG \"16\"\n#elif BITSOF_LONG == 32\n#define PyArray_INT32 PyArray_LONG\n#define PyArray_UINT32 PyArray_ULONG\n\ttypedef long Int32;\n\ttypedef unsigned long UInt32;\n\ttypedef unsigned long PyArray_UCS4;\n#define STRBITSOF_LONG \"32\"\n#elif BITSOF_LONG == 64\n#define PyArray_INT64 PyArray_LONG\n#define PyArray_UINT64 PyArray_ULONG\n\ttypedef long Int64;\n\ttypedef unsigned long UInt64;\n#define STRBITSOF_LONG \"64\"\n#elif BITSOF_LONG == 128\n#define PyArray_INT128 PyArray_LONG\n#define PyArray_UINT128 PyArray_ULONG\n\ttypedef long Int128;\n\ttypedef unsigned long UInt128;\n#define STRBITSOF_LONG \"128\"\n#endif\n\n#if BITSOF_LONGLONG == 8\n# ifndef PyArray_INT8\n# define PyArray_INT8 PyArray_LONGLONG\n# define PyArray_UINT8 PyArray_ULONGLONG\n\ttypedef longlong Int8;\n\ttypedef ulonglong UInt8;\n# endif\n# define MAX_LONGLONG MAX_INT8\n# define MIN_LONGLONG MIN_INT8\n# define MAX_ULONGLONG MAX_UINT8\n#define STRBITSOF_LONGLONG \"8\"\n#elif BITSOF_LONGLONG == 16\n# ifndef PyArray_INT16\n# define PyArray_INT16 PyArray_LONGLONG\n# define PyArray_UINT16 PyArray_ULONGLONG\n\ttypedef longlong Int16;\n\ttypedef ulonglong UInt16;\n# endif\n# define MAX_LONGLONG MAX_INT16\n# define MIN_LONGLONG MIN_INT16\n# define MAX_ULONGLONG MAX_UINT16\n#define STRBITSOF_LONGLONG \"16\"\n#elif BITSOF_LONGLONG == 32\n# ifndef PyArray_INT32\n# define PyArray_INT32 PyArray_LONGLONG\n# define PyArray_UINT32 PyArray_ULONGLONG\n\ttypedef longlong Int32;\n\ttypedef ulonglong UInt32;\n\ttypedef ulonglong PyArray_UCS4;\n# endif\n# define MAX_LONGLONG MAX_INT32\n# define MIN_LONGLONG MIN_INT32\n# define MAX_ULONGLONG MAX_UINT32\n#define STRBITSOF_LONGLONG \"32\"\n#elif BITSOF_LONGLONG == 64\n# ifndef PyArray_INT64\n# define PyArray_INT64 PyArray_LONGLONG\n# define PyArray_UINT64 PyArray_ULONGLONG\n\ttypedef longlong Int64;\n\ttypedef ulonglong UInt64;\n# endif\n# define MAX_LONGLONG MAX_INT64\n# define MIN_LONGLONG MIN_INT64\n# define MAX_ULONGLONG MAX_UINT64\n#define STRBITSOF_LONGLONG \"64\"\n#elif BITSOF_LONGLONG == 128\n# ifndef PyArray_INT128\n# define PyArray_INT128 PyArray_LONGLONG\n# define PyArray_UINT128 PyArray_ULONGLONG\n\ttypedef longlong Int128;\n\ttypedef ulonglong UInt128;\n# endif\n# define MAX_LONGLONG MAX_INT128\n# define MIN_LONGLONG MIN_INT128\n# define MAX_ULONGLONG MAX_UINT128\n#define STRBITSOF_LONGLONG \"128\"\n#elif BITSOF_LONGLONG == 256\n# define PyArray_INT256 PyArray_LONGLONG\n# define PyArray_UINT256 PyArray_ULONGLONG\n\ttypedef longlong Int256;\n\ttypedef ulonglong UInt256;\n# define MAX_LONGLONG MAX_INT256\n# define MIN_LONGLONG MIN_INT256\n# define MAX_ULONGLONG MAX_UINT256\n#define STRBITSOF_LONGLONG \"256\"\n#endif\n\n#if BITSOF_INT == 8\n#ifndef PyArray_INT8\n#define PyArray_INT8 PyArray_INT\n#define PyArray_UINT8 PyArray_UINT\n\ttypedef int Int8;\n\ttypedef unsigned int UInt8;\n#endif\n#define STRBITSOF_INT \"8\"\n#elif BITSOF_INT == 16\n#ifndef PyArray_INT16\n#define PyArray_INT16 PyArray_INT\n#define PyArray_UINT16 PyArray_UINT\n\ttypedef int Int16;\n\ttypedef unsigned int UInt16;\n#endif\n#define STRBITSOF_INT \"16\"\n#elif BITSOF_INT == 32\n#ifndef PyArray_INT32\n#define PyArray_INT32 PyArray_INT\n#define PyArray_UINT32 PyArray_UINT\n\ttypedef int Int32;\n\ttypedef unsigned int UInt32;\n\ttypedef unsigned int PyArray_UCS4;\n#endif\n#define STRBITSOF_INT \"32\"\n#elif BITSOF_INT == 64\n#ifndef PyArray_INT64\n#define PyArray_INT64 PyArray_INT\n#define PyArray_UINT64 PyArray_UINT\n\ttypedef int Int64;\n\ttypedef unsigned int UInt64;\n#endif\n#define STRBITSOF_INT \"64\"\n#elif BITSOF_INT == 128\n#ifndef PyArray_INT128\n#define PyArray_INT128 PyArray_INT\n#define PyArray_UINT128 PyArray_UINT\n\ttypedef int Int128;\n\ttypedef unsigned int UInt128;\n#endif\n#define STRBITSOF_INT \"128\"\n#endif\n\n#if BITSOF_SHORT == 8\n#ifndef PyArray_INT8\n#define PyArray_INT8 PyArray_SHORT\n#define PyArray_UINT8 PyArray_USHORT\n\ttypedef short Int8;\n\ttypedef unsigned short UInt8;\n#endif\n#define STRBITSOF_SHORT \"8\"\n#elif BITSOF_SHORT == 16\n#ifndef PyArray_INT16\n#define PyArray_INT16 PyArray_SHORT\n#define PyArray_UINT16 PyArray_USHORT\n\ttypedef short Int16;\n\ttypedef unsigned short UInt16;\n#endif\n#define STRBITSOF_SHORT \"16\"\n#elif BITSOF_SHORT == 32\n#ifndef PyArray_INT32\n#define PyArray_INT32 PyArray_SHORT\n#define PyArray_UINT32 PyArray_USHORT\n\ttypedef short Int32;\n\ttypedef unsigned short UInt32;\n\ttypedef unsigned short PyArray_UCS4;\n#endif\n#define STRBITSOF_SHORT \"32\"\n#elif BITSOF_SHORT == 64\n#ifndef PyArray_INT64\n#define PyArray_INT64 PyArray_SHORT\n#define PyArray_UINT64 PyArray_USHORT\n\ttypedef short Int64;\n\ttypedef unsigned short UInt64;\n#endif\n#define STRBITSOF_SHORT \"64\"\n#elif BITSOF_SHORT == 128\n#ifndef PyArray_INT128\n#define PyArray_INT128 PyArray_SHORT\n#define PyArray_UINT128 PyArray_USHORT\n\ttypedef short Int128;\n\ttypedef unsigned short UInt128;\n#endif\n#define STRBITSOF_SHORT \"128\"\n#endif\n\n\n#if BITSOF_CHAR == 8\n#ifndef PyArray_INT8\n#define PyArray_INT8 PyArray_BYTE\n#define PyArray_UINT8 PyArray_UBYTE\n\ttypedef signed char Int8;\n\ttypedef unsigned char UInt8;\n#endif\n#define STRBITSOF_CHAR \"8\"\n#elif BITSOF_CHAR == 16\n#ifndef PyArray_INT16\n#define PyArray_INT16 PyArray_BYTE\n#define PyArray_UINT16 PyArray_UBYTE\n\ttypedef signed char Int16;\n\ttypedef unsigned char UInt16;\n#endif\n#define STRBITSOF_CHAR \"16\"\n#elif BITSOF_CHAR == 32\n#ifndef PyArray_INT32\n#define PyArray_INT32 PyArray_BYTE\n#define PyArray_UINT32 PyArray_UBYTE\n\ttypedef signed char Int32;\n\ttypedef unsigned char UInt32;\n\ttypedef unsigned char PyArray_UCS4;\n#endif\n#define STRBITSOF_CHAR \"32\"\n#elif BITSOF_CHAR == 64\n#ifndef PyArray_INT64\n#define PyArray_INT64 PyArray_BYTE\n#define PyArray_UINT64 PyArray_UBYTE\n\ttypedef signed char Int64;\n\ttypedef unsigned char UInt64;\n#endif\n#define STRBITSOF_CHAR \"64\"\n#elif BITSOF_CHAR == 128\n#ifndef PyArray_INT128\n#define PyArray_INT128 PyArray_BYTE\n#define PyArray_UINT128 PyArray_UBYTE\n\ttypedef signed char Int128;\n\ttypedef unsigned char UInt128;\n#endif\n#define STRBITSOF_CHAR \"128\"\n#endif\n\n\n\n#if BITSOF_DOUBLE == 16\n#define STRBITSOF_DOUBLE \"16\"\n#define STRBITSOF_CDOUBLE \"32\"\n#ifndef PyArray_FLOAT16\n#define PyArray_FLOAT16 PyArray_DOUBLE\n#define PyArray_COMPLEX32 PyArray_CDOUBLE\n\ttypedef double Float16;\n\ttypedef cdouble Complex32;\n#endif\n#elif BITSOF_DOUBLE == 32\n#define STRBITSOF_DOUBLE \"32\"\n#define STRBITSOF_CDOUBLE \"64\"\n#ifndef PyArray_FLOAT32\n#define PyArray_FLOAT32 PyArray_DOUBLE\n#define PyArray_COMPLEX64 PyArray_CDOUBLE\n\ttypedef double Float32;\n\ttypedef cdouble Complex64;\n#endif\n#elif BITSOF_DOUBLE == 64\n#define STRBITSOF_DOUBLE \"64\"\n#define STRBITSOF_CDOUBLE \"128\"\n#ifndef PyArray_FLOAT64\n#define PyArray_FLOAT64 PyArray_DOUBLE\n#define PyArray_COMPLEX128 PyArray_CDOUBLE\n\ttypedef double Float64;\n\ttypedef cdouble Complex128;\n#endif\n#elif BITSOF_DOUBLE == 80\n#define STRBITSOF_DOUBLE \"80\"\n#define STRBITSOF_CDOUBLE \"160\"\n#ifndef PyArray_FLOAT80\n#define PyArray_FLOAT80 PyArray_DOUBLE\n#define PyArray_COMPLEX160 PyArray_CDOUBLE\n\ttypedef double Float80;\n\ttypedef cdouble Complex160;\n#endif\n#elif BITSOF_DOUBLE == 96\n#define STRBITSOF_DOUBLE \"96\"\n#define STRBITSOF_CDOUBLE \"192\"\n#ifndef PyArray_FLOAT96\n#define PyArray_FLOAT96 PyArray_DOUBLE\n#define PyArray_COMPLEX192 PyArray_CDOUBLE\n\ttypedef double Float96;\n\ttypedef cdouble Complex192;\n#endif\n#elif BITSOF_DOUBLE == 128\n#define STRBITSOF_DOUBLE \"128\"\n#define STRBITSOF_CDOUBLE \"256\"\n#ifndef PyArray_FLOAT128\n#define PyArray_FLOAT128 PyArray_DOUBLE\n#define PyArray_COMPLEX256 PyArray_CDOUBLE\n\ttypedef double Float128;\n\ttypedef cdouble Complex256;\n#endif\n#endif\n\n\n\n#if BITSOF_FLOAT == 16\n#define STRBITSOF_FLOAT \"16\"\n#define STRBITSOF_CFLOAT \"32\"\n#ifndef PyArray_FLOAT16\n#define PyArray_FLOAT16 PyArray_FLOAT\n#define PyArray_COMPLEX32 PyArray_CFLOAT\n\ttypedef float Float16;\n\ttypedef cfloat Complex32;\n#endif\n#elif BITSOF_FLOAT == 32\n#define STRBITSOF_FLOAT \"32\"\n#define STRBITSOF_CFLOAT \"64\"\n#ifndef PyArray_FLOAT32\n#define PyArray_FLOAT32 PyArray_FLOAT\n#define PyArray_COMPLEX64 PyArray_CFLOAT\n\ttypedef float Float32;\n\ttypedef cfloat Complex64;\n#endif\n#elif BITSOF_FLOAT == 64\n#define STRBITSOF_FLOAT \"64\"\n#define STRBITSOF_CFLOAT \"128\"\n#ifndef PyArray_FLOAT64\n#define PyArray_FLOAT64 PyArray_FLOAT\n#define PyArray_COMPLEX128 PyArray_CFLOAT\n\ttypedef float Float64;\n\ttypedef cfloat Complex128;\n#endif\n#elif BITSOF_FLOAT == 80\n#define STRBITSOF_FLOAT \"80\"\n#define STRBITSOF_CFLOAT \"160\"\n#ifndef PyArray_FLOAT80\n#define PyArray_FLOAT80 PyArray_FLOAT\n#define PyArray_COMPLEX160 PyArray_CFLOAT\n\ttypedef float Float80;\n\ttypedef cfloat Complex160;\n#endif\n#elif BITSOF_FLOAT == 96\n#define STRBITSOF_FLOAT \"96\"\n#define STRBITSOF_CFLOAT \"192\"\n#ifndef PyArray_FLOAT96\n#define PyArray_FLOAT96 PyArray_FLOAT\n#define PyArray_COMPLEX192 PyArray_CFLOAT\n\ttypedef float Float96;\n\ttypedef cfloat Complex192;\n#endif\n#elif BITSOF_FLOAT == 128\n#define STRBITSOF_FLOAT \"128\"\n#define STRBITSOF_CFLOAT \"256\"\n#ifndef PyArray_FLOAT128\n#define PyArray_FLOAT128 PyArray_FLOAT\n#define PyArray_COMPLEX256 PyArray_CFLOAT\n\ttypedef float Float128;\n\ttypedef cfloat Complex256;\n#endif\n#endif\n\n\n#if BITSOF_LONGDOUBLE == 16\n#define STRBITSOF_LONGDOUBLE \"16\"\n#define STRBITSOF_CLONGDOUBLE \"32\"\n#ifndef PyArray_FLOAT16\n#define PyArray_FLOAT16 PyArray_LONGDOUBLE\n#define PyArray_COMPLEX32 PyArray_CLONGDOUBLE\n\ttypedef longdouble Float16;\n\ttypedef clongdouble Complex32;\n#endif\n#elif BITSOF_LONGDOUBLE == 32\n#define STRBITSOF_LONGDOUBLE \"32\"\n#define STRBITSOF_CLONGDOUBLE \"64\"\n#ifndef PyArray_FLOAT32\n#define PyArray_FLOAT32 PyArray_LONGDOUBLE\n#define PyArray_COMPLEX64 PyArray_CLONGDOUBLE\n\ttypedef longdouble Float32;\n\ttypedef clongdouble Complex64;\n#endif\n#elif BITSOF_LONGDOUBLE == 64\n#define STRBITSOF_LONGDOUBLE \"64\"\n#define STRBITSOF_CLONGDOUBLE \"128\"\n#ifndef PyArray_FLOAT64\n#define PyArray_FLOAT64 PyArray_LONGDOUBLE\n#define PyArray_COMPLEX128 PyArray_CLONGDOUBLE\n\ttypedef longdouble Float64;\n\ttypedef clongdouble Complex128;\n#endif\n#elif BITSOF_LONGDOUBLE == 80\n#define STRBITSOF_LONGDOUBLE \"80\"\n#define STRBITSOF_CLONGDOUBLE \"160\"\n#ifndef PyArray_FLOAT80\n#define PyArray_FLOAT80 PyArray_LONGDOUBLE\n#define PyArray_COMPLEX160 PyArray_CLONGDOUBLE\n\ttypedef longdouble Float80;\n\ttypedef clongdouble Complex160;\n#endif\n#elif BITSOF_LONGDOUBLE == 96\n#define STRBITSOF_LONGDOUBLE \"96\"\n#define STRBITSOF_CLONGDOUBLE \"192\"\n#ifndef PyArray_FLOAT96\n#define PyArray_FLOAT96 PyArray_LONGDOUBLE\n#define PyArray_COMPLEX192 PyArray_CLONGDOUBLE\n\ttypedef longdouble Float96;\n\ttypedef clongdouble Complex192;\n#endif\n#elif BITSOF_LONGDOUBLE == 128\n#define STRBITSOF_LONGDOUBLE \"128\"\n#define STRBITSOF_CLONGDOUBLE \"256\"\n#ifndef PyArray_FLOAT128\n#define PyArray_FLOAT128 PyArray_LONGDOUBLE\n#define PyArray_COMPLEX256 PyArray_CLONGDOUBLE\n\ttypedef longdouble Float128;\n\ttypedef clongdouble Complex256;\n#endif\n#elif BITSOF_LONGDOUBLE == 256\n#define STRBITSOF_LONGDOUBLE \"256\"\n#define STRBITSOF_CLONGDOUBLE \"512\"\n#define PyArray_FLOAT256 PyArray_LONGDOUBLE\n#define PyArray_COMPLEX512 PyArray_CLONGDOUBLE\n\ttypedef longdouble Float256;\n\ttypedef clongdouble Complex512;\n#endif\n\n\n\t/* End of typedefs for numarray style bit-width names */\n\n/* This is to typedef Intp to the appropriate pointer size for this platform.\n * Py_intptr_t, Py_uintptr_t are defined in pyport.h. */\ntypedef Py_intptr_t intp;\ntypedef Py_uintptr_t uintp;\n#define SIZEOF_INTP SIZEOF_PY_INTPTR_T\n#define SIZEOF_UINTP SIZEOF_PY_INTPTR_T\n\n#define INTP_FMT \"d\"\n\n#if SIZEOF_PY_INTPTR_T == SIZEOF_INT\n\t#define PyArray_INTP PyArray_INT\n\t#define PyArray_UINTP PyArray_UINT\n #define PyIntpArrType_Type PyIntArrType_Type\n #define PyUIntpArrType_Type PyUIntArrType_Type\n\t#define MAX_INTP MAX_INT\n\t#define MIN_INTP MIN_INT\n\t#define MAX_UINTP MAX_UINT\n#elif SIZEOF_PY_INTPTR_T == SIZEOF_LONG\n\t#define PyArray_INTP PyArray_LONG\n\t#define PyArray_UINTP PyArray_ULONG\n #define PyIntpArrType_Type PyLongArrType_Type\n #define PyUIntpArrType_Type PyULongArrType_Type\n\t#define MAX_INTP MAX_LONG\n\t#define MIN_INTP MIN_LONG\n\t#define MAX_UINTP MAX_ULONG\n #undef INTP_FMT\n #define INTP_FMT \"ld\"\n#elif defined(PY_LONG_LONG) && (SIZEOF_PY_INTPTR_T == SIZEOF_LONG_LONG)\n\t#define PyArray_INTP PyArray_LONGLONG\n\t#define PyArray_UINTP PyArray_ULONGLONG\n #define PyIntpArrType_Type PyLongLongArrType_Type\n #define PyUIntpArrType_Type PyULongLongArrType_Type\n\t#define MAX_INTP MAX_LONGLONG\n\t#define MIN_INTP MIN_LONGLONG\n\t#define MAX_UINTP MAX_ULONGLONG\n #undef INTP_FMT\n #define INTP_FMT \"Ld\"\n#endif\n\n#define ERR(str) fprintf(stderr, #str); fflush(stderr);\n#define ERR2(str) fprintf(stderr, str); fflush(stderr);\n\n /* Macros to define how array, and dimension/strides data is\n allocated.\n */\n\n /* Data buffer */\n#define PyDataMem_NEW(size) ((char *)malloc(size))\n /* #define PyArrayMem_NEW(size) PyMem_NEW(char, size)*/\n#define PyDataMem_FREE(ptr) free(ptr)\n /* #define PyArrayMem_FREE(ptr) PyMem_Free(ptr) */\n#define PyDataMem_RENEW(ptr,size) ((char *)realloc(ptr,size))\n\n#define PyArray_USE_PYMEM 0\n\n#if PyArray_USE_PYMEM == 1\n#define _pya_malloc PyObject_Malloc\n#define _pya_free PyObject_Free\n#define _pya_realloc PyObject_Realloc\n#else\n#define _pya_malloc malloc\n#define _pya_free free\n#define _pya_realloc realloc\n#endif\n\n/* Dimensions and strides */\n#define PyDimMem_NEW(size) ((intp *)_pya_malloc(size*sizeof(intp)))\n#define PyDimMem_FREE(ptr) _pya_free(ptr)\n#define PyDimMem_RENEW(ptr,size) ((intp *)_pya_realloc(ptr,size*sizeof(intp)))\n\n\n /* These must deal with unaligned and swapped data if necessary */\ntypedef PyObject * (PyArray_GetItemFunc) (void *, void *);\ntypedef int (PyArray_SetItemFunc)(PyObject *, void *, void *);\n\ntypedef void (PyArray_CopySwapNFunc)(void *, void *, intp, int, int);\ntypedef void (PyArray_CopySwapFunc)(void *, void *, int, int);\ntypedef Bool (PyArray_NonzeroFunc)(void *, void *);\n\n\n /* These assume aligned and notswapped data -- a buffer will be\n used before or contiguous data will be obtained\n */\ntypedef int (PyArray_CompareFunc)(const void *, const void *, void *);\ntypedef int (PyArray_ArgFunc)(void*, intp, intp*, void *);\ntypedef void (PyArray_DotFunc)(void *, intp, void *, intp, void *, intp,\n\t\t\t void *);\ntypedef void (PyArray_VectorUnaryFunc)(void *, void *, intp, void *, void *);\ntypedef int (PyArray_ScanFunc)(FILE *, void *, void *, void *);\ntypedef int (PyArray_FromStrFunc)(char *, void *, char **, void *);\n\ntypedef int (PyArray_FillFunc)(void *, intp, void *);\n\ntypedef int (PyArray_SortFunc)(void *, intp, void *);\ntypedef int (PyArray_ArgSortFunc)(void *, intp *, intp, void *);\n\ntypedef struct {\n intp *ptr;\n int len;\n} PyArray_Dims;\n\ntypedef struct {\n\t/* Functions to cast to all other standard types*/\n\tPyArray_VectorUnaryFunc *cast[PyArray_NTYPES];\n\n\t/* Functions to get and set items with standard\n\t Python types -- not array scalars */\n\tPyArray_GetItemFunc *getitem;\n\tPyArray_SetItemFunc *setitem;\n\n\t/* Copy and/or swap data. Memory areas may not overlap */\n\t/* Use memmove first if they might */\n\tPyArray_CopySwapNFunc *copyswapn;\n PyArray_CopySwapFunc *copyswap;\n\n\t/* Function to compare items */\n\tPyArray_CompareFunc *compare;\n\n\t/* Function to select largest */\n\tPyArray_ArgFunc *argmax;\n\n\t/* Function to compute dot product */\n\tPyArray_DotFunc\t*dotfunc;\n\n\t/* Function to scan an ASCII file and\n\t place a single value plus possible separator */\n\tPyArray_ScanFunc *scanfunc;\n\n\t/* Function to read a single value from a string */\n\t/* and adjust the pointer */\n\tPyArray_FromStrFunc *fromstr;\n\n\t/* Function to determine if data is zero or not */\n\tPyArray_NonzeroFunc *nonzero;\n\n\t/* Used for arange */\n\tPyArray_FillFunc *fill;\n\n\t/* Sorting functions */\n\tPyArray_SortFunc *sort[PyArray_NSORTS];\n\tPyArray_ArgSortFunc *argsort[PyArray_NSORTS];\n\n} PyArray_ArrFuncs;\n\n\ntypedef struct {\n\tPyObject_HEAD\n\tPyTypeObject *typeobj; /* the type object representing an\n\t\t\t\t intance of this type */\n\tchar kind; /* kind for this type */\n\tchar type; /* unique-character representing this type */\n\tchar byteorder; /* '>' (big), '<' (little), '|'\n\t\t\t\t (not-applicable), or '=' (native). */\n char hasobject; /* non-zero if it has object arrays in fields */\n\tint type_num; /* number representing this type */\n\tint elsize; /* element size for this type */\n\tint alignment; /* alignment needed for this type */\n\tstruct _arr_descr\t\t\t\t\t\\\n\t*subarray; /* Non-NULL if this type is\n\t\t\t\t is an array (C-contiguous)\n\t\t\t\t of some other type\n\t\t\t\t*/\n\tPyObject *fields; /* The fields dictionary for this type */\n\t /* For statically defined descr this\n\t\t\t\t is always Py_None */\n\n\tPyArray_ArrFuncs *f; /* a table of functions specific for each\n\t\t\t\t basic data descriptor */\n} PyArray_Descr;\n\ntypedef struct _arr_descr {\n\tPyArray_Descr *base;\n\tPyObject *shape; /* a tuple */\n} PyArray_ArrayDescr;\n\n\n/*\n The main array object structure. It is recommended to use the macros\n defined below (PyArray_DATA and friends) access fields here, instead\n of the members themselves.\n */\n\ntypedef struct PyArrayObject {\n\tPyObject_HEAD\n\tchar *data; /* pointer to raw data buffer */\n\tint nd; /* number of dimensions, also called ndim */\n\tintp *dimensions; /* size in each dimension */\n intp *strides; /* bytes to jump to get to the\n\t\t\t\t next element in each dimension */\n\tPyObject *base; /* This object should be decref'd\n\t\t\t\t upon deletion of array */\n\t /* For views it points to the original array */\n\t /* For creation from buffer object it points\n\t\t\t\t to an object that shold be decref'd on\n\t\t\t\t deletion */\n\t /* For UPDATEIFCOPY flag this is an array\n\t\t\t\t to-be-updated upon deletion of this one */\n\tPyArray_Descr *descr; /* Pointer to type structure */\n\tint flags; /* Flags describing array -- see below*/\n\tPyObject *weakreflist; /* For weakreferences */\n} PyArrayObject;\n\n#define fortran fortran_ /* For some compilers */\n\n/* Mirrors buffer object to ptr */\n\ntypedef struct {\n PyObject_HEAD\n PyObject *base;\n void *ptr;\n intp len;\n int flags;\n} PyArray_Chunk;\n\n/* Array flags */\n\n/* Means c-style contiguous (last index varies the fastest). The\n data elements right after each other. */\n#define CONTIGUOUS 0x0001\n/* set if array is a contiguous Fortran array: the first index\n varies the fastest in memory (strides array is reverse of\n C-contiguous array)*/\n#define FORTRAN 0x0002\n\n/*\n Note: all 0-d arrays are CONTIGUOUS and FORTRAN contiguous. If a\n 1-d array is CONTIGUOUS it is also FORTRAN contiguous\n*/\n\n/* If set, the array owns the data: it will be free'd when the array\n is deleted. */\n#define OWNDATA 0x0004\n#define OWN_DATA OWNDATA\n\n/* An array never has these three set; they're only used as parameter\n flags to the the various FromAny functions */\n/* Cause a cast to occur regardless of whether or not it is safe. */\n#define FORCECAST 0x0010\n/* Always copy the array. Returned arrays are always CONTIGUOUS, ALIGNED,\n and WRITEABLE. */\n#define ENSURECOPY 0x0020\n/* Make sure the returned array is an ndarray or a bigndarray */\n#define ENSUREARRAY 0x0040\n\n/* Array data is aligned on the appropiate memory address for the\n type stored (e.g., an array of doubles (8 bytes each) starts on\n a memory address that's a multiple of 8) */\n#define ALIGNED 0x0100\n/* Array data has the native endianness */\n#define NOTSWAPPED 0x0200\n/* Array data is writeable */\n#define WRITEABLE 0x0400\n/* If this flag is set, then base contains a pointer to an array of\n the same size that should be updated with the current contents of\n this array when this array is deallocated\n*/\n#define UPDATEIFCOPY 0x1000\n\n\n#define BEHAVED_FLAGS ALIGNED | WRITEABLE\n#define BEHAVED_NS_FLAGS ALIGNED | WRITEABLE | NOTSWAPPED\n#define CARRAY_FLAGS CONTIGUOUS | BEHAVED_FLAGS\n#define CARRAY_FLAGS_RO CONTIGUOUS | ALIGNED\n#define FARRAY_FLAGS FORTRAN | BEHAVED_FLAGS\n#define FARRAY_FLAGS_RO FORTRAN | ALIGNED\n#define DEFAULT_FLAGS CARRAY_FLAGS\n\n#define UPDATE_ALL_FLAGS CONTIGUOUS | FORTRAN | ALIGNED\n\n\n/* Size of internal buffers used for alignment */\n#define PyArray_BUFSIZE 10000\n#define PyArray_MIN_BUFSIZE 5\n#define PyArray_MAX_BUFSIZE 100000000\n\n/*\n * C API: consists of Macros and functions. The MACROS are defined here.\n */\n\n\n#define PyArray_CHKFLAGS(m, FLAGS) \\\n\t((((PyArrayObject *)(m))->flags & (FLAGS)) == (FLAGS))\n#define PyArray_ISCONTIGUOUS(m) PyArray_CHKFLAGS(m, CONTIGUOUS)\n#define PyArray_ISWRITEABLE(m) PyArray_CHKFLAGS(m, WRITEABLE)\n#define PyArray_ISALIGNED(m) PyArray_CHKFLAGS(m, ALIGNED)\n\n#ifndef MAX\n#define MAX(a,b) (((a)>(b))?(a):(b))\n#endif\n#ifndef MIN\n#define MIN(a,b) (((a)<(b))?(a):(b))\n#endif\n\n/* Useful if a and b have to be evaluated. */\n\n#define tMAX(a,b,typ) {typ _x_=(a); typ _y_=(b); _x_>_y_ ? _x_ : _y_}\n#define tMIN(a,b,typ) {typ _x_=(a); typ _y_=(b); _x_<_y_ ? _x_ : _y_}\n\n#if defined(ALLOW_THREADS)\n#define BEGIN_THREADS_DEF PyThreadState *_save;\n#define BEGIN_THREADS _save = PyEval_SaveThread();\n#define END_THREADS PyEval_RestoreThread(_save);\n#define ALLOW_C_API_DEF PyGILState_STATE __save__;\n#define ALLOW_C_API __save__ = PyGILState_Ensure();\n#define DISABLE_C_API PyGILState_Release(__save__);\n#else\n#define BEGIN_THREADS_DEF\n#define BEGIN_THREADS\n#define END_THREADS\n#define ALLOW_C_API_DEF\n#define\tALLOW_C_API\n#define\tDISABLE_C_API\n#endif\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\ntypedef struct {\n PyObject_HEAD\n\tint nd_m1; /* number of dimensions - 1 */\n intp\t\t index, size;\n\tintp coordinates[MAX_DIMS];/* N-dimensional loop */\n intp dims_m1[MAX_DIMS]; /* ao->dimensions - 1 */\n\tintp strides[MAX_DIMS]; /* ao->strides or fake */\n\tintp backstrides[MAX_DIMS];/* how far to jump back */\n\tintp factors[MAX_DIMS]; /* shape factors */\n\tPyArrayObject *ao;\n\tchar *dataptr; /* pointer to current item*/\n Bool contiguous;\n} PyArrayIterObject;\n\n\n/* Iterator API */\n#define PyArrayIter_Check(op) PyObject_TypeCheck(op, &PyArrayIter_Type)\n\n#define PyArray_ITER_RESET(it) {\t\t\t\t\t\\\n\tit->index = 0;\t\t\t\t\t\t \\\n\tit->dataptr = it->ao->data;\t\t\t\t\t\\\n\tmemset(it->coordinates, 0, (it->nd_m1+1)*sizeof(intp));\t\t\\\n}\n\n#define _PyArray_ITER_NEXT1(it) {\t\t\\\n\t\tit->dataptr += it->strides[0];\t\\\n\t\tit->coordinates[0]++;\t\t\\\n\t}\n\n#define _PyArray_ITER_NEXT2(it) {\t\t\t\t\t\\\n\t\tif (it->coordinates[1] < it->dims_m1[1]) {\t\t\\\n\t\t\tit->coordinates[1]++;\t\t\t\t\\\n\t\t\tit->dataptr += it->strides[1];\t\t\t\\\n\t\t}\t\t\t\t\t\t\t\\\n\t\telse {\t\t\t\t\t\t\t\\\n\t\t\tit->coordinates[1] = 0;\t\t\t\t\\\n\t\t\tit->coordinates[0]++;\t\t\t\t\\\n\t\t\tit->dataptr += it->strides[0] -\t\t\t\\\n\t\t\t\tit->backstrides[1];\t\t\t\\\n\t\t}\t\t\t\t\t\t\t\\\n\t}\n\n#define PyArray_ITER_NEXT(it) {\t\t\t\t\t\t\\\n\tit->index++;\t\t\t\t\t\t \\\n if (it->nd_m1 == 0) {\t\t\t\t\t\t\\\n\t\t_PyArray_ITER_NEXT1(it);\t\t\t\t\\\n\t}\t\t\t\t\t\t\t\t\\\n\telse if (it->contiguous) it->dataptr += it->ao->descr->elsize; \\\n\telse if (it->nd_m1 == 1) {\t\t\t\t\t\\\n\t\t_PyArray_ITER_NEXT2(it);\t\t\t\t\\\n\t}\t\t\t\t\t\t\t\t\\\n\telse {\t\t\t\t\t\t\t\t\\\n\t\tint _i_;\t\t\t\t\t\t\\\n\t\tfor (_i_ = it->nd_m1; _i_ >= 0; _i_--) {\t\t\\\n\t\t\tif (it->coordinates[_i_] <\t\t\t\\\n\t\t\t it->dims_m1[_i_]) {\t\t\t\t\\\n\t\t\t\tit->coordinates[_i_]++;\t\t\t\\\n\t\t\t\tit->dataptr += it->strides[_i_];\t\\\n\t\t\t\tbreak;\t\t\t\t\t\\\n\t\t\t}\t\t\t\t\t\t\\\n\t\t\telse {\t\t\t\t\t\t\\\n\t\t\t\tit->coordinates[_i_] = 0;\t\t\\\n\t\t\t\tit->dataptr -= it->backstrides[_i_];\t\\\n\t\t\t}\t\t\t\t\t\t\\\n\t\t}\t\t\t\t\t\t\t\\\n\t}\t\t\t\t\t\t\t\t\\\n}\n\n#define PyArray_ITER_GOTO(it, destination) {\t\t\t\t\\\n\t\tint _i_;\t\t\t\t\t\t\\\n\t\tit->index = 0;\t\t\t\t\t\t\\\n\t\tit->dataptr = it->ao->data;\t\t\t\t\\\n\t\tfor (_i_ = it->nd_m1; _i_>=0; _i_--) {\t\t\t\\\n\t\t\tit->dataptr += destination[_i_] *\t\t\\\n\t\t\t\tit->strides[_i_];\t\t\t\\\n\t\t\tit->coordinates[_i_] = destination[_i_];\t\\\n\t\t\tit->index += destination[_i_] *\t\t\t\\\n\t\t\t\t( _i_==it->nd_m1 ? 1 :\t\t\t\\\n\t\t\t\t it->dims_m1[i+1]+1) ;\t\t \\\n\t\t}\t\t\t\t\t\t\t\\\n\t}\n\n#define PyArray_ITER_GOTO1D(it, ind) { \\\n\t\tint _i_;\t\t\t\t\t\t\\\n\t\tintp _lind_ = (intp) (ind);\t\t\t\t\\\n\t\tit->index = _lind_;\t\t\t\t\t\\\n if (it->nd_m1 == 0) { \\\n it->dataptr = it->ao->data + (ind) * \\\n it->strides[0]; \\\n } \\\n else if (it->contiguous) \\\n\t\t\tit->dataptr = it->ao->data + (ind) *\t\t\\\n\t\t\t\tit->ao->descr->elsize;\t\t\t\\\n\t\telse {\t\t\t\t\t\t\t\\\n\t\t\tit->dataptr = it->ao->data;\t\t\t\\\n\t\t\tfor (_i_ = 0; _i_<=it->nd_m1; _i_++) {\t\t\\\n\t\t\t\tit->dataptr += (_lind_ / it->factors[_i_]) \\\n\t\t\t\t\t* it->strides[_i_];\t\t\\\n\t\t\t\t_lind_ %= it->factors[_i_];\t\t\\\n\t\t\t}\t\t\t\t\t\t\\\n\t\t}\t\t\t\t\t\t\t\\\n}\n\n#define PyArray_ITER_DATA(it) ((PyArrayIterObject *)it)->dataptr\n\n\n/*\n Any object passed to PyArray_Broadcast must be binary compatible with\n this structure.\n*/\n\ntypedef struct {\n\tPyObject_HEAD\n\n\tint numiter; /* number of iters */\n\tintp size; /* broadcasted size */\n\tintp index; /* current index */\n\tint nd; /* number of dims */\n\tintp dimensions[MAX_DIMS]; /* dimensions */\n\tPyArrayIterObject *iters[MAX_DIMS]; /* iterators */\n} PyArrayMultiIterObject;\n\n#define PyArray_MultiIter_RESET(multi) {\t\t\t \\\n\t\tint _mi_;\t\t\t\t\t \\\n\t\tPyArrayMultiIterObject *_mul_ = (multi);\t \\\n\t\t_mul_->index = 0;\t\t\t\t \\\n\t\tfor (_mi_ = 0; _mi_ < _mul_->numiter; _mi_++) {\t \\\n\t\t\tPyArray_ITER_RESET(_mul_->iters[_mi_]);\t \\\n\t\t}\t\t\t\t\t\t \\\n\t}\n\n#define PyArray_MultiIter_NEXT(multi) {\t\t\t\t \\\n\t\tint _mi_;\t\t\t\t\t \\\n\t\tPyArrayMultiIterObject *_mul_ = (multi);\t \\\n\t\t_mul_->index += 1;\t\t\t\t \\\n\t\tfor (_mi_=0; _mi_<_mul_->numiter; _mi_++) {\t \\\n\t\t\tPyArray_ITER_NEXT(_mul_->iters[_mi_]);\t \\\n\t\t}\t\t\t\t\t\t \\\n\t}\n\n#define PyArray_MultiIter_GOTO(multi, dest) {\t\t\t\t\\\n\t\tint _mi_;\t\t\t\t\t\t\\\n\t\tPyArrayMultiIterObject *_mul_ = (multi);\t\t\\\n\t\tfor (_mi_=0; _mi_<_mul_->numiter; _mi_++) {\t\t\\\n\t\t\tPyArray_ITER_GOTO(_mul_->iters[_mi_], dest);\t\\\n\t\t}\t\t\t\t\t\t\t\\\n\t\t_mul_->index = _mul_->iters[0]->index;\t\t\t\\\n\t}\n\n#define PyArray_MultiIter_GOTO1D(multi, ind) {\t\t\t\t\\\n\t\tint _mi_;\t\t\t\t\t\t\\\n\t\tPyArrayMultiIterObject *_mul_ = (multi);\t\t\\\n\t\tfor (_mi_=0; _mi_<_mul_->numiter; _mi_++) {\t\t\\\n\t\t\tPyArray_ITER_GOTO1D(_mul_->iters[_mi_], ind);\t\\\n\t\t}\t\t\t\t\t\t\t\\\n\t\t_mul_->index = _mul_->iters[0]->index;\t\t\t\\\n\t}\n\n#define PyArray_MultiIter_DATA(multi, i) \\\n\t((PyArrayMultiIterObject *)multi)->iters[i]->dataptr\n\n#define PyArray_MultiIter_SIZE(multi) \\\n\t((PyArrayMultiIterObject *)multi)->size;\n\n\n/* Store the information needed for fancy-indexing over an array */\n\ntypedef struct {\n\tPyObject_HEAD\n\t/* Multi-iterator portion --- needs to be present in this order to\n\t work with PyArray_Broadcast */\n\n\tint numiter; /* number of index-array\n\t\t\t\t\t\t\t iterators */\n\tintp size; /* size of broadcasted\n\t\t\t\t\t\t\t result */\n\tintp index; /* current index */\n\tint nd; /* number of dims */\n\tintp dimensions[MAX_DIMS]; /* dimensions */\n\tPyArrayIterObject *iters[MAX_DIMS]; /* index object\n\t\t\t\t\t\t\t iterators */\n\tPyArrayIterObject *ait; /* flat Iterator for\n\t\t\t\t\t\t\t underlying array */\n\n\t/* flat iterator for subspace (when numiter < nd) */\n\tPyArrayIterObject *subspace;\n\n\t/* if subspace iteration, then this is the array of\n\t axes in the underlying array represented by the\n\t index objects */\n\tint iteraxes[MAX_DIMS];\n\t/* if subspace iteration, the these are the coordinates\n\t to the start of the subspace.\n\t*/\n\tintp bscoord[MAX_DIMS];\n\n\tPyObject *indexobj; /* reference to\n\t\t\t\t\t\t\t creating obj */\n\tint view;\n\tint consec;\n\tchar *dataptr;\n\n} PyArrayMapIterObject;\n\n/* All sorts of useful ways to look into a PyArrayObject.\n These are the recommended over casting to PyArrayObject and accessing\n the members directly.\n */\n\n#define PyArray_NDIM(obj) (((PyArrayObject *)(obj))->nd)\n#define PyArray_ISONESEGMENT(m) (PyArray_NDIM(m) == 0 || PyArray_CHKFLAGS(m, CONTIGUOUS) || \\\n\t\t\t\t PyArray_CHKFLAGS(m, FORTRAN))\n#define PyArray_ISFORTRAN(m) (PyArray_CHKFLAGS(m, FORTRAN) && (PyArray_NDIM(m) > 1))\n#define FORTRAN_IF(m) ((PyArray_CHKFLAGS(m, FORTRAN) ? FORTRAN : 0))\n#define PyArray_DATA(obj) ((void *)(((PyArrayObject *)(obj))->data))\n#define PyArray_BYTES(obj) (((PyArrayObject *)(obj))->data)\n#define PyArray_DIMS(obj) (((PyArrayObject *)(obj))->dimensions)\n#define PyArray_STRIDES(obj) (((PyArrayObject *)(obj))->strides)\n#define PyArray_DIM(obj,n) (((PyArrayObject *)(obj))->dimensions[n])\n#define PyArray_STRIDE(obj,n) (((PyArrayObject *)(obj))->strides[n])\n#define PyArray_BASE(obj) (((PyArrayObject *)(obj))->base)\n#define PyArray_DESCR(obj) (((PyArrayObject *)(obj))->descr)\n#define PyArray_FLAGS(obj) (((PyArrayObject *)(obj))->flags)\n#define PyArray_ITEMSIZE(obj) (((PyArrayObject *)(obj))->descr->elsize)\n#define PyArray_TYPE(obj) (((PyArrayObject *)(obj))->descr->type_num)\n#define PyArray_GETITEM(obj,itemptr)\t\t\t\\\n\t((PyArrayObject *)(obj))->descr->getitem((char *)itemptr,\t\\\n\t\t\t\t\t\t (PyArrayObject *)obj);\n#define PyArray_SETITEM(obj,itemptr,v)\t\t\t\t\t\\\n\t(obj)->descr->setitem((PyObject *)v,(char *)(itemptr),\t\t\\\n\t\t\t (PyArrayObject *)(obj));\n\n\n#define PyTypeNum_ISBOOL(type) (type == PyArray_BOOL)\n#define PyTypeNum_ISUNSIGNED(type) ((type == PyArray_UBYTE) || \\\n\t\t\t\t (type == PyArray_USHORT) || \\\n\t\t\t\t (type == PyArray_UINT) ||\t\\\n\t\t\t\t (type == PyArray_ULONG) || \\\n\t\t\t\t (type == PyArray_ULONGLONG))\n\n#define PyTypeNum_ISSIGNED(type) ((type == PyArray_BYTE) ||\t\\\n\t\t\t (type == PyArray_SHORT) ||\t\\\n\t\t\t (type == PyArray_INT) ||\t\\\n\t\t\t (type == PyArray_LONG) ||\t\\\n\t\t\t (type == PyArray_LONGLONG))\n\n#define PyTypeNum_ISINTEGER(type) ((type >= PyArray_BYTE) &&\t\\\n\t\t\t\t(type <= PyArray_ULONGLONG))\n\n#define PyTypeNum_ISFLOAT(type) ((type >= PyArray_FLOAT) && \\\n\t\t\t (type <= PyArray_LONGDOUBLE))\n\n#define PyTypeNum_ISNUMBER(type) (type <= PyArray_CLONGDOUBLE)\n\n#define PyTypeNum_ISSTRING(type) ((type == PyArray_UCHAR) || \\\n\t\t\t (type == PyArray_UNICODE))\n\n#define PyTypeNum_ISCOMPLEX(type) ((type >= PyArray_CFLOAT) && \\\n\t\t\t\t(type <= PyArray_CLONGDOUBLE))\n\n#define PyTypeNum_ISPYTHON(type) ((type == PyArray_LONG) || \\\n\t\t\t\t (type == PyArray_DOUBLE) ||\t\\\n\t\t\t\t (type == PyArray_CDOUBLE) ||\t\\\n\t\t (type == PyArray_BOOL) || \\\n\t\t\t\t (type == PyArray_OBJECT ))\n\n#define PyTypeNum_ISFLEXIBLE(type) ((type>=PyArray_STRING) && \\\n\t\t\t\t (type<=PyArray_VOID))\n\n#define PyTypeNum_ISUSERDEF(type) ((type >= PyArray_USERDEF) && \\\n\t\t\t\t (type < PyArray_USERDEF+\\\n\t\t\t\t PyArray_NUMUSERTYPES))\n\n#define PyTypeNum_ISEXTENDED(type) (PyTypeNum_ISFLEXIBLE(type) || \\\n PyTypeNum_ISUSERDEF(type))\n\n#define PyTypeNum_ISOBJECT(type) ((type) == PyArray_OBJECT)\n\n#define _PyADt(o) ((PyArray_Descr *)o)->type_num\n#define PyDescr_ISBOOL(obj) PyTypeNum_ISBOOL(_PyADt(obj))\n#define PyDescr_ISUNSIGNED(obj) PyTypeNum_ISUNSIGNED(_PyADt(obj))\n#define PyDescr_ISSIGNED(obj) PyTypeNum_ISSIGNED(_PyADt(obj))\n#define PyDescr_ISINTEGER(obj) PyTypeNum_ISINTEGER(_PyADt(obj))\n#define PyDescr_ISFLOAT(obj) PyTypeNum_ISFLOAT(_PyADt(obj))\n#define PyDescr_ISNUMBER(obj) PyTypeNum_ISNUMBER(_PyADt(obj))\n#define PyDescr_ISSTRING(obj) PyTypeNum_ISSTRING(_PyADt(obj))\n#define PyDescr_ISCOMPLEX(obj) PyTypeNum_ISCOMPLEX(_PyADt(obj))\n#define PyDescr_ISPYTHON(obj) PyTypeNum_ISPYTHON(_PyADt(obj))\n#define PyDescr_ISFLEXIBLE(obj) PyTypeNum_ISFLEXIBLE(_PyADt(obj))\n#define PyDescr_ISUSERDEF(obj) PyTypeNum_ISUSERDEF(_PyADt(obj))\n#define PyDescr_ISEXTENDED(obj) PyTypeNum_ISEXTENDED(_PyADt(obj))\n#define PyDescr_ISOBJECT(obj) PyTypeNum_ISOBJECT(_PyADt(obj))\n#undef _PyAD\n\n#define PyArray_ISBOOL(obj) PyTypeNum_ISBOOL(PyArray_TYPE(obj))\n#define PyArray_ISUNSIGNED(obj) PyTypeNum_ISUNSIGNED(PyArray_TYPE(obj))\n#define PyArray_ISSIGNED(obj) PyTypeNum_ISSIGNED(PyArray_TYPE(obj))\n#define PyArray_ISINTEGER(obj) PyTypeNum_ISINTEGER(PyArray_TYPE(obj))\n#define PyArray_ISFLOAT(obj) PyTypeNum_ISFLOAT(PyArray_TYPE(obj))\n#define PyArray_ISNUMBER(obj) PyTypeNum_ISNUMBER(PyArray_TYPE(obj))\n#define PyArray_ISSTRING(obj) PyTypeNum_ISSTRING(PyArray_TYPE(obj))\n#define PyArray_ISCOMPLEX(obj) PyTypeNum_ISCOMPLEX(PyArray_TYPE(obj))\n#define PyArray_ISPYTHON(obj) PyTypeNum_ISPYTHON(PyArray_TYPE(obj))\n#define PyArray_ISFLEXIBLE(obj) PyTypeNum_ISFLEXIBLE(PyArray_TYPE(obj))\n#define PyArray_ISUSERDEF(obj) PyTypeNum_ISUSERDEF(PyArray_TYPE(obj))\n#define PyArray_ISEXTENDED(obj) PyTypeNum_ISEXTENDED(PyArray_TYPE(obj))\n#define PyArray_ISOBJECT(obj) PyTypeNum_ISOBJECT(PyArray_TYPE(obj))\n\n#define PyArray_LITTLE '<'\n#define PyArray_BIG '>'\n#define PyArray_NATIVE '='\n#define PyArray_SWAP 's'\n#define PyArray_IGNORE '|'\n\n#ifdef WORDS_BIGENDIAN\n#define PyArray_NATBYTE PyArray_BIG\n#define PyArray_OPPBYTE PyArray_LITTLE\n#else\n#define PyArray_NATBYTE PyArray_LITTLE\n#define PyArray_OPPBYTE PyArray_BIG\n#endif\n\n#define PyArray_ISNBO(arg) ((arg) != PyArray_OPPBYTE)\n#define PyArray_IsNativeByteOrder PyArray_ISNBO\n#define PyArray_ISNOTSWAPPED(m) PyArray_ISNBO(PyArray_DESCR(m)->byteorder)\n\n#define PyArray_FLAGSWAP(m, flags) (PyArray_CHKFLAGS(m, flags) &&\t\\\n\t\t\t\t PyArray_ISNOTSWAPPED(m))\n#define PyArray_ISCARRAY(m) PyArray_FLAGSWAP(m, CARRAY_FLAGS)\n#define PyArray_ISCARRAY_RO(m) PyArray_FLAGSWAP(m, CARRAY_FLAGS_RO)\n#define PyArray_ISFARRAY(m) PyArray_FLAGSWAP(m, FARRAY_FLAGS)\n#define PyArray_ISFARRAY_RO(m) PyArray_FLAGSWAP(m, FARRAY_FLAGS_RO)\n#define PyArray_ISBEHAVED(m) PyArray_FLAGSWAP(m, BEHAVED_FLAGS)\n#define PyArray_ISBEHAVED_RO(m) PyArray_FLAGSWAP(m, ALIGNED)\n\n\n\n/* This is the form of the struct that's returned pointed by the\n PyCObject attribute of an array __array_struct__. See\n http://numeric.scipy.org/array_interface.html for the full\n documentation. */\ntypedef struct {\n int version; /* contains the integer 2 as a sanity check */\n int nd; /* number of dimensions */\n char typekind; /* kind in array --- character code of typestr */\n int itemsize; /* size of each element */\n int flags; /* how should be data interpreted. Valid\n flags are CONTIGUOUS (1), FORTRAN (2),\n ALIGNED (0x100), NOTSWAPPED (0x200), and\n WRITEABLE (0x400)*/\n intp *shape; /* A length-nd array of shape information */\n intp *strides; /* A length-nd array of stride information */\n void *data; /* A pointer to the first element of the array */\n} PyArrayInterface;\n\n/* Includes the \"function\" C-API -- these are all stored in a\n list of pointers --- one for each file\n The two lists are concatenated into one in multiarray.\n\n They are available as import_array()\n*/\n\n\n#include \"__multiarray_api.h\"\n\n\n/* C-API that requries previous API to be defined */\n\n#define PyArray_DescrCheck(op) ((op)->ob_type == &PyArrayDescr_Type)\n\n#define PyArray_Check(op) ((op)->ob_type == &PyArray_Type || \\\n\t\t\t PyObject_TypeCheck((op), &PyBigArray_Type))\n#define PyBigArray_CheckExact(op) ((op)->ob_type == &PyBigArray_Type)\n#define PyArray_CheckExact(op) ((op)->ob_type == &PyArray_Type)\n\n#define PyArray_IsZeroDim(op) (PyArray_Check(op) && (PyArray_NDIM(op) == 0))\n#define PyArray_IsScalar(obj, cls)\t\t\t\t\\\n\t(PyObject_TypeCheck((obj), &Py##cls##ArrType_Type))\n#define PyArray_CheckScalar(m) (PyArray_IsScalar(m, Generic) || \\\n PyArray_IsZeroDim(m))\n#define PyArray_IsPythonScalar(obj) \\\n\t(PyInt_Check(obj) || PyFloat_Check(obj) || PyComplex_Check(obj) || \\\n\t PyLong_Check(obj) || PyBool_Check(obj) || PyString_Check(obj) || \\\n\t PyUnicode_Check(obj))\n#define PyArray_IsAnyScalar(obj)\t\t\t\t\t\\\n\t(PyArray_IsScalar(obj, Generic) || PyArray_IsPythonScalar(obj))\n#define PyArray_CheckAnyScalar(obj) (PyArray_IsPythonScalar(obj) || \\\n\t\t\t\t PyArray_CheckScalar(obj))\n\n#define PyArray_GETCONTIGUOUS(m) (PyArray_ISCONTIGUOUS(m) ? Py_INCREF(m), m : \\\n (PyArrayObject *)(PyArray_Copy(m)))\n\n#define PyArray_SIZE(m) PyArray_MultiplyList(PyArray_DIMS(m), PyArray_NDIM(m))\n#define PyArray_NBYTES(m) (PyArray_ITEMSIZE(m) * PyArray_SIZE(m))\n#define PyArray_FROM_O(m) PyArray_FromAny(m, NULL, 0, 0, 0, NULL)\n#define PyArray_FROM_OF(m,flags) PyArray_CheckFromAny(m, NULL, 0, 0, flags, NULL)\n#define PyArray_FROM_OT(m,type) PyArray_FromAny(m, PyArray_DescrFromType(type), \\\n 0, 0, 0, NULL);\n#define PyArray_FROM_OTF(m, type, flags) \\\n\tPyArray_FromAny(m, PyArray_DescrFromType(type), 0, 0, \\\n (((flags) & ENSURECOPY) ? \\\n ((flags) | DEFAULT_FLAGS) : (flags)), NULL)\n#define PyArray_FROMANY(m, type, min, max, flags) \\\n\tPyArray_FromAny(m, PyArray_DescrFromType(type), min, max, \\\n (((flags) & ENSURECOPY) ? \\\n (flags) | DEFAULT_FLAGS : (flags)), NULL)\n\n#define PyArray_FILLWBYTE(obj, val) memset(PyArray_DATA(obj), (val), PyArray_NBYTES(obj))\n\n#define REFCOUNT(obj) (((PyObject *)(obj))->ob_refcnt)\n#define MAX_ELSIZE 2*SIZEOF_LONGDOUBLE\n\n#define PyArray_ContiguousFromAny(op, type, min_depth, max_depth) \\\n PyArray_FromAny(op, PyArray_DescrFromType(type), min_depth, \\\n max_depth, DEFAULT_FLAGS, NULL)\n\n#define PyArray_EquivArrTypes(a1, a2)\t\t\t\t\t\\\n\tPyArray_EquivTypes(PyArray_DESCR(a1), PyArray_DESCR(a2))\n#define PyArray_EquivTypenums(typenum1, typenum2)\t\t\\\n\tPyArray_EquivTypes(PyArray_DescrFromType(typenum1),\t\\\n\t\t\t PyArray_DescrFromType(typenum2))\n\n#define PyArray_EquivByteorders(b1, b2) \\\n\t((b1 == b2) || (PyArray_ISNBO(b1) == PyArray_ISNBO(b2)))\n\n#define PyArray_SimpleNew(nd, dims, typenum) \\\n\tPyArray_New(&PyArray_Type, nd, dims, typenum, NULL, NULL, 0, 0, NULL)\n#define PyArray_SimpleNewFromData(nd, dims, typenum, data) \\\n PyArray_New(&PyArray_Type, nd, dims, typenum, NULL, data, 0, CARRAY_FLAGS, NULL)\n#define PyArray_SimpleNewFromDescr(nd, dims, descr) \\\n\tPyArray_NewFromDescr(&PyArray_Type, descr, nd, dims, NULL, NULL, 0, NULL)\n\n\n/* These might be faster without the dereferencing of obj\n going on inside -- of course an optimizing compiler should\n inline the constants inside a for loop making it a moot point\n*/\n\n#define PyArray_GETPTR1(obj, i) (PyArray_DATA(obj) +\t\t\\\n\t\t\t\t i*PyArray_STRIDE(obj, 0))\n\n#define PyArray_GETPTR2(obj, i, j) (PyArray_DATA(obj) +\t\t\\\n\t\t\t\t i*PyArray_STRIDE(obj, 0) +\t\\\n\t\t\t\t j*PyArray_STRIDE(obj, 1))\n\n#define PyArray_GETPTR3(obj, i, j, k) (PyArray_DATA(obj) +\t\t\\\n\t\t\t\t i*PyArray_STRIDE(obj, 0) +\t\\\n\t\t\t\t j*PyArray_STRIDE(obj, 1) +\t\\\n\t\t\t\t k*PyArray_STRIDE(obj, 2))\t\\\n\n#define PyArray_GETPTR4(obj, i, j, k, l) (PyArray_DATA(obj) +\t\t\\\n\t\t\t\t\t i*PyArray_STRIDE(obj, 0) +\t\\\n\t\t\t\t\t j*PyArray_STRIDE(obj, 1) +\t\\\n\t\t\t\t\t k*PyArray_STRIDE(obj, 2) +\t\\\n\t\t\t\t\t l*PyArray_STRIDE(obj, 3))\n\n#define PyArray_DESCR_REPLACE(descr) do {\t\\\n\t\tPyArray_Descr *_new_;\t\t\t\\\n\t\t_new_ = PyArray_DescrNew(descr);\t\\\n\t\tPy_XDECREF(descr);\t\t\t\\\n\t\tdescr = _new_;\t\t\t\t\\\n\t} while(0)\n\n/* Copy should always return contiguous array */\n#define PyArray_Copy(obj) PyArray_NewCopy(obj, 0)\n\n#define PyArray_FromObject(op, type, min_depth, max_depth)\t\t\\\n\tPyArray_FromAny(op, PyArray_DescrFromType(type), min_depth,\t\\\n max_depth, BEHAVED_FLAGS | ENSUREARRAY, NULL)\n\n#define PyArray_ContiguousFromObject(op, type, min_depth, max_depth)\t\\\n PyArray_FromAny(op, PyArray_DescrFromType(type), min_depth,\t\\\n max_depth, DEFAULT_FLAGS | ENSUREARRAY, NULL)\n\n#define PyArray_CopyFromObject(op, type, min_depth, max_depth)\t\t\\\n PyArray_FromAny(op, PyArray_DescrFromType(type), min_depth, \\\n max_depth, ENSURECOPY | DEFAULT_FLAGS | ENSUREARRAY, NULL)\n\n#define PyArray_Cast(mp, type_num) \\\n\tPyArray_CastToType(mp, PyArray_DescrFromType(type_num), 0)\n\n/* Compatibility with old Numeric stuff -- don't use in new code */\n\n#define PyArray_FromDimsAndData(nd, d, type, data) \\\n\tPyArray_FromDimsAndDataAndDescr(nd, d, PyArray_DescrFromType(type), \\\n\t\t\t\t\tdata)\n\n#define PyArray_UNSIGNED_TYPES\n#define PyArray_SBYTE PyArray_BYTE\n#define PyArray_CHAR PyArray_BYTE\n#define PyArray_CopyArray PyArray_CopyInto\n#define _PyArray_multiply_list PyArray_MultiplyIntList\n#define PyArray_ISSPACESAVER(m) FALSE\n#define PyScalarArray_Check PyArray_CheckScalar\n\n#ifdef PY_ARRAY_TYPES_PREFIX\n# undef CAT\n# undef CAT2\n# undef NS\n# undef longlong\n# undef ulonglong\n# undef Bool\n# undef longdouble\n# undef byte\n# undef ubyte\n# undef ushort\n# undef uint\n# undef ulong\n# undef cfloat\n# undef cdouble\n# undef clongdouble\n# undef Int8\n# undef UInt8\n# undef Int16\n# undef UInt16\n# undef Int32\n# undef UInt32\n# undef Int64\n# undef UInt64\n# undef Int128\n# undef UInt128\n# undef Int256\n# undef UInt256\n# undef Float16\n# undef Complex32\n# undef Float32\n# undef Complex64\n# undef Float64\n# undef Complex128\n# undef Float80\n# undef Complex160\n# undef Float96\n# undef Complex192\n# undef Float128\n# undef Complex256\n# undef intp\n# undef uintp\n#endif\n\n#ifdef __cplusplus\n}\n#endif\n\n#endif /* !Py_ARRAYOBJECT_H */\n", + "methods": [], + "methods_before": [], + "changed_methods": [], + "nloc": 289, + "complexity": 0, + "token_count": 1354, + "diff_parsed": { + "added": [ + "#define PyArray_GETPTR1(obj, i) (void *)(PyArray_BYTES(obj) +\t\t\\", + "#define PyArray_GETPTR2(obj, i, j) (void *)(PyArray_BYTES(obj) +\t\t\\", + "#define PyArray_GETPTR3(obj, i, j, k) (void *)(PyArray_BYTES(obj) +\t\t\\", + "#define PyArray_GETPTR4(obj, i, j, k, l) (void *)(PyArray_BYTES(obj) +\t\t\\" + ], + "deleted": [ + "#define PyArray_GETPTR1(obj, i) (PyArray_DATA(obj) +\t\t\\", + "#define PyArray_GETPTR2(obj, i, j) (PyArray_DATA(obj) +\t\t\\", + "#define PyArray_GETPTR3(obj, i, j, k) (PyArray_DATA(obj) +\t\t\\", + "#define PyArray_GETPTR4(obj, i, j, k, l) (PyArray_DATA(obj) +\t\t\\" + ] + } + }, + { + "old_path": "numpy/core/src/multiarraymodule.c", + "new_path": "numpy/core/src/multiarraymodule.c", + "filename": "multiarraymodule.c", + "extension": "c", + "change_type": "MODIFY", + "diff": "@@ -93,7 +93,7 @@ PyArray_MultiplyList(register intp *l1, register int n)\n /*MULTIARRAY_API\n Produce a pointer into array\n */\n-static char *\n+static void *\n PyArray_GetPtr(PyArrayObject *obj, register intp* ind)\n {\n \tregister int n = obj->nd;\n@@ -101,7 +101,7 @@ PyArray_GetPtr(PyArrayObject *obj, register intp* ind)\n \tregister char *dptr = obj->data;\n \t\n \twhile (n--) dptr += (*strides++) * (*ind++);\n-\treturn dptr;\n+\treturn (void *)dptr;\n }\n \n /*MULTIARRAY_API\n", + "added_lines": 2, + "deleted_lines": 2, + "source_code": "\n/*\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 extensively for numpy 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, \"dtype\");\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 void *\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 (void *)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, \"dtype\",\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)) == 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\tif (mps[i]->ob_type != subtype) {\n\t\t\tprior2 = PyArray_GetPriority((PyObject *)(mps[i]), 0.0);\n\t\t\tif (prior2 > prior1) {\n\t\t\t\tprior1 = prior2;\n\t\t\t\tsubtype = mps[i]->ob_type;\n\t\t\t\tret = mps[i];\n\t\t\t}\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; idescr->elsize;\n\tbyteorder = arr->descr->byteorder;\n\tptr = arr->data;\n\tif (elsize > 1 && \\\n\t (byteorder == PyArray_LITTLE ||\t\\\n\t (byteorder == PyArray_NATIVE &&\n\t PyArray_ISNBO(PyArray_LITTLE))))\n\t\tptr += elsize-1;\n\t\n\treturn ((*ptr & bitmask) != 0);\t\n}\n\n\n/*OBJECT_API*/\nstatic char\nPyArray_ScalarKind(int typenum, PyArrayObject **arr) \n{\n\tif (PyTypeNum_ISSIGNED(typenum)) {\n\t\tif (arr && _signbit_set(*arr)) return UFUNC_INTNEG_SCALAR;\n\t\telse return UFUNC_INTPOS_SCALAR;\n\t}\n\tif (PyTypeNum_ISFLOAT(typenum)) return UFUNC_FLOAT_SCALAR;\n\tif (PyTypeNum_ISUNSIGNED(typenum)) return UFUNC_INTPOS_SCALAR;\n\tif (PyTypeNum_ISCOMPLEX(typenum)) return UFUNC_COMPLEX_SCALAR;\n\tif (PyTypeNum_ISBOOL(typenum)) return UFUNC_BOOL_SCALAR;\n\n\treturn UFUNC_OBJECT_SCALAR;\n}\n\n\n/*OBJECT_API*/\nstatic int \nPyArray_CanCoerceScalar(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\n/* This needs to change to allow scalars of a different \"kind\" to alter the input type\n */\n\n/*OBJECT_API*/\nstatic PyArrayObject **\nPyArray_ConvertToCommonType(PyObject *op, int *retn)\n{\n\tint i, n, allscalars=0; \n\tPyArrayObject **mps=NULL;\n\tPyObject *otmp;\n\tPyArray_Descr *intype=NULL, *stype=NULL;\n\tPyArray_Descr *newtype=NULL;\n\tchar scalarkind;\n\n\t\n\t*retn = n = PySequence_Length(op);\n\tif (PyErr_Occurred()) {*retn = 0; return NULL;}\n\t\n\tmps = (PyArrayObject **)PyDataMem_NEW(n*sizeof(PyArrayObject *));\n\tif (mps == NULL) {\n\t\t*retn = 0;\n\t\treturn (void*)PyErr_NoMemory();\n\t}\n\t\n\tfor(i=0; itype_num, NULL);\n\t\t\tif (intype && !PyArray_CanCoerceScalar(newtype->type_num,\n\t\t\t\t\t\t\t intype->type_num, \n\t\t\t\t\t\t\t scalarkind)) {\n\t\t\t\tPy_XDECREF(intype);\n\t\t\t\tintype = stype;\n\t\t\t}\n\t\t\tmps[i] = (PyArrayObject *)Py_None;\n\t\t\tPy_INCREF(Py_None);\n\t\t}\n\t\tPy_XDECREF(otmp);\n\t}\n\tif (intype==NULL) { /* all scalars */\n\t\tallscalars = 1;\n\t\tintype = stype;\n\t\tPy_INCREF(intype);\n\t\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, NULL);\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 Make a new empty array, of the passed size, of a type that takes the\n priority of ap1 and ap2 into account.\n */\nstatic PyArrayObject *\nnew_array_for_sum(PyArrayObject *ap1, PyArrayObject *ap2,\n\t\t int nd, intp dimensions[], int typenum)\n{\n\tPyArrayObject *ret;\n\tPyTypeObject *subtype;\n\tdouble prior1, prior2;\n\t/* Need to choose an output array that can hold a sum \n\t -- use priority to determine which subtype.\n\t */\n\tif (ap2->ob_type != ap1->ob_type) {\n\t\tprior2 = PyArray_GetPriority((PyObject *)ap2, 0.0);\n\t\tprior1 = PyArray_GetPriority((PyObject *)ap1, 0.0);\n\n\t\tsubtype = (prior2 > prior1 ? ap2->ob_type : ap1->ob_type);\n\t} else {\n\t\tprior1 = prior2 = 0.0;\n\t\tsubtype = ap1->ob_type;\n\t}\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\treturn ret;\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\tPyArrayIterObject *it1, *it2;\n\tintp i, j, l;\n\tint typenum, nd;\n\tintp is1, is2, os;\n\tchar *op;\n\tintp dimensions[MAX_DIMS];\n\tPyArray_DotFunc *dot;\n\tPyArray_Descr *typec;\n\t\n\ttypenum = PyArray_ObjectType(op1, 0); \n\ttypenum = PyArray_ObjectType(op2, typenum);\n\n\ttypec = PyArray_DescrFromType(typenum);\n\tPy_INCREF(typec);\n\tap1 = (PyArrayObject *)PyArray_FromAny(op1, typec, 0, 0, \n\t\t\t\t\t BEHAVED_FLAGS, NULL);\n\tif (ap1 == NULL) {Py_DECREF(typec); return NULL;}\n\tap2 = (PyArrayObject *)PyArray_FromAny(op2, typec, 0, 0,\n\t\t\t\t\t BEHAVED_FLAGS, NULL);\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\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\tret = new_array_for_sum(ap1, ap2, nd, dimensions, typenum);\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\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\tit1 = (PyArrayIterObject *)\\\n\t\tPyArray_IterAllButAxis((PyObject *)ap1, ap1->nd-1);\n\tit2 = (PyArrayIterObject *)\\\n\t\tPyArray_IterAllButAxis((PyObject *)ap2, ap2->nd-1);\n\n\twhile(1) {\n\t\twhile(it2->index < it2->size) {\n\t\t\tdot(it1->dataptr, is1, it2->dataptr, is2, op, l, ret);\n\t\t\top += os;\n\t\t\tPyArray_ITER_NEXT(it2);\n\t\t}\n\t\tPyArray_ITER_NEXT(it1);\n\t\tif (it1->index >= it1->size) break;\n\t\tPyArray_ITER_RESET(it2);\n\t}\n\tPy_DECREF(it1);\n\tPy_DECREF(it2);\n\n\tif (PyErr_Occurred()) goto fail;\n\t\t\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/* just like inner product but does the swapaxes stuff on the fly */\n/*MULTIARRAY_API\n Numeric.matrixproduct(a,v)\n*/\nstatic PyObject *\nPyArray_MatrixProduct(PyObject *op1, PyObject *op2) \n{\n\tPyArrayObject *ap1, *ap2, *ret=NULL;\n\tPyArrayIterObject *it1, *it2;\n\tintp i, j, l;\n\tint typenum, nd;\n\tintp is1, is2, os;\n\tchar *op;\n\tintp dimensions[MAX_DIMS];\n\tPyArray_DotFunc *dot;\n\tintp matchDim;\n\tPyArray_Descr *typec;\n\n\ttypenum = PyArray_ObjectType(op1, 0); \n\ttypenum = PyArray_ObjectType(op2, typenum);\t\n\t\n\ttypec = PyArray_DescrFromType(typenum);\n\tPy_INCREF(typec);\n\tap1 = (PyArrayObject *)PyArray_FromAny(op1, typec, 0, 0, \n\t\t\t\t\t BEHAVED_FLAGS, NULL);\n\tif (ap1 == NULL) {Py_DECREF(typec); return NULL;}\n\tap2 = (PyArrayObject *)PyArray_FromAny(op2, typec, 0, 0,\n\t\t\t\t\t BEHAVED_FLAGS, NULL);\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\tif (ap2->nd > 1) {\n\t\tmatchDim = ap2->nd - 2;\n\t}\n\telse {\n\t\tmatchDim = 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\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; istrides[ap1->nd-1]; is2 = ap2->strides[matchDim];\n\n /* Choose which subtype to return */\n\tret = new_array_for_sum(ap1, ap2, nd, dimensions, typenum);\n\tif (ret == NULL) goto fail;\n\n\t/* Ensure that multiarray.dot([],[]) -> 0 */\n\tmemset(PyArray_DATA(ret), 0, PyArray_ITEMSIZE(ret));\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\top = ret->data; os = ret->descr->elsize;\n\n\tit1 = (PyArrayIterObject *)\\\n\t\tPyArray_IterAllButAxis((PyObject *)ap1, ap1->nd-1);\n\tit2 = (PyArrayIterObject *)\\\n\t\tPyArray_IterAllButAxis((PyObject *)ap2, matchDim);\n\n\twhile(1) {\n\t\twhile(it2->index < it2->size) {\n\t\t\tdot(it1->dataptr, is1, it2->dataptr, is2, op, l, ret);\n\t\t\top += os;\n\t\t\tPyArray_ITER_NEXT(it2);\n\t\t}\n\t\tPyArray_ITER_NEXT(it1);\n\t\tif (it1->index >= it1->size) break;\n\t\tPyArray_ITER_RESET(it2);\n\t}\n\tPy_DECREF(it1);\n\tPy_DECREF(it2);\n\tif (PyErr_Occurred()) goto fail; /* only for OBJECT arrays */\n\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/*MULTIARRAY_API\n Fast Copy and Transpose\n*/\nstatic PyObject *\nPyArray_CopyAndTranspose(PyObject *op) \n{\n\tPyObject *ret, *arr;\n\tint nd;\n\tintp dims[2];\n\tintp i,j;\n\tint elsize, str2;\n\tchar *iptr;\n\tchar *optr;\n\n\t/* make sure it is well-behaved */\n\tarr = PyArray_FromAny(op, NULL, 0, 0, CARRAY_FLAGS, NULL);\n\tnd = PyArray_NDIM(arr);\n\tif (nd == 1) { /* we will give in to old behavior */\n\t\tret = PyArray_Copy((PyArrayObject *)arr);\n\t\tPy_DECREF(arr);\n\t\treturn ret;\t\t\n\t}\n\telse if (nd != 2) {\n\t\tPy_DECREF(arr);\n\t\tPyErr_SetString(PyExc_ValueError, \n\t\t\t\t\"only 2-d arrays are allowed\");\n\t\treturn NULL;\n\t}\n\n\t/* Now construct output array */\n\tdims[0] = PyArray_DIM(arr,1);\n\tdims[1] = PyArray_DIM(arr,0);\n\telsize = PyArray_ITEMSIZE(arr);\n\t\n\tPy_INCREF(PyArray_DESCR(arr));\n\tret = PyArray_NewFromDescr(arr->ob_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\tret = new_array_for_sum(ap1, ap2, 1, &length, typenum);\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 Py_INCREF(self->descr); \n\tvalues = (PyArrayObject *)PyArray_FromAny(values0, self->descr, 0, 0, \n\t\t\t\t\t\t DEFAULT_FLAGS | FORCECAST, NULL); \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, NULL);\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\tif (type->type_num == PyArray_UNICODE)\n\t\t\ttype->elsize = itemsize << 2; \n\t\telse\n\t\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\tif (type->hasobject) newdescr->hasobject = 1;\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 int hasobject=0;\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; ihasobject)\n hasobject = 1;\n\t\ttup = PyTuple_New(2);\n\t\tPyTuple_SET_ITEM(tup, 0, (PyObject *)conv);\n\t\tPyTuple_SET_ITEM(tup, 1, PyInt_FromLong((long) totalsize));\n\t\ttotalsize += conv->elsize;\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 new->hasobject=hasobject;\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 int hasobject=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; ihasobject)\n\t\t\thasobject=1;\t\t\t\n\t\tPyTuple_SET_ITEM(tup, 0, (PyObject *)conv);\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\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\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 new->hasobject=hasobject;\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 int hasobject=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\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\tPyTuple_SET_ITEM(tup, 1, PyInt_FromLong(totalsize));\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\tif (PyDict_GetItem(fields, name) != NULL) {\n\t\t\tPyErr_SetString(PyExc_ValueError,\n\t\t\t\t\t\"name already used as a name or title\");\n\t\t\tret = PY_FAIL;\n\t\t}\n\t\tPyDict_SetItem(fields, name, tup);\n\t\tPy_DECREF(name);\n\t\tif (len == 3) {\n\t\t\tif (PyDict_GetItem(fields, item) != NULL) {\n\t\t\t\tPyErr_SetString(PyExc_ValueError, \n\t\t\t\t\t\t\"title already used as a name or \" \\\n\t\t\t\t\t\t\" title.\");\n\t\t\t\tret=PY_FAIL;\n\t\t\t}\n\t\t\telse {\n\t\t\t\tPyDict_SetItem(fields, item, tup);\n\t\t\t}\n\t\t}\n\t\tPy_DECREF(tup);\n\t\tif ((ret == PY_FAIL) || (newdescr->elsize == 0)) goto fail;\n if (!hasobject && newdescr->hasobject)\n hasobject = 1;\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 new->hasobject=hasobject;\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 == '|' || (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\tint i;\n\t\t\telsize = atoi(type+1);\n\t\t\t/* check for commas present */\n\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\nstatic PyObject *\n_prepend_ones(PyArrayObject *arr, int nd, int ndmin)\n{\n\tintp newdims[MAX_DIMS];\n\tintp newstrides[MAX_DIMS];\n\tint i,k,num;\n\tPyObject *ret;\n\n\tnum = ndmin-nd;\n\tfor (i=0; idescr->elsize;\n\t}\n\tfor (i=num;idimensions[k];\n\t\tnewstrides[i] = arr->strides[k];\n\t}\n\tPy_INCREF(arr->descr);\n\tret = PyArray_NewFromDescr(arr->ob_type, arr->descr, ndmin,\n\t\t\t\t newdims, newstrides, arr->data, arr->flags,\n\t\t\t\t (PyObject *)arr);\n\t/* steals a reference to arr --- so don't increment\n\t here */\n\tPyArray_BASE(ret) = (PyObject *)arr;\n\treturn ret;\n}\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,ndmin=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\"\\\n\t\"The ndmin argument specifies how many dimensions the returned\\n\"\\\n\t\"array should have as a minimum. 1's will be pre-pended to the\\n\"\\\n\t\"shape as needed to meet this requirement.\";\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\t\t\t \"ndmin\", NULL};\n Bool subok=FALSE;\n\tBool copy=TRUE;\n\tint ndmin=0, nd;\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&i\", 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\t\t\t\t&ndmin)) \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\tret = op;\n\t\t\t\tgoto finish;\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\tgoto finish;\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\tret = op;\n\t\t\t\tgoto finish;\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\tgoto finish;\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_CheckFromAny(op, type, 0, 0, flags, NULL)) == NULL) \n\t\treturn NULL;\n\n finish:\n\n\tif ((nd=PyArray_NDIM(ret)) >= ndmin) return ret;\n\t/* create a new array from the same data with ones in the shape */\n\t/* steals a reference to ret */\n\treturn _prepend_ones((PyArrayObject *)ret, nd, ndmin);\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(dtype,obj) will return a new scalar array of the given type initialized with obj. Mainly for pickle support. The dtype must be a valid data-type descriptor. If dtype 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[] = {\"dtype\",\"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}; /* XXX ? */\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\nstatic int\n_skip_sep(char **ptr, char *sep)\n{\n\tchar *a;\n\tint n;\n\tn = strlen(sep);\n\ta = *ptr;\n\twhile(*a != '\\0' && (strncmp(a, sep, n) != 0))\n\t\ta++;\n\tif (*a == '\\0') return -1;\n\t*ptr = a+strlen(sep);\n\treturn 0;\n}\n\n/* steals a reference to dtype -- accepts NULL */\n/*OBJECT_API*/\nstatic PyObject *\nPyArray_FromString(char *data, intp slen, PyArray_Descr *dtype, \n\t\t intp n, char *sep)\n{\n\tint itemsize;\n\tPyArrayObject *ret;\n\tBool binary;\n\n\tif (dtype == NULL)\n\t\tdtype=PyArray_DescrFromType(PyArray_LONG);\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\n\tbinary = ((sep == NULL) || (strlen(sep) == 0));\t\n\n\tif (binary) {\n\t\tif (dtype == &OBJECT_Descr) {\n\t\t\tPyErr_SetString(PyExc_ValueError, \n\t\t\t\t\t\"Cannot create an object array from\"\\\n\t\t\t\t\t\" a binary string\");\n\t\t\tPy_DECREF(dtype);\n\t\t\treturn NULL;\n\t\t}\t\t\n\t\tif (n < 0 ) {\n\t\t\tif (slen % itemsize != 0) {\n\t\t\t\tPyErr_SetString(PyExc_ValueError, \n\t\t\t\t\t\t\"string size must be a \"\\\n\t\t\t\t\t\t\"multiple of element size\");\n\t\t\t\tPy_DECREF(dtype);\n\t\t\t\treturn NULL;\n\t\t\t}\n\t\t\tn = slen/itemsize;\n\t\t} else {\n\t\t\tif (slen < n*itemsize) {\n\t\t\t\tPyErr_SetString(PyExc_ValueError, \n\t\t\t\t\t\t\"string is smaller than \" \\\n\t\t\t\t\t\t\"requested size\");\n\t\t\t\tPy_DECREF(dtype);\n\t\t\t\treturn NULL;\n\t\t\t}\n\t\t}\n\t\n\t\tif ((ret = (PyArrayObject *)\\\n\t\t PyArray_NewFromDescr(&PyArray_Type, dtype,\n\t\t\t\t\t 1, &n, NULL, NULL,\n\t\t\t\t\t 0, NULL)) == NULL)\n\t\t\treturn NULL;\t\t\n\t\tmemcpy(ret->data, data, n*dtype->elsize);\n\t\treturn (PyObject *)ret;\n\t}\n\telse { /* read from character-based string */\n\t\tchar *ptr;\t\t\n\t\tPyArray_FromStrFunc *fromstr;\n\t\tchar *dptr;\n\t\tintp nread=0;\n\t\tintp index;\n\n\t\tfromstr = dtype->f->fromstr;\n\t\tif (fromstr == 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 strings for given \"\t\\\n\t\t\t\t\t\"array type\");\n\t\t\tPy_DECREF(dtype);\n\t\t\treturn NULL;\n\t\t}\n\n\t\tif (n!=-1) {\n\t\t\tret = (PyArrayObject *) \\\n\t\t\t\tPyArray_NewFromDescr(&PyArray_Type,\n\t\t\t\t\t\t dtype, 1, &n, NULL,\n\t\t\t\t\t\t NULL, 0, NULL);\n\t\t\tif (ret == NULL) return NULL;\n\t\t\tptr = data;\n\t\t\tdptr = ret->data;\n\t\t\tfor (index=0; index < n; index++) {\n\t\t\t\tif (fromstr(ptr, dptr, &ptr, ret) < 0)\n\t\t\t\t\tbreak;\n\t\t\t\tnread += 1;\n\t\t\t\tdptr += dtype->elsize;\n\t\t\t\tif (_skip_sep(&ptr, sep) < 0) \n\t\t\t\t\tbreak;\n\t\t\t}\n\t\t\tif (nread < n) {\n\t\t\t\tfprintf(stderr, \"%ld items requested but \"\\\n\t\t\t\t\t\"only %ld read\\n\", \n\t\t\t\t\t(long) n, (long) nread);\n\t\t\t\tret->data = \\\n\t\t\t\t\tPyDataMem_RENEW(ret->data, \n\t\t\t\t\t\t\tnread *\t\t\\\n\t\t\t\t\t\t\tret->descr->elsize);\n\t\t\t\tPyArray_DIM(ret,0) = nread;\n\t\t\t}\n\t\t}\n\t\telse {\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\t\t\tchar *end;\n\t\t\tint val;\n\n\t\t\tret = (PyArrayObject *)\\\n\t\t\t\tPyArray_NewFromDescr(&PyArray_Type, \n\t\t\t\t\t\t dtype,\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 (ret==NULL) return NULL;\n\t\t\ttotalbytes = bytes = size * dtype->elsize;\n\t\t\tdptr = ret->data;\n\t\t\tptr = data;\n\t\t\tend = data+slen;\n\t\t\twhile (ptr < end) {\n\t\t\t\tval = fromstr(ptr, dptr, &ptr, ret);\n\t\t\t\tif (val < 0) break;\n\t\t\t\tnread += 1;\n\t\t\t\tval = _skip_sep(&ptr, sep);\n\t\t\t\tif (val < 0) break;\n\t\t\t\tthisbuf += 1;\n\t\t\t\tdptr += dtype->elsize;\n\t\t\t\tif (thisbuf == size) {\n\t\t\t\t\ttotalbytes += bytes;\n\t\t\t\t\tret->data = PyDataMem_RENEW(ret->data, \n\t\t\t\t\t\t\t\t totalbytes);\n\t\t\t\t\tdptr = ret->data + \\\n\t\t\t\t\t\t(totalbytes - bytes);\n\t\t\t\t\tthisbuf = 0;\n\t\t\t\t}\n\t\t\t}\n\t\t\tret->data = PyDataMem_RENEW(ret->data, \n\t\t\t\t\t\t nread*ret->descr->elsize);\n\t\t\tPyArray_DIM(ret,0) = nread;\n#undef _FILEBUFNUM\n\t\t}\n\t}\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\tchar *sep=NULL;\n\tint s;\n\tstatic char *kwlist[] = {\"string\", \"dtype\", \"count\", \"sep\", NULL};\n\tPyArray_Descr *descr=NULL;\n\n\tif (!PyArg_ParseTupleAndKeywords(args, keywds, \"s#|O&Ls\", 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, &sep)) {\n\t\treturn NULL;\n\t}\n\n\treturn PyArray_FromString(data, (intp)s, descr, (intp)nin, sep);\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\tPy_DECREF(typecode);\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\tPy_DECREF(typecode);\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\tPy_DECREF(typecode);\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 platform-independent method of persistence. But it can be \\n\"\\\n\t\" useful to 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_BYTES(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_BYTES(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[] = \n\"arange([start,] stop[, step,], dtype=None)\\n\\n\"\n\"For integer arguments, just like range() except it returns an array whose type can\\n\"\n\"be specified by the keyword argument dtype.\\n\\n\"\n\"If dtype is not specified, the type of the result is deduced from the type of the\\n\"\n\"arguments.\\n\\n\"\n\"For floating point arguments, the length of the result is ceil((stop - start)/step).\\n\"\n\"This rule may result in the last element of the result be greater than stop.\";\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_DescrConverter2,\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/*MULTIARRAY_API\n GetNDArrayCVersion\n*/\nstatic unsigned int\nPyArray_GetNDArrayCVersion(void)\n{\n\treturn (unsigned int)NDARRAY_VERSION;\n}\n\nstatic char \ndoc__get_ndarray_c_version[] = \"_get_ndarray_c_version() gets the compile time NDARRAY_VERSION number\";\n\nstatic PyObject *\narray__get_ndarray_c_version(PyObject *dummy, PyObject *args, PyObject *kwds) \n{\n\tstatic char *kwlist[] = {NULL};\n\tif(!PyArg_ParseTupleAndKeywords(args, kwds, \"\", kwlist )) return NULL;\n\t\n\treturn PyInt_FromLong( (long) PyArray_GetNDArrayCVersion() );\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, NULL);\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{\"_get_ndarray_c_version\", (PyCFunction)array__get_ndarray_c_version, \n\t METH_VARARGS|METH_KEYWORDS, doc__get_ndarray_c_version},\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, \"dtype\", (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\tif (!PyErr_Occurred()) {\n\t\tPyErr_SetString(PyExc_RuntimeError, \n\t\t\t\t\"cannot load multiarray module.\");\n\t}\n\treturn;\n}\n\n", + "source_code_before": "\n/*\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 extensively for numpy 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, \"dtype\");\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, \"dtype\",\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)) == 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\tif (mps[i]->ob_type != subtype) {\n\t\t\tprior2 = PyArray_GetPriority((PyObject *)(mps[i]), 0.0);\n\t\t\tif (prior2 > prior1) {\n\t\t\t\tprior1 = prior2;\n\t\t\t\tsubtype = mps[i]->ob_type;\n\t\t\t\tret = mps[i];\n\t\t\t}\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; idescr->elsize;\n\tbyteorder = arr->descr->byteorder;\n\tptr = arr->data;\n\tif (elsize > 1 && \\\n\t (byteorder == PyArray_LITTLE ||\t\\\n\t (byteorder == PyArray_NATIVE &&\n\t PyArray_ISNBO(PyArray_LITTLE))))\n\t\tptr += elsize-1;\n\t\n\treturn ((*ptr & bitmask) != 0);\t\n}\n\n\n/*OBJECT_API*/\nstatic char\nPyArray_ScalarKind(int typenum, PyArrayObject **arr) \n{\n\tif (PyTypeNum_ISSIGNED(typenum)) {\n\t\tif (arr && _signbit_set(*arr)) return UFUNC_INTNEG_SCALAR;\n\t\telse return UFUNC_INTPOS_SCALAR;\n\t}\n\tif (PyTypeNum_ISFLOAT(typenum)) return UFUNC_FLOAT_SCALAR;\n\tif (PyTypeNum_ISUNSIGNED(typenum)) return UFUNC_INTPOS_SCALAR;\n\tif (PyTypeNum_ISCOMPLEX(typenum)) return UFUNC_COMPLEX_SCALAR;\n\tif (PyTypeNum_ISBOOL(typenum)) return UFUNC_BOOL_SCALAR;\n\n\treturn UFUNC_OBJECT_SCALAR;\n}\n\n\n/*OBJECT_API*/\nstatic int \nPyArray_CanCoerceScalar(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\n/* This needs to change to allow scalars of a different \"kind\" to alter the input type\n */\n\n/*OBJECT_API*/\nstatic PyArrayObject **\nPyArray_ConvertToCommonType(PyObject *op, int *retn)\n{\n\tint i, n, allscalars=0; \n\tPyArrayObject **mps=NULL;\n\tPyObject *otmp;\n\tPyArray_Descr *intype=NULL, *stype=NULL;\n\tPyArray_Descr *newtype=NULL;\n\tchar scalarkind;\n\n\t\n\t*retn = n = PySequence_Length(op);\n\tif (PyErr_Occurred()) {*retn = 0; return NULL;}\n\t\n\tmps = (PyArrayObject **)PyDataMem_NEW(n*sizeof(PyArrayObject *));\n\tif (mps == NULL) {\n\t\t*retn = 0;\n\t\treturn (void*)PyErr_NoMemory();\n\t}\n\t\n\tfor(i=0; itype_num, NULL);\n\t\t\tif (intype && !PyArray_CanCoerceScalar(newtype->type_num,\n\t\t\t\t\t\t\t intype->type_num, \n\t\t\t\t\t\t\t scalarkind)) {\n\t\t\t\tPy_XDECREF(intype);\n\t\t\t\tintype = stype;\n\t\t\t}\n\t\t\tmps[i] = (PyArrayObject *)Py_None;\n\t\t\tPy_INCREF(Py_None);\n\t\t}\n\t\tPy_XDECREF(otmp);\n\t}\n\tif (intype==NULL) { /* all scalars */\n\t\tallscalars = 1;\n\t\tintype = stype;\n\t\tPy_INCREF(intype);\n\t\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, NULL);\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 Make a new empty array, of the passed size, of a type that takes the\n priority of ap1 and ap2 into account.\n */\nstatic PyArrayObject *\nnew_array_for_sum(PyArrayObject *ap1, PyArrayObject *ap2,\n\t\t int nd, intp dimensions[], int typenum)\n{\n\tPyArrayObject *ret;\n\tPyTypeObject *subtype;\n\tdouble prior1, prior2;\n\t/* Need to choose an output array that can hold a sum \n\t -- use priority to determine which subtype.\n\t */\n\tif (ap2->ob_type != ap1->ob_type) {\n\t\tprior2 = PyArray_GetPriority((PyObject *)ap2, 0.0);\n\t\tprior1 = PyArray_GetPriority((PyObject *)ap1, 0.0);\n\n\t\tsubtype = (prior2 > prior1 ? ap2->ob_type : ap1->ob_type);\n\t} else {\n\t\tprior1 = prior2 = 0.0;\n\t\tsubtype = ap1->ob_type;\n\t}\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\treturn ret;\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\tPyArrayIterObject *it1, *it2;\n\tintp i, j, l;\n\tint typenum, nd;\n\tintp is1, is2, os;\n\tchar *op;\n\tintp dimensions[MAX_DIMS];\n\tPyArray_DotFunc *dot;\n\tPyArray_Descr *typec;\n\t\n\ttypenum = PyArray_ObjectType(op1, 0); \n\ttypenum = PyArray_ObjectType(op2, typenum);\n\n\ttypec = PyArray_DescrFromType(typenum);\n\tPy_INCREF(typec);\n\tap1 = (PyArrayObject *)PyArray_FromAny(op1, typec, 0, 0, \n\t\t\t\t\t BEHAVED_FLAGS, NULL);\n\tif (ap1 == NULL) {Py_DECREF(typec); return NULL;}\n\tap2 = (PyArrayObject *)PyArray_FromAny(op2, typec, 0, 0,\n\t\t\t\t\t BEHAVED_FLAGS, NULL);\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\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\tret = new_array_for_sum(ap1, ap2, nd, dimensions, typenum);\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\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\tit1 = (PyArrayIterObject *)\\\n\t\tPyArray_IterAllButAxis((PyObject *)ap1, ap1->nd-1);\n\tit2 = (PyArrayIterObject *)\\\n\t\tPyArray_IterAllButAxis((PyObject *)ap2, ap2->nd-1);\n\n\twhile(1) {\n\t\twhile(it2->index < it2->size) {\n\t\t\tdot(it1->dataptr, is1, it2->dataptr, is2, op, l, ret);\n\t\t\top += os;\n\t\t\tPyArray_ITER_NEXT(it2);\n\t\t}\n\t\tPyArray_ITER_NEXT(it1);\n\t\tif (it1->index >= it1->size) break;\n\t\tPyArray_ITER_RESET(it2);\n\t}\n\tPy_DECREF(it1);\n\tPy_DECREF(it2);\n\n\tif (PyErr_Occurred()) goto fail;\n\t\t\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/* just like inner product but does the swapaxes stuff on the fly */\n/*MULTIARRAY_API\n Numeric.matrixproduct(a,v)\n*/\nstatic PyObject *\nPyArray_MatrixProduct(PyObject *op1, PyObject *op2) \n{\n\tPyArrayObject *ap1, *ap2, *ret=NULL;\n\tPyArrayIterObject *it1, *it2;\n\tintp i, j, l;\n\tint typenum, nd;\n\tintp is1, is2, os;\n\tchar *op;\n\tintp dimensions[MAX_DIMS];\n\tPyArray_DotFunc *dot;\n\tintp matchDim;\n\tPyArray_Descr *typec;\n\n\ttypenum = PyArray_ObjectType(op1, 0); \n\ttypenum = PyArray_ObjectType(op2, typenum);\t\n\t\n\ttypec = PyArray_DescrFromType(typenum);\n\tPy_INCREF(typec);\n\tap1 = (PyArrayObject *)PyArray_FromAny(op1, typec, 0, 0, \n\t\t\t\t\t BEHAVED_FLAGS, NULL);\n\tif (ap1 == NULL) {Py_DECREF(typec); return NULL;}\n\tap2 = (PyArrayObject *)PyArray_FromAny(op2, typec, 0, 0,\n\t\t\t\t\t BEHAVED_FLAGS, NULL);\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\tif (ap2->nd > 1) {\n\t\tmatchDim = ap2->nd - 2;\n\t}\n\telse {\n\t\tmatchDim = 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\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; istrides[ap1->nd-1]; is2 = ap2->strides[matchDim];\n\n /* Choose which subtype to return */\n\tret = new_array_for_sum(ap1, ap2, nd, dimensions, typenum);\n\tif (ret == NULL) goto fail;\n\n\t/* Ensure that multiarray.dot([],[]) -> 0 */\n\tmemset(PyArray_DATA(ret), 0, PyArray_ITEMSIZE(ret));\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\top = ret->data; os = ret->descr->elsize;\n\n\tit1 = (PyArrayIterObject *)\\\n\t\tPyArray_IterAllButAxis((PyObject *)ap1, ap1->nd-1);\n\tit2 = (PyArrayIterObject *)\\\n\t\tPyArray_IterAllButAxis((PyObject *)ap2, matchDim);\n\n\twhile(1) {\n\t\twhile(it2->index < it2->size) {\n\t\t\tdot(it1->dataptr, is1, it2->dataptr, is2, op, l, ret);\n\t\t\top += os;\n\t\t\tPyArray_ITER_NEXT(it2);\n\t\t}\n\t\tPyArray_ITER_NEXT(it1);\n\t\tif (it1->index >= it1->size) break;\n\t\tPyArray_ITER_RESET(it2);\n\t}\n\tPy_DECREF(it1);\n\tPy_DECREF(it2);\n\tif (PyErr_Occurred()) goto fail; /* only for OBJECT arrays */\n\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/*MULTIARRAY_API\n Fast Copy and Transpose\n*/\nstatic PyObject *\nPyArray_CopyAndTranspose(PyObject *op) \n{\n\tPyObject *ret, *arr;\n\tint nd;\n\tintp dims[2];\n\tintp i,j;\n\tint elsize, str2;\n\tchar *iptr;\n\tchar *optr;\n\n\t/* make sure it is well-behaved */\n\tarr = PyArray_FromAny(op, NULL, 0, 0, CARRAY_FLAGS, NULL);\n\tnd = PyArray_NDIM(arr);\n\tif (nd == 1) { /* we will give in to old behavior */\n\t\tret = PyArray_Copy((PyArrayObject *)arr);\n\t\tPy_DECREF(arr);\n\t\treturn ret;\t\t\n\t}\n\telse if (nd != 2) {\n\t\tPy_DECREF(arr);\n\t\tPyErr_SetString(PyExc_ValueError, \n\t\t\t\t\"only 2-d arrays are allowed\");\n\t\treturn NULL;\n\t}\n\n\t/* Now construct output array */\n\tdims[0] = PyArray_DIM(arr,1);\n\tdims[1] = PyArray_DIM(arr,0);\n\telsize = PyArray_ITEMSIZE(arr);\n\t\n\tPy_INCREF(PyArray_DESCR(arr));\n\tret = PyArray_NewFromDescr(arr->ob_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\tret = new_array_for_sum(ap1, ap2, 1, &length, typenum);\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 Py_INCREF(self->descr); \n\tvalues = (PyArrayObject *)PyArray_FromAny(values0, self->descr, 0, 0, \n\t\t\t\t\t\t DEFAULT_FLAGS | FORCECAST, NULL); \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, NULL);\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\tif (type->type_num == PyArray_UNICODE)\n\t\t\ttype->elsize = itemsize << 2; \n\t\telse\n\t\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\tif (type->hasobject) newdescr->hasobject = 1;\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 int hasobject=0;\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; ihasobject)\n hasobject = 1;\n\t\ttup = PyTuple_New(2);\n\t\tPyTuple_SET_ITEM(tup, 0, (PyObject *)conv);\n\t\tPyTuple_SET_ITEM(tup, 1, PyInt_FromLong((long) totalsize));\n\t\ttotalsize += conv->elsize;\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 new->hasobject=hasobject;\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 int hasobject=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; ihasobject)\n\t\t\thasobject=1;\t\t\t\n\t\tPyTuple_SET_ITEM(tup, 0, (PyObject *)conv);\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\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\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 new->hasobject=hasobject;\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 int hasobject=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\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\tPyTuple_SET_ITEM(tup, 1, PyInt_FromLong(totalsize));\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\tif (PyDict_GetItem(fields, name) != NULL) {\n\t\t\tPyErr_SetString(PyExc_ValueError,\n\t\t\t\t\t\"name already used as a name or title\");\n\t\t\tret = PY_FAIL;\n\t\t}\n\t\tPyDict_SetItem(fields, name, tup);\n\t\tPy_DECREF(name);\n\t\tif (len == 3) {\n\t\t\tif (PyDict_GetItem(fields, item) != NULL) {\n\t\t\t\tPyErr_SetString(PyExc_ValueError, \n\t\t\t\t\t\t\"title already used as a name or \" \\\n\t\t\t\t\t\t\" title.\");\n\t\t\t\tret=PY_FAIL;\n\t\t\t}\n\t\t\telse {\n\t\t\t\tPyDict_SetItem(fields, item, tup);\n\t\t\t}\n\t\t}\n\t\tPy_DECREF(tup);\n\t\tif ((ret == PY_FAIL) || (newdescr->elsize == 0)) goto fail;\n if (!hasobject && newdescr->hasobject)\n hasobject = 1;\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 new->hasobject=hasobject;\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 == '|' || (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\tint i;\n\t\t\telsize = atoi(type+1);\n\t\t\t/* check for commas present */\n\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\nstatic PyObject *\n_prepend_ones(PyArrayObject *arr, int nd, int ndmin)\n{\n\tintp newdims[MAX_DIMS];\n\tintp newstrides[MAX_DIMS];\n\tint i,k,num;\n\tPyObject *ret;\n\n\tnum = ndmin-nd;\n\tfor (i=0; idescr->elsize;\n\t}\n\tfor (i=num;idimensions[k];\n\t\tnewstrides[i] = arr->strides[k];\n\t}\n\tPy_INCREF(arr->descr);\n\tret = PyArray_NewFromDescr(arr->ob_type, arr->descr, ndmin,\n\t\t\t\t newdims, newstrides, arr->data, arr->flags,\n\t\t\t\t (PyObject *)arr);\n\t/* steals a reference to arr --- so don't increment\n\t here */\n\tPyArray_BASE(ret) = (PyObject *)arr;\n\treturn ret;\n}\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,ndmin=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\"\\\n\t\"The ndmin argument specifies how many dimensions the returned\\n\"\\\n\t\"array should have as a minimum. 1's will be pre-pended to the\\n\"\\\n\t\"shape as needed to meet this requirement.\";\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\t\t\t \"ndmin\", NULL};\n Bool subok=FALSE;\n\tBool copy=TRUE;\n\tint ndmin=0, nd;\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&i\", 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\t\t\t\t&ndmin)) \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\tret = op;\n\t\t\t\tgoto finish;\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\tgoto finish;\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\tret = op;\n\t\t\t\tgoto finish;\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\tgoto finish;\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_CheckFromAny(op, type, 0, 0, flags, NULL)) == NULL) \n\t\treturn NULL;\n\n finish:\n\n\tif ((nd=PyArray_NDIM(ret)) >= ndmin) return ret;\n\t/* create a new array from the same data with ones in the shape */\n\t/* steals a reference to ret */\n\treturn _prepend_ones((PyArrayObject *)ret, nd, ndmin);\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(dtype,obj) will return a new scalar array of the given type initialized with obj. Mainly for pickle support. The dtype must be a valid data-type descriptor. If dtype 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[] = {\"dtype\",\"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}; /* XXX ? */\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\nstatic int\n_skip_sep(char **ptr, char *sep)\n{\n\tchar *a;\n\tint n;\n\tn = strlen(sep);\n\ta = *ptr;\n\twhile(*a != '\\0' && (strncmp(a, sep, n) != 0))\n\t\ta++;\n\tif (*a == '\\0') return -1;\n\t*ptr = a+strlen(sep);\n\treturn 0;\n}\n\n/* steals a reference to dtype -- accepts NULL */\n/*OBJECT_API*/\nstatic PyObject *\nPyArray_FromString(char *data, intp slen, PyArray_Descr *dtype, \n\t\t intp n, char *sep)\n{\n\tint itemsize;\n\tPyArrayObject *ret;\n\tBool binary;\n\n\tif (dtype == NULL)\n\t\tdtype=PyArray_DescrFromType(PyArray_LONG);\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\n\tbinary = ((sep == NULL) || (strlen(sep) == 0));\t\n\n\tif (binary) {\n\t\tif (dtype == &OBJECT_Descr) {\n\t\t\tPyErr_SetString(PyExc_ValueError, \n\t\t\t\t\t\"Cannot create an object array from\"\\\n\t\t\t\t\t\" a binary string\");\n\t\t\tPy_DECREF(dtype);\n\t\t\treturn NULL;\n\t\t}\t\t\n\t\tif (n < 0 ) {\n\t\t\tif (slen % itemsize != 0) {\n\t\t\t\tPyErr_SetString(PyExc_ValueError, \n\t\t\t\t\t\t\"string size must be a \"\\\n\t\t\t\t\t\t\"multiple of element size\");\n\t\t\t\tPy_DECREF(dtype);\n\t\t\t\treturn NULL;\n\t\t\t}\n\t\t\tn = slen/itemsize;\n\t\t} else {\n\t\t\tif (slen < n*itemsize) {\n\t\t\t\tPyErr_SetString(PyExc_ValueError, \n\t\t\t\t\t\t\"string is smaller than \" \\\n\t\t\t\t\t\t\"requested size\");\n\t\t\t\tPy_DECREF(dtype);\n\t\t\t\treturn NULL;\n\t\t\t}\n\t\t}\n\t\n\t\tif ((ret = (PyArrayObject *)\\\n\t\t PyArray_NewFromDescr(&PyArray_Type, dtype,\n\t\t\t\t\t 1, &n, NULL, NULL,\n\t\t\t\t\t 0, NULL)) == NULL)\n\t\t\treturn NULL;\t\t\n\t\tmemcpy(ret->data, data, n*dtype->elsize);\n\t\treturn (PyObject *)ret;\n\t}\n\telse { /* read from character-based string */\n\t\tchar *ptr;\t\t\n\t\tPyArray_FromStrFunc *fromstr;\n\t\tchar *dptr;\n\t\tintp nread=0;\n\t\tintp index;\n\n\t\tfromstr = dtype->f->fromstr;\n\t\tif (fromstr == 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 strings for given \"\t\\\n\t\t\t\t\t\"array type\");\n\t\t\tPy_DECREF(dtype);\n\t\t\treturn NULL;\n\t\t}\n\n\t\tif (n!=-1) {\n\t\t\tret = (PyArrayObject *) \\\n\t\t\t\tPyArray_NewFromDescr(&PyArray_Type,\n\t\t\t\t\t\t dtype, 1, &n, NULL,\n\t\t\t\t\t\t NULL, 0, NULL);\n\t\t\tif (ret == NULL) return NULL;\n\t\t\tptr = data;\n\t\t\tdptr = ret->data;\n\t\t\tfor (index=0; index < n; index++) {\n\t\t\t\tif (fromstr(ptr, dptr, &ptr, ret) < 0)\n\t\t\t\t\tbreak;\n\t\t\t\tnread += 1;\n\t\t\t\tdptr += dtype->elsize;\n\t\t\t\tif (_skip_sep(&ptr, sep) < 0) \n\t\t\t\t\tbreak;\n\t\t\t}\n\t\t\tif (nread < n) {\n\t\t\t\tfprintf(stderr, \"%ld items requested but \"\\\n\t\t\t\t\t\"only %ld read\\n\", \n\t\t\t\t\t(long) n, (long) nread);\n\t\t\t\tret->data = \\\n\t\t\t\t\tPyDataMem_RENEW(ret->data, \n\t\t\t\t\t\t\tnread *\t\t\\\n\t\t\t\t\t\t\tret->descr->elsize);\n\t\t\t\tPyArray_DIM(ret,0) = nread;\n\t\t\t}\n\t\t}\n\t\telse {\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\t\t\tchar *end;\n\t\t\tint val;\n\n\t\t\tret = (PyArrayObject *)\\\n\t\t\t\tPyArray_NewFromDescr(&PyArray_Type, \n\t\t\t\t\t\t dtype,\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 (ret==NULL) return NULL;\n\t\t\ttotalbytes = bytes = size * dtype->elsize;\n\t\t\tdptr = ret->data;\n\t\t\tptr = data;\n\t\t\tend = data+slen;\n\t\t\twhile (ptr < end) {\n\t\t\t\tval = fromstr(ptr, dptr, &ptr, ret);\n\t\t\t\tif (val < 0) break;\n\t\t\t\tnread += 1;\n\t\t\t\tval = _skip_sep(&ptr, sep);\n\t\t\t\tif (val < 0) break;\n\t\t\t\tthisbuf += 1;\n\t\t\t\tdptr += dtype->elsize;\n\t\t\t\tif (thisbuf == size) {\n\t\t\t\t\ttotalbytes += bytes;\n\t\t\t\t\tret->data = PyDataMem_RENEW(ret->data, \n\t\t\t\t\t\t\t\t totalbytes);\n\t\t\t\t\tdptr = ret->data + \\\n\t\t\t\t\t\t(totalbytes - bytes);\n\t\t\t\t\tthisbuf = 0;\n\t\t\t\t}\n\t\t\t}\n\t\t\tret->data = PyDataMem_RENEW(ret->data, \n\t\t\t\t\t\t nread*ret->descr->elsize);\n\t\t\tPyArray_DIM(ret,0) = nread;\n#undef _FILEBUFNUM\n\t\t}\n\t}\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\tchar *sep=NULL;\n\tint s;\n\tstatic char *kwlist[] = {\"string\", \"dtype\", \"count\", \"sep\", NULL};\n\tPyArray_Descr *descr=NULL;\n\n\tif (!PyArg_ParseTupleAndKeywords(args, keywds, \"s#|O&Ls\", 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, &sep)) {\n\t\treturn NULL;\n\t}\n\n\treturn PyArray_FromString(data, (intp)s, descr, (intp)nin, sep);\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\tPy_DECREF(typecode);\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\tPy_DECREF(typecode);\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\tPy_DECREF(typecode);\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 platform-independent method of persistence. But it can be \\n\"\\\n\t\" useful to 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_BYTES(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_BYTES(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[] = \n\"arange([start,] stop[, step,], dtype=None)\\n\\n\"\n\"For integer arguments, just like range() except it returns an array whose type can\\n\"\n\"be specified by the keyword argument dtype.\\n\\n\"\n\"If dtype is not specified, the type of the result is deduced from the type of the\\n\"\n\"arguments.\\n\\n\"\n\"For floating point arguments, the length of the result is ceil((stop - start)/step).\\n\"\n\"This rule may result in the last element of the result be greater than stop.\";\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_DescrConverter2,\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/*MULTIARRAY_API\n GetNDArrayCVersion\n*/\nstatic unsigned int\nPyArray_GetNDArrayCVersion(void)\n{\n\treturn (unsigned int)NDARRAY_VERSION;\n}\n\nstatic char \ndoc__get_ndarray_c_version[] = \"_get_ndarray_c_version() gets the compile time NDARRAY_VERSION number\";\n\nstatic PyObject *\narray__get_ndarray_c_version(PyObject *dummy, PyObject *args, PyObject *kwds) \n{\n\tstatic char *kwlist[] = {NULL};\n\tif(!PyArg_ParseTupleAndKeywords(args, kwds, \"\", kwlist )) return NULL;\n\t\n\treturn PyInt_FromLong( (long) PyArray_GetNDArrayCVersion() );\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, NULL);\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{\"_get_ndarray_c_version\", (PyCFunction)array__get_ndarray_c_version, \n\t METH_VARARGS|METH_KEYWORDS, doc__get_ndarray_c_version},\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, \"dtype\", (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\tif (!PyErr_Occurred()) {\n\t\tPyErr_SetString(PyExc_RuntimeError, \n\t\t\t\t\"cannot load multiarray module.\");\n\t}\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": 35, + "end_line": 50, + "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": 75, + "end_line": 80, + "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": 86, + "end_line": 91, + "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": 65, + "parameters": [ + "obj", + "ind" + ], + "start_line": 97, + "end_line": 105, + "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": 111, + "end_line": 123, + "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": 129, + "end_line": 136, + "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": 143, + "end_line": 173, + "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": 179, + "end_line": 196, + "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": 202, + "end_line": 237, + "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": 248, + "end_line": 257, + "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": 260, + "end_line": 286, + "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": 297, + "end_line": 384, + "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": 393, + "end_line": 428, + "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": 435, + "end_line": 456, + "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": 463, + "end_line": 522, + "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": 529, + "end_line": 539, + "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": 545, + "end_line": 555, + "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": 561, + "end_line": 571, + "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": 577, + "end_line": 588, + "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": 594, + "end_line": 605, + "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": 611, + "end_line": 622, + "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": 102, + "parameters": [ + "self", + "condition", + "axis" + ], + "start_line": 629, + "end_line": 649, + "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": 655, + "end_line": 714, + "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": 720, + "end_line": 750, + "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": 756, + "end_line": 792, + "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": 798, + "end_line": 808, + "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": 776, + "parameters": [ + "self", + "offset", + "axis1", + "axis2" + ], + "start_line": 814, + "end_line": 933, + "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": 402, + "parameters": [ + "op", + "ptr", + "dims", + "nd", + "typedescr" + ], + "start_line": 949, + "end_line": 1000, + "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": 1008, + "end_line": 1018, + "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": 1024, + "end_line": 1036, + "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": 1044, + "end_line": 1055, + "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": 1059, + "end_line": 1087, + "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": 94, + "complexity": 21, + "token_count": 630, + "parameters": [ + "op", + "axis" + ], + "start_line": 1099, + "end_line": 1205, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 107, + "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": 1211, + "end_line": 1252, + "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": 1258, + "end_line": 1311, + "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": 1317, + "end_line": 1412, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 96, + "top_nesting_level": 0 + }, + { + "name": "_signbit_set", + "long_name": "_signbit_set( PyArrayObject * arr)", + "filename": "multiarraymodule.c", + "nloc": 16, + "complexity": 5, + "token_count": 89, + "parameters": [ + "arr" + ], + "start_line": 1416, + "end_line": 1433, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 18, + "top_nesting_level": 0 + }, + { + "name": "PyArray_ScalarKind", + "long_name": "PyArray_ScalarKind( int typenum , PyArrayObject ** arr)", + "filename": "multiarraymodule.c", + "nloc": 12, + "complexity": 8, + "token_count": 80, + "parameters": [ + "typenum", + "arr" + ], + "start_line": 1438, + "end_line": 1450, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 13, + "top_nesting_level": 0 + }, + { + "name": "PyArray_CanCoerceScalar", + "long_name": "PyArray_CanCoerceScalar( char thistype , char neededtype , char scalar)", + "filename": "multiarraymodule.c", + "nloc": 21, + "complexity": 9, + "token_count": 101, + "parameters": [ + "thistype", + "neededtype", + "scalar" + ], + "start_line": 1455, + "end_line": 1476, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 22, + "top_nesting_level": 0 + }, + { + "name": "PyArray_ConvertToCommonType", + "long_name": "PyArray_ConvertToCommonType( PyObject * op , int * retn)", + "filename": "multiarraymodule.c", + "nloc": 73, + "complexity": 15, + "token_count": 482, + "parameters": [ + "op", + "retn" + ], + "start_line": 1484, + "end_line": 1563, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 80, + "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": 1570, + "end_line": 1651, + "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": 1654, + "end_line": 1661, + "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": 1672, + "end_line": 1726, + "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": 1729, + "end_line": 1807, + "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": 1815, + "end_line": 1818, + "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": 355, + "parameters": [ + "op", + "axis", + "which" + ], + "start_line": 1873, + "end_line": 1939, + "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": 1945, + "end_line": 1953, + "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": 1959, + "end_line": 2039, + "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": 2051, + "end_line": 2195, + "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": 2199, + "end_line": 2234, + "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": 2240, + "end_line": 2285, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 46, + "top_nesting_level": 0 + }, + { + "name": "new_array_for_sum", + "long_name": "new_array_for_sum( PyArrayObject * ap1 , PyArrayObject * ap2 , int nd , intp dimensions [ ] , int typenum)", + "filename": "multiarraymodule.c", + "nloc": 20, + "complexity": 4, + "token_count": 147, + "parameters": [ + "ap1", + "ap2", + "nd", + "typenum" + ], + "start_line": 2292, + "end_line": 2316, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 25, + "top_nesting_level": 0 + }, + { + "name": "PyArray_InnerProduct", + "long_name": "PyArray_InnerProduct( PyObject * op1 , PyObject * op2)", + "filename": "multiarraymodule.c", + "nloc": 79, + "complexity": 15, + "token_count": 624, + "parameters": [ + "op1", + "op2" + ], + "start_line": 2325, + "end_line": 2423, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 99, + "top_nesting_level": 0 + }, + { + "name": "PyArray_MatrixProduct", + "long_name": "PyArray_MatrixProduct( PyObject * op1 , PyObject * op2)", + "filename": "multiarraymodule.c", + "nloc": 89, + "complexity": 17, + "token_count": 680, + "parameters": [ + "op1", + "op2" + ], + "start_line": 2431, + "end_line": 2542, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 112, + "top_nesting_level": 0 + }, + { + "name": "PyArray_CopyAndTranspose", + "long_name": "PyArray_CopyAndTranspose( PyObject * op)", + "filename": "multiarraymodule.c", + "nloc": 47, + "complexity": 6, + "token_count": 286, + "parameters": [ + "op" + ], + "start_line": 2548, + "end_line": 2602, + "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": 86, + "complexity": 13, + "token_count": 601, + "parameters": [ + "op1", + "op2", + "mode" + ], + "start_line": 2608, + "end_line": 2705, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 98, + "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": 2712, + "end_line": 2736, + "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": 2742, + "end_line": 2753, + "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": 2759, + "end_line": 2770, + "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": 2776, + "end_line": 2799, + "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": 2806, + "end_line": 2863, + "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": 2870, + "end_line": 2945, + "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": 64, + "complexity": 15, + "token_count": 479, + "parameters": [ + "self", + "values0", + "indices0" + ], + "start_line": 2951, + "end_line": 3021, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 71, + "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": 3027, + "end_line": 3098, + "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": 68, + "parameters": [ + "object", + "address" + ], + "start_line": 3114, + "end_line": 3126, + "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": 3132, + "end_line": 3140, + "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": 3147, + "end_line": 3262, + "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": 3280, + "end_line": 3305, + "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": 3320, + "end_line": 3356, + "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": 3374, + "end_line": 3407, + "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": 65, + "complexity": 16, + "token_count": 399, + "parameters": [ + "obj" + ], + "start_line": 3410, + "end_line": 3487, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 78, + "top_nesting_level": 0 + }, + { + "name": "_convert_from_array_descr", + "long_name": "_convert_from_array_descr( PyObject * obj)", + "filename": "multiarraymodule.c", + "nloc": 69, + "complexity": 14, + "token_count": 442, + "parameters": [ + "obj" + ], + "start_line": 3495, + "end_line": 3566, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 72, + "top_nesting_level": 0 + }, + { + "name": "_convert_from_list", + "long_name": "_convert_from_list( PyObject * obj , int align , int try_descr)", + "filename": "multiarraymodule.c", + "nloc": 70, + "complexity": 13, + "token_count": 428, + "parameters": [ + "obj", + "align", + "try_descr" + ], + "start_line": 3577, + "end_line": 3648, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 72, + "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": 3661, + "end_line": 3677, + "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": 3714, + "end_line": 3719, + "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": 112, + "complexity": 29, + "token_count": 720, + "parameters": [ + "obj", + "align" + ], + "start_line": 3722, + "end_line": 3843, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 122, + "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": 3861, + "end_line": 3868, + "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": 141, + "complexity": 55, + "token_count": 886, + "parameters": [ + "obj", + "at" + ], + "start_line": 3885, + "end_line": 4065, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 181, + "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": 4071, + "end_line": 4103, + "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": 4109, + "end_line": 4135, + "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": 4144, + "end_line": 4163, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 20, + "top_nesting_level": 0 + }, + { + "name": "_prepend_ones", + "long_name": "_prepend_ones( PyArrayObject * arr , int nd , int ndmin)", + "filename": "multiarraymodule.c", + "nloc": 23, + "complexity": 3, + "token_count": 175, + "parameters": [ + "arr", + "nd", + "ndmin" + ], + "start_line": 4168, + "end_line": 4193, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 26, + "top_nesting_level": 0 + }, + { + "name": "_array_fromobject", + "long_name": "_array_fromobject( PyObject * ignored , PyObject * args , PyObject * kws)", + "filename": "multiarraymodule.c", + "nloc": 66, + "complexity": 16, + "token_count": 380, + "parameters": [ + "ignored", + "args", + "kws" + ], + "start_line": 4215, + "end_line": 4290, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 76, + "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": 4298, + "end_line": 4313, + "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": 4319, + "end_line": 4343, + "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": 4348, + "end_line": 4406, + "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": 4415, + "end_line": 4439, + "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": 4445, + "end_line": 4469, + "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": 4476, + "end_line": 4485, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 10, + "top_nesting_level": 0 + }, + { + "name": "_skip_sep", + "long_name": "_skip_sep( char ** ptr , char * sep)", + "filename": "multiarraymodule.c", + "nloc": 12, + "complexity": 4, + "token_count": 78, + "parameters": [ + "ptr", + "sep" + ], + "start_line": 4488, + "end_line": 4499, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 12, + "top_nesting_level": 0 + }, + { + "name": "PyArray_FromString", + "long_name": "PyArray_FromString( char * data , intp slen , PyArray_Descr * dtype , intp n , char * sep)", + "filename": "multiarraymodule.c", + "nloc": 133, + "complexity": 22, + "token_count": 711, + "parameters": [ + "data", + "slen", + "dtype", + "n", + "sep" + ], + "start_line": 4504, + "end_line": 4646, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 143, + "top_nesting_level": 0 + }, + { + "name": "array_fromString", + "long_name": "array_fromString( PyObject * ignored , PyObject * args , PyObject * keywds)", + "filename": "multiarraymodule.c", + "nloc": 16, + "complexity": 2, + "token_count": 116, + "parameters": [ + "ignored", + "args", + "keywds" + ], + "start_line": 4651, + "end_line": 4668, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 18, + "top_nesting_level": 0 + }, + { + "name": "PyArray_FromFile", + "long_name": "PyArray_FromFile( FILE * fp , PyArray_Descr * typecode , intp num , char * sep)", + "filename": "multiarraymodule.c", + "nloc": 114, + "complexity": 22, + "token_count": 664, + "parameters": [ + "fp", + "typecode", + "num", + "sep" + ], + "start_line": 4682, + "end_line": 4810, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 129, + "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": 4828, + "end_line": 4866, + "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": 4870, + "end_line": 4963, + "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": 4979, + "end_line": 4996, + "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": 5002, + "end_line": 5013, + "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": 5020, + "end_line": 5026, + "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": 5033, + "end_line": 5039, + "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": 5043, + "end_line": 5049, + "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": 5053, + "end_line": 5062, + "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": 5069, + "end_line": 5120, + "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": 5126, + "end_line": 5158, + "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": 5165, + "end_line": 5249, + "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": 5262, + "end_line": 5274, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 13, + "top_nesting_level": 0 + }, + { + "name": "PyArray_GetNDArrayCVersion", + "long_name": "PyArray_GetNDArrayCVersion()", + "filename": "multiarraymodule.c", + "nloc": 4, + "complexity": 1, + "token_count": 13, + "parameters": [], + "start_line": 5280, + "end_line": 5283, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 0 + }, + { + "name": "array__get_ndarray_c_version", + "long_name": "array__get_ndarray_c_version( PyObject * dummy , PyObject * args , PyObject * kwds)", + "filename": "multiarraymodule.c", + "nloc": 6, + "complexity": 2, + "token_count": 55, + "parameters": [ + "dummy", + "args", + "kwds" + ], + "start_line": 5289, + "end_line": 5295, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 7, + "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": 5301, + "end_line": 5317, + "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": 5323, + "end_line": 5340, + "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": 233, + "parameters": [ + "condition", + "x", + "y" + ], + "start_line": 5347, + "end_line": 5387, + "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": 5395, + "end_line": 5403, + "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": 5415, + "end_line": 5425, + "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": 5434, + "end_line": 5445, + "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": 5452, + "end_line": 5475, + "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": 5482, + "end_line": 5490, + "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": 5499, + "end_line": 5517, + "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": 5583, + "end_line": 5696, + "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": 5701, + "end_line": 5725, + "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": 64, + "complexity": 15, + "token_count": 435, + "parameters": [], + "start_line": 5730, + "end_line": 5822, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 93, + "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": 35, + "end_line": 50, + "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": 75, + "end_line": 80, + "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": 86, + "end_line": 91, + "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": 97, + "end_line": 105, + "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": 111, + "end_line": 123, + "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": 129, + "end_line": 136, + "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": 143, + "end_line": 173, + "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": 179, + "end_line": 196, + "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": 202, + "end_line": 237, + "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": 248, + "end_line": 257, + "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": 260, + "end_line": 286, + "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": 297, + "end_line": 384, + "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": 393, + "end_line": 428, + "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": 435, + "end_line": 456, + "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": 463, + "end_line": 522, + "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": 529, + "end_line": 539, + "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": 545, + "end_line": 555, + "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": 561, + "end_line": 571, + "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": 577, + "end_line": 588, + "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": 594, + "end_line": 605, + "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": 611, + "end_line": 622, + "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": 102, + "parameters": [ + "self", + "condition", + "axis" + ], + "start_line": 629, + "end_line": 649, + "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": 655, + "end_line": 714, + "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": 720, + "end_line": 750, + "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": 756, + "end_line": 792, + "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": 798, + "end_line": 808, + "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": 776, + "parameters": [ + "self", + "offset", + "axis1", + "axis2" + ], + "start_line": 814, + "end_line": 933, + "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": 402, + "parameters": [ + "op", + "ptr", + "dims", + "nd", + "typedescr" + ], + "start_line": 949, + "end_line": 1000, + "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": 1008, + "end_line": 1018, + "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": 1024, + "end_line": 1036, + "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": 1044, + "end_line": 1055, + "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": 1059, + "end_line": 1087, + "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": 94, + "complexity": 21, + "token_count": 630, + "parameters": [ + "op", + "axis" + ], + "start_line": 1099, + "end_line": 1205, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 107, + "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": 1211, + "end_line": 1252, + "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": 1258, + "end_line": 1311, + "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": 1317, + "end_line": 1412, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 96, + "top_nesting_level": 0 + }, + { + "name": "_signbit_set", + "long_name": "_signbit_set( PyArrayObject * arr)", + "filename": "multiarraymodule.c", + "nloc": 16, + "complexity": 5, + "token_count": 89, + "parameters": [ + "arr" + ], + "start_line": 1416, + "end_line": 1433, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 18, + "top_nesting_level": 0 + }, + { + "name": "PyArray_ScalarKind", + "long_name": "PyArray_ScalarKind( int typenum , PyArrayObject ** arr)", + "filename": "multiarraymodule.c", + "nloc": 12, + "complexity": 8, + "token_count": 80, + "parameters": [ + "typenum", + "arr" + ], + "start_line": 1438, + "end_line": 1450, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 13, + "top_nesting_level": 0 + }, + { + "name": "PyArray_CanCoerceScalar", + "long_name": "PyArray_CanCoerceScalar( char thistype , char neededtype , char scalar)", + "filename": "multiarraymodule.c", + "nloc": 21, + "complexity": 9, + "token_count": 101, + "parameters": [ + "thistype", + "neededtype", + "scalar" + ], + "start_line": 1455, + "end_line": 1476, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 22, + "top_nesting_level": 0 + }, + { + "name": "PyArray_ConvertToCommonType", + "long_name": "PyArray_ConvertToCommonType( PyObject * op , int * retn)", + "filename": "multiarraymodule.c", + "nloc": 73, + "complexity": 15, + "token_count": 482, + "parameters": [ + "op", + "retn" + ], + "start_line": 1484, + "end_line": 1563, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 80, + "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": 1570, + "end_line": 1651, + "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": 1654, + "end_line": 1661, + "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": 1672, + "end_line": 1726, + "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": 1729, + "end_line": 1807, + "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": 1815, + "end_line": 1818, + "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": 355, + "parameters": [ + "op", + "axis", + "which" + ], + "start_line": 1873, + "end_line": 1939, + "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": 1945, + "end_line": 1953, + "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": 1959, + "end_line": 2039, + "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": 2051, + "end_line": 2195, + "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": 2199, + "end_line": 2234, + "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": 2240, + "end_line": 2285, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 46, + "top_nesting_level": 0 + }, + { + "name": "new_array_for_sum", + "long_name": "new_array_for_sum( PyArrayObject * ap1 , PyArrayObject * ap2 , int nd , intp dimensions [ ] , int typenum)", + "filename": "multiarraymodule.c", + "nloc": 20, + "complexity": 4, + "token_count": 147, + "parameters": [ + "ap1", + "ap2", + "nd", + "typenum" + ], + "start_line": 2292, + "end_line": 2316, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 25, + "top_nesting_level": 0 + }, + { + "name": "PyArray_InnerProduct", + "long_name": "PyArray_InnerProduct( PyObject * op1 , PyObject * op2)", + "filename": "multiarraymodule.c", + "nloc": 79, + "complexity": 15, + "token_count": 624, + "parameters": [ + "op1", + "op2" + ], + "start_line": 2325, + "end_line": 2423, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 99, + "top_nesting_level": 0 + }, + { + "name": "PyArray_MatrixProduct", + "long_name": "PyArray_MatrixProduct( PyObject * op1 , PyObject * op2)", + "filename": "multiarraymodule.c", + "nloc": 89, + "complexity": 17, + "token_count": 680, + "parameters": [ + "op1", + "op2" + ], + "start_line": 2431, + "end_line": 2542, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 112, + "top_nesting_level": 0 + }, + { + "name": "PyArray_CopyAndTranspose", + "long_name": "PyArray_CopyAndTranspose( PyObject * op)", + "filename": "multiarraymodule.c", + "nloc": 47, + "complexity": 6, + "token_count": 286, + "parameters": [ + "op" + ], + "start_line": 2548, + "end_line": 2602, + "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": 86, + "complexity": 13, + "token_count": 601, + "parameters": [ + "op1", + "op2", + "mode" + ], + "start_line": 2608, + "end_line": 2705, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 98, + "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": 2712, + "end_line": 2736, + "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": 2742, + "end_line": 2753, + "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": 2759, + "end_line": 2770, + "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": 2776, + "end_line": 2799, + "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": 2806, + "end_line": 2863, + "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": 2870, + "end_line": 2945, + "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": 64, + "complexity": 15, + "token_count": 479, + "parameters": [ + "self", + "values0", + "indices0" + ], + "start_line": 2951, + "end_line": 3021, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 71, + "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": 3027, + "end_line": 3098, + "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": 68, + "parameters": [ + "object", + "address" + ], + "start_line": 3114, + "end_line": 3126, + "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": 3132, + "end_line": 3140, + "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": 3147, + "end_line": 3262, + "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": 3280, + "end_line": 3305, + "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": 3320, + "end_line": 3356, + "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": 3374, + "end_line": 3407, + "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": 65, + "complexity": 16, + "token_count": 399, + "parameters": [ + "obj" + ], + "start_line": 3410, + "end_line": 3487, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 78, + "top_nesting_level": 0 + }, + { + "name": "_convert_from_array_descr", + "long_name": "_convert_from_array_descr( PyObject * obj)", + "filename": "multiarraymodule.c", + "nloc": 69, + "complexity": 14, + "token_count": 442, + "parameters": [ + "obj" + ], + "start_line": 3495, + "end_line": 3566, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 72, + "top_nesting_level": 0 + }, + { + "name": "_convert_from_list", + "long_name": "_convert_from_list( PyObject * obj , int align , int try_descr)", + "filename": "multiarraymodule.c", + "nloc": 70, + "complexity": 13, + "token_count": 428, + "parameters": [ + "obj", + "align", + "try_descr" + ], + "start_line": 3577, + "end_line": 3648, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 72, + "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": 3661, + "end_line": 3677, + "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": 3714, + "end_line": 3719, + "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": 112, + "complexity": 29, + "token_count": 720, + "parameters": [ + "obj", + "align" + ], + "start_line": 3722, + "end_line": 3843, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 122, + "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": 3861, + "end_line": 3868, + "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": 141, + "complexity": 55, + "token_count": 886, + "parameters": [ + "obj", + "at" + ], + "start_line": 3885, + "end_line": 4065, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 181, + "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": 4071, + "end_line": 4103, + "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": 4109, + "end_line": 4135, + "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": 4144, + "end_line": 4163, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 20, + "top_nesting_level": 0 + }, + { + "name": "_prepend_ones", + "long_name": "_prepend_ones( PyArrayObject * arr , int nd , int ndmin)", + "filename": "multiarraymodule.c", + "nloc": 23, + "complexity": 3, + "token_count": 175, + "parameters": [ + "arr", + "nd", + "ndmin" + ], + "start_line": 4168, + "end_line": 4193, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 26, + "top_nesting_level": 0 + }, + { + "name": "_array_fromobject", + "long_name": "_array_fromobject( PyObject * ignored , PyObject * args , PyObject * kws)", + "filename": "multiarraymodule.c", + "nloc": 66, + "complexity": 16, + "token_count": 380, + "parameters": [ + "ignored", + "args", + "kws" + ], + "start_line": 4215, + "end_line": 4290, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 76, + "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": 4298, + "end_line": 4313, + "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": 4319, + "end_line": 4343, + "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": 4348, + "end_line": 4406, + "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": 4415, + "end_line": 4439, + "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": 4445, + "end_line": 4469, + "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": 4476, + "end_line": 4485, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 10, + "top_nesting_level": 0 + }, + { + "name": "_skip_sep", + "long_name": "_skip_sep( char ** ptr , char * sep)", + "filename": "multiarraymodule.c", + "nloc": 12, + "complexity": 4, + "token_count": 78, + "parameters": [ + "ptr", + "sep" + ], + "start_line": 4488, + "end_line": 4499, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 12, + "top_nesting_level": 0 + }, + { + "name": "PyArray_FromString", + "long_name": "PyArray_FromString( char * data , intp slen , PyArray_Descr * dtype , intp n , char * sep)", + "filename": "multiarraymodule.c", + "nloc": 133, + "complexity": 22, + "token_count": 711, + "parameters": [ + "data", + "slen", + "dtype", + "n", + "sep" + ], + "start_line": 4504, + "end_line": 4646, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 143, + "top_nesting_level": 0 + }, + { + "name": "array_fromString", + "long_name": "array_fromString( PyObject * ignored , PyObject * args , PyObject * keywds)", + "filename": "multiarraymodule.c", + "nloc": 16, + "complexity": 2, + "token_count": 116, + "parameters": [ + "ignored", + "args", + "keywds" + ], + "start_line": 4651, + "end_line": 4668, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 18, + "top_nesting_level": 0 + }, + { + "name": "PyArray_FromFile", + "long_name": "PyArray_FromFile( FILE * fp , PyArray_Descr * typecode , intp num , char * sep)", + "filename": "multiarraymodule.c", + "nloc": 114, + "complexity": 22, + "token_count": 664, + "parameters": [ + "fp", + "typecode", + "num", + "sep" + ], + "start_line": 4682, + "end_line": 4810, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 129, + "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": 4828, + "end_line": 4866, + "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": 4870, + "end_line": 4963, + "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": 4979, + "end_line": 4996, + "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": 5002, + "end_line": 5013, + "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": 5020, + "end_line": 5026, + "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": 5033, + "end_line": 5039, + "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": 5043, + "end_line": 5049, + "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": 5053, + "end_line": 5062, + "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": 5069, + "end_line": 5120, + "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": 5126, + "end_line": 5158, + "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": 5165, + "end_line": 5249, + "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": 5262, + "end_line": 5274, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 13, + "top_nesting_level": 0 + }, + { + "name": "PyArray_GetNDArrayCVersion", + "long_name": "PyArray_GetNDArrayCVersion()", + "filename": "multiarraymodule.c", + "nloc": 4, + "complexity": 1, + "token_count": 13, + "parameters": [], + "start_line": 5280, + "end_line": 5283, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 0 + }, + { + "name": "array__get_ndarray_c_version", + "long_name": "array__get_ndarray_c_version( PyObject * dummy , PyObject * args , PyObject * kwds)", + "filename": "multiarraymodule.c", + "nloc": 6, + "complexity": 2, + "token_count": 55, + "parameters": [ + "dummy", + "args", + "kwds" + ], + "start_line": 5289, + "end_line": 5295, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 7, + "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": 5301, + "end_line": 5317, + "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": 5323, + "end_line": 5340, + "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": 233, + "parameters": [ + "condition", + "x", + "y" + ], + "start_line": 5347, + "end_line": 5387, + "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": 5395, + "end_line": 5403, + "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": 5415, + "end_line": 5425, + "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": 5434, + "end_line": 5445, + "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": 5452, + "end_line": 5475, + "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": 5482, + "end_line": 5490, + "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": 5499, + "end_line": 5517, + "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": 5583, + "end_line": 5696, + "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": 5701, + "end_line": 5725, + "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": 64, + "complexity": 15, + "token_count": 435, + "parameters": [], + "start_line": 5730, + "end_line": 5822, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 93, + "top_nesting_level": 0 + } + ], + "changed_methods": [ + { + "name": "PyArray_GetPtr", + "long_name": "PyArray_GetPtr( PyArrayObject * obj , register intp * ind)", + "filename": "multiarraymodule.c", + "nloc": 8, + "complexity": 2, + "token_count": 65, + "parameters": [ + "obj", + "ind" + ], + "start_line": 97, + "end_line": 105, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 9, + "top_nesting_level": 0 + } + ], + "nloc": 4413, + "complexity": 968, + "token_count": 28570, + "diff_parsed": { + "added": [ + "static void *", + "\treturn (void *)dptr;" + ], + "deleted": [ + "static char *", + "\treturn dptr;" + ] + } + } + ] + }, + { + "hash": "6b93ba8d5761b2a2c84c8375b80d2bd1e2c9cfd3", + "msg": "Added unit-tests from Francesc Alted", + "author": { + "name": "Travis Oliphant", + "email": "oliphant@enthought.com" + }, + "committer": { + "name": "Travis Oliphant", + "email": "oliphant@enthought.com" + }, + "author_date": "2006-02-14T22:54:07+00:00", + "author_timezone": 0, + "committer_date": "2006-02-14T22:54:07+00:00", + "committer_timezone": 0, + "branches": [ + "main" + ], + "in_main_branch": true, + "merge": false, + "parents": [ + "263df7516f66a53dd9a93f6cd08ce98e30ad0eca" + ], + "project_name": "repo_copy", + "project_path": "/tmp/tmpdjwupkfu/repo_copy", + "deletions": 65, + "insertions": 448, + "lines": 513, + "files": 5, + "dmm_unit_size": 0.7380952380952381, + "dmm_unit_complexity": 1.0, + "dmm_unit_interfacing": 0.7916666666666666, + "modified_files": [ + { + "old_path": "THANKS.txt", + "new_path": "THANKS.txt", + "filename": "THANKS.txt", + "extension": "txt", + "change_type": "MODIFY", + "diff": "@@ -15,3 +15,5 @@ Eric Firing for bugfixes.\n Arnd Baecker for 64-bit testing\n David Cooke for many code improvements including the auto-generated C-API\n Alexander Belopolsky (sasha) for Masked array bug-fixes and tests and rank-0 array improvements\n+Francesc Altet for unicode and nested record tests and help with nested records\n+Tim Hochberg for getting the build working on MSVC\n", + "added_lines": 2, + "deleted_lines": 0, + "source_code": "Travis Oliphant for the majority of code adaptation\nJim Hugunin, Paul Dubois, Konrad Hinsen, David Ascher, and many others for \n Numeric on which the code is based.\nPerry Greenfield, J Todd Miller, Rick White, Paul Barrett for Numarray\n which gave much inspiration and showed the way forward.\nPaul Dubois for Masked Arrays\nPearu Peterson for f2py and distutils and help with code organization\nRobert Kern for mtrand, bug fixes, help with distutils, and code organization\nEric Jones for sundry subroutines\nFernando Perez for code snippets, ideas, bufixes, and testing.\nJohn Hunter for code snippets (from matplotlib)\nChris Hanley for help with records.py, testing, and bug fixes.\nTravis Vaught and Joe Cooper for administration of numpy.org web site and SVN \nEric Firing for bugfixes.\nArnd Baecker for 64-bit testing\nDavid Cooke for many code improvements including the auto-generated C-API\nAlexander Belopolsky (sasha) for Masked array bug-fixes and tests and rank-0 array improvements\nFrancesc Altet for unicode and nested record tests and help with nested records\nTim Hochberg for getting the build working on MSVC\n", + "source_code_before": "Travis Oliphant for the majority of code adaptation\nJim Hugunin, Paul Dubois, Konrad Hinsen, David Ascher, and many others for \n Numeric on which the code is based.\nPerry Greenfield, J Todd Miller, Rick White, Paul Barrett for Numarray\n which gave much inspiration and showed the way forward.\nPaul Dubois for Masked Arrays\nPearu Peterson for f2py and distutils and help with code organization\nRobert Kern for mtrand, bug fixes, help with distutils, and code organization\nEric Jones for sundry subroutines\nFernando Perez for code snippets, ideas, bufixes, and testing.\nJohn Hunter for code snippets (from matplotlib)\nChris Hanley for help with records.py, testing, and bug fixes.\nTravis Vaught and Joe Cooper for administration of numpy.org web site and SVN \nEric Firing for bugfixes.\nArnd Baecker for 64-bit testing\nDavid Cooke for many code improvements including the auto-generated C-API\nAlexander Belopolsky (sasha) for Masked array bug-fixes and tests and rank-0 array improvements\n", + "methods": [], + "methods_before": [], + "changed_methods": [], + "nloc": null, + "complexity": null, + "token_count": null, + "diff_parsed": { + "added": [ + "Francesc Altet for unicode and nested record tests and help with nested records", + "Tim Hochberg for getting the build working on MSVC" + ], + "deleted": [] + } + }, + { + "old_path": "numpy/core/include/numpy/arrayobject.h", + "new_path": "numpy/core/include/numpy/arrayobject.h", + "filename": "arrayobject.h", + "extension": "h", + "change_type": "MODIFY", + "diff": "@@ -1466,22 +1466,22 @@ typedef struct {\n */\n \n #define PyArray_GETPTR1(obj, i) (void *)(PyArray_BYTES(obj) +\t\t\\\n-\t\t\t\t i*PyArray_STRIDE(obj, 0))\n-\n-#define PyArray_GETPTR2(obj, i, j) (void *)(PyArray_BYTES(obj) +\t\t\\\n-\t\t\t\t i*PyArray_STRIDE(obj, 0) +\t\\\n-\t\t\t\t j*PyArray_STRIDE(obj, 1))\n-\n-#define PyArray_GETPTR3(obj, i, j, k) (void *)(PyArray_BYTES(obj) +\t\t\\\n-\t\t\t\t i*PyArray_STRIDE(obj, 0) +\t\\\n-\t\t\t\t j*PyArray_STRIDE(obj, 1) +\t\\\n-\t\t\t\t k*PyArray_STRIDE(obj, 2))\t\\\n-\n-#define PyArray_GETPTR4(obj, i, j, k, l) (void *)(PyArray_BYTES(obj) +\t\t\\\n-\t\t\t\t\t i*PyArray_STRIDE(obj, 0) +\t\\\n-\t\t\t\t\t j*PyArray_STRIDE(obj, 1) +\t\\\n-\t\t\t\t\t k*PyArray_STRIDE(obj, 2) +\t\\\n-\t\t\t\t\t l*PyArray_STRIDE(obj, 3))\n+\t\t\t\t\t i*PyArray_STRIDE(obj, 0))\n+\n+#define PyArray_GETPTR2(obj, i, j) (void *)(PyArray_BYTES(obj) +\t\\\n+\t\t\t\t\t i*PyArray_STRIDE(obj, 0) +\t\\\n+\t\t\t\t\t j*PyArray_STRIDE(obj, 1))\n+\n+#define PyArray_GETPTR3(obj, i, j, k) (void *)(PyArray_BYTES(obj) +\t\\\n+\t\t\t\t\t i*PyArray_STRIDE(obj, 0) + \\\n+\t\t\t\t\t j*PyArray_STRIDE(obj, 1) + \\\n+\t\t\t\t\t k*PyArray_STRIDE(obj, 2)) \\\n+\n+#define PyArray_GETPTR4(obj, i, j, k, l) (void *)(PyArray_BYTES(obj) +\t\\\n+\t\t\t\t\t\t i*PyArray_STRIDE(obj, 0) + \\\n+\t\t\t\t\t\t j*PyArray_STRIDE(obj, 1) + \\\n+\t\t\t\t\t\t k*PyArray_STRIDE(obj, 2) + \\\n+\t\t\t\t\t\t l*PyArray_STRIDE(obj, 3))\n \n #define PyArray_DESCR_REPLACE(descr) do {\t\\\n \t\tPyArray_Descr *_new_;\t\t\t\\\n", + "added_lines": 16, + "deleted_lines": 16, + "source_code": "/* This expects the following variables to be defined (besides\n the usual ones from pyconfig.h\n\n SIZEOF_LONG_DOUBLE -- sizeof(long double) or sizeof(double) if no\n long double is present on platform.\n CHAR_BIT -- number of bits in a char (usually 8)\n (should be in limits.h)\n*/\n\n#ifndef Py_ARRAYOBJECT_H\n#define Py_ARRAYOBJECT_H\n#ifdef __cplusplus\n#define CONFUSE_EMACS {\n#define CONFUSE_EMACS2 }\nextern \"C\" CONFUSE_EMACS\n#undef CONFUSE_EMACS\n#undef CONFUSE_EMACS2\n/* ... otherwise a semi-smart idententer (like emacs) tries to indent\n everything when you're typing */\n#endif\n#include \"config.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 longlong NS(longlong)\n# define ulonglong NS(ulonglong)\n# define Bool NS(Bool)\n# define longdouble NS(longdouble)\n# define byte NS(byte)\n# define ubyte NS(ubyte)\n# define ushort NS(ushort)\n# define uint NS(uint)\n# define ulong NS(ulong)\n# define cfloat NS(cfloat)\n# define cdouble NS(cdouble)\n# define clongdouble NS(clongdouble)\n# define Int8 NS(Int8)\n# define UInt8 NS(UInt8)\n# define Int16 NS(Int16)\n# define UInt16 NS(UInt16)\n# define Int32 NS(Int32)\n# define UInt32 NS(UInt32)\n# define Int64 NS(Int64)\n# define UInt64 NS(UInt64)\n# define Int128 NS(Int128)\n# define UInt128 NS(UInt128)\n# define Int256 NS(Int256)\n# define UInt256 NS(UInt256)\n# define Float16 NS(Float16)\n# define Complex32 NS(Complex32)\n# define Float32 NS(Float32)\n# define Complex64 NS(Complex64)\n# define Float64 NS(Float64)\n# define Complex128 NS(Complex128)\n# define Float80 NS(Float80)\n# define Complex160 NS(Complex160)\n# define Float96 NS(Float96)\n# define Complex192 NS(Complex192)\n# define Float128 NS(Float128)\n# define Complex256 NS(Complex256)\n# define intp NS(intp)\n# define uintp NS(uintp)\n#endif\n\n/* There are several places in the code where an array of dimensions is */\n/* allocated statically. This is the size of that static allocation. */\n/* The array creation itself could have arbitrary dimensions but\n * all the places where static allocation is used would need to\n * be changed to dynamic (including inside of structures)\n */\n\n#define MAX_DIMS 32\n\n/* Used for Converter Functions \"O&\" code in ParseTuple */\n#define PY_FAIL 0\n#define PY_SUCCEED 1\n\n\t/* Helpful to distinguish what is installed */\n#define NDARRAY_VERSION 0x00090405\n\n\t/* Some platforms don't define bool, long long, or long double.\n\t Handle that here.\n\t */\n\n#ifdef PY_LONG_LONG\ntypedef PY_LONG_LONG longlong;\ntypedef unsigned PY_LONG_LONG ulonglong;\n# ifdef _MSC_VER\n# define LONGLONG_FMT \"I64d\"\n# define ULONGLONG_FMT \"I64u\"\n# define LONGLONG_SUFFIX(x) (x##i64)\n# define ULONGLONG_SUFFIX(x) (x##Ui64)\n# else\n\t/* #define LONGLONG_FMT \"lld\" Another possible variant\n #define ULONGLONG_FMT \"llu\"\n\n\t #define LONGLONG_FMT \"qd\" -- BSD perhaps?\n\t #define ULONGLONG_FMT \"qu\"\n\t*/\n# define LONGLONG_FMT \"Ld\"\n# define ULONGLONG_FMT \"Lu\"\n# define LONGLONG_SUFFIX(x) (x##LL)\n# define ULONGLONG_SUFFIX(x) (x##ULL)\n# endif\n#else\ntypedef long longlong;\ntypedef unsigned long ulonglong;\n# define LONGLONG_SUFFIX(x) (x##L)\n# define ULONGLONG_SUFFIX(x) (x##UL)\n#endif\n\ntypedef unsigned char Bool;\n#ifndef FALSE\n#define FALSE 0\n#endif\n#ifndef TRUE\n#define TRUE 1\n#endif\n\n#if SIZEOF_LONG_DOUBLE==SIZEOF_DOUBLE\n\ttypedef double longdouble;\n #define LONGDOUBLE_FMT \"g\"\n#else\n\ttypedef long double longdouble;\n #define LONGDOUBLE_FMT \"Lg\"\n#endif\n\n#ifndef Py_USING_UNICODE\n#error Must use Python with unicode enabled. \n#endif\n\n\ntypedef signed char byte;\ntypedef unsigned char ubyte;\n#ifndef _BSD_SOURCE\ntypedef unsigned short ushort;\ntypedef unsigned int uint;\ntypedef unsigned long ulong;\n#endif\n\ntypedef struct { float real, imag; } cfloat;\ntypedef struct { double real, imag; } cdouble;\ntypedef struct {longdouble real, imag;} clongdouble;\n\nenum PyArray_TYPES { PyArray_BOOL=0,\n PyArray_BYTE, PyArray_UBYTE,\n\t\t PyArray_SHORT, PyArray_USHORT,\n\t\t PyArray_INT, PyArray_UINT,\n\t\t\tPyArray_LONG, PyArray_ULONG,\n PyArray_LONGLONG, PyArray_ULONGLONG,\n\t\t\tPyArray_FLOAT, PyArray_DOUBLE, PyArray_LONGDOUBLE,\n\t\t\tPyArray_CFLOAT, PyArray_CDOUBLE, PyArray_CLONGDOUBLE,\n\t\t\tPyArray_OBJECT=17,\n PyArray_STRING, PyArray_UNICODE,\n\t\t\tPyArray_VOID,\n\t\t\tPyArray_NTYPES,\n\t\t\tPyArray_NOTYPE,\n\t\t\tPyArray_USERDEF=256 /* leave room for characters */\n};\n\n\t/* basetype array priority */\n#define PyArray_PRIORITY 0.0\n#define PyArray_BIG_PRIORITY 0.1\n\t/* default subtype priority */\n#define PyArray_SUBTYPE_PRIORITY 1.0\n\n\t/* How many floating point types are there */\n#define PyArray_NUM_FLOATTYPE 3\n\n\n\t/* We need to match intp to a signed integer of the same size as\n\t a pointer variable. uintp to the equivalent unsigned integer\n\t*/\n\n\n\t/* These characters correspond to the array type and the\n\t struct module */\n\n\t/* except 'p' -- signed integer for pointer type */\n\nenum PyArray_TYPECHAR { PyArray_BOOLLTR = '?',\n\t\t\tPyArray_BYTELTR = 'b',\n\t\t\tPyArray_UBYTELTR = 'B',\n\t\t\tPyArray_SHORTLTR = 'h',\n\t\t\tPyArray_USHORTLTR = 'H',\n\t\t\tPyArray_INTLTR = 'i',\n\t\t\tPyArray_UINTLTR = 'I',\n\t\t\tPyArray_LONGLTR = 'l',\n\t\t\tPyArray_ULONGLTR = 'L',\n\t\t\tPyArray_LONGLONGLTR = 'q',\n\t\t\tPyArray_ULONGLONGLTR = 'Q',\n\t\t\tPyArray_FLOATLTR = 'f',\n\t\t\tPyArray_DOUBLELTR = 'd',\n\t\t\tPyArray_LONGDOUBLELTR = 'g',\n\t\t\tPyArray_CFLOATLTR = 'F',\n\t\t\tPyArray_CDOUBLELTR = 'D',\n\t\t\tPyArray_CLONGDOUBLELTR = 'G',\n\t\t\tPyArray_OBJECTLTR = 'O',\n\t\t\tPyArray_STRINGLTR = 'S',\n\t\t\tPyArray_STRINGLTR2 = 'a',\n\t\t\tPyArray_UNICODELTR = 'U',\n\t\t PyArray_VOIDLTR = 'V',\n\n\t\t\t/* No Descriptor, just a define -- this let's\n\t\t\t Python users specify an array of integers\n\t\t\t large enough to hold a pointer on the platform*/\n\t\t\tPyArray_INTPLTR = 'p',\n\t\t\tPyArray_UINTPLTR = 'P',\n\n\t\t\tPyArray_GENBOOLLTR ='b',\n\t\t\tPyArray_SIGNEDLTR = 'i',\n\t\t\tPyArray_UNSIGNEDLTR = 'u',\n\t\t\tPyArray_FLOATINGLTR = 'f',\n\t\t\tPyArray_COMPLEXLTR = 'c'\n};\n\ntypedef enum {\n\tPyArray_QUICKSORT=0,\n\tPyArray_HEAPSORT=1,\n\tPyArray_MERGESORT=2,\n\tPyArray_TIMSORT=3 /* the sort Python uses -- specialized */\n} PyArray_SORTKIND;\n#define PyArray_NSORTS PyArray_TIMSORT + 1\n\n\t/* Define bit-width array types and typedefs */\n\n#define MAX_INT8 127\n#define MIN_INT8 -128\n#define MAX_UINT8 255\n#define MAX_INT16 32767\n#define MIN_INT16 -32768\n#define MAX_UINT16 65535\n#define MAX_INT32 2147483647\n#define MIN_INT32 (-MAX_INT32 - 1)\n#define MAX_UINT32 4294967295U\n#define MAX_INT64 LONGLONG_SUFFIX(9223372036854775807)\n#define MIN_INT64 (-MAX_INT64 - LONGLONG_SUFFIX(1))\n#define MAX_UINT64 ULONGLONG_SUFFIX(18446744073709551615)\n#define MAX_INT128 LONGLONG_SUFFIX(85070591730234615865843651857942052864)\n#define MIN_INT128 (-MAX_INT128 - LONGLONG_SUFFIX(1))\n#define MAX_UINT128 ULONGLONG_SUFFIX(170141183460469231731687303715884105728)\n#define MAX_INT256 LONGLONG_SUFFIX(57896044618658097711785492504343953926634992332820282019728792003956564819967)\n#define MIN_INT256 (-MAX_INT256 - LONGLONG_SUFFIX(1))\n#define MAX_UINT256 ULONGLONG_SUFFIX(115792089237316195423570985008687907853269984665640564039457584007913129639935)\n\n\t/* Need to find the number of bits for each type and\n\t make definitions accordingly.\n\n\t C states that sizeof(char) == 1 by definition\n\n\t So, just using the sizeof keyword won't help.\n\n\t It also looks like Python itself uses sizeof(char) quite a\n\t bit, which by definition should be 1 all the time.\n\n\t Idea: Make Use of CHAR_BIT which should tell us how many\n\t BITS per CHARACTER\n\t*/\n\n\t/* Include platform definitions -- These are in the C89/90 standard */\n#include \n#define MAX_BYTE SCHAR_MAX\n#define MIN_BYTE SCHAR_MIN\n#define MAX_UBYTE UCHAR_MAX\n#define MAX_SHORT SHRT_MAX\n#define MIN_SHORT SHRT_MIN\n#define MAX_USHORT USHRT_MAX\n#define MAX_INT INT_MAX\n#ifndef INT_MIN\n#define INT_MIN (-INT_MAX - 1)\n#endif\n#define MIN_INT INT_MIN\n#define MAX_UINT UINT_MAX\n#define MAX_LONG LONG_MAX\n#define MIN_LONG LONG_MIN\n#define MAX_ULONG ULONG_MAX\n\n#define SIZEOF_LONGDOUBLE SIZEOF_LONG_DOUBLE\n#define SIZEOF_LONGLONG SIZEOF_LONG_LONG\n#define BITSOF_BOOL sizeof(Bool)*CHAR_BIT\n#define BITSOF_CHAR CHAR_BIT\n#define BITSOF_SHORT (SIZEOF_SHORT*CHAR_BIT)\n#define BITSOF_INT (SIZEOF_INT*CHAR_BIT)\n#define BITSOF_LONG (SIZEOF_LONG*CHAR_BIT)\n#define BITSOF_LONGLONG (SIZEOF_LONGLONG*CHAR_BIT)\n#define BITSOF_FLOAT (SIZEOF_FLOAT*CHAR_BIT)\n#define BITSOF_DOUBLE (SIZEOF_DOUBLE*CHAR_BIT)\n#define BITSOF_LONGDOUBLE (SIZEOF_LONGDOUBLE*CHAR_BIT)\n\n\n#if BITSOF_LONG == 8\n#define PyArray_INT8 PyArray_LONG\n#define PyArray_UINT8 PyArray_ULONG\n\ttypedef long Int8;\n\ttypedef unsigned long UInt8;\n#define STRBITSOF_LONG \"8\"\n#elif BITSOF_LONG == 16\n#define PyArray_INT16 PyArray_LONG\n#define PyArray_UINT16 PyArray_ULONG\n\ttypedef long Int16;\n\ttypedef unsigned long UInt16;\n#define STRBITSOF_LONG \"16\"\n#elif BITSOF_LONG == 32\n#define PyArray_INT32 PyArray_LONG\n#define PyArray_UINT32 PyArray_ULONG\n\ttypedef long Int32;\n\ttypedef unsigned long UInt32;\n\ttypedef unsigned long PyArray_UCS4;\n#define STRBITSOF_LONG \"32\"\n#elif BITSOF_LONG == 64\n#define PyArray_INT64 PyArray_LONG\n#define PyArray_UINT64 PyArray_ULONG\n\ttypedef long Int64;\n\ttypedef unsigned long UInt64;\n#define STRBITSOF_LONG \"64\"\n#elif BITSOF_LONG == 128\n#define PyArray_INT128 PyArray_LONG\n#define PyArray_UINT128 PyArray_ULONG\n\ttypedef long Int128;\n\ttypedef unsigned long UInt128;\n#define STRBITSOF_LONG \"128\"\n#endif\n\n#if BITSOF_LONGLONG == 8\n# ifndef PyArray_INT8\n# define PyArray_INT8 PyArray_LONGLONG\n# define PyArray_UINT8 PyArray_ULONGLONG\n\ttypedef longlong Int8;\n\ttypedef ulonglong UInt8;\n# endif\n# define MAX_LONGLONG MAX_INT8\n# define MIN_LONGLONG MIN_INT8\n# define MAX_ULONGLONG MAX_UINT8\n#define STRBITSOF_LONGLONG \"8\"\n#elif BITSOF_LONGLONG == 16\n# ifndef PyArray_INT16\n# define PyArray_INT16 PyArray_LONGLONG\n# define PyArray_UINT16 PyArray_ULONGLONG\n\ttypedef longlong Int16;\n\ttypedef ulonglong UInt16;\n# endif\n# define MAX_LONGLONG MAX_INT16\n# define MIN_LONGLONG MIN_INT16\n# define MAX_ULONGLONG MAX_UINT16\n#define STRBITSOF_LONGLONG \"16\"\n#elif BITSOF_LONGLONG == 32\n# ifndef PyArray_INT32\n# define PyArray_INT32 PyArray_LONGLONG\n# define PyArray_UINT32 PyArray_ULONGLONG\n\ttypedef longlong Int32;\n\ttypedef ulonglong UInt32;\n\ttypedef ulonglong PyArray_UCS4;\n# endif\n# define MAX_LONGLONG MAX_INT32\n# define MIN_LONGLONG MIN_INT32\n# define MAX_ULONGLONG MAX_UINT32\n#define STRBITSOF_LONGLONG \"32\"\n#elif BITSOF_LONGLONG == 64\n# ifndef PyArray_INT64\n# define PyArray_INT64 PyArray_LONGLONG\n# define PyArray_UINT64 PyArray_ULONGLONG\n\ttypedef longlong Int64;\n\ttypedef ulonglong UInt64;\n# endif\n# define MAX_LONGLONG MAX_INT64\n# define MIN_LONGLONG MIN_INT64\n# define MAX_ULONGLONG MAX_UINT64\n#define STRBITSOF_LONGLONG \"64\"\n#elif BITSOF_LONGLONG == 128\n# ifndef PyArray_INT128\n# define PyArray_INT128 PyArray_LONGLONG\n# define PyArray_UINT128 PyArray_ULONGLONG\n\ttypedef longlong Int128;\n\ttypedef ulonglong UInt128;\n# endif\n# define MAX_LONGLONG MAX_INT128\n# define MIN_LONGLONG MIN_INT128\n# define MAX_ULONGLONG MAX_UINT128\n#define STRBITSOF_LONGLONG \"128\"\n#elif BITSOF_LONGLONG == 256\n# define PyArray_INT256 PyArray_LONGLONG\n# define PyArray_UINT256 PyArray_ULONGLONG\n\ttypedef longlong Int256;\n\ttypedef ulonglong UInt256;\n# define MAX_LONGLONG MAX_INT256\n# define MIN_LONGLONG MIN_INT256\n# define MAX_ULONGLONG MAX_UINT256\n#define STRBITSOF_LONGLONG \"256\"\n#endif\n\n#if BITSOF_INT == 8\n#ifndef PyArray_INT8\n#define PyArray_INT8 PyArray_INT\n#define PyArray_UINT8 PyArray_UINT\n\ttypedef int Int8;\n\ttypedef unsigned int UInt8;\n#endif\n#define STRBITSOF_INT \"8\"\n#elif BITSOF_INT == 16\n#ifndef PyArray_INT16\n#define PyArray_INT16 PyArray_INT\n#define PyArray_UINT16 PyArray_UINT\n\ttypedef int Int16;\n\ttypedef unsigned int UInt16;\n#endif\n#define STRBITSOF_INT \"16\"\n#elif BITSOF_INT == 32\n#ifndef PyArray_INT32\n#define PyArray_INT32 PyArray_INT\n#define PyArray_UINT32 PyArray_UINT\n\ttypedef int Int32;\n\ttypedef unsigned int UInt32;\n\ttypedef unsigned int PyArray_UCS4;\n#endif\n#define STRBITSOF_INT \"32\"\n#elif BITSOF_INT == 64\n#ifndef PyArray_INT64\n#define PyArray_INT64 PyArray_INT\n#define PyArray_UINT64 PyArray_UINT\n\ttypedef int Int64;\n\ttypedef unsigned int UInt64;\n#endif\n#define STRBITSOF_INT \"64\"\n#elif BITSOF_INT == 128\n#ifndef PyArray_INT128\n#define PyArray_INT128 PyArray_INT\n#define PyArray_UINT128 PyArray_UINT\n\ttypedef int Int128;\n\ttypedef unsigned int UInt128;\n#endif\n#define STRBITSOF_INT \"128\"\n#endif\n\n#if BITSOF_SHORT == 8\n#ifndef PyArray_INT8\n#define PyArray_INT8 PyArray_SHORT\n#define PyArray_UINT8 PyArray_USHORT\n\ttypedef short Int8;\n\ttypedef unsigned short UInt8;\n#endif\n#define STRBITSOF_SHORT \"8\"\n#elif BITSOF_SHORT == 16\n#ifndef PyArray_INT16\n#define PyArray_INT16 PyArray_SHORT\n#define PyArray_UINT16 PyArray_USHORT\n\ttypedef short Int16;\n\ttypedef unsigned short UInt16;\n#endif\n#define STRBITSOF_SHORT \"16\"\n#elif BITSOF_SHORT == 32\n#ifndef PyArray_INT32\n#define PyArray_INT32 PyArray_SHORT\n#define PyArray_UINT32 PyArray_USHORT\n\ttypedef short Int32;\n\ttypedef unsigned short UInt32;\n\ttypedef unsigned short PyArray_UCS4;\n#endif\n#define STRBITSOF_SHORT \"32\"\n#elif BITSOF_SHORT == 64\n#ifndef PyArray_INT64\n#define PyArray_INT64 PyArray_SHORT\n#define PyArray_UINT64 PyArray_USHORT\n\ttypedef short Int64;\n\ttypedef unsigned short UInt64;\n#endif\n#define STRBITSOF_SHORT \"64\"\n#elif BITSOF_SHORT == 128\n#ifndef PyArray_INT128\n#define PyArray_INT128 PyArray_SHORT\n#define PyArray_UINT128 PyArray_USHORT\n\ttypedef short Int128;\n\ttypedef unsigned short UInt128;\n#endif\n#define STRBITSOF_SHORT \"128\"\n#endif\n\n\n#if BITSOF_CHAR == 8\n#ifndef PyArray_INT8\n#define PyArray_INT8 PyArray_BYTE\n#define PyArray_UINT8 PyArray_UBYTE\n\ttypedef signed char Int8;\n\ttypedef unsigned char UInt8;\n#endif\n#define STRBITSOF_CHAR \"8\"\n#elif BITSOF_CHAR == 16\n#ifndef PyArray_INT16\n#define PyArray_INT16 PyArray_BYTE\n#define PyArray_UINT16 PyArray_UBYTE\n\ttypedef signed char Int16;\n\ttypedef unsigned char UInt16;\n#endif\n#define STRBITSOF_CHAR \"16\"\n#elif BITSOF_CHAR == 32\n#ifndef PyArray_INT32\n#define PyArray_INT32 PyArray_BYTE\n#define PyArray_UINT32 PyArray_UBYTE\n\ttypedef signed char Int32;\n\ttypedef unsigned char UInt32;\n\ttypedef unsigned char PyArray_UCS4;\n#endif\n#define STRBITSOF_CHAR \"32\"\n#elif BITSOF_CHAR == 64\n#ifndef PyArray_INT64\n#define PyArray_INT64 PyArray_BYTE\n#define PyArray_UINT64 PyArray_UBYTE\n\ttypedef signed char Int64;\n\ttypedef unsigned char UInt64;\n#endif\n#define STRBITSOF_CHAR \"64\"\n#elif BITSOF_CHAR == 128\n#ifndef PyArray_INT128\n#define PyArray_INT128 PyArray_BYTE\n#define PyArray_UINT128 PyArray_UBYTE\n\ttypedef signed char Int128;\n\ttypedef unsigned char UInt128;\n#endif\n#define STRBITSOF_CHAR \"128\"\n#endif\n\n\n\n#if BITSOF_DOUBLE == 16\n#define STRBITSOF_DOUBLE \"16\"\n#define STRBITSOF_CDOUBLE \"32\"\n#ifndef PyArray_FLOAT16\n#define PyArray_FLOAT16 PyArray_DOUBLE\n#define PyArray_COMPLEX32 PyArray_CDOUBLE\n\ttypedef double Float16;\n\ttypedef cdouble Complex32;\n#endif\n#elif BITSOF_DOUBLE == 32\n#define STRBITSOF_DOUBLE \"32\"\n#define STRBITSOF_CDOUBLE \"64\"\n#ifndef PyArray_FLOAT32\n#define PyArray_FLOAT32 PyArray_DOUBLE\n#define PyArray_COMPLEX64 PyArray_CDOUBLE\n\ttypedef double Float32;\n\ttypedef cdouble Complex64;\n#endif\n#elif BITSOF_DOUBLE == 64\n#define STRBITSOF_DOUBLE \"64\"\n#define STRBITSOF_CDOUBLE \"128\"\n#ifndef PyArray_FLOAT64\n#define PyArray_FLOAT64 PyArray_DOUBLE\n#define PyArray_COMPLEX128 PyArray_CDOUBLE\n\ttypedef double Float64;\n\ttypedef cdouble Complex128;\n#endif\n#elif BITSOF_DOUBLE == 80\n#define STRBITSOF_DOUBLE \"80\"\n#define STRBITSOF_CDOUBLE \"160\"\n#ifndef PyArray_FLOAT80\n#define PyArray_FLOAT80 PyArray_DOUBLE\n#define PyArray_COMPLEX160 PyArray_CDOUBLE\n\ttypedef double Float80;\n\ttypedef cdouble Complex160;\n#endif\n#elif BITSOF_DOUBLE == 96\n#define STRBITSOF_DOUBLE \"96\"\n#define STRBITSOF_CDOUBLE \"192\"\n#ifndef PyArray_FLOAT96\n#define PyArray_FLOAT96 PyArray_DOUBLE\n#define PyArray_COMPLEX192 PyArray_CDOUBLE\n\ttypedef double Float96;\n\ttypedef cdouble Complex192;\n#endif\n#elif BITSOF_DOUBLE == 128\n#define STRBITSOF_DOUBLE \"128\"\n#define STRBITSOF_CDOUBLE \"256\"\n#ifndef PyArray_FLOAT128\n#define PyArray_FLOAT128 PyArray_DOUBLE\n#define PyArray_COMPLEX256 PyArray_CDOUBLE\n\ttypedef double Float128;\n\ttypedef cdouble Complex256;\n#endif\n#endif\n\n\n\n#if BITSOF_FLOAT == 16\n#define STRBITSOF_FLOAT \"16\"\n#define STRBITSOF_CFLOAT \"32\"\n#ifndef PyArray_FLOAT16\n#define PyArray_FLOAT16 PyArray_FLOAT\n#define PyArray_COMPLEX32 PyArray_CFLOAT\n\ttypedef float Float16;\n\ttypedef cfloat Complex32;\n#endif\n#elif BITSOF_FLOAT == 32\n#define STRBITSOF_FLOAT \"32\"\n#define STRBITSOF_CFLOAT \"64\"\n#ifndef PyArray_FLOAT32\n#define PyArray_FLOAT32 PyArray_FLOAT\n#define PyArray_COMPLEX64 PyArray_CFLOAT\n\ttypedef float Float32;\n\ttypedef cfloat Complex64;\n#endif\n#elif BITSOF_FLOAT == 64\n#define STRBITSOF_FLOAT \"64\"\n#define STRBITSOF_CFLOAT \"128\"\n#ifndef PyArray_FLOAT64\n#define PyArray_FLOAT64 PyArray_FLOAT\n#define PyArray_COMPLEX128 PyArray_CFLOAT\n\ttypedef float Float64;\n\ttypedef cfloat Complex128;\n#endif\n#elif BITSOF_FLOAT == 80\n#define STRBITSOF_FLOAT \"80\"\n#define STRBITSOF_CFLOAT \"160\"\n#ifndef PyArray_FLOAT80\n#define PyArray_FLOAT80 PyArray_FLOAT\n#define PyArray_COMPLEX160 PyArray_CFLOAT\n\ttypedef float Float80;\n\ttypedef cfloat Complex160;\n#endif\n#elif BITSOF_FLOAT == 96\n#define STRBITSOF_FLOAT \"96\"\n#define STRBITSOF_CFLOAT \"192\"\n#ifndef PyArray_FLOAT96\n#define PyArray_FLOAT96 PyArray_FLOAT\n#define PyArray_COMPLEX192 PyArray_CFLOAT\n\ttypedef float Float96;\n\ttypedef cfloat Complex192;\n#endif\n#elif BITSOF_FLOAT == 128\n#define STRBITSOF_FLOAT \"128\"\n#define STRBITSOF_CFLOAT \"256\"\n#ifndef PyArray_FLOAT128\n#define PyArray_FLOAT128 PyArray_FLOAT\n#define PyArray_COMPLEX256 PyArray_CFLOAT\n\ttypedef float Float128;\n\ttypedef cfloat Complex256;\n#endif\n#endif\n\n\n#if BITSOF_LONGDOUBLE == 16\n#define STRBITSOF_LONGDOUBLE \"16\"\n#define STRBITSOF_CLONGDOUBLE \"32\"\n#ifndef PyArray_FLOAT16\n#define PyArray_FLOAT16 PyArray_LONGDOUBLE\n#define PyArray_COMPLEX32 PyArray_CLONGDOUBLE\n\ttypedef longdouble Float16;\n\ttypedef clongdouble Complex32;\n#endif\n#elif BITSOF_LONGDOUBLE == 32\n#define STRBITSOF_LONGDOUBLE \"32\"\n#define STRBITSOF_CLONGDOUBLE \"64\"\n#ifndef PyArray_FLOAT32\n#define PyArray_FLOAT32 PyArray_LONGDOUBLE\n#define PyArray_COMPLEX64 PyArray_CLONGDOUBLE\n\ttypedef longdouble Float32;\n\ttypedef clongdouble Complex64;\n#endif\n#elif BITSOF_LONGDOUBLE == 64\n#define STRBITSOF_LONGDOUBLE \"64\"\n#define STRBITSOF_CLONGDOUBLE \"128\"\n#ifndef PyArray_FLOAT64\n#define PyArray_FLOAT64 PyArray_LONGDOUBLE\n#define PyArray_COMPLEX128 PyArray_CLONGDOUBLE\n\ttypedef longdouble Float64;\n\ttypedef clongdouble Complex128;\n#endif\n#elif BITSOF_LONGDOUBLE == 80\n#define STRBITSOF_LONGDOUBLE \"80\"\n#define STRBITSOF_CLONGDOUBLE \"160\"\n#ifndef PyArray_FLOAT80\n#define PyArray_FLOAT80 PyArray_LONGDOUBLE\n#define PyArray_COMPLEX160 PyArray_CLONGDOUBLE\n\ttypedef longdouble Float80;\n\ttypedef clongdouble Complex160;\n#endif\n#elif BITSOF_LONGDOUBLE == 96\n#define STRBITSOF_LONGDOUBLE \"96\"\n#define STRBITSOF_CLONGDOUBLE \"192\"\n#ifndef PyArray_FLOAT96\n#define PyArray_FLOAT96 PyArray_LONGDOUBLE\n#define PyArray_COMPLEX192 PyArray_CLONGDOUBLE\n\ttypedef longdouble Float96;\n\ttypedef clongdouble Complex192;\n#endif\n#elif BITSOF_LONGDOUBLE == 128\n#define STRBITSOF_LONGDOUBLE \"128\"\n#define STRBITSOF_CLONGDOUBLE \"256\"\n#ifndef PyArray_FLOAT128\n#define PyArray_FLOAT128 PyArray_LONGDOUBLE\n#define PyArray_COMPLEX256 PyArray_CLONGDOUBLE\n\ttypedef longdouble Float128;\n\ttypedef clongdouble Complex256;\n#endif\n#elif BITSOF_LONGDOUBLE == 256\n#define STRBITSOF_LONGDOUBLE \"256\"\n#define STRBITSOF_CLONGDOUBLE \"512\"\n#define PyArray_FLOAT256 PyArray_LONGDOUBLE\n#define PyArray_COMPLEX512 PyArray_CLONGDOUBLE\n\ttypedef longdouble Float256;\n\ttypedef clongdouble Complex512;\n#endif\n\n\n\t/* End of typedefs for numarray style bit-width names */\n\n/* This is to typedef Intp to the appropriate pointer size for this platform.\n * Py_intptr_t, Py_uintptr_t are defined in pyport.h. */\ntypedef Py_intptr_t intp;\ntypedef Py_uintptr_t uintp;\n#define SIZEOF_INTP SIZEOF_PY_INTPTR_T\n#define SIZEOF_UINTP SIZEOF_PY_INTPTR_T\n\n#define INTP_FMT \"d\"\n\n#if SIZEOF_PY_INTPTR_T == SIZEOF_INT\n\t#define PyArray_INTP PyArray_INT\n\t#define PyArray_UINTP PyArray_UINT\n #define PyIntpArrType_Type PyIntArrType_Type\n #define PyUIntpArrType_Type PyUIntArrType_Type\n\t#define MAX_INTP MAX_INT\n\t#define MIN_INTP MIN_INT\n\t#define MAX_UINTP MAX_UINT\n#elif SIZEOF_PY_INTPTR_T == SIZEOF_LONG\n\t#define PyArray_INTP PyArray_LONG\n\t#define PyArray_UINTP PyArray_ULONG\n #define PyIntpArrType_Type PyLongArrType_Type\n #define PyUIntpArrType_Type PyULongArrType_Type\n\t#define MAX_INTP MAX_LONG\n\t#define MIN_INTP MIN_LONG\n\t#define MAX_UINTP MAX_ULONG\n #undef INTP_FMT\n #define INTP_FMT \"ld\"\n#elif defined(PY_LONG_LONG) && (SIZEOF_PY_INTPTR_T == SIZEOF_LONG_LONG)\n\t#define PyArray_INTP PyArray_LONGLONG\n\t#define PyArray_UINTP PyArray_ULONGLONG\n #define PyIntpArrType_Type PyLongLongArrType_Type\n #define PyUIntpArrType_Type PyULongLongArrType_Type\n\t#define MAX_INTP MAX_LONGLONG\n\t#define MIN_INTP MIN_LONGLONG\n\t#define MAX_UINTP MAX_ULONGLONG\n #undef INTP_FMT\n #define INTP_FMT \"Ld\"\n#endif\n\n#define ERR(str) fprintf(stderr, #str); fflush(stderr);\n#define ERR2(str) fprintf(stderr, str); fflush(stderr);\n\n /* Macros to define how array, and dimension/strides data is\n allocated.\n */\n\n /* Data buffer */\n#define PyDataMem_NEW(size) ((char *)malloc(size))\n /* #define PyArrayMem_NEW(size) PyMem_NEW(char, size)*/\n#define PyDataMem_FREE(ptr) free(ptr)\n /* #define PyArrayMem_FREE(ptr) PyMem_Free(ptr) */\n#define PyDataMem_RENEW(ptr,size) ((char *)realloc(ptr,size))\n\n#define PyArray_USE_PYMEM 0\n\n#if PyArray_USE_PYMEM == 1\n#define _pya_malloc PyObject_Malloc\n#define _pya_free PyObject_Free\n#define _pya_realloc PyObject_Realloc\n#else\n#define _pya_malloc malloc\n#define _pya_free free\n#define _pya_realloc realloc\n#endif\n\n/* Dimensions and strides */\n#define PyDimMem_NEW(size) ((intp *)_pya_malloc(size*sizeof(intp)))\n#define PyDimMem_FREE(ptr) _pya_free(ptr)\n#define PyDimMem_RENEW(ptr,size) ((intp *)_pya_realloc(ptr,size*sizeof(intp)))\n\n\n /* These must deal with unaligned and swapped data if necessary */\ntypedef PyObject * (PyArray_GetItemFunc) (void *, void *);\ntypedef int (PyArray_SetItemFunc)(PyObject *, void *, void *);\n\ntypedef void (PyArray_CopySwapNFunc)(void *, void *, intp, int, int);\ntypedef void (PyArray_CopySwapFunc)(void *, void *, int, int);\ntypedef Bool (PyArray_NonzeroFunc)(void *, void *);\n\n\n /* These assume aligned and notswapped data -- a buffer will be\n used before or contiguous data will be obtained\n */\ntypedef int (PyArray_CompareFunc)(const void *, const void *, void *);\ntypedef int (PyArray_ArgFunc)(void*, intp, intp*, void *);\ntypedef void (PyArray_DotFunc)(void *, intp, void *, intp, void *, intp,\n\t\t\t void *);\ntypedef void (PyArray_VectorUnaryFunc)(void *, void *, intp, void *, void *);\ntypedef int (PyArray_ScanFunc)(FILE *, void *, void *, void *);\ntypedef int (PyArray_FromStrFunc)(char *, void *, char **, void *);\n\ntypedef int (PyArray_FillFunc)(void *, intp, void *);\n\ntypedef int (PyArray_SortFunc)(void *, intp, void *);\ntypedef int (PyArray_ArgSortFunc)(void *, intp *, intp, void *);\n\ntypedef struct {\n intp *ptr;\n int len;\n} PyArray_Dims;\n\ntypedef struct {\n\t/* Functions to cast to all other standard types*/\n\tPyArray_VectorUnaryFunc *cast[PyArray_NTYPES];\n\n\t/* Functions to get and set items with standard\n\t Python types -- not array scalars */\n\tPyArray_GetItemFunc *getitem;\n\tPyArray_SetItemFunc *setitem;\n\n\t/* Copy and/or swap data. Memory areas may not overlap */\n\t/* Use memmove first if they might */\n\tPyArray_CopySwapNFunc *copyswapn;\n PyArray_CopySwapFunc *copyswap;\n\n\t/* Function to compare items */\n\tPyArray_CompareFunc *compare;\n\n\t/* Function to select largest */\n\tPyArray_ArgFunc *argmax;\n\n\t/* Function to compute dot product */\n\tPyArray_DotFunc\t*dotfunc;\n\n\t/* Function to scan an ASCII file and\n\t place a single value plus possible separator */\n\tPyArray_ScanFunc *scanfunc;\n\n\t/* Function to read a single value from a string */\n\t/* and adjust the pointer */\n\tPyArray_FromStrFunc *fromstr;\n\n\t/* Function to determine if data is zero or not */\n\tPyArray_NonzeroFunc *nonzero;\n\n\t/* Used for arange */\n\tPyArray_FillFunc *fill;\n\n\t/* Sorting functions */\n\tPyArray_SortFunc *sort[PyArray_NSORTS];\n\tPyArray_ArgSortFunc *argsort[PyArray_NSORTS];\n\n} PyArray_ArrFuncs;\n\n\ntypedef struct {\n\tPyObject_HEAD\n\tPyTypeObject *typeobj; /* the type object representing an\n\t\t\t\t intance of this type */\n\tchar kind; /* kind for this type */\n\tchar type; /* unique-character representing this type */\n\tchar byteorder; /* '>' (big), '<' (little), '|'\n\t\t\t\t (not-applicable), or '=' (native). */\n char hasobject; /* non-zero if it has object arrays in fields */\n\tint type_num; /* number representing this type */\n\tint elsize; /* element size for this type */\n\tint alignment; /* alignment needed for this type */\n\tstruct _arr_descr\t\t\t\t\t\\\n\t*subarray; /* Non-NULL if this type is\n\t\t\t\t is an array (C-contiguous)\n\t\t\t\t of some other type\n\t\t\t\t*/\n\tPyObject *fields; /* The fields dictionary for this type */\n\t /* For statically defined descr this\n\t\t\t\t is always Py_None */\n\n\tPyArray_ArrFuncs *f; /* a table of functions specific for each\n\t\t\t\t basic data descriptor */\n} PyArray_Descr;\n\ntypedef struct _arr_descr {\n\tPyArray_Descr *base;\n\tPyObject *shape; /* a tuple */\n} PyArray_ArrayDescr;\n\n\n/*\n The main array object structure. It is recommended to use the macros\n defined below (PyArray_DATA and friends) access fields here, instead\n of the members themselves.\n */\n\ntypedef struct PyArrayObject {\n\tPyObject_HEAD\n\tchar *data; /* pointer to raw data buffer */\n\tint nd; /* number of dimensions, also called ndim */\n\tintp *dimensions; /* size in each dimension */\n intp *strides; /* bytes to jump to get to the\n\t\t\t\t next element in each dimension */\n\tPyObject *base; /* This object should be decref'd\n\t\t\t\t upon deletion of array */\n\t /* For views it points to the original array */\n\t /* For creation from buffer object it points\n\t\t\t\t to an object that shold be decref'd on\n\t\t\t\t deletion */\n\t /* For UPDATEIFCOPY flag this is an array\n\t\t\t\t to-be-updated upon deletion of this one */\n\tPyArray_Descr *descr; /* Pointer to type structure */\n\tint flags; /* Flags describing array -- see below*/\n\tPyObject *weakreflist; /* For weakreferences */\n} PyArrayObject;\n\n#define fortran fortran_ /* For some compilers */\n\n/* Mirrors buffer object to ptr */\n\ntypedef struct {\n PyObject_HEAD\n PyObject *base;\n void *ptr;\n intp len;\n int flags;\n} PyArray_Chunk;\n\n/* Array flags */\n\n/* Means c-style contiguous (last index varies the fastest). The\n data elements right after each other. */\n#define CONTIGUOUS 0x0001\n/* set if array is a contiguous Fortran array: the first index\n varies the fastest in memory (strides array is reverse of\n C-contiguous array)*/\n#define FORTRAN 0x0002\n\n/*\n Note: all 0-d arrays are CONTIGUOUS and FORTRAN contiguous. If a\n 1-d array is CONTIGUOUS it is also FORTRAN contiguous\n*/\n\n/* If set, the array owns the data: it will be free'd when the array\n is deleted. */\n#define OWNDATA 0x0004\n#define OWN_DATA OWNDATA\n\n/* An array never has these three set; they're only used as parameter\n flags to the the various FromAny functions */\n/* Cause a cast to occur regardless of whether or not it is safe. */\n#define FORCECAST 0x0010\n/* Always copy the array. Returned arrays are always CONTIGUOUS, ALIGNED,\n and WRITEABLE. */\n#define ENSURECOPY 0x0020\n/* Make sure the returned array is an ndarray or a bigndarray */\n#define ENSUREARRAY 0x0040\n\n/* Array data is aligned on the appropiate memory address for the\n type stored (e.g., an array of doubles (8 bytes each) starts on\n a memory address that's a multiple of 8) */\n#define ALIGNED 0x0100\n/* Array data has the native endianness */\n#define NOTSWAPPED 0x0200\n/* Array data is writeable */\n#define WRITEABLE 0x0400\n/* If this flag is set, then base contains a pointer to an array of\n the same size that should be updated with the current contents of\n this array when this array is deallocated\n*/\n#define UPDATEIFCOPY 0x1000\n\n\n#define BEHAVED_FLAGS ALIGNED | WRITEABLE\n#define BEHAVED_NS_FLAGS ALIGNED | WRITEABLE | NOTSWAPPED\n#define CARRAY_FLAGS CONTIGUOUS | BEHAVED_FLAGS\n#define CARRAY_FLAGS_RO CONTIGUOUS | ALIGNED\n#define FARRAY_FLAGS FORTRAN | BEHAVED_FLAGS\n#define FARRAY_FLAGS_RO FORTRAN | ALIGNED\n#define DEFAULT_FLAGS CARRAY_FLAGS\n\n#define UPDATE_ALL_FLAGS CONTIGUOUS | FORTRAN | ALIGNED\n\n\n/* Size of internal buffers used for alignment */\n#define PyArray_BUFSIZE 10000\n#define PyArray_MIN_BUFSIZE 5\n#define PyArray_MAX_BUFSIZE 100000000\n\n/*\n * C API: consists of Macros and functions. The MACROS are defined here.\n */\n\n\n#define PyArray_CHKFLAGS(m, FLAGS) \\\n\t((((PyArrayObject *)(m))->flags & (FLAGS)) == (FLAGS))\n#define PyArray_ISCONTIGUOUS(m) PyArray_CHKFLAGS(m, CONTIGUOUS)\n#define PyArray_ISWRITEABLE(m) PyArray_CHKFLAGS(m, WRITEABLE)\n#define PyArray_ISALIGNED(m) PyArray_CHKFLAGS(m, ALIGNED)\n\n#ifndef MAX\n#define MAX(a,b) (((a)>(b))?(a):(b))\n#endif\n#ifndef MIN\n#define MIN(a,b) (((a)<(b))?(a):(b))\n#endif\n\n/* Useful if a and b have to be evaluated. */\n\n#define tMAX(a,b,typ) {typ _x_=(a); typ _y_=(b); _x_>_y_ ? _x_ : _y_}\n#define tMIN(a,b,typ) {typ _x_=(a); typ _y_=(b); _x_<_y_ ? _x_ : _y_}\n\n#if defined(ALLOW_THREADS)\n#define BEGIN_THREADS_DEF PyThreadState *_save;\n#define BEGIN_THREADS _save = PyEval_SaveThread();\n#define END_THREADS PyEval_RestoreThread(_save);\n#define ALLOW_C_API_DEF PyGILState_STATE __save__;\n#define ALLOW_C_API __save__ = PyGILState_Ensure();\n#define DISABLE_C_API PyGILState_Release(__save__);\n#else\n#define BEGIN_THREADS_DEF\n#define BEGIN_THREADS\n#define END_THREADS\n#define ALLOW_C_API_DEF\n#define\tALLOW_C_API\n#define\tDISABLE_C_API\n#endif\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\ntypedef struct {\n PyObject_HEAD\n\tint nd_m1; /* number of dimensions - 1 */\n intp\t\t index, size;\n\tintp coordinates[MAX_DIMS];/* N-dimensional loop */\n intp dims_m1[MAX_DIMS]; /* ao->dimensions - 1 */\n\tintp strides[MAX_DIMS]; /* ao->strides or fake */\n\tintp backstrides[MAX_DIMS];/* how far to jump back */\n\tintp factors[MAX_DIMS]; /* shape factors */\n\tPyArrayObject *ao;\n\tchar *dataptr; /* pointer to current item*/\n Bool contiguous;\n} PyArrayIterObject;\n\n\n/* Iterator API */\n#define PyArrayIter_Check(op) PyObject_TypeCheck(op, &PyArrayIter_Type)\n\n#define PyArray_ITER_RESET(it) {\t\t\t\t\t\\\n\tit->index = 0;\t\t\t\t\t\t \\\n\tit->dataptr = it->ao->data;\t\t\t\t\t\\\n\tmemset(it->coordinates, 0, (it->nd_m1+1)*sizeof(intp));\t\t\\\n}\n\n#define _PyArray_ITER_NEXT1(it) {\t\t\\\n\t\tit->dataptr += it->strides[0];\t\\\n\t\tit->coordinates[0]++;\t\t\\\n\t}\n\n#define _PyArray_ITER_NEXT2(it) {\t\t\t\t\t\\\n\t\tif (it->coordinates[1] < it->dims_m1[1]) {\t\t\\\n\t\t\tit->coordinates[1]++;\t\t\t\t\\\n\t\t\tit->dataptr += it->strides[1];\t\t\t\\\n\t\t}\t\t\t\t\t\t\t\\\n\t\telse {\t\t\t\t\t\t\t\\\n\t\t\tit->coordinates[1] = 0;\t\t\t\t\\\n\t\t\tit->coordinates[0]++;\t\t\t\t\\\n\t\t\tit->dataptr += it->strides[0] -\t\t\t\\\n\t\t\t\tit->backstrides[1];\t\t\t\\\n\t\t}\t\t\t\t\t\t\t\\\n\t}\n\n#define PyArray_ITER_NEXT(it) {\t\t\t\t\t\t\\\n\tit->index++;\t\t\t\t\t\t \\\n if (it->nd_m1 == 0) {\t\t\t\t\t\t\\\n\t\t_PyArray_ITER_NEXT1(it);\t\t\t\t\\\n\t}\t\t\t\t\t\t\t\t\\\n\telse if (it->contiguous) it->dataptr += it->ao->descr->elsize; \\\n\telse if (it->nd_m1 == 1) {\t\t\t\t\t\\\n\t\t_PyArray_ITER_NEXT2(it);\t\t\t\t\\\n\t}\t\t\t\t\t\t\t\t\\\n\telse {\t\t\t\t\t\t\t\t\\\n\t\tint _i_;\t\t\t\t\t\t\\\n\t\tfor (_i_ = it->nd_m1; _i_ >= 0; _i_--) {\t\t\\\n\t\t\tif (it->coordinates[_i_] <\t\t\t\\\n\t\t\t it->dims_m1[_i_]) {\t\t\t\t\\\n\t\t\t\tit->coordinates[_i_]++;\t\t\t\\\n\t\t\t\tit->dataptr += it->strides[_i_];\t\\\n\t\t\t\tbreak;\t\t\t\t\t\\\n\t\t\t}\t\t\t\t\t\t\\\n\t\t\telse {\t\t\t\t\t\t\\\n\t\t\t\tit->coordinates[_i_] = 0;\t\t\\\n\t\t\t\tit->dataptr -= it->backstrides[_i_];\t\\\n\t\t\t}\t\t\t\t\t\t\\\n\t\t}\t\t\t\t\t\t\t\\\n\t}\t\t\t\t\t\t\t\t\\\n}\n\n#define PyArray_ITER_GOTO(it, destination) {\t\t\t\t\\\n\t\tint _i_;\t\t\t\t\t\t\\\n\t\tit->index = 0;\t\t\t\t\t\t\\\n\t\tit->dataptr = it->ao->data;\t\t\t\t\\\n\t\tfor (_i_ = it->nd_m1; _i_>=0; _i_--) {\t\t\t\\\n\t\t\tit->dataptr += destination[_i_] *\t\t\\\n\t\t\t\tit->strides[_i_];\t\t\t\\\n\t\t\tit->coordinates[_i_] = destination[_i_];\t\\\n\t\t\tit->index += destination[_i_] *\t\t\t\\\n\t\t\t\t( _i_==it->nd_m1 ? 1 :\t\t\t\\\n\t\t\t\t it->dims_m1[i+1]+1) ;\t\t \\\n\t\t}\t\t\t\t\t\t\t\\\n\t}\n\n#define PyArray_ITER_GOTO1D(it, ind) { \\\n\t\tint _i_;\t\t\t\t\t\t\\\n\t\tintp _lind_ = (intp) (ind);\t\t\t\t\\\n\t\tit->index = _lind_;\t\t\t\t\t\\\n if (it->nd_m1 == 0) { \\\n it->dataptr = it->ao->data + (ind) * \\\n it->strides[0]; \\\n } \\\n else if (it->contiguous) \\\n\t\t\tit->dataptr = it->ao->data + (ind) *\t\t\\\n\t\t\t\tit->ao->descr->elsize;\t\t\t\\\n\t\telse {\t\t\t\t\t\t\t\\\n\t\t\tit->dataptr = it->ao->data;\t\t\t\\\n\t\t\tfor (_i_ = 0; _i_<=it->nd_m1; _i_++) {\t\t\\\n\t\t\t\tit->dataptr += (_lind_ / it->factors[_i_]) \\\n\t\t\t\t\t* it->strides[_i_];\t\t\\\n\t\t\t\t_lind_ %= it->factors[_i_];\t\t\\\n\t\t\t}\t\t\t\t\t\t\\\n\t\t}\t\t\t\t\t\t\t\\\n}\n\n#define PyArray_ITER_DATA(it) ((PyArrayIterObject *)it)->dataptr\n\n\n/*\n Any object passed to PyArray_Broadcast must be binary compatible with\n this structure.\n*/\n\ntypedef struct {\n\tPyObject_HEAD\n\n\tint numiter; /* number of iters */\n\tintp size; /* broadcasted size */\n\tintp index; /* current index */\n\tint nd; /* number of dims */\n\tintp dimensions[MAX_DIMS]; /* dimensions */\n\tPyArrayIterObject *iters[MAX_DIMS]; /* iterators */\n} PyArrayMultiIterObject;\n\n#define PyArray_MultiIter_RESET(multi) {\t\t\t \\\n\t\tint _mi_;\t\t\t\t\t \\\n\t\tPyArrayMultiIterObject *_mul_ = (multi);\t \\\n\t\t_mul_->index = 0;\t\t\t\t \\\n\t\tfor (_mi_ = 0; _mi_ < _mul_->numiter; _mi_++) {\t \\\n\t\t\tPyArray_ITER_RESET(_mul_->iters[_mi_]);\t \\\n\t\t}\t\t\t\t\t\t \\\n\t}\n\n#define PyArray_MultiIter_NEXT(multi) {\t\t\t\t \\\n\t\tint _mi_;\t\t\t\t\t \\\n\t\tPyArrayMultiIterObject *_mul_ = (multi);\t \\\n\t\t_mul_->index += 1;\t\t\t\t \\\n\t\tfor (_mi_=0; _mi_<_mul_->numiter; _mi_++) {\t \\\n\t\t\tPyArray_ITER_NEXT(_mul_->iters[_mi_]);\t \\\n\t\t}\t\t\t\t\t\t \\\n\t}\n\n#define PyArray_MultiIter_GOTO(multi, dest) {\t\t\t\t\\\n\t\tint _mi_;\t\t\t\t\t\t\\\n\t\tPyArrayMultiIterObject *_mul_ = (multi);\t\t\\\n\t\tfor (_mi_=0; _mi_<_mul_->numiter; _mi_++) {\t\t\\\n\t\t\tPyArray_ITER_GOTO(_mul_->iters[_mi_], dest);\t\\\n\t\t}\t\t\t\t\t\t\t\\\n\t\t_mul_->index = _mul_->iters[0]->index;\t\t\t\\\n\t}\n\n#define PyArray_MultiIter_GOTO1D(multi, ind) {\t\t\t\t\\\n\t\tint _mi_;\t\t\t\t\t\t\\\n\t\tPyArrayMultiIterObject *_mul_ = (multi);\t\t\\\n\t\tfor (_mi_=0; _mi_<_mul_->numiter; _mi_++) {\t\t\\\n\t\t\tPyArray_ITER_GOTO1D(_mul_->iters[_mi_], ind);\t\\\n\t\t}\t\t\t\t\t\t\t\\\n\t\t_mul_->index = _mul_->iters[0]->index;\t\t\t\\\n\t}\n\n#define PyArray_MultiIter_DATA(multi, i) \\\n\t((PyArrayMultiIterObject *)multi)->iters[i]->dataptr\n\n#define PyArray_MultiIter_SIZE(multi) \\\n\t((PyArrayMultiIterObject *)multi)->size;\n\n\n/* Store the information needed for fancy-indexing over an array */\n\ntypedef struct {\n\tPyObject_HEAD\n\t/* Multi-iterator portion --- needs to be present in this order to\n\t work with PyArray_Broadcast */\n\n\tint numiter; /* number of index-array\n\t\t\t\t\t\t\t iterators */\n\tintp size; /* size of broadcasted\n\t\t\t\t\t\t\t result */\n\tintp index; /* current index */\n\tint nd; /* number of dims */\n\tintp dimensions[MAX_DIMS]; /* dimensions */\n\tPyArrayIterObject *iters[MAX_DIMS]; /* index object\n\t\t\t\t\t\t\t iterators */\n\tPyArrayIterObject *ait; /* flat Iterator for\n\t\t\t\t\t\t\t underlying array */\n\n\t/* flat iterator for subspace (when numiter < nd) */\n\tPyArrayIterObject *subspace;\n\n\t/* if subspace iteration, then this is the array of\n\t axes in the underlying array represented by the\n\t index objects */\n\tint iteraxes[MAX_DIMS];\n\t/* if subspace iteration, the these are the coordinates\n\t to the start of the subspace.\n\t*/\n\tintp bscoord[MAX_DIMS];\n\n\tPyObject *indexobj; /* reference to\n\t\t\t\t\t\t\t creating obj */\n\tint view;\n\tint consec;\n\tchar *dataptr;\n\n} PyArrayMapIterObject;\n\n/* All sorts of useful ways to look into a PyArrayObject.\n These are the recommended over casting to PyArrayObject and accessing\n the members directly.\n */\n\n#define PyArray_NDIM(obj) (((PyArrayObject *)(obj))->nd)\n#define PyArray_ISONESEGMENT(m) (PyArray_NDIM(m) == 0 || PyArray_CHKFLAGS(m, CONTIGUOUS) || \\\n\t\t\t\t PyArray_CHKFLAGS(m, FORTRAN))\n#define PyArray_ISFORTRAN(m) (PyArray_CHKFLAGS(m, FORTRAN) && (PyArray_NDIM(m) > 1))\n#define FORTRAN_IF(m) ((PyArray_CHKFLAGS(m, FORTRAN) ? FORTRAN : 0))\n#define PyArray_DATA(obj) ((void *)(((PyArrayObject *)(obj))->data))\n#define PyArray_BYTES(obj) (((PyArrayObject *)(obj))->data)\n#define PyArray_DIMS(obj) (((PyArrayObject *)(obj))->dimensions)\n#define PyArray_STRIDES(obj) (((PyArrayObject *)(obj))->strides)\n#define PyArray_DIM(obj,n) (((PyArrayObject *)(obj))->dimensions[n])\n#define PyArray_STRIDE(obj,n) (((PyArrayObject *)(obj))->strides[n])\n#define PyArray_BASE(obj) (((PyArrayObject *)(obj))->base)\n#define PyArray_DESCR(obj) (((PyArrayObject *)(obj))->descr)\n#define PyArray_FLAGS(obj) (((PyArrayObject *)(obj))->flags)\n#define PyArray_ITEMSIZE(obj) (((PyArrayObject *)(obj))->descr->elsize)\n#define PyArray_TYPE(obj) (((PyArrayObject *)(obj))->descr->type_num)\n#define PyArray_GETITEM(obj,itemptr)\t\t\t\\\n\t((PyArrayObject *)(obj))->descr->getitem((char *)itemptr,\t\\\n\t\t\t\t\t\t (PyArrayObject *)obj);\n#define PyArray_SETITEM(obj,itemptr,v)\t\t\t\t\t\\\n\t(obj)->descr->setitem((PyObject *)v,(char *)(itemptr),\t\t\\\n\t\t\t (PyArrayObject *)(obj));\n\n\n#define PyTypeNum_ISBOOL(type) (type == PyArray_BOOL)\n#define PyTypeNum_ISUNSIGNED(type) ((type == PyArray_UBYTE) || \\\n\t\t\t\t (type == PyArray_USHORT) || \\\n\t\t\t\t (type == PyArray_UINT) ||\t\\\n\t\t\t\t (type == PyArray_ULONG) || \\\n\t\t\t\t (type == PyArray_ULONGLONG))\n\n#define PyTypeNum_ISSIGNED(type) ((type == PyArray_BYTE) ||\t\\\n\t\t\t (type == PyArray_SHORT) ||\t\\\n\t\t\t (type == PyArray_INT) ||\t\\\n\t\t\t (type == PyArray_LONG) ||\t\\\n\t\t\t (type == PyArray_LONGLONG))\n\n#define PyTypeNum_ISINTEGER(type) ((type >= PyArray_BYTE) &&\t\\\n\t\t\t\t(type <= PyArray_ULONGLONG))\n\n#define PyTypeNum_ISFLOAT(type) ((type >= PyArray_FLOAT) && \\\n\t\t\t (type <= PyArray_LONGDOUBLE))\n\n#define PyTypeNum_ISNUMBER(type) (type <= PyArray_CLONGDOUBLE)\n\n#define PyTypeNum_ISSTRING(type) ((type == PyArray_UCHAR) || \\\n\t\t\t (type == PyArray_UNICODE))\n\n#define PyTypeNum_ISCOMPLEX(type) ((type >= PyArray_CFLOAT) && \\\n\t\t\t\t(type <= PyArray_CLONGDOUBLE))\n\n#define PyTypeNum_ISPYTHON(type) ((type == PyArray_LONG) || \\\n\t\t\t\t (type == PyArray_DOUBLE) ||\t\\\n\t\t\t\t (type == PyArray_CDOUBLE) ||\t\\\n\t\t (type == PyArray_BOOL) || \\\n\t\t\t\t (type == PyArray_OBJECT ))\n\n#define PyTypeNum_ISFLEXIBLE(type) ((type>=PyArray_STRING) && \\\n\t\t\t\t (type<=PyArray_VOID))\n\n#define PyTypeNum_ISUSERDEF(type) ((type >= PyArray_USERDEF) && \\\n\t\t\t\t (type < PyArray_USERDEF+\\\n\t\t\t\t PyArray_NUMUSERTYPES))\n\n#define PyTypeNum_ISEXTENDED(type) (PyTypeNum_ISFLEXIBLE(type) || \\\n PyTypeNum_ISUSERDEF(type))\n\n#define PyTypeNum_ISOBJECT(type) ((type) == PyArray_OBJECT)\n\n#define _PyADt(o) ((PyArray_Descr *)o)->type_num\n#define PyDescr_ISBOOL(obj) PyTypeNum_ISBOOL(_PyADt(obj))\n#define PyDescr_ISUNSIGNED(obj) PyTypeNum_ISUNSIGNED(_PyADt(obj))\n#define PyDescr_ISSIGNED(obj) PyTypeNum_ISSIGNED(_PyADt(obj))\n#define PyDescr_ISINTEGER(obj) PyTypeNum_ISINTEGER(_PyADt(obj))\n#define PyDescr_ISFLOAT(obj) PyTypeNum_ISFLOAT(_PyADt(obj))\n#define PyDescr_ISNUMBER(obj) PyTypeNum_ISNUMBER(_PyADt(obj))\n#define PyDescr_ISSTRING(obj) PyTypeNum_ISSTRING(_PyADt(obj))\n#define PyDescr_ISCOMPLEX(obj) PyTypeNum_ISCOMPLEX(_PyADt(obj))\n#define PyDescr_ISPYTHON(obj) PyTypeNum_ISPYTHON(_PyADt(obj))\n#define PyDescr_ISFLEXIBLE(obj) PyTypeNum_ISFLEXIBLE(_PyADt(obj))\n#define PyDescr_ISUSERDEF(obj) PyTypeNum_ISUSERDEF(_PyADt(obj))\n#define PyDescr_ISEXTENDED(obj) PyTypeNum_ISEXTENDED(_PyADt(obj))\n#define PyDescr_ISOBJECT(obj) PyTypeNum_ISOBJECT(_PyADt(obj))\n#undef _PyAD\n\n#define PyArray_ISBOOL(obj) PyTypeNum_ISBOOL(PyArray_TYPE(obj))\n#define PyArray_ISUNSIGNED(obj) PyTypeNum_ISUNSIGNED(PyArray_TYPE(obj))\n#define PyArray_ISSIGNED(obj) PyTypeNum_ISSIGNED(PyArray_TYPE(obj))\n#define PyArray_ISINTEGER(obj) PyTypeNum_ISINTEGER(PyArray_TYPE(obj))\n#define PyArray_ISFLOAT(obj) PyTypeNum_ISFLOAT(PyArray_TYPE(obj))\n#define PyArray_ISNUMBER(obj) PyTypeNum_ISNUMBER(PyArray_TYPE(obj))\n#define PyArray_ISSTRING(obj) PyTypeNum_ISSTRING(PyArray_TYPE(obj))\n#define PyArray_ISCOMPLEX(obj) PyTypeNum_ISCOMPLEX(PyArray_TYPE(obj))\n#define PyArray_ISPYTHON(obj) PyTypeNum_ISPYTHON(PyArray_TYPE(obj))\n#define PyArray_ISFLEXIBLE(obj) PyTypeNum_ISFLEXIBLE(PyArray_TYPE(obj))\n#define PyArray_ISUSERDEF(obj) PyTypeNum_ISUSERDEF(PyArray_TYPE(obj))\n#define PyArray_ISEXTENDED(obj) PyTypeNum_ISEXTENDED(PyArray_TYPE(obj))\n#define PyArray_ISOBJECT(obj) PyTypeNum_ISOBJECT(PyArray_TYPE(obj))\n\n#define PyArray_LITTLE '<'\n#define PyArray_BIG '>'\n#define PyArray_NATIVE '='\n#define PyArray_SWAP 's'\n#define PyArray_IGNORE '|'\n\n#ifdef WORDS_BIGENDIAN\n#define PyArray_NATBYTE PyArray_BIG\n#define PyArray_OPPBYTE PyArray_LITTLE\n#else\n#define PyArray_NATBYTE PyArray_LITTLE\n#define PyArray_OPPBYTE PyArray_BIG\n#endif\n\n#define PyArray_ISNBO(arg) ((arg) != PyArray_OPPBYTE)\n#define PyArray_IsNativeByteOrder PyArray_ISNBO\n#define PyArray_ISNOTSWAPPED(m) PyArray_ISNBO(PyArray_DESCR(m)->byteorder)\n\n#define PyArray_FLAGSWAP(m, flags) (PyArray_CHKFLAGS(m, flags) &&\t\\\n\t\t\t\t PyArray_ISNOTSWAPPED(m))\n#define PyArray_ISCARRAY(m) PyArray_FLAGSWAP(m, CARRAY_FLAGS)\n#define PyArray_ISCARRAY_RO(m) PyArray_FLAGSWAP(m, CARRAY_FLAGS_RO)\n#define PyArray_ISFARRAY(m) PyArray_FLAGSWAP(m, FARRAY_FLAGS)\n#define PyArray_ISFARRAY_RO(m) PyArray_FLAGSWAP(m, FARRAY_FLAGS_RO)\n#define PyArray_ISBEHAVED(m) PyArray_FLAGSWAP(m, BEHAVED_FLAGS)\n#define PyArray_ISBEHAVED_RO(m) PyArray_FLAGSWAP(m, ALIGNED)\n\n\n\n/* This is the form of the struct that's returned pointed by the\n PyCObject attribute of an array __array_struct__. See\n http://numeric.scipy.org/array_interface.html for the full\n documentation. */\ntypedef struct {\n int version; /* contains the integer 2 as a sanity check */\n int nd; /* number of dimensions */\n char typekind; /* kind in array --- character code of typestr */\n int itemsize; /* size of each element */\n int flags; /* how should be data interpreted. Valid\n flags are CONTIGUOUS (1), FORTRAN (2),\n ALIGNED (0x100), NOTSWAPPED (0x200), and\n WRITEABLE (0x400)*/\n intp *shape; /* A length-nd array of shape information */\n intp *strides; /* A length-nd array of stride information */\n void *data; /* A pointer to the first element of the array */\n} PyArrayInterface;\n\n/* Includes the \"function\" C-API -- these are all stored in a\n list of pointers --- one for each file\n The two lists are concatenated into one in multiarray.\n\n They are available as import_array()\n*/\n\n\n#include \"__multiarray_api.h\"\n\n\n/* C-API that requries previous API to be defined */\n\n#define PyArray_DescrCheck(op) ((op)->ob_type == &PyArrayDescr_Type)\n\n#define PyArray_Check(op) ((op)->ob_type == &PyArray_Type || \\\n\t\t\t PyObject_TypeCheck((op), &PyBigArray_Type))\n#define PyBigArray_CheckExact(op) ((op)->ob_type == &PyBigArray_Type)\n#define PyArray_CheckExact(op) ((op)->ob_type == &PyArray_Type)\n\n#define PyArray_IsZeroDim(op) (PyArray_Check(op) && (PyArray_NDIM(op) == 0))\n#define PyArray_IsScalar(obj, cls)\t\t\t\t\\\n\t(PyObject_TypeCheck((obj), &Py##cls##ArrType_Type))\n#define PyArray_CheckScalar(m) (PyArray_IsScalar(m, Generic) || \\\n PyArray_IsZeroDim(m))\n#define PyArray_IsPythonScalar(obj) \\\n\t(PyInt_Check(obj) || PyFloat_Check(obj) || PyComplex_Check(obj) || \\\n\t PyLong_Check(obj) || PyBool_Check(obj) || PyString_Check(obj) || \\\n\t PyUnicode_Check(obj))\n#define PyArray_IsAnyScalar(obj)\t\t\t\t\t\\\n\t(PyArray_IsScalar(obj, Generic) || PyArray_IsPythonScalar(obj))\n#define PyArray_CheckAnyScalar(obj) (PyArray_IsPythonScalar(obj) || \\\n\t\t\t\t PyArray_CheckScalar(obj))\n\n#define PyArray_GETCONTIGUOUS(m) (PyArray_ISCONTIGUOUS(m) ? Py_INCREF(m), m : \\\n (PyArrayObject *)(PyArray_Copy(m)))\n\n#define PyArray_SIZE(m) PyArray_MultiplyList(PyArray_DIMS(m), PyArray_NDIM(m))\n#define PyArray_NBYTES(m) (PyArray_ITEMSIZE(m) * PyArray_SIZE(m))\n#define PyArray_FROM_O(m) PyArray_FromAny(m, NULL, 0, 0, 0, NULL)\n#define PyArray_FROM_OF(m,flags) PyArray_CheckFromAny(m, NULL, 0, 0, flags, NULL)\n#define PyArray_FROM_OT(m,type) PyArray_FromAny(m, PyArray_DescrFromType(type), \\\n 0, 0, 0, NULL);\n#define PyArray_FROM_OTF(m, type, flags) \\\n\tPyArray_FromAny(m, PyArray_DescrFromType(type), 0, 0, \\\n (((flags) & ENSURECOPY) ? \\\n ((flags) | DEFAULT_FLAGS) : (flags)), NULL)\n#define PyArray_FROMANY(m, type, min, max, flags) \\\n\tPyArray_FromAny(m, PyArray_DescrFromType(type), min, max, \\\n (((flags) & ENSURECOPY) ? \\\n (flags) | DEFAULT_FLAGS : (flags)), NULL)\n\n#define PyArray_FILLWBYTE(obj, val) memset(PyArray_DATA(obj), (val), PyArray_NBYTES(obj))\n\n#define REFCOUNT(obj) (((PyObject *)(obj))->ob_refcnt)\n#define MAX_ELSIZE 2*SIZEOF_LONGDOUBLE\n\n#define PyArray_ContiguousFromAny(op, type, min_depth, max_depth) \\\n PyArray_FromAny(op, PyArray_DescrFromType(type), min_depth, \\\n max_depth, DEFAULT_FLAGS, NULL)\n\n#define PyArray_EquivArrTypes(a1, a2)\t\t\t\t\t\\\n\tPyArray_EquivTypes(PyArray_DESCR(a1), PyArray_DESCR(a2))\n#define PyArray_EquivTypenums(typenum1, typenum2)\t\t\\\n\tPyArray_EquivTypes(PyArray_DescrFromType(typenum1),\t\\\n\t\t\t PyArray_DescrFromType(typenum2))\n\n#define PyArray_EquivByteorders(b1, b2) \\\n\t((b1 == b2) || (PyArray_ISNBO(b1) == PyArray_ISNBO(b2)))\n\n#define PyArray_SimpleNew(nd, dims, typenum) \\\n\tPyArray_New(&PyArray_Type, nd, dims, typenum, NULL, NULL, 0, 0, NULL)\n#define PyArray_SimpleNewFromData(nd, dims, typenum, data) \\\n PyArray_New(&PyArray_Type, nd, dims, typenum, NULL, data, 0, CARRAY_FLAGS, NULL)\n#define PyArray_SimpleNewFromDescr(nd, dims, descr) \\\n\tPyArray_NewFromDescr(&PyArray_Type, descr, nd, dims, NULL, NULL, 0, NULL)\n\n\n/* These might be faster without the dereferencing of obj\n going on inside -- of course an optimizing compiler should\n inline the constants inside a for loop making it a moot point\n*/\n\n#define PyArray_GETPTR1(obj, i) (void *)(PyArray_BYTES(obj) +\t\t\\\n\t\t\t\t\t i*PyArray_STRIDE(obj, 0))\n\n#define PyArray_GETPTR2(obj, i, j) (void *)(PyArray_BYTES(obj) +\t\\\n\t\t\t\t\t i*PyArray_STRIDE(obj, 0) +\t\\\n\t\t\t\t\t j*PyArray_STRIDE(obj, 1))\n\n#define PyArray_GETPTR3(obj, i, j, k) (void *)(PyArray_BYTES(obj) +\t\\\n\t\t\t\t\t i*PyArray_STRIDE(obj, 0) + \\\n\t\t\t\t\t j*PyArray_STRIDE(obj, 1) + \\\n\t\t\t\t\t k*PyArray_STRIDE(obj, 2)) \\\n\n#define PyArray_GETPTR4(obj, i, j, k, l) (void *)(PyArray_BYTES(obj) +\t\\\n\t\t\t\t\t\t i*PyArray_STRIDE(obj, 0) + \\\n\t\t\t\t\t\t j*PyArray_STRIDE(obj, 1) + \\\n\t\t\t\t\t\t k*PyArray_STRIDE(obj, 2) + \\\n\t\t\t\t\t\t l*PyArray_STRIDE(obj, 3))\n\n#define PyArray_DESCR_REPLACE(descr) do {\t\\\n\t\tPyArray_Descr *_new_;\t\t\t\\\n\t\t_new_ = PyArray_DescrNew(descr);\t\\\n\t\tPy_XDECREF(descr);\t\t\t\\\n\t\tdescr = _new_;\t\t\t\t\\\n\t} while(0)\n\n/* Copy should always return contiguous array */\n#define PyArray_Copy(obj) PyArray_NewCopy(obj, 0)\n\n#define PyArray_FromObject(op, type, min_depth, max_depth)\t\t\\\n\tPyArray_FromAny(op, PyArray_DescrFromType(type), min_depth,\t\\\n max_depth, BEHAVED_FLAGS | ENSUREARRAY, NULL)\n\n#define PyArray_ContiguousFromObject(op, type, min_depth, max_depth)\t\\\n PyArray_FromAny(op, PyArray_DescrFromType(type), min_depth,\t\\\n max_depth, DEFAULT_FLAGS | ENSUREARRAY, NULL)\n\n#define PyArray_CopyFromObject(op, type, min_depth, max_depth)\t\t\\\n PyArray_FromAny(op, PyArray_DescrFromType(type), min_depth, \\\n max_depth, ENSURECOPY | DEFAULT_FLAGS | ENSUREARRAY, NULL)\n\n#define PyArray_Cast(mp, type_num) \\\n\tPyArray_CastToType(mp, PyArray_DescrFromType(type_num), 0)\n\n/* Compatibility with old Numeric stuff -- don't use in new code */\n\n#define PyArray_FromDimsAndData(nd, d, type, data) \\\n\tPyArray_FromDimsAndDataAndDescr(nd, d, PyArray_DescrFromType(type), \\\n\t\t\t\t\tdata)\n\n#define PyArray_UNSIGNED_TYPES\n#define PyArray_SBYTE PyArray_BYTE\n#define PyArray_CHAR PyArray_BYTE\n#define PyArray_CopyArray PyArray_CopyInto\n#define _PyArray_multiply_list PyArray_MultiplyIntList\n#define PyArray_ISSPACESAVER(m) FALSE\n#define PyScalarArray_Check PyArray_CheckScalar\n\n#ifdef PY_ARRAY_TYPES_PREFIX\n# undef CAT\n# undef CAT2\n# undef NS\n# undef longlong\n# undef ulonglong\n# undef Bool\n# undef longdouble\n# undef byte\n# undef ubyte\n# undef ushort\n# undef uint\n# undef ulong\n# undef cfloat\n# undef cdouble\n# undef clongdouble\n# undef Int8\n# undef UInt8\n# undef Int16\n# undef UInt16\n# undef Int32\n# undef UInt32\n# undef Int64\n# undef UInt64\n# undef Int128\n# undef UInt128\n# undef Int256\n# undef UInt256\n# undef Float16\n# undef Complex32\n# undef Float32\n# undef Complex64\n# undef Float64\n# undef Complex128\n# undef Float80\n# undef Complex160\n# undef Float96\n# undef Complex192\n# undef Float128\n# undef Complex256\n# undef intp\n# undef uintp\n#endif\n\n#ifdef __cplusplus\n}\n#endif\n\n#endif /* !Py_ARRAYOBJECT_H */\n", + "source_code_before": "/* This expects the following variables to be defined (besides\n the usual ones from pyconfig.h\n\n SIZEOF_LONG_DOUBLE -- sizeof(long double) or sizeof(double) if no\n long double is present on platform.\n CHAR_BIT -- number of bits in a char (usually 8)\n (should be in limits.h)\n*/\n\n#ifndef Py_ARRAYOBJECT_H\n#define Py_ARRAYOBJECT_H\n#ifdef __cplusplus\n#define CONFUSE_EMACS {\n#define CONFUSE_EMACS2 }\nextern \"C\" CONFUSE_EMACS\n#undef CONFUSE_EMACS\n#undef CONFUSE_EMACS2\n/* ... otherwise a semi-smart idententer (like emacs) tries to indent\n everything when you're typing */\n#endif\n#include \"config.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 longlong NS(longlong)\n# define ulonglong NS(ulonglong)\n# define Bool NS(Bool)\n# define longdouble NS(longdouble)\n# define byte NS(byte)\n# define ubyte NS(ubyte)\n# define ushort NS(ushort)\n# define uint NS(uint)\n# define ulong NS(ulong)\n# define cfloat NS(cfloat)\n# define cdouble NS(cdouble)\n# define clongdouble NS(clongdouble)\n# define Int8 NS(Int8)\n# define UInt8 NS(UInt8)\n# define Int16 NS(Int16)\n# define UInt16 NS(UInt16)\n# define Int32 NS(Int32)\n# define UInt32 NS(UInt32)\n# define Int64 NS(Int64)\n# define UInt64 NS(UInt64)\n# define Int128 NS(Int128)\n# define UInt128 NS(UInt128)\n# define Int256 NS(Int256)\n# define UInt256 NS(UInt256)\n# define Float16 NS(Float16)\n# define Complex32 NS(Complex32)\n# define Float32 NS(Float32)\n# define Complex64 NS(Complex64)\n# define Float64 NS(Float64)\n# define Complex128 NS(Complex128)\n# define Float80 NS(Float80)\n# define Complex160 NS(Complex160)\n# define Float96 NS(Float96)\n# define Complex192 NS(Complex192)\n# define Float128 NS(Float128)\n# define Complex256 NS(Complex256)\n# define intp NS(intp)\n# define uintp NS(uintp)\n#endif\n\n/* There are several places in the code where an array of dimensions is */\n/* allocated statically. This is the size of that static allocation. */\n/* The array creation itself could have arbitrary dimensions but\n * all the places where static allocation is used would need to\n * be changed to dynamic (including inside of structures)\n */\n\n#define MAX_DIMS 32\n\n/* Used for Converter Functions \"O&\" code in ParseTuple */\n#define PY_FAIL 0\n#define PY_SUCCEED 1\n\n\t/* Helpful to distinguish what is installed */\n#define NDARRAY_VERSION 0x00090405\n\n\t/* Some platforms don't define bool, long long, or long double.\n\t Handle that here.\n\t */\n\n#ifdef PY_LONG_LONG\ntypedef PY_LONG_LONG longlong;\ntypedef unsigned PY_LONG_LONG ulonglong;\n# ifdef _MSC_VER\n# define LONGLONG_FMT \"I64d\"\n# define ULONGLONG_FMT \"I64u\"\n# define LONGLONG_SUFFIX(x) (x##i64)\n# define ULONGLONG_SUFFIX(x) (x##Ui64)\n# else\n\t/* #define LONGLONG_FMT \"lld\" Another possible variant\n #define ULONGLONG_FMT \"llu\"\n\n\t #define LONGLONG_FMT \"qd\" -- BSD perhaps?\n\t #define ULONGLONG_FMT \"qu\"\n\t*/\n# define LONGLONG_FMT \"Ld\"\n# define ULONGLONG_FMT \"Lu\"\n# define LONGLONG_SUFFIX(x) (x##LL)\n# define ULONGLONG_SUFFIX(x) (x##ULL)\n# endif\n#else\ntypedef long longlong;\ntypedef unsigned long ulonglong;\n# define LONGLONG_SUFFIX(x) (x##L)\n# define ULONGLONG_SUFFIX(x) (x##UL)\n#endif\n\ntypedef unsigned char Bool;\n#ifndef FALSE\n#define FALSE 0\n#endif\n#ifndef TRUE\n#define TRUE 1\n#endif\n\n#if SIZEOF_LONG_DOUBLE==SIZEOF_DOUBLE\n\ttypedef double longdouble;\n #define LONGDOUBLE_FMT \"g\"\n#else\n\ttypedef long double longdouble;\n #define LONGDOUBLE_FMT \"Lg\"\n#endif\n\n#ifndef Py_USING_UNICODE\n#error Must use Python with unicode enabled. \n#endif\n\n\ntypedef signed char byte;\ntypedef unsigned char ubyte;\n#ifndef _BSD_SOURCE\ntypedef unsigned short ushort;\ntypedef unsigned int uint;\ntypedef unsigned long ulong;\n#endif\n\ntypedef struct { float real, imag; } cfloat;\ntypedef struct { double real, imag; } cdouble;\ntypedef struct {longdouble real, imag;} clongdouble;\n\nenum PyArray_TYPES { PyArray_BOOL=0,\n PyArray_BYTE, PyArray_UBYTE,\n\t\t PyArray_SHORT, PyArray_USHORT,\n\t\t PyArray_INT, PyArray_UINT,\n\t\t\tPyArray_LONG, PyArray_ULONG,\n PyArray_LONGLONG, PyArray_ULONGLONG,\n\t\t\tPyArray_FLOAT, PyArray_DOUBLE, PyArray_LONGDOUBLE,\n\t\t\tPyArray_CFLOAT, PyArray_CDOUBLE, PyArray_CLONGDOUBLE,\n\t\t\tPyArray_OBJECT=17,\n PyArray_STRING, PyArray_UNICODE,\n\t\t\tPyArray_VOID,\n\t\t\tPyArray_NTYPES,\n\t\t\tPyArray_NOTYPE,\n\t\t\tPyArray_USERDEF=256 /* leave room for characters */\n};\n\n\t/* basetype array priority */\n#define PyArray_PRIORITY 0.0\n#define PyArray_BIG_PRIORITY 0.1\n\t/* default subtype priority */\n#define PyArray_SUBTYPE_PRIORITY 1.0\n\n\t/* How many floating point types are there */\n#define PyArray_NUM_FLOATTYPE 3\n\n\n\t/* We need to match intp to a signed integer of the same size as\n\t a pointer variable. uintp to the equivalent unsigned integer\n\t*/\n\n\n\t/* These characters correspond to the array type and the\n\t struct module */\n\n\t/* except 'p' -- signed integer for pointer type */\n\nenum PyArray_TYPECHAR { PyArray_BOOLLTR = '?',\n\t\t\tPyArray_BYTELTR = 'b',\n\t\t\tPyArray_UBYTELTR = 'B',\n\t\t\tPyArray_SHORTLTR = 'h',\n\t\t\tPyArray_USHORTLTR = 'H',\n\t\t\tPyArray_INTLTR = 'i',\n\t\t\tPyArray_UINTLTR = 'I',\n\t\t\tPyArray_LONGLTR = 'l',\n\t\t\tPyArray_ULONGLTR = 'L',\n\t\t\tPyArray_LONGLONGLTR = 'q',\n\t\t\tPyArray_ULONGLONGLTR = 'Q',\n\t\t\tPyArray_FLOATLTR = 'f',\n\t\t\tPyArray_DOUBLELTR = 'd',\n\t\t\tPyArray_LONGDOUBLELTR = 'g',\n\t\t\tPyArray_CFLOATLTR = 'F',\n\t\t\tPyArray_CDOUBLELTR = 'D',\n\t\t\tPyArray_CLONGDOUBLELTR = 'G',\n\t\t\tPyArray_OBJECTLTR = 'O',\n\t\t\tPyArray_STRINGLTR = 'S',\n\t\t\tPyArray_STRINGLTR2 = 'a',\n\t\t\tPyArray_UNICODELTR = 'U',\n\t\t PyArray_VOIDLTR = 'V',\n\n\t\t\t/* No Descriptor, just a define -- this let's\n\t\t\t Python users specify an array of integers\n\t\t\t large enough to hold a pointer on the platform*/\n\t\t\tPyArray_INTPLTR = 'p',\n\t\t\tPyArray_UINTPLTR = 'P',\n\n\t\t\tPyArray_GENBOOLLTR ='b',\n\t\t\tPyArray_SIGNEDLTR = 'i',\n\t\t\tPyArray_UNSIGNEDLTR = 'u',\n\t\t\tPyArray_FLOATINGLTR = 'f',\n\t\t\tPyArray_COMPLEXLTR = 'c'\n};\n\ntypedef enum {\n\tPyArray_QUICKSORT=0,\n\tPyArray_HEAPSORT=1,\n\tPyArray_MERGESORT=2,\n\tPyArray_TIMSORT=3 /* the sort Python uses -- specialized */\n} PyArray_SORTKIND;\n#define PyArray_NSORTS PyArray_TIMSORT + 1\n\n\t/* Define bit-width array types and typedefs */\n\n#define MAX_INT8 127\n#define MIN_INT8 -128\n#define MAX_UINT8 255\n#define MAX_INT16 32767\n#define MIN_INT16 -32768\n#define MAX_UINT16 65535\n#define MAX_INT32 2147483647\n#define MIN_INT32 (-MAX_INT32 - 1)\n#define MAX_UINT32 4294967295U\n#define MAX_INT64 LONGLONG_SUFFIX(9223372036854775807)\n#define MIN_INT64 (-MAX_INT64 - LONGLONG_SUFFIX(1))\n#define MAX_UINT64 ULONGLONG_SUFFIX(18446744073709551615)\n#define MAX_INT128 LONGLONG_SUFFIX(85070591730234615865843651857942052864)\n#define MIN_INT128 (-MAX_INT128 - LONGLONG_SUFFIX(1))\n#define MAX_UINT128 ULONGLONG_SUFFIX(170141183460469231731687303715884105728)\n#define MAX_INT256 LONGLONG_SUFFIX(57896044618658097711785492504343953926634992332820282019728792003956564819967)\n#define MIN_INT256 (-MAX_INT256 - LONGLONG_SUFFIX(1))\n#define MAX_UINT256 ULONGLONG_SUFFIX(115792089237316195423570985008687907853269984665640564039457584007913129639935)\n\n\t/* Need to find the number of bits for each type and\n\t make definitions accordingly.\n\n\t C states that sizeof(char) == 1 by definition\n\n\t So, just using the sizeof keyword won't help.\n\n\t It also looks like Python itself uses sizeof(char) quite a\n\t bit, which by definition should be 1 all the time.\n\n\t Idea: Make Use of CHAR_BIT which should tell us how many\n\t BITS per CHARACTER\n\t*/\n\n\t/* Include platform definitions -- These are in the C89/90 standard */\n#include \n#define MAX_BYTE SCHAR_MAX\n#define MIN_BYTE SCHAR_MIN\n#define MAX_UBYTE UCHAR_MAX\n#define MAX_SHORT SHRT_MAX\n#define MIN_SHORT SHRT_MIN\n#define MAX_USHORT USHRT_MAX\n#define MAX_INT INT_MAX\n#ifndef INT_MIN\n#define INT_MIN (-INT_MAX - 1)\n#endif\n#define MIN_INT INT_MIN\n#define MAX_UINT UINT_MAX\n#define MAX_LONG LONG_MAX\n#define MIN_LONG LONG_MIN\n#define MAX_ULONG ULONG_MAX\n\n#define SIZEOF_LONGDOUBLE SIZEOF_LONG_DOUBLE\n#define SIZEOF_LONGLONG SIZEOF_LONG_LONG\n#define BITSOF_BOOL sizeof(Bool)*CHAR_BIT\n#define BITSOF_CHAR CHAR_BIT\n#define BITSOF_SHORT (SIZEOF_SHORT*CHAR_BIT)\n#define BITSOF_INT (SIZEOF_INT*CHAR_BIT)\n#define BITSOF_LONG (SIZEOF_LONG*CHAR_BIT)\n#define BITSOF_LONGLONG (SIZEOF_LONGLONG*CHAR_BIT)\n#define BITSOF_FLOAT (SIZEOF_FLOAT*CHAR_BIT)\n#define BITSOF_DOUBLE (SIZEOF_DOUBLE*CHAR_BIT)\n#define BITSOF_LONGDOUBLE (SIZEOF_LONGDOUBLE*CHAR_BIT)\n\n\n#if BITSOF_LONG == 8\n#define PyArray_INT8 PyArray_LONG\n#define PyArray_UINT8 PyArray_ULONG\n\ttypedef long Int8;\n\ttypedef unsigned long UInt8;\n#define STRBITSOF_LONG \"8\"\n#elif BITSOF_LONG == 16\n#define PyArray_INT16 PyArray_LONG\n#define PyArray_UINT16 PyArray_ULONG\n\ttypedef long Int16;\n\ttypedef unsigned long UInt16;\n#define STRBITSOF_LONG \"16\"\n#elif BITSOF_LONG == 32\n#define PyArray_INT32 PyArray_LONG\n#define PyArray_UINT32 PyArray_ULONG\n\ttypedef long Int32;\n\ttypedef unsigned long UInt32;\n\ttypedef unsigned long PyArray_UCS4;\n#define STRBITSOF_LONG \"32\"\n#elif BITSOF_LONG == 64\n#define PyArray_INT64 PyArray_LONG\n#define PyArray_UINT64 PyArray_ULONG\n\ttypedef long Int64;\n\ttypedef unsigned long UInt64;\n#define STRBITSOF_LONG \"64\"\n#elif BITSOF_LONG == 128\n#define PyArray_INT128 PyArray_LONG\n#define PyArray_UINT128 PyArray_ULONG\n\ttypedef long Int128;\n\ttypedef unsigned long UInt128;\n#define STRBITSOF_LONG \"128\"\n#endif\n\n#if BITSOF_LONGLONG == 8\n# ifndef PyArray_INT8\n# define PyArray_INT8 PyArray_LONGLONG\n# define PyArray_UINT8 PyArray_ULONGLONG\n\ttypedef longlong Int8;\n\ttypedef ulonglong UInt8;\n# endif\n# define MAX_LONGLONG MAX_INT8\n# define MIN_LONGLONG MIN_INT8\n# define MAX_ULONGLONG MAX_UINT8\n#define STRBITSOF_LONGLONG \"8\"\n#elif BITSOF_LONGLONG == 16\n# ifndef PyArray_INT16\n# define PyArray_INT16 PyArray_LONGLONG\n# define PyArray_UINT16 PyArray_ULONGLONG\n\ttypedef longlong Int16;\n\ttypedef ulonglong UInt16;\n# endif\n# define MAX_LONGLONG MAX_INT16\n# define MIN_LONGLONG MIN_INT16\n# define MAX_ULONGLONG MAX_UINT16\n#define STRBITSOF_LONGLONG \"16\"\n#elif BITSOF_LONGLONG == 32\n# ifndef PyArray_INT32\n# define PyArray_INT32 PyArray_LONGLONG\n# define PyArray_UINT32 PyArray_ULONGLONG\n\ttypedef longlong Int32;\n\ttypedef ulonglong UInt32;\n\ttypedef ulonglong PyArray_UCS4;\n# endif\n# define MAX_LONGLONG MAX_INT32\n# define MIN_LONGLONG MIN_INT32\n# define MAX_ULONGLONG MAX_UINT32\n#define STRBITSOF_LONGLONG \"32\"\n#elif BITSOF_LONGLONG == 64\n# ifndef PyArray_INT64\n# define PyArray_INT64 PyArray_LONGLONG\n# define PyArray_UINT64 PyArray_ULONGLONG\n\ttypedef longlong Int64;\n\ttypedef ulonglong UInt64;\n# endif\n# define MAX_LONGLONG MAX_INT64\n# define MIN_LONGLONG MIN_INT64\n# define MAX_ULONGLONG MAX_UINT64\n#define STRBITSOF_LONGLONG \"64\"\n#elif BITSOF_LONGLONG == 128\n# ifndef PyArray_INT128\n# define PyArray_INT128 PyArray_LONGLONG\n# define PyArray_UINT128 PyArray_ULONGLONG\n\ttypedef longlong Int128;\n\ttypedef ulonglong UInt128;\n# endif\n# define MAX_LONGLONG MAX_INT128\n# define MIN_LONGLONG MIN_INT128\n# define MAX_ULONGLONG MAX_UINT128\n#define STRBITSOF_LONGLONG \"128\"\n#elif BITSOF_LONGLONG == 256\n# define PyArray_INT256 PyArray_LONGLONG\n# define PyArray_UINT256 PyArray_ULONGLONG\n\ttypedef longlong Int256;\n\ttypedef ulonglong UInt256;\n# define MAX_LONGLONG MAX_INT256\n# define MIN_LONGLONG MIN_INT256\n# define MAX_ULONGLONG MAX_UINT256\n#define STRBITSOF_LONGLONG \"256\"\n#endif\n\n#if BITSOF_INT == 8\n#ifndef PyArray_INT8\n#define PyArray_INT8 PyArray_INT\n#define PyArray_UINT8 PyArray_UINT\n\ttypedef int Int8;\n\ttypedef unsigned int UInt8;\n#endif\n#define STRBITSOF_INT \"8\"\n#elif BITSOF_INT == 16\n#ifndef PyArray_INT16\n#define PyArray_INT16 PyArray_INT\n#define PyArray_UINT16 PyArray_UINT\n\ttypedef int Int16;\n\ttypedef unsigned int UInt16;\n#endif\n#define STRBITSOF_INT \"16\"\n#elif BITSOF_INT == 32\n#ifndef PyArray_INT32\n#define PyArray_INT32 PyArray_INT\n#define PyArray_UINT32 PyArray_UINT\n\ttypedef int Int32;\n\ttypedef unsigned int UInt32;\n\ttypedef unsigned int PyArray_UCS4;\n#endif\n#define STRBITSOF_INT \"32\"\n#elif BITSOF_INT == 64\n#ifndef PyArray_INT64\n#define PyArray_INT64 PyArray_INT\n#define PyArray_UINT64 PyArray_UINT\n\ttypedef int Int64;\n\ttypedef unsigned int UInt64;\n#endif\n#define STRBITSOF_INT \"64\"\n#elif BITSOF_INT == 128\n#ifndef PyArray_INT128\n#define PyArray_INT128 PyArray_INT\n#define PyArray_UINT128 PyArray_UINT\n\ttypedef int Int128;\n\ttypedef unsigned int UInt128;\n#endif\n#define STRBITSOF_INT \"128\"\n#endif\n\n#if BITSOF_SHORT == 8\n#ifndef PyArray_INT8\n#define PyArray_INT8 PyArray_SHORT\n#define PyArray_UINT8 PyArray_USHORT\n\ttypedef short Int8;\n\ttypedef unsigned short UInt8;\n#endif\n#define STRBITSOF_SHORT \"8\"\n#elif BITSOF_SHORT == 16\n#ifndef PyArray_INT16\n#define PyArray_INT16 PyArray_SHORT\n#define PyArray_UINT16 PyArray_USHORT\n\ttypedef short Int16;\n\ttypedef unsigned short UInt16;\n#endif\n#define STRBITSOF_SHORT \"16\"\n#elif BITSOF_SHORT == 32\n#ifndef PyArray_INT32\n#define PyArray_INT32 PyArray_SHORT\n#define PyArray_UINT32 PyArray_USHORT\n\ttypedef short Int32;\n\ttypedef unsigned short UInt32;\n\ttypedef unsigned short PyArray_UCS4;\n#endif\n#define STRBITSOF_SHORT \"32\"\n#elif BITSOF_SHORT == 64\n#ifndef PyArray_INT64\n#define PyArray_INT64 PyArray_SHORT\n#define PyArray_UINT64 PyArray_USHORT\n\ttypedef short Int64;\n\ttypedef unsigned short UInt64;\n#endif\n#define STRBITSOF_SHORT \"64\"\n#elif BITSOF_SHORT == 128\n#ifndef PyArray_INT128\n#define PyArray_INT128 PyArray_SHORT\n#define PyArray_UINT128 PyArray_USHORT\n\ttypedef short Int128;\n\ttypedef unsigned short UInt128;\n#endif\n#define STRBITSOF_SHORT \"128\"\n#endif\n\n\n#if BITSOF_CHAR == 8\n#ifndef PyArray_INT8\n#define PyArray_INT8 PyArray_BYTE\n#define PyArray_UINT8 PyArray_UBYTE\n\ttypedef signed char Int8;\n\ttypedef unsigned char UInt8;\n#endif\n#define STRBITSOF_CHAR \"8\"\n#elif BITSOF_CHAR == 16\n#ifndef PyArray_INT16\n#define PyArray_INT16 PyArray_BYTE\n#define PyArray_UINT16 PyArray_UBYTE\n\ttypedef signed char Int16;\n\ttypedef unsigned char UInt16;\n#endif\n#define STRBITSOF_CHAR \"16\"\n#elif BITSOF_CHAR == 32\n#ifndef PyArray_INT32\n#define PyArray_INT32 PyArray_BYTE\n#define PyArray_UINT32 PyArray_UBYTE\n\ttypedef signed char Int32;\n\ttypedef unsigned char UInt32;\n\ttypedef unsigned char PyArray_UCS4;\n#endif\n#define STRBITSOF_CHAR \"32\"\n#elif BITSOF_CHAR == 64\n#ifndef PyArray_INT64\n#define PyArray_INT64 PyArray_BYTE\n#define PyArray_UINT64 PyArray_UBYTE\n\ttypedef signed char Int64;\n\ttypedef unsigned char UInt64;\n#endif\n#define STRBITSOF_CHAR \"64\"\n#elif BITSOF_CHAR == 128\n#ifndef PyArray_INT128\n#define PyArray_INT128 PyArray_BYTE\n#define PyArray_UINT128 PyArray_UBYTE\n\ttypedef signed char Int128;\n\ttypedef unsigned char UInt128;\n#endif\n#define STRBITSOF_CHAR \"128\"\n#endif\n\n\n\n#if BITSOF_DOUBLE == 16\n#define STRBITSOF_DOUBLE \"16\"\n#define STRBITSOF_CDOUBLE \"32\"\n#ifndef PyArray_FLOAT16\n#define PyArray_FLOAT16 PyArray_DOUBLE\n#define PyArray_COMPLEX32 PyArray_CDOUBLE\n\ttypedef double Float16;\n\ttypedef cdouble Complex32;\n#endif\n#elif BITSOF_DOUBLE == 32\n#define STRBITSOF_DOUBLE \"32\"\n#define STRBITSOF_CDOUBLE \"64\"\n#ifndef PyArray_FLOAT32\n#define PyArray_FLOAT32 PyArray_DOUBLE\n#define PyArray_COMPLEX64 PyArray_CDOUBLE\n\ttypedef double Float32;\n\ttypedef cdouble Complex64;\n#endif\n#elif BITSOF_DOUBLE == 64\n#define STRBITSOF_DOUBLE \"64\"\n#define STRBITSOF_CDOUBLE \"128\"\n#ifndef PyArray_FLOAT64\n#define PyArray_FLOAT64 PyArray_DOUBLE\n#define PyArray_COMPLEX128 PyArray_CDOUBLE\n\ttypedef double Float64;\n\ttypedef cdouble Complex128;\n#endif\n#elif BITSOF_DOUBLE == 80\n#define STRBITSOF_DOUBLE \"80\"\n#define STRBITSOF_CDOUBLE \"160\"\n#ifndef PyArray_FLOAT80\n#define PyArray_FLOAT80 PyArray_DOUBLE\n#define PyArray_COMPLEX160 PyArray_CDOUBLE\n\ttypedef double Float80;\n\ttypedef cdouble Complex160;\n#endif\n#elif BITSOF_DOUBLE == 96\n#define STRBITSOF_DOUBLE \"96\"\n#define STRBITSOF_CDOUBLE \"192\"\n#ifndef PyArray_FLOAT96\n#define PyArray_FLOAT96 PyArray_DOUBLE\n#define PyArray_COMPLEX192 PyArray_CDOUBLE\n\ttypedef double Float96;\n\ttypedef cdouble Complex192;\n#endif\n#elif BITSOF_DOUBLE == 128\n#define STRBITSOF_DOUBLE \"128\"\n#define STRBITSOF_CDOUBLE \"256\"\n#ifndef PyArray_FLOAT128\n#define PyArray_FLOAT128 PyArray_DOUBLE\n#define PyArray_COMPLEX256 PyArray_CDOUBLE\n\ttypedef double Float128;\n\ttypedef cdouble Complex256;\n#endif\n#endif\n\n\n\n#if BITSOF_FLOAT == 16\n#define STRBITSOF_FLOAT \"16\"\n#define STRBITSOF_CFLOAT \"32\"\n#ifndef PyArray_FLOAT16\n#define PyArray_FLOAT16 PyArray_FLOAT\n#define PyArray_COMPLEX32 PyArray_CFLOAT\n\ttypedef float Float16;\n\ttypedef cfloat Complex32;\n#endif\n#elif BITSOF_FLOAT == 32\n#define STRBITSOF_FLOAT \"32\"\n#define STRBITSOF_CFLOAT \"64\"\n#ifndef PyArray_FLOAT32\n#define PyArray_FLOAT32 PyArray_FLOAT\n#define PyArray_COMPLEX64 PyArray_CFLOAT\n\ttypedef float Float32;\n\ttypedef cfloat Complex64;\n#endif\n#elif BITSOF_FLOAT == 64\n#define STRBITSOF_FLOAT \"64\"\n#define STRBITSOF_CFLOAT \"128\"\n#ifndef PyArray_FLOAT64\n#define PyArray_FLOAT64 PyArray_FLOAT\n#define PyArray_COMPLEX128 PyArray_CFLOAT\n\ttypedef float Float64;\n\ttypedef cfloat Complex128;\n#endif\n#elif BITSOF_FLOAT == 80\n#define STRBITSOF_FLOAT \"80\"\n#define STRBITSOF_CFLOAT \"160\"\n#ifndef PyArray_FLOAT80\n#define PyArray_FLOAT80 PyArray_FLOAT\n#define PyArray_COMPLEX160 PyArray_CFLOAT\n\ttypedef float Float80;\n\ttypedef cfloat Complex160;\n#endif\n#elif BITSOF_FLOAT == 96\n#define STRBITSOF_FLOAT \"96\"\n#define STRBITSOF_CFLOAT \"192\"\n#ifndef PyArray_FLOAT96\n#define PyArray_FLOAT96 PyArray_FLOAT\n#define PyArray_COMPLEX192 PyArray_CFLOAT\n\ttypedef float Float96;\n\ttypedef cfloat Complex192;\n#endif\n#elif BITSOF_FLOAT == 128\n#define STRBITSOF_FLOAT \"128\"\n#define STRBITSOF_CFLOAT \"256\"\n#ifndef PyArray_FLOAT128\n#define PyArray_FLOAT128 PyArray_FLOAT\n#define PyArray_COMPLEX256 PyArray_CFLOAT\n\ttypedef float Float128;\n\ttypedef cfloat Complex256;\n#endif\n#endif\n\n\n#if BITSOF_LONGDOUBLE == 16\n#define STRBITSOF_LONGDOUBLE \"16\"\n#define STRBITSOF_CLONGDOUBLE \"32\"\n#ifndef PyArray_FLOAT16\n#define PyArray_FLOAT16 PyArray_LONGDOUBLE\n#define PyArray_COMPLEX32 PyArray_CLONGDOUBLE\n\ttypedef longdouble Float16;\n\ttypedef clongdouble Complex32;\n#endif\n#elif BITSOF_LONGDOUBLE == 32\n#define STRBITSOF_LONGDOUBLE \"32\"\n#define STRBITSOF_CLONGDOUBLE \"64\"\n#ifndef PyArray_FLOAT32\n#define PyArray_FLOAT32 PyArray_LONGDOUBLE\n#define PyArray_COMPLEX64 PyArray_CLONGDOUBLE\n\ttypedef longdouble Float32;\n\ttypedef clongdouble Complex64;\n#endif\n#elif BITSOF_LONGDOUBLE == 64\n#define STRBITSOF_LONGDOUBLE \"64\"\n#define STRBITSOF_CLONGDOUBLE \"128\"\n#ifndef PyArray_FLOAT64\n#define PyArray_FLOAT64 PyArray_LONGDOUBLE\n#define PyArray_COMPLEX128 PyArray_CLONGDOUBLE\n\ttypedef longdouble Float64;\n\ttypedef clongdouble Complex128;\n#endif\n#elif BITSOF_LONGDOUBLE == 80\n#define STRBITSOF_LONGDOUBLE \"80\"\n#define STRBITSOF_CLONGDOUBLE \"160\"\n#ifndef PyArray_FLOAT80\n#define PyArray_FLOAT80 PyArray_LONGDOUBLE\n#define PyArray_COMPLEX160 PyArray_CLONGDOUBLE\n\ttypedef longdouble Float80;\n\ttypedef clongdouble Complex160;\n#endif\n#elif BITSOF_LONGDOUBLE == 96\n#define STRBITSOF_LONGDOUBLE \"96\"\n#define STRBITSOF_CLONGDOUBLE \"192\"\n#ifndef PyArray_FLOAT96\n#define PyArray_FLOAT96 PyArray_LONGDOUBLE\n#define PyArray_COMPLEX192 PyArray_CLONGDOUBLE\n\ttypedef longdouble Float96;\n\ttypedef clongdouble Complex192;\n#endif\n#elif BITSOF_LONGDOUBLE == 128\n#define STRBITSOF_LONGDOUBLE \"128\"\n#define STRBITSOF_CLONGDOUBLE \"256\"\n#ifndef PyArray_FLOAT128\n#define PyArray_FLOAT128 PyArray_LONGDOUBLE\n#define PyArray_COMPLEX256 PyArray_CLONGDOUBLE\n\ttypedef longdouble Float128;\n\ttypedef clongdouble Complex256;\n#endif\n#elif BITSOF_LONGDOUBLE == 256\n#define STRBITSOF_LONGDOUBLE \"256\"\n#define STRBITSOF_CLONGDOUBLE \"512\"\n#define PyArray_FLOAT256 PyArray_LONGDOUBLE\n#define PyArray_COMPLEX512 PyArray_CLONGDOUBLE\n\ttypedef longdouble Float256;\n\ttypedef clongdouble Complex512;\n#endif\n\n\n\t/* End of typedefs for numarray style bit-width names */\n\n/* This is to typedef Intp to the appropriate pointer size for this platform.\n * Py_intptr_t, Py_uintptr_t are defined in pyport.h. */\ntypedef Py_intptr_t intp;\ntypedef Py_uintptr_t uintp;\n#define SIZEOF_INTP SIZEOF_PY_INTPTR_T\n#define SIZEOF_UINTP SIZEOF_PY_INTPTR_T\n\n#define INTP_FMT \"d\"\n\n#if SIZEOF_PY_INTPTR_T == SIZEOF_INT\n\t#define PyArray_INTP PyArray_INT\n\t#define PyArray_UINTP PyArray_UINT\n #define PyIntpArrType_Type PyIntArrType_Type\n #define PyUIntpArrType_Type PyUIntArrType_Type\n\t#define MAX_INTP MAX_INT\n\t#define MIN_INTP MIN_INT\n\t#define MAX_UINTP MAX_UINT\n#elif SIZEOF_PY_INTPTR_T == SIZEOF_LONG\n\t#define PyArray_INTP PyArray_LONG\n\t#define PyArray_UINTP PyArray_ULONG\n #define PyIntpArrType_Type PyLongArrType_Type\n #define PyUIntpArrType_Type PyULongArrType_Type\n\t#define MAX_INTP MAX_LONG\n\t#define MIN_INTP MIN_LONG\n\t#define MAX_UINTP MAX_ULONG\n #undef INTP_FMT\n #define INTP_FMT \"ld\"\n#elif defined(PY_LONG_LONG) && (SIZEOF_PY_INTPTR_T == SIZEOF_LONG_LONG)\n\t#define PyArray_INTP PyArray_LONGLONG\n\t#define PyArray_UINTP PyArray_ULONGLONG\n #define PyIntpArrType_Type PyLongLongArrType_Type\n #define PyUIntpArrType_Type PyULongLongArrType_Type\n\t#define MAX_INTP MAX_LONGLONG\n\t#define MIN_INTP MIN_LONGLONG\n\t#define MAX_UINTP MAX_ULONGLONG\n #undef INTP_FMT\n #define INTP_FMT \"Ld\"\n#endif\n\n#define ERR(str) fprintf(stderr, #str); fflush(stderr);\n#define ERR2(str) fprintf(stderr, str); fflush(stderr);\n\n /* Macros to define how array, and dimension/strides data is\n allocated.\n */\n\n /* Data buffer */\n#define PyDataMem_NEW(size) ((char *)malloc(size))\n /* #define PyArrayMem_NEW(size) PyMem_NEW(char, size)*/\n#define PyDataMem_FREE(ptr) free(ptr)\n /* #define PyArrayMem_FREE(ptr) PyMem_Free(ptr) */\n#define PyDataMem_RENEW(ptr,size) ((char *)realloc(ptr,size))\n\n#define PyArray_USE_PYMEM 0\n\n#if PyArray_USE_PYMEM == 1\n#define _pya_malloc PyObject_Malloc\n#define _pya_free PyObject_Free\n#define _pya_realloc PyObject_Realloc\n#else\n#define _pya_malloc malloc\n#define _pya_free free\n#define _pya_realloc realloc\n#endif\n\n/* Dimensions and strides */\n#define PyDimMem_NEW(size) ((intp *)_pya_malloc(size*sizeof(intp)))\n#define PyDimMem_FREE(ptr) _pya_free(ptr)\n#define PyDimMem_RENEW(ptr,size) ((intp *)_pya_realloc(ptr,size*sizeof(intp)))\n\n\n /* These must deal with unaligned and swapped data if necessary */\ntypedef PyObject * (PyArray_GetItemFunc) (void *, void *);\ntypedef int (PyArray_SetItemFunc)(PyObject *, void *, void *);\n\ntypedef void (PyArray_CopySwapNFunc)(void *, void *, intp, int, int);\ntypedef void (PyArray_CopySwapFunc)(void *, void *, int, int);\ntypedef Bool (PyArray_NonzeroFunc)(void *, void *);\n\n\n /* These assume aligned and notswapped data -- a buffer will be\n used before or contiguous data will be obtained\n */\ntypedef int (PyArray_CompareFunc)(const void *, const void *, void *);\ntypedef int (PyArray_ArgFunc)(void*, intp, intp*, void *);\ntypedef void (PyArray_DotFunc)(void *, intp, void *, intp, void *, intp,\n\t\t\t void *);\ntypedef void (PyArray_VectorUnaryFunc)(void *, void *, intp, void *, void *);\ntypedef int (PyArray_ScanFunc)(FILE *, void *, void *, void *);\ntypedef int (PyArray_FromStrFunc)(char *, void *, char **, void *);\n\ntypedef int (PyArray_FillFunc)(void *, intp, void *);\n\ntypedef int (PyArray_SortFunc)(void *, intp, void *);\ntypedef int (PyArray_ArgSortFunc)(void *, intp *, intp, void *);\n\ntypedef struct {\n intp *ptr;\n int len;\n} PyArray_Dims;\n\ntypedef struct {\n\t/* Functions to cast to all other standard types*/\n\tPyArray_VectorUnaryFunc *cast[PyArray_NTYPES];\n\n\t/* Functions to get and set items with standard\n\t Python types -- not array scalars */\n\tPyArray_GetItemFunc *getitem;\n\tPyArray_SetItemFunc *setitem;\n\n\t/* Copy and/or swap data. Memory areas may not overlap */\n\t/* Use memmove first if they might */\n\tPyArray_CopySwapNFunc *copyswapn;\n PyArray_CopySwapFunc *copyswap;\n\n\t/* Function to compare items */\n\tPyArray_CompareFunc *compare;\n\n\t/* Function to select largest */\n\tPyArray_ArgFunc *argmax;\n\n\t/* Function to compute dot product */\n\tPyArray_DotFunc\t*dotfunc;\n\n\t/* Function to scan an ASCII file and\n\t place a single value plus possible separator */\n\tPyArray_ScanFunc *scanfunc;\n\n\t/* Function to read a single value from a string */\n\t/* and adjust the pointer */\n\tPyArray_FromStrFunc *fromstr;\n\n\t/* Function to determine if data is zero or not */\n\tPyArray_NonzeroFunc *nonzero;\n\n\t/* Used for arange */\n\tPyArray_FillFunc *fill;\n\n\t/* Sorting functions */\n\tPyArray_SortFunc *sort[PyArray_NSORTS];\n\tPyArray_ArgSortFunc *argsort[PyArray_NSORTS];\n\n} PyArray_ArrFuncs;\n\n\ntypedef struct {\n\tPyObject_HEAD\n\tPyTypeObject *typeobj; /* the type object representing an\n\t\t\t\t intance of this type */\n\tchar kind; /* kind for this type */\n\tchar type; /* unique-character representing this type */\n\tchar byteorder; /* '>' (big), '<' (little), '|'\n\t\t\t\t (not-applicable), or '=' (native). */\n char hasobject; /* non-zero if it has object arrays in fields */\n\tint type_num; /* number representing this type */\n\tint elsize; /* element size for this type */\n\tint alignment; /* alignment needed for this type */\n\tstruct _arr_descr\t\t\t\t\t\\\n\t*subarray; /* Non-NULL if this type is\n\t\t\t\t is an array (C-contiguous)\n\t\t\t\t of some other type\n\t\t\t\t*/\n\tPyObject *fields; /* The fields dictionary for this type */\n\t /* For statically defined descr this\n\t\t\t\t is always Py_None */\n\n\tPyArray_ArrFuncs *f; /* a table of functions specific for each\n\t\t\t\t basic data descriptor */\n} PyArray_Descr;\n\ntypedef struct _arr_descr {\n\tPyArray_Descr *base;\n\tPyObject *shape; /* a tuple */\n} PyArray_ArrayDescr;\n\n\n/*\n The main array object structure. It is recommended to use the macros\n defined below (PyArray_DATA and friends) access fields here, instead\n of the members themselves.\n */\n\ntypedef struct PyArrayObject {\n\tPyObject_HEAD\n\tchar *data; /* pointer to raw data buffer */\n\tint nd; /* number of dimensions, also called ndim */\n\tintp *dimensions; /* size in each dimension */\n intp *strides; /* bytes to jump to get to the\n\t\t\t\t next element in each dimension */\n\tPyObject *base; /* This object should be decref'd\n\t\t\t\t upon deletion of array */\n\t /* For views it points to the original array */\n\t /* For creation from buffer object it points\n\t\t\t\t to an object that shold be decref'd on\n\t\t\t\t deletion */\n\t /* For UPDATEIFCOPY flag this is an array\n\t\t\t\t to-be-updated upon deletion of this one */\n\tPyArray_Descr *descr; /* Pointer to type structure */\n\tint flags; /* Flags describing array -- see below*/\n\tPyObject *weakreflist; /* For weakreferences */\n} PyArrayObject;\n\n#define fortran fortran_ /* For some compilers */\n\n/* Mirrors buffer object to ptr */\n\ntypedef struct {\n PyObject_HEAD\n PyObject *base;\n void *ptr;\n intp len;\n int flags;\n} PyArray_Chunk;\n\n/* Array flags */\n\n/* Means c-style contiguous (last index varies the fastest). The\n data elements right after each other. */\n#define CONTIGUOUS 0x0001\n/* set if array is a contiguous Fortran array: the first index\n varies the fastest in memory (strides array is reverse of\n C-contiguous array)*/\n#define FORTRAN 0x0002\n\n/*\n Note: all 0-d arrays are CONTIGUOUS and FORTRAN contiguous. If a\n 1-d array is CONTIGUOUS it is also FORTRAN contiguous\n*/\n\n/* If set, the array owns the data: it will be free'd when the array\n is deleted. */\n#define OWNDATA 0x0004\n#define OWN_DATA OWNDATA\n\n/* An array never has these three set; they're only used as parameter\n flags to the the various FromAny functions */\n/* Cause a cast to occur regardless of whether or not it is safe. */\n#define FORCECAST 0x0010\n/* Always copy the array. Returned arrays are always CONTIGUOUS, ALIGNED,\n and WRITEABLE. */\n#define ENSURECOPY 0x0020\n/* Make sure the returned array is an ndarray or a bigndarray */\n#define ENSUREARRAY 0x0040\n\n/* Array data is aligned on the appropiate memory address for the\n type stored (e.g., an array of doubles (8 bytes each) starts on\n a memory address that's a multiple of 8) */\n#define ALIGNED 0x0100\n/* Array data has the native endianness */\n#define NOTSWAPPED 0x0200\n/* Array data is writeable */\n#define WRITEABLE 0x0400\n/* If this flag is set, then base contains a pointer to an array of\n the same size that should be updated with the current contents of\n this array when this array is deallocated\n*/\n#define UPDATEIFCOPY 0x1000\n\n\n#define BEHAVED_FLAGS ALIGNED | WRITEABLE\n#define BEHAVED_NS_FLAGS ALIGNED | WRITEABLE | NOTSWAPPED\n#define CARRAY_FLAGS CONTIGUOUS | BEHAVED_FLAGS\n#define CARRAY_FLAGS_RO CONTIGUOUS | ALIGNED\n#define FARRAY_FLAGS FORTRAN | BEHAVED_FLAGS\n#define FARRAY_FLAGS_RO FORTRAN | ALIGNED\n#define DEFAULT_FLAGS CARRAY_FLAGS\n\n#define UPDATE_ALL_FLAGS CONTIGUOUS | FORTRAN | ALIGNED\n\n\n/* Size of internal buffers used for alignment */\n#define PyArray_BUFSIZE 10000\n#define PyArray_MIN_BUFSIZE 5\n#define PyArray_MAX_BUFSIZE 100000000\n\n/*\n * C API: consists of Macros and functions. The MACROS are defined here.\n */\n\n\n#define PyArray_CHKFLAGS(m, FLAGS) \\\n\t((((PyArrayObject *)(m))->flags & (FLAGS)) == (FLAGS))\n#define PyArray_ISCONTIGUOUS(m) PyArray_CHKFLAGS(m, CONTIGUOUS)\n#define PyArray_ISWRITEABLE(m) PyArray_CHKFLAGS(m, WRITEABLE)\n#define PyArray_ISALIGNED(m) PyArray_CHKFLAGS(m, ALIGNED)\n\n#ifndef MAX\n#define MAX(a,b) (((a)>(b))?(a):(b))\n#endif\n#ifndef MIN\n#define MIN(a,b) (((a)<(b))?(a):(b))\n#endif\n\n/* Useful if a and b have to be evaluated. */\n\n#define tMAX(a,b,typ) {typ _x_=(a); typ _y_=(b); _x_>_y_ ? _x_ : _y_}\n#define tMIN(a,b,typ) {typ _x_=(a); typ _y_=(b); _x_<_y_ ? _x_ : _y_}\n\n#if defined(ALLOW_THREADS)\n#define BEGIN_THREADS_DEF PyThreadState *_save;\n#define BEGIN_THREADS _save = PyEval_SaveThread();\n#define END_THREADS PyEval_RestoreThread(_save);\n#define ALLOW_C_API_DEF PyGILState_STATE __save__;\n#define ALLOW_C_API __save__ = PyGILState_Ensure();\n#define DISABLE_C_API PyGILState_Release(__save__);\n#else\n#define BEGIN_THREADS_DEF\n#define BEGIN_THREADS\n#define END_THREADS\n#define ALLOW_C_API_DEF\n#define\tALLOW_C_API\n#define\tDISABLE_C_API\n#endif\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\ntypedef struct {\n PyObject_HEAD\n\tint nd_m1; /* number of dimensions - 1 */\n intp\t\t index, size;\n\tintp coordinates[MAX_DIMS];/* N-dimensional loop */\n intp dims_m1[MAX_DIMS]; /* ao->dimensions - 1 */\n\tintp strides[MAX_DIMS]; /* ao->strides or fake */\n\tintp backstrides[MAX_DIMS];/* how far to jump back */\n\tintp factors[MAX_DIMS]; /* shape factors */\n\tPyArrayObject *ao;\n\tchar *dataptr; /* pointer to current item*/\n Bool contiguous;\n} PyArrayIterObject;\n\n\n/* Iterator API */\n#define PyArrayIter_Check(op) PyObject_TypeCheck(op, &PyArrayIter_Type)\n\n#define PyArray_ITER_RESET(it) {\t\t\t\t\t\\\n\tit->index = 0;\t\t\t\t\t\t \\\n\tit->dataptr = it->ao->data;\t\t\t\t\t\\\n\tmemset(it->coordinates, 0, (it->nd_m1+1)*sizeof(intp));\t\t\\\n}\n\n#define _PyArray_ITER_NEXT1(it) {\t\t\\\n\t\tit->dataptr += it->strides[0];\t\\\n\t\tit->coordinates[0]++;\t\t\\\n\t}\n\n#define _PyArray_ITER_NEXT2(it) {\t\t\t\t\t\\\n\t\tif (it->coordinates[1] < it->dims_m1[1]) {\t\t\\\n\t\t\tit->coordinates[1]++;\t\t\t\t\\\n\t\t\tit->dataptr += it->strides[1];\t\t\t\\\n\t\t}\t\t\t\t\t\t\t\\\n\t\telse {\t\t\t\t\t\t\t\\\n\t\t\tit->coordinates[1] = 0;\t\t\t\t\\\n\t\t\tit->coordinates[0]++;\t\t\t\t\\\n\t\t\tit->dataptr += it->strides[0] -\t\t\t\\\n\t\t\t\tit->backstrides[1];\t\t\t\\\n\t\t}\t\t\t\t\t\t\t\\\n\t}\n\n#define PyArray_ITER_NEXT(it) {\t\t\t\t\t\t\\\n\tit->index++;\t\t\t\t\t\t \\\n if (it->nd_m1 == 0) {\t\t\t\t\t\t\\\n\t\t_PyArray_ITER_NEXT1(it);\t\t\t\t\\\n\t}\t\t\t\t\t\t\t\t\\\n\telse if (it->contiguous) it->dataptr += it->ao->descr->elsize; \\\n\telse if (it->nd_m1 == 1) {\t\t\t\t\t\\\n\t\t_PyArray_ITER_NEXT2(it);\t\t\t\t\\\n\t}\t\t\t\t\t\t\t\t\\\n\telse {\t\t\t\t\t\t\t\t\\\n\t\tint _i_;\t\t\t\t\t\t\\\n\t\tfor (_i_ = it->nd_m1; _i_ >= 0; _i_--) {\t\t\\\n\t\t\tif (it->coordinates[_i_] <\t\t\t\\\n\t\t\t it->dims_m1[_i_]) {\t\t\t\t\\\n\t\t\t\tit->coordinates[_i_]++;\t\t\t\\\n\t\t\t\tit->dataptr += it->strides[_i_];\t\\\n\t\t\t\tbreak;\t\t\t\t\t\\\n\t\t\t}\t\t\t\t\t\t\\\n\t\t\telse {\t\t\t\t\t\t\\\n\t\t\t\tit->coordinates[_i_] = 0;\t\t\\\n\t\t\t\tit->dataptr -= it->backstrides[_i_];\t\\\n\t\t\t}\t\t\t\t\t\t\\\n\t\t}\t\t\t\t\t\t\t\\\n\t}\t\t\t\t\t\t\t\t\\\n}\n\n#define PyArray_ITER_GOTO(it, destination) {\t\t\t\t\\\n\t\tint _i_;\t\t\t\t\t\t\\\n\t\tit->index = 0;\t\t\t\t\t\t\\\n\t\tit->dataptr = it->ao->data;\t\t\t\t\\\n\t\tfor (_i_ = it->nd_m1; _i_>=0; _i_--) {\t\t\t\\\n\t\t\tit->dataptr += destination[_i_] *\t\t\\\n\t\t\t\tit->strides[_i_];\t\t\t\\\n\t\t\tit->coordinates[_i_] = destination[_i_];\t\\\n\t\t\tit->index += destination[_i_] *\t\t\t\\\n\t\t\t\t( _i_==it->nd_m1 ? 1 :\t\t\t\\\n\t\t\t\t it->dims_m1[i+1]+1) ;\t\t \\\n\t\t}\t\t\t\t\t\t\t\\\n\t}\n\n#define PyArray_ITER_GOTO1D(it, ind) { \\\n\t\tint _i_;\t\t\t\t\t\t\\\n\t\tintp _lind_ = (intp) (ind);\t\t\t\t\\\n\t\tit->index = _lind_;\t\t\t\t\t\\\n if (it->nd_m1 == 0) { \\\n it->dataptr = it->ao->data + (ind) * \\\n it->strides[0]; \\\n } \\\n else if (it->contiguous) \\\n\t\t\tit->dataptr = it->ao->data + (ind) *\t\t\\\n\t\t\t\tit->ao->descr->elsize;\t\t\t\\\n\t\telse {\t\t\t\t\t\t\t\\\n\t\t\tit->dataptr = it->ao->data;\t\t\t\\\n\t\t\tfor (_i_ = 0; _i_<=it->nd_m1; _i_++) {\t\t\\\n\t\t\t\tit->dataptr += (_lind_ / it->factors[_i_]) \\\n\t\t\t\t\t* it->strides[_i_];\t\t\\\n\t\t\t\t_lind_ %= it->factors[_i_];\t\t\\\n\t\t\t}\t\t\t\t\t\t\\\n\t\t}\t\t\t\t\t\t\t\\\n}\n\n#define PyArray_ITER_DATA(it) ((PyArrayIterObject *)it)->dataptr\n\n\n/*\n Any object passed to PyArray_Broadcast must be binary compatible with\n this structure.\n*/\n\ntypedef struct {\n\tPyObject_HEAD\n\n\tint numiter; /* number of iters */\n\tintp size; /* broadcasted size */\n\tintp index; /* current index */\n\tint nd; /* number of dims */\n\tintp dimensions[MAX_DIMS]; /* dimensions */\n\tPyArrayIterObject *iters[MAX_DIMS]; /* iterators */\n} PyArrayMultiIterObject;\n\n#define PyArray_MultiIter_RESET(multi) {\t\t\t \\\n\t\tint _mi_;\t\t\t\t\t \\\n\t\tPyArrayMultiIterObject *_mul_ = (multi);\t \\\n\t\t_mul_->index = 0;\t\t\t\t \\\n\t\tfor (_mi_ = 0; _mi_ < _mul_->numiter; _mi_++) {\t \\\n\t\t\tPyArray_ITER_RESET(_mul_->iters[_mi_]);\t \\\n\t\t}\t\t\t\t\t\t \\\n\t}\n\n#define PyArray_MultiIter_NEXT(multi) {\t\t\t\t \\\n\t\tint _mi_;\t\t\t\t\t \\\n\t\tPyArrayMultiIterObject *_mul_ = (multi);\t \\\n\t\t_mul_->index += 1;\t\t\t\t \\\n\t\tfor (_mi_=0; _mi_<_mul_->numiter; _mi_++) {\t \\\n\t\t\tPyArray_ITER_NEXT(_mul_->iters[_mi_]);\t \\\n\t\t}\t\t\t\t\t\t \\\n\t}\n\n#define PyArray_MultiIter_GOTO(multi, dest) {\t\t\t\t\\\n\t\tint _mi_;\t\t\t\t\t\t\\\n\t\tPyArrayMultiIterObject *_mul_ = (multi);\t\t\\\n\t\tfor (_mi_=0; _mi_<_mul_->numiter; _mi_++) {\t\t\\\n\t\t\tPyArray_ITER_GOTO(_mul_->iters[_mi_], dest);\t\\\n\t\t}\t\t\t\t\t\t\t\\\n\t\t_mul_->index = _mul_->iters[0]->index;\t\t\t\\\n\t}\n\n#define PyArray_MultiIter_GOTO1D(multi, ind) {\t\t\t\t\\\n\t\tint _mi_;\t\t\t\t\t\t\\\n\t\tPyArrayMultiIterObject *_mul_ = (multi);\t\t\\\n\t\tfor (_mi_=0; _mi_<_mul_->numiter; _mi_++) {\t\t\\\n\t\t\tPyArray_ITER_GOTO1D(_mul_->iters[_mi_], ind);\t\\\n\t\t}\t\t\t\t\t\t\t\\\n\t\t_mul_->index = _mul_->iters[0]->index;\t\t\t\\\n\t}\n\n#define PyArray_MultiIter_DATA(multi, i) \\\n\t((PyArrayMultiIterObject *)multi)->iters[i]->dataptr\n\n#define PyArray_MultiIter_SIZE(multi) \\\n\t((PyArrayMultiIterObject *)multi)->size;\n\n\n/* Store the information needed for fancy-indexing over an array */\n\ntypedef struct {\n\tPyObject_HEAD\n\t/* Multi-iterator portion --- needs to be present in this order to\n\t work with PyArray_Broadcast */\n\n\tint numiter; /* number of index-array\n\t\t\t\t\t\t\t iterators */\n\tintp size; /* size of broadcasted\n\t\t\t\t\t\t\t result */\n\tintp index; /* current index */\n\tint nd; /* number of dims */\n\tintp dimensions[MAX_DIMS]; /* dimensions */\n\tPyArrayIterObject *iters[MAX_DIMS]; /* index object\n\t\t\t\t\t\t\t iterators */\n\tPyArrayIterObject *ait; /* flat Iterator for\n\t\t\t\t\t\t\t underlying array */\n\n\t/* flat iterator for subspace (when numiter < nd) */\n\tPyArrayIterObject *subspace;\n\n\t/* if subspace iteration, then this is the array of\n\t axes in the underlying array represented by the\n\t index objects */\n\tint iteraxes[MAX_DIMS];\n\t/* if subspace iteration, the these are the coordinates\n\t to the start of the subspace.\n\t*/\n\tintp bscoord[MAX_DIMS];\n\n\tPyObject *indexobj; /* reference to\n\t\t\t\t\t\t\t creating obj */\n\tint view;\n\tint consec;\n\tchar *dataptr;\n\n} PyArrayMapIterObject;\n\n/* All sorts of useful ways to look into a PyArrayObject.\n These are the recommended over casting to PyArrayObject and accessing\n the members directly.\n */\n\n#define PyArray_NDIM(obj) (((PyArrayObject *)(obj))->nd)\n#define PyArray_ISONESEGMENT(m) (PyArray_NDIM(m) == 0 || PyArray_CHKFLAGS(m, CONTIGUOUS) || \\\n\t\t\t\t PyArray_CHKFLAGS(m, FORTRAN))\n#define PyArray_ISFORTRAN(m) (PyArray_CHKFLAGS(m, FORTRAN) && (PyArray_NDIM(m) > 1))\n#define FORTRAN_IF(m) ((PyArray_CHKFLAGS(m, FORTRAN) ? FORTRAN : 0))\n#define PyArray_DATA(obj) ((void *)(((PyArrayObject *)(obj))->data))\n#define PyArray_BYTES(obj) (((PyArrayObject *)(obj))->data)\n#define PyArray_DIMS(obj) (((PyArrayObject *)(obj))->dimensions)\n#define PyArray_STRIDES(obj) (((PyArrayObject *)(obj))->strides)\n#define PyArray_DIM(obj,n) (((PyArrayObject *)(obj))->dimensions[n])\n#define PyArray_STRIDE(obj,n) (((PyArrayObject *)(obj))->strides[n])\n#define PyArray_BASE(obj) (((PyArrayObject *)(obj))->base)\n#define PyArray_DESCR(obj) (((PyArrayObject *)(obj))->descr)\n#define PyArray_FLAGS(obj) (((PyArrayObject *)(obj))->flags)\n#define PyArray_ITEMSIZE(obj) (((PyArrayObject *)(obj))->descr->elsize)\n#define PyArray_TYPE(obj) (((PyArrayObject *)(obj))->descr->type_num)\n#define PyArray_GETITEM(obj,itemptr)\t\t\t\\\n\t((PyArrayObject *)(obj))->descr->getitem((char *)itemptr,\t\\\n\t\t\t\t\t\t (PyArrayObject *)obj);\n#define PyArray_SETITEM(obj,itemptr,v)\t\t\t\t\t\\\n\t(obj)->descr->setitem((PyObject *)v,(char *)(itemptr),\t\t\\\n\t\t\t (PyArrayObject *)(obj));\n\n\n#define PyTypeNum_ISBOOL(type) (type == PyArray_BOOL)\n#define PyTypeNum_ISUNSIGNED(type) ((type == PyArray_UBYTE) || \\\n\t\t\t\t (type == PyArray_USHORT) || \\\n\t\t\t\t (type == PyArray_UINT) ||\t\\\n\t\t\t\t (type == PyArray_ULONG) || \\\n\t\t\t\t (type == PyArray_ULONGLONG))\n\n#define PyTypeNum_ISSIGNED(type) ((type == PyArray_BYTE) ||\t\\\n\t\t\t (type == PyArray_SHORT) ||\t\\\n\t\t\t (type == PyArray_INT) ||\t\\\n\t\t\t (type == PyArray_LONG) ||\t\\\n\t\t\t (type == PyArray_LONGLONG))\n\n#define PyTypeNum_ISINTEGER(type) ((type >= PyArray_BYTE) &&\t\\\n\t\t\t\t(type <= PyArray_ULONGLONG))\n\n#define PyTypeNum_ISFLOAT(type) ((type >= PyArray_FLOAT) && \\\n\t\t\t (type <= PyArray_LONGDOUBLE))\n\n#define PyTypeNum_ISNUMBER(type) (type <= PyArray_CLONGDOUBLE)\n\n#define PyTypeNum_ISSTRING(type) ((type == PyArray_UCHAR) || \\\n\t\t\t (type == PyArray_UNICODE))\n\n#define PyTypeNum_ISCOMPLEX(type) ((type >= PyArray_CFLOAT) && \\\n\t\t\t\t(type <= PyArray_CLONGDOUBLE))\n\n#define PyTypeNum_ISPYTHON(type) ((type == PyArray_LONG) || \\\n\t\t\t\t (type == PyArray_DOUBLE) ||\t\\\n\t\t\t\t (type == PyArray_CDOUBLE) ||\t\\\n\t\t (type == PyArray_BOOL) || \\\n\t\t\t\t (type == PyArray_OBJECT ))\n\n#define PyTypeNum_ISFLEXIBLE(type) ((type>=PyArray_STRING) && \\\n\t\t\t\t (type<=PyArray_VOID))\n\n#define PyTypeNum_ISUSERDEF(type) ((type >= PyArray_USERDEF) && \\\n\t\t\t\t (type < PyArray_USERDEF+\\\n\t\t\t\t PyArray_NUMUSERTYPES))\n\n#define PyTypeNum_ISEXTENDED(type) (PyTypeNum_ISFLEXIBLE(type) || \\\n PyTypeNum_ISUSERDEF(type))\n\n#define PyTypeNum_ISOBJECT(type) ((type) == PyArray_OBJECT)\n\n#define _PyADt(o) ((PyArray_Descr *)o)->type_num\n#define PyDescr_ISBOOL(obj) PyTypeNum_ISBOOL(_PyADt(obj))\n#define PyDescr_ISUNSIGNED(obj) PyTypeNum_ISUNSIGNED(_PyADt(obj))\n#define PyDescr_ISSIGNED(obj) PyTypeNum_ISSIGNED(_PyADt(obj))\n#define PyDescr_ISINTEGER(obj) PyTypeNum_ISINTEGER(_PyADt(obj))\n#define PyDescr_ISFLOAT(obj) PyTypeNum_ISFLOAT(_PyADt(obj))\n#define PyDescr_ISNUMBER(obj) PyTypeNum_ISNUMBER(_PyADt(obj))\n#define PyDescr_ISSTRING(obj) PyTypeNum_ISSTRING(_PyADt(obj))\n#define PyDescr_ISCOMPLEX(obj) PyTypeNum_ISCOMPLEX(_PyADt(obj))\n#define PyDescr_ISPYTHON(obj) PyTypeNum_ISPYTHON(_PyADt(obj))\n#define PyDescr_ISFLEXIBLE(obj) PyTypeNum_ISFLEXIBLE(_PyADt(obj))\n#define PyDescr_ISUSERDEF(obj) PyTypeNum_ISUSERDEF(_PyADt(obj))\n#define PyDescr_ISEXTENDED(obj) PyTypeNum_ISEXTENDED(_PyADt(obj))\n#define PyDescr_ISOBJECT(obj) PyTypeNum_ISOBJECT(_PyADt(obj))\n#undef _PyAD\n\n#define PyArray_ISBOOL(obj) PyTypeNum_ISBOOL(PyArray_TYPE(obj))\n#define PyArray_ISUNSIGNED(obj) PyTypeNum_ISUNSIGNED(PyArray_TYPE(obj))\n#define PyArray_ISSIGNED(obj) PyTypeNum_ISSIGNED(PyArray_TYPE(obj))\n#define PyArray_ISINTEGER(obj) PyTypeNum_ISINTEGER(PyArray_TYPE(obj))\n#define PyArray_ISFLOAT(obj) PyTypeNum_ISFLOAT(PyArray_TYPE(obj))\n#define PyArray_ISNUMBER(obj) PyTypeNum_ISNUMBER(PyArray_TYPE(obj))\n#define PyArray_ISSTRING(obj) PyTypeNum_ISSTRING(PyArray_TYPE(obj))\n#define PyArray_ISCOMPLEX(obj) PyTypeNum_ISCOMPLEX(PyArray_TYPE(obj))\n#define PyArray_ISPYTHON(obj) PyTypeNum_ISPYTHON(PyArray_TYPE(obj))\n#define PyArray_ISFLEXIBLE(obj) PyTypeNum_ISFLEXIBLE(PyArray_TYPE(obj))\n#define PyArray_ISUSERDEF(obj) PyTypeNum_ISUSERDEF(PyArray_TYPE(obj))\n#define PyArray_ISEXTENDED(obj) PyTypeNum_ISEXTENDED(PyArray_TYPE(obj))\n#define PyArray_ISOBJECT(obj) PyTypeNum_ISOBJECT(PyArray_TYPE(obj))\n\n#define PyArray_LITTLE '<'\n#define PyArray_BIG '>'\n#define PyArray_NATIVE '='\n#define PyArray_SWAP 's'\n#define PyArray_IGNORE '|'\n\n#ifdef WORDS_BIGENDIAN\n#define PyArray_NATBYTE PyArray_BIG\n#define PyArray_OPPBYTE PyArray_LITTLE\n#else\n#define PyArray_NATBYTE PyArray_LITTLE\n#define PyArray_OPPBYTE PyArray_BIG\n#endif\n\n#define PyArray_ISNBO(arg) ((arg) != PyArray_OPPBYTE)\n#define PyArray_IsNativeByteOrder PyArray_ISNBO\n#define PyArray_ISNOTSWAPPED(m) PyArray_ISNBO(PyArray_DESCR(m)->byteorder)\n\n#define PyArray_FLAGSWAP(m, flags) (PyArray_CHKFLAGS(m, flags) &&\t\\\n\t\t\t\t PyArray_ISNOTSWAPPED(m))\n#define PyArray_ISCARRAY(m) PyArray_FLAGSWAP(m, CARRAY_FLAGS)\n#define PyArray_ISCARRAY_RO(m) PyArray_FLAGSWAP(m, CARRAY_FLAGS_RO)\n#define PyArray_ISFARRAY(m) PyArray_FLAGSWAP(m, FARRAY_FLAGS)\n#define PyArray_ISFARRAY_RO(m) PyArray_FLAGSWAP(m, FARRAY_FLAGS_RO)\n#define PyArray_ISBEHAVED(m) PyArray_FLAGSWAP(m, BEHAVED_FLAGS)\n#define PyArray_ISBEHAVED_RO(m) PyArray_FLAGSWAP(m, ALIGNED)\n\n\n\n/* This is the form of the struct that's returned pointed by the\n PyCObject attribute of an array __array_struct__. See\n http://numeric.scipy.org/array_interface.html for the full\n documentation. */\ntypedef struct {\n int version; /* contains the integer 2 as a sanity check */\n int nd; /* number of dimensions */\n char typekind; /* kind in array --- character code of typestr */\n int itemsize; /* size of each element */\n int flags; /* how should be data interpreted. Valid\n flags are CONTIGUOUS (1), FORTRAN (2),\n ALIGNED (0x100), NOTSWAPPED (0x200), and\n WRITEABLE (0x400)*/\n intp *shape; /* A length-nd array of shape information */\n intp *strides; /* A length-nd array of stride information */\n void *data; /* A pointer to the first element of the array */\n} PyArrayInterface;\n\n/* Includes the \"function\" C-API -- these are all stored in a\n list of pointers --- one for each file\n The two lists are concatenated into one in multiarray.\n\n They are available as import_array()\n*/\n\n\n#include \"__multiarray_api.h\"\n\n\n/* C-API that requries previous API to be defined */\n\n#define PyArray_DescrCheck(op) ((op)->ob_type == &PyArrayDescr_Type)\n\n#define PyArray_Check(op) ((op)->ob_type == &PyArray_Type || \\\n\t\t\t PyObject_TypeCheck((op), &PyBigArray_Type))\n#define PyBigArray_CheckExact(op) ((op)->ob_type == &PyBigArray_Type)\n#define PyArray_CheckExact(op) ((op)->ob_type == &PyArray_Type)\n\n#define PyArray_IsZeroDim(op) (PyArray_Check(op) && (PyArray_NDIM(op) == 0))\n#define PyArray_IsScalar(obj, cls)\t\t\t\t\\\n\t(PyObject_TypeCheck((obj), &Py##cls##ArrType_Type))\n#define PyArray_CheckScalar(m) (PyArray_IsScalar(m, Generic) || \\\n PyArray_IsZeroDim(m))\n#define PyArray_IsPythonScalar(obj) \\\n\t(PyInt_Check(obj) || PyFloat_Check(obj) || PyComplex_Check(obj) || \\\n\t PyLong_Check(obj) || PyBool_Check(obj) || PyString_Check(obj) || \\\n\t PyUnicode_Check(obj))\n#define PyArray_IsAnyScalar(obj)\t\t\t\t\t\\\n\t(PyArray_IsScalar(obj, Generic) || PyArray_IsPythonScalar(obj))\n#define PyArray_CheckAnyScalar(obj) (PyArray_IsPythonScalar(obj) || \\\n\t\t\t\t PyArray_CheckScalar(obj))\n\n#define PyArray_GETCONTIGUOUS(m) (PyArray_ISCONTIGUOUS(m) ? Py_INCREF(m), m : \\\n (PyArrayObject *)(PyArray_Copy(m)))\n\n#define PyArray_SIZE(m) PyArray_MultiplyList(PyArray_DIMS(m), PyArray_NDIM(m))\n#define PyArray_NBYTES(m) (PyArray_ITEMSIZE(m) * PyArray_SIZE(m))\n#define PyArray_FROM_O(m) PyArray_FromAny(m, NULL, 0, 0, 0, NULL)\n#define PyArray_FROM_OF(m,flags) PyArray_CheckFromAny(m, NULL, 0, 0, flags, NULL)\n#define PyArray_FROM_OT(m,type) PyArray_FromAny(m, PyArray_DescrFromType(type), \\\n 0, 0, 0, NULL);\n#define PyArray_FROM_OTF(m, type, flags) \\\n\tPyArray_FromAny(m, PyArray_DescrFromType(type), 0, 0, \\\n (((flags) & ENSURECOPY) ? \\\n ((flags) | DEFAULT_FLAGS) : (flags)), NULL)\n#define PyArray_FROMANY(m, type, min, max, flags) \\\n\tPyArray_FromAny(m, PyArray_DescrFromType(type), min, max, \\\n (((flags) & ENSURECOPY) ? \\\n (flags) | DEFAULT_FLAGS : (flags)), NULL)\n\n#define PyArray_FILLWBYTE(obj, val) memset(PyArray_DATA(obj), (val), PyArray_NBYTES(obj))\n\n#define REFCOUNT(obj) (((PyObject *)(obj))->ob_refcnt)\n#define MAX_ELSIZE 2*SIZEOF_LONGDOUBLE\n\n#define PyArray_ContiguousFromAny(op, type, min_depth, max_depth) \\\n PyArray_FromAny(op, PyArray_DescrFromType(type), min_depth, \\\n max_depth, DEFAULT_FLAGS, NULL)\n\n#define PyArray_EquivArrTypes(a1, a2)\t\t\t\t\t\\\n\tPyArray_EquivTypes(PyArray_DESCR(a1), PyArray_DESCR(a2))\n#define PyArray_EquivTypenums(typenum1, typenum2)\t\t\\\n\tPyArray_EquivTypes(PyArray_DescrFromType(typenum1),\t\\\n\t\t\t PyArray_DescrFromType(typenum2))\n\n#define PyArray_EquivByteorders(b1, b2) \\\n\t((b1 == b2) || (PyArray_ISNBO(b1) == PyArray_ISNBO(b2)))\n\n#define PyArray_SimpleNew(nd, dims, typenum) \\\n\tPyArray_New(&PyArray_Type, nd, dims, typenum, NULL, NULL, 0, 0, NULL)\n#define PyArray_SimpleNewFromData(nd, dims, typenum, data) \\\n PyArray_New(&PyArray_Type, nd, dims, typenum, NULL, data, 0, CARRAY_FLAGS, NULL)\n#define PyArray_SimpleNewFromDescr(nd, dims, descr) \\\n\tPyArray_NewFromDescr(&PyArray_Type, descr, nd, dims, NULL, NULL, 0, NULL)\n\n\n/* These might be faster without the dereferencing of obj\n going on inside -- of course an optimizing compiler should\n inline the constants inside a for loop making it a moot point\n*/\n\n#define PyArray_GETPTR1(obj, i) (void *)(PyArray_BYTES(obj) +\t\t\\\n\t\t\t\t i*PyArray_STRIDE(obj, 0))\n\n#define PyArray_GETPTR2(obj, i, j) (void *)(PyArray_BYTES(obj) +\t\t\\\n\t\t\t\t i*PyArray_STRIDE(obj, 0) +\t\\\n\t\t\t\t j*PyArray_STRIDE(obj, 1))\n\n#define PyArray_GETPTR3(obj, i, j, k) (void *)(PyArray_BYTES(obj) +\t\t\\\n\t\t\t\t i*PyArray_STRIDE(obj, 0) +\t\\\n\t\t\t\t j*PyArray_STRIDE(obj, 1) +\t\\\n\t\t\t\t k*PyArray_STRIDE(obj, 2))\t\\\n\n#define PyArray_GETPTR4(obj, i, j, k, l) (void *)(PyArray_BYTES(obj) +\t\t\\\n\t\t\t\t\t i*PyArray_STRIDE(obj, 0) +\t\\\n\t\t\t\t\t j*PyArray_STRIDE(obj, 1) +\t\\\n\t\t\t\t\t k*PyArray_STRIDE(obj, 2) +\t\\\n\t\t\t\t\t l*PyArray_STRIDE(obj, 3))\n\n#define PyArray_DESCR_REPLACE(descr) do {\t\\\n\t\tPyArray_Descr *_new_;\t\t\t\\\n\t\t_new_ = PyArray_DescrNew(descr);\t\\\n\t\tPy_XDECREF(descr);\t\t\t\\\n\t\tdescr = _new_;\t\t\t\t\\\n\t} while(0)\n\n/* Copy should always return contiguous array */\n#define PyArray_Copy(obj) PyArray_NewCopy(obj, 0)\n\n#define PyArray_FromObject(op, type, min_depth, max_depth)\t\t\\\n\tPyArray_FromAny(op, PyArray_DescrFromType(type), min_depth,\t\\\n max_depth, BEHAVED_FLAGS | ENSUREARRAY, NULL)\n\n#define PyArray_ContiguousFromObject(op, type, min_depth, max_depth)\t\\\n PyArray_FromAny(op, PyArray_DescrFromType(type), min_depth,\t\\\n max_depth, DEFAULT_FLAGS | ENSUREARRAY, NULL)\n\n#define PyArray_CopyFromObject(op, type, min_depth, max_depth)\t\t\\\n PyArray_FromAny(op, PyArray_DescrFromType(type), min_depth, \\\n max_depth, ENSURECOPY | DEFAULT_FLAGS | ENSUREARRAY, NULL)\n\n#define PyArray_Cast(mp, type_num) \\\n\tPyArray_CastToType(mp, PyArray_DescrFromType(type_num), 0)\n\n/* Compatibility with old Numeric stuff -- don't use in new code */\n\n#define PyArray_FromDimsAndData(nd, d, type, data) \\\n\tPyArray_FromDimsAndDataAndDescr(nd, d, PyArray_DescrFromType(type), \\\n\t\t\t\t\tdata)\n\n#define PyArray_UNSIGNED_TYPES\n#define PyArray_SBYTE PyArray_BYTE\n#define PyArray_CHAR PyArray_BYTE\n#define PyArray_CopyArray PyArray_CopyInto\n#define _PyArray_multiply_list PyArray_MultiplyIntList\n#define PyArray_ISSPACESAVER(m) FALSE\n#define PyScalarArray_Check PyArray_CheckScalar\n\n#ifdef PY_ARRAY_TYPES_PREFIX\n# undef CAT\n# undef CAT2\n# undef NS\n# undef longlong\n# undef ulonglong\n# undef Bool\n# undef longdouble\n# undef byte\n# undef ubyte\n# undef ushort\n# undef uint\n# undef ulong\n# undef cfloat\n# undef cdouble\n# undef clongdouble\n# undef Int8\n# undef UInt8\n# undef Int16\n# undef UInt16\n# undef Int32\n# undef UInt32\n# undef Int64\n# undef UInt64\n# undef Int128\n# undef UInt128\n# undef Int256\n# undef UInt256\n# undef Float16\n# undef Complex32\n# undef Float32\n# undef Complex64\n# undef Float64\n# undef Complex128\n# undef Float80\n# undef Complex160\n# undef Float96\n# undef Complex192\n# undef Float128\n# undef Complex256\n# undef intp\n# undef uintp\n#endif\n\n#ifdef __cplusplus\n}\n#endif\n\n#endif /* !Py_ARRAYOBJECT_H */\n", + "methods": [], + "methods_before": [], + "changed_methods": [], + "nloc": 289, + "complexity": 0, + "token_count": 1354, + "diff_parsed": { + "added": [ + "\t\t\t\t\t i*PyArray_STRIDE(obj, 0))", + "", + "#define PyArray_GETPTR2(obj, i, j) (void *)(PyArray_BYTES(obj) +\t\\", + "\t\t\t\t\t i*PyArray_STRIDE(obj, 0) +\t\\", + "\t\t\t\t\t j*PyArray_STRIDE(obj, 1))", + "", + "#define PyArray_GETPTR3(obj, i, j, k) (void *)(PyArray_BYTES(obj) +\t\\", + "\t\t\t\t\t i*PyArray_STRIDE(obj, 0) + \\", + "\t\t\t\t\t j*PyArray_STRIDE(obj, 1) + \\", + "\t\t\t\t\t k*PyArray_STRIDE(obj, 2)) \\", + "", + "#define PyArray_GETPTR4(obj, i, j, k, l) (void *)(PyArray_BYTES(obj) +\t\\", + "\t\t\t\t\t\t i*PyArray_STRIDE(obj, 0) + \\", + "\t\t\t\t\t\t j*PyArray_STRIDE(obj, 1) + \\", + "\t\t\t\t\t\t k*PyArray_STRIDE(obj, 2) + \\", + "\t\t\t\t\t\t l*PyArray_STRIDE(obj, 3))" + ], + "deleted": [ + "\t\t\t\t i*PyArray_STRIDE(obj, 0))", + "", + "#define PyArray_GETPTR2(obj, i, j) (void *)(PyArray_BYTES(obj) +\t\t\\", + "\t\t\t\t i*PyArray_STRIDE(obj, 0) +\t\\", + "\t\t\t\t j*PyArray_STRIDE(obj, 1))", + "", + "#define PyArray_GETPTR3(obj, i, j, k) (void *)(PyArray_BYTES(obj) +\t\t\\", + "\t\t\t\t i*PyArray_STRIDE(obj, 0) +\t\\", + "\t\t\t\t j*PyArray_STRIDE(obj, 1) +\t\\", + "\t\t\t\t k*PyArray_STRIDE(obj, 2))\t\\", + "", + "#define PyArray_GETPTR4(obj, i, j, k, l) (void *)(PyArray_BYTES(obj) +\t\t\\", + "\t\t\t\t\t i*PyArray_STRIDE(obj, 0) +\t\\", + "\t\t\t\t\t j*PyArray_STRIDE(obj, 1) +\t\\", + "\t\t\t\t\t k*PyArray_STRIDE(obj, 2) +\t\\", + "\t\t\t\t\t l*PyArray_STRIDE(obj, 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": "@@ -191,6 +191,8 @@ def check_test_interning(self):\n self.failUnless(array([True])[0] is a1)\n self.failUnless(array(True)[...] is a1)\n \n+# Import tests from unicode\n+from test_unicode import *\n \n if __name__ == \"__main__\":\n ScipyTest('numpy.core.multiarray').run()\n", + "added_lines": 2, + "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.dtype.itemsize)\n assert_equal(self.two.base, arange(20))\n\n def check_dtypeattr(self):\n assert_equal(self.one.dtype, dtype(int_))\n assert_equal(self.three.dtype, dtype(float_))\n assert_equal(self.one.dtype.char, 'l')\n assert_equal(self.three.dtype.char, 'd')\n self.failUnless(self.three.dtype.str[0] in '<>')\n assert_equal(self.one.dtype.str[1], 'i')\n assert_equal(self.three.dtype.str[1], 'f')\n\n def check_stridesattr(self):\n x = self.one\n def make_array(size, offset, strides):\n return ndarray([size], buffer=x,\n offset=offset*x.itemsize,\n strides=strides*x.itemsize)\n assert_equal(make_array(4, 4, -1), array([4, 3, 2, 1]))\n self.failUnlessRaises(ValueError, make_array, 4, 4, -2)\n self.failUnlessRaises(ValueError, make_array, 4, 3, -1)\n self.failUnlessRaises(ValueError, make_array, 8, 3, 1)\n self.failUnlessRaises(ValueError, make_array, 8, 3, 0)\n self.failUnlessRaises(ValueError, lambda: ndarray([1], strides=4))\n \n\n def check_set_stridesattr(self):\n x = self.one\n def make_array(size, offset, strides):\n try:\n r = ndarray([size], buffer=x, offset=offset*x.itemsize)\n except:\n pass\n r.strides = strides=strides*x.itemsize\n return r\n assert_equal(make_array(4, 4, -1), array([4, 3, 2, 1]))\n self.failUnlessRaises(ValueError, make_array, 4, 4, -2)\n self.failUnlessRaises(ValueError, make_array, 4, 3, -1)\n self.failUnlessRaises(ValueError, make_array, 8, 3, 1)\n self.failUnlessRaises(ValueError, make_array, 8, 3, 0)\n\n\nclass test_dtypedescr(ScipyTestCase):\n def check_construction(self):\n d1 = dtype('i4')\n assert_equal(d1, dtype(int32))\n d2 = dtype('f8')\n assert_equal(d2, dtype(float64))\n\nclass test_fromstring(ScipyTestCase):\n def check_binary(self):\n a = fromstring('\\x00\\x00\\x80?\\x00\\x00\\x00@\\x00\\x00@@\\x00\\x00\\x80@',dtype='')\n assert_equal(self.one.dtype.str[1], 'i')\n assert_equal(self.three.dtype.str[1], 'f')\n\n def check_stridesattr(self):\n x = self.one\n def make_array(size, offset, strides):\n return ndarray([size], buffer=x,\n offset=offset*x.itemsize,\n strides=strides*x.itemsize)\n assert_equal(make_array(4, 4, -1), array([4, 3, 2, 1]))\n self.failUnlessRaises(ValueError, make_array, 4, 4, -2)\n self.failUnlessRaises(ValueError, make_array, 4, 3, -1)\n self.failUnlessRaises(ValueError, make_array, 8, 3, 1)\n self.failUnlessRaises(ValueError, make_array, 8, 3, 0)\n self.failUnlessRaises(ValueError, lambda: ndarray([1], strides=4))\n \n\n def check_set_stridesattr(self):\n x = self.one\n def make_array(size, offset, strides):\n try:\n r = ndarray([size], buffer=x, offset=offset*x.itemsize)\n except:\n pass\n r.strides = strides=strides*x.itemsize\n return r\n assert_equal(make_array(4, 4, -1), array([4, 3, 2, 1]))\n self.failUnlessRaises(ValueError, make_array, 4, 4, -2)\n self.failUnlessRaises(ValueError, make_array, 4, 3, -1)\n self.failUnlessRaises(ValueError, make_array, 8, 3, 1)\n self.failUnlessRaises(ValueError, make_array, 8, 3, 0)\n\n\nclass test_dtypedescr(ScipyTestCase):\n def check_construction(self):\n d1 = dtype('i4')\n assert_equal(d1, dtype(int32))\n d2 = dtype('f8')\n assert_equal(d2, dtype(float64))\n\nclass test_fromstring(ScipyTestCase):\n def check_binary(self):\n a = fromstring('\\x00\\x00\\x80?\\x00\\x00\\x00@\\x00\\x00@@\\x00\\x00\\x80@',dtype=''}[sys.byteorder]\n \n def normalize_descr(descr):\n- \"Normalize a description adding the addient byteorder.\"\n+ \"Normalize a description adding the platform byteorder.\"\n \n out = []\n for item in descr:\n@@ -97,30 +96,39 @@ def normalize_descr(descr):\n \n \n ############################################################\n-# Creating tests\n+# Creation tests\n ############################################################\n \n class create_zeros(ScipyTestCase):\n \"\"\"Check the creation of heterogeneous arrays zero-valued\"\"\"\n \n- def check_zerosScalar(self):\n- \"\"\"Check creation of multirow objects\"\"\"\n+ def check_zeros0D(self):\n+ \"\"\"Check creation of 0-dimensional objects\"\"\"\n h = zeros((), dtype=self._descr)\n self.assert_(normalize_descr(self._descr) == h.dtype.descr)\n+ self.assert_(h.dtype.fields['x'][0].name[:4] == 'void') \n+ self.assert_(h.dtype.fields['x'][0].char == 'V') \n+ self.assert_(h.dtype.fields['x'][0].type == numpy.void) \n # A small check that data is ok\n assert_equal(h['z'], zeros((), dtype='u1'))\n \n def check_zerosSD(self):\n- \"\"\"Check creation of multirow objects\"\"\"\n+ \"\"\"Check creation of single-dimensional objects\"\"\"\n h = zeros((2,), dtype=self._descr)\n self.assert_(normalize_descr(self._descr) == h.dtype.descr)\n+ self.assert_(h.dtype['y'].name[:4] == 'void') \n+ self.assert_(h.dtype['y'].char == 'V') \n+ self.assert_(h.dtype['y'].type == numpy.void) \n # A small check that data is ok\n assert_equal(h['z'], zeros((2,), dtype='u1'))\n \n def check_zerosMD(self):\n- \"\"\"Check creation of multidimensional objects\"\"\"\n+ \"\"\"Check creation of multi-dimensional objects\"\"\"\n h = zeros((2,3), dtype=self._descr)\n self.assert_(normalize_descr(self._descr) == h.dtype.descr)\n+ self.assert_(h.dtype['z'].name == 'uint8') \n+ self.assert_(h.dtype['z'].char == 'B') \n+ self.assert_(h.dtype['z'].type == numpy.uint8) \n # A small check that data is ok\n assert_equal(h['z'], zeros((2,3), dtype='u1'))\n \n@@ -140,7 +148,7 @@ class create_values(ScipyTestCase):\n \n def check_tuple(self):\n \"\"\"Check creation from tuples\"\"\"\n- h = array(self._bufferT, dtype=self._descr)\n+ h = array(self._buffer, dtype=self._descr)\n self.assert_(normalize_descr(self._descr) == h.dtype.descr)\n if self.multiple_rows:\n self.assert_(h.shape == (2,))\n@@ -149,7 +157,7 @@ def check_tuple(self):\n \n def check_list_of_tuple(self):\n \"\"\"Check creation from list of tuples\"\"\"\n- h = array([self._bufferT], dtype=self._descr)\n+ h = array([self._buffer], dtype=self._descr)\n self.assert_(normalize_descr(self._descr) == h.dtype.descr)\n if self.multiple_rows:\n self.assert_(h.shape == (1,2))\n@@ -158,7 +166,7 @@ def check_list_of_tuple(self):\n \n def check_list_of_list_of_tuple(self):\n \"\"\"Check creation from list of list of tuples\"\"\"\n- h = array([[self._bufferT]], dtype=self._descr)\n+ h = array([[self._buffer]], dtype=self._descr)\n self.assert_(normalize_descr(self._descr) == h.dtype.descr)\n if self.multiple_rows:\n self.assert_(h.shape == (1,1,2))\n@@ -170,25 +178,25 @@ class test_create_values_plain_single(create_values):\n \"\"\"Check the creation of heterogeneous arrays (plain, single row)\"\"\"\n _descr = Pdescr\n multiple_rows = 0\n- _bufferT = PbufferT[0]\n+ _buffer = PbufferT[0]\n \n class test_create_values_plain_multiple(create_values):\n \"\"\"Check the creation of heterogeneous arrays (plain, multiple rows)\"\"\"\n _descr = Pdescr\n multiple_rows = 1\n- _bufferT = PbufferT\n+ _buffer = PbufferT\n \n class test_create_values_nested_single(create_values):\n \"\"\"Check the creation of heterogeneous arrays (nested, single row)\"\"\"\n _descr = Ndescr\n multiple_rows = 0\n- _bufferT = NbufferT[0]\n+ _buffer = NbufferT[0]\n \n class test_create_values_nested_multiple(create_values):\n \"\"\"Check the creation of heterogeneous arrays (nested, multiple rows)\"\"\"\n _descr = Ndescr\n multiple_rows = 1\n- _bufferT = NbufferT\n+ _buffer = NbufferT\n \n \n ############################################################\n@@ -198,65 +206,131 @@ class test_create_values_nested_multiple(create_values):\n class read_values_plain(ScipyTestCase):\n \"\"\"Check the reading of values in heterogeneous arrays (plain)\"\"\"\n \n- def is_correct(self):\n- if self.multiple_rows:\n- assert_equal(self.h['x'], array(self._buffer[0][0], dtype='i4'))\n- assert_equal(self.h['y'], array(self._buffer[0][1], dtype='f8'))\n- assert_equal(self.h['z'], array(self._buffer[0][2], dtype='u1'))\n+ def check_access_fields(self):\n+ h = array(self._buffer, dtype=self._descr)\n+ if not self.multiple_rows:\n+ self.assert_(h.shape == ())\n+ assert_equal(h['x'], array(self._buffer[0], dtype='i4'))\n+ assert_equal(h['y'], array(self._buffer[1], dtype='f8'))\n+ assert_equal(h['z'], array(self._buffer[2], dtype='u1'))\n else:\n- assert_equal(self.h['x'], array([self._buffer[0][0],\n+ self.assert_(len(h) == 2)\n+ assert_equal(h['x'], array([self._buffer[0][0],\n self._buffer[1][0]], dtype='i4'))\n- assert_equal(self.h['y'], array([self._buffer[0][1],\n+ assert_equal(h['y'], array([self._buffer[0][1],\n self._buffer[1][1]], dtype='f8'))\n- assert_equal(self.h['z'], array([self._buffer[0][2],\n+ assert_equal(h['z'], array([self._buffer[0][2],\n self._buffer[1][2]], dtype='u1'))\n \n \n- def check_read_full_tuples(self):\n- \"\"\"Check reading from objects created from tuples\"\"\"\n- self._buffer = self._bufferT\n- self.h = array(self._buffer, dtype=self._descr)\n-\n-\n class test_read_values_plain_single(read_values_plain):\n \"\"\"Check the creation of heterogeneous arrays (plain, single row)\"\"\"\n _descr = Pdescr\n multiple_rows = 0\n- _bufferT = PbufferT[0]\n+ _buffer = PbufferT[0]\n \n class test_read_values_plain_multiple(read_values_plain):\n \"\"\"Check the values of heterogeneous arrays (plain, multiple rows)\"\"\"\n _descr = Pdescr\n multiple_rows = 1\n- _bufferT = PbufferT\n+ _buffer = PbufferT\n \n-class read_values_nested(read_values_plain):\n+class read_values_nested(ScipyTestCase):\n \"\"\"Check the reading of values in heterogeneous arrays (nested)\"\"\"\n \n \n- # Uncomment this when numpy will eventually support lists as inputs.\n- def _check_read_full_list(self):\n- \"\"\"Check reading from objects created from list\"\"\"\n- h = array(self._bufferT, dtype=self._descr)\n- # Add here more code to check this...\n-\n- def check_read_full_tuple(self):\n- \"\"\"Check reading from objects created from tuples\"\"\"\n- h = array(self._bufferT, dtype=self._descr)\n- # Add here more code to check this...\n-\n-# The next test classes are not finished yet...\n-class _test_read_values_nested_single(read_values_nested):\n+ def check_access_top_fields(self):\n+ \"\"\"Check reading the top fields of a nested array\"\"\"\n+ h = array(self._buffer, dtype=self._descr)\n+ if not self.multiple_rows:\n+ self.assert_(h.shape == ())\n+ assert_equal(h['x'], array(self._buffer[0], dtype='i4'))\n+ assert_equal(h['y'], array(self._buffer[4], dtype='f8'))\n+ assert_equal(h['z'], array(self._buffer[5], dtype='u1'))\n+ else:\n+ self.assert_(len(h) == 2)\n+ assert_equal(h['x'], array([self._buffer[0][0],\n+ self._buffer[1][0]], dtype='i4'))\n+ assert_equal(h['y'], array([self._buffer[0][4],\n+ self._buffer[1][4]], dtype='f8'))\n+ assert_equal(h['z'], array([self._buffer[0][5],\n+ self._buffer[1][5]], dtype='u1'))\n+\n+\n+ def check_nested1_acessors(self):\n+ \"\"\"Check reading the nested fields of a nested array (1st level)\"\"\"\n+ h = array(self._buffer, dtype=self._descr)\n+ if not self.multiple_rows:\n+ assert_equal(h['Info']['value'],\n+ array(self._buffer[1][0], dtype='c16'))\n+ assert_equal(h['Info']['y2'],\n+ array(self._buffer[1][1], dtype='f8'))\n+ assert_equal(h['info']['Name'],\n+ array(self._buffer[3][0], dtype='U2'))\n+ assert_equal(h['info']['Value'],\n+ array(self._buffer[3][1], dtype='c16'))\n+ else:\n+ assert_equal(h['Info']['value'],\n+ array([self._buffer[0][1][0],\n+ self._buffer[1][1][0]],\n+ dtype='c16'))\n+ assert_equal(h['Info']['y2'],\n+ array([self._buffer[0][1][1],\n+ self._buffer[1][1][1]],\n+ dtype='f8'))\n+ assert_equal(h['info']['Name'],\n+ array([self._buffer[0][3][0],\n+ self._buffer[1][3][0]],\n+ dtype='U2'))\n+ assert_equal(h['info']['Value'],\n+ array([self._buffer[0][3][1],\n+ self._buffer[1][3][1]],\n+ dtype='c16'))\n+\n+ def check_nested2_acessors(self):\n+ \"\"\"Check reading the nested fields of a nested array (2nd level)\"\"\"\n+ h = array(self._buffer, dtype=self._descr)\n+ if not self.multiple_rows:\n+ assert_equal(h['Info']['Info2']['value'],\n+ array(self._buffer[1][2][1], dtype='c16'))\n+ assert_equal(h['Info']['Info2']['z3'],\n+ array(self._buffer[1][2][3], dtype='u4'))\n+ else:\n+ assert_equal(h['Info']['Info2']['value'],\n+ array([self._buffer[0][1][2][1],\n+ self._buffer[1][1][2][1]],\n+ dtype='c16'))\n+ assert_equal(h['Info']['Info2']['z3'],\n+ array([self._buffer[0][1][2][3],\n+ self._buffer[1][1][2][3]],\n+ dtype='u4'))\n+\n+ def check_nested1_descriptor(self):\n+ \"\"\"Check access nested descriptors of a nested array (1st level)\"\"\"\n+ h = array(self._buffer, dtype=self._descr)\n+ self.assert_(h.dtype['Info']['value'].name == 'complex128')\n+ self.assert_(h.dtype['Info']['y2'].name == 'float64')\n+ self.assert_(h.dtype['info']['Name'].name == 'unicode256')\n+ self.assert_(h.dtype['info']['Value'].name == 'complex128')\n+\n+ def check_nested2_descriptor(self):\n+ \"\"\"Check access nested descriptors of a nested array (2nd level)\"\"\"\n+ h = array(self._buffer, dtype=self._descr)\n+ self.assert_(h.dtype['Info']['Info2']['value'].name == 'void256')\n+ self.assert_(h.dtype['Info']['Info2']['z3'].name == 'void64')\n+\n+\n+class test_read_values_nested_single(read_values_nested):\n \"\"\"Check the values of heterogeneous arrays (nested, single row)\"\"\"\n _descr = Ndescr\n multiple_rows = 0\n- _bufferT = NbufferT[0]\n+ _buffer = NbufferT[0]\n \n-class _test_read_values_nested_multiple(read_values_nested):\n+class test_read_values_nested_multiple(read_values_nested):\n \"\"\"Check the values of heterogeneous arrays (nested, multiple rows)\"\"\"\n _descr = Ndescr\n multiple_rows = 1\n- _bufferT = NbufferT\n+ _buffer = NbufferT\n \n \n if __name__ == \"__main__\":\n", + "added_lines": 123, + "deleted_lines": 49, + "source_code": "import sys\nfrom numpy.testing import *\nimport numpy\nfrom numpy import zeros, ones, array\n\n\n# This is the structure of the table used for plain objects:\n#\n# +-+-+-+\n# |x|y|z|\n# +-+-+-+\n\n# Structure of a plain array description:\nPdescr = [\n ('x', 'i4', (2,)),\n ('y', 'f8', (2, 2)),\n ('z', 'u1')]\n\n# A plain list of tuples with values for testing:\nPbufferT = [\n # x y z\n ([3,2], [[6.,4.],[6.,4.]], 8),\n ([4,3], [[7.,5.],[7.,5.]], 9),\n ]\n\n\n# This is the structure of the table used for nested objects (DON'T PANIC!):\n#\n# +-+---------------------------------+-----+----------+-+-+\n# |x|Info |color|info |y|z|\n# | +-----+--+----------------+----+--+ +----+-----+ | |\n# | |value|y2|Info2 |name|z2| |Name|Value| | |\n# | | | +----+-----+--+--+ | | | | | | |\n# | | | |name|value|y3|z3| | | | | | | |\n# +-+-----+--+----+-----+--+--+----+--+-----+----+-----+-+-+\n#\n\n# The corresponding nested array description:\nNdescr = [\n ('x', 'i4', (2,)),\n ('Info', [\n ('value', 'c16'),\n ('y2', 'f8'),\n ('Info2', [\n ('name', 'S2'),\n ('value', 'c16', (2,)),\n ('y3', 'f8', (2,)),\n ('z3', 'u4', (2,))]),\n ('name', 'S2'),\n ('z2', 'b1')]),\n ('color', 'S2'),\n ('info', [\n ('Name', 'U8'), # Try out 'U8' when interpretation of Unicode strings is more clear\n ('Value', 'c16')]),\n ('y', 'f8', (2, 2)),\n ('z', 'u1')]\n\nNbufferT = [\n # x Info color info y z\n # value y2 Info2 name z2 Name Value\n # name value y3 z3\n ([3,2], (6j, 6., ('nn', [6j,4j], [6.,4.], [1,2]), 'NN', True), 'cc', ('NN', 6j), [[6.,4.],[6.,4.]], 8),\n ([4,3], (7j, 7., ('oo', [7j,5j], [7.,5.], [2,1]), 'OO', False), 'dd', ('OO', 7j), [[7.,5.],[7.,5.]], 9),\n ]\n\n\nbyteorder = {'little':'<', 'big':'>'}[sys.byteorder]\n\ndef normalize_descr(descr):\n \"Normalize a description adding the platform byteorder.\"\n\n out = []\n for item in descr:\n dtype = item[1]\n if isinstance(dtype, str):\n if dtype[0] not in ['|','<','>']:\n onebyte = dtype[1:] == \"1\"\n if onebyte or dtype[0] in ['S', 'V', 'b']:\n dtype = \"|\" + dtype\n else:\n dtype = byteorder + dtype\n if len(item) > 2 and item[2] > 1:\n nitem = (item[0], dtype, item[2])\n else:\n nitem = (item[0], dtype)\n out.append(nitem)\n elif isinstance(item[1], list):\n l = []\n for j in normalize_descr(item[1]):\n l.append(j)\n out.append((item[0], l))\n else:\n raise ValueError(\"Expected a str or list and got %s\" % \\\n (type(item)))\n return out\n\n\n############################################################\n# Creation tests\n############################################################\n\nclass create_zeros(ScipyTestCase):\n \"\"\"Check the creation of heterogeneous arrays zero-valued\"\"\"\n\n def check_zeros0D(self):\n \"\"\"Check creation of 0-dimensional objects\"\"\"\n h = zeros((), dtype=self._descr)\n self.assert_(normalize_descr(self._descr) == h.dtype.descr)\n self.assert_(h.dtype.fields['x'][0].name[:4] == 'void') \n self.assert_(h.dtype.fields['x'][0].char == 'V') \n self.assert_(h.dtype.fields['x'][0].type == numpy.void) \n # A small check that data is ok\n assert_equal(h['z'], zeros((), dtype='u1'))\n\n def check_zerosSD(self):\n \"\"\"Check creation of single-dimensional objects\"\"\"\n h = zeros((2,), dtype=self._descr)\n self.assert_(normalize_descr(self._descr) == h.dtype.descr)\n self.assert_(h.dtype['y'].name[:4] == 'void') \n self.assert_(h.dtype['y'].char == 'V') \n self.assert_(h.dtype['y'].type == numpy.void) \n # A small check that data is ok\n assert_equal(h['z'], zeros((2,), dtype='u1'))\n\n def check_zerosMD(self):\n \"\"\"Check creation of multi-dimensional objects\"\"\"\n h = zeros((2,3), dtype=self._descr)\n self.assert_(normalize_descr(self._descr) == h.dtype.descr)\n self.assert_(h.dtype['z'].name == 'uint8') \n self.assert_(h.dtype['z'].char == 'B') \n self.assert_(h.dtype['z'].type == numpy.uint8) \n # A small check that data is ok\n assert_equal(h['z'], zeros((2,3), dtype='u1'))\n\n\nclass test_create_zeros_plain(create_zeros):\n \"\"\"Check the creation of heterogeneous arrays zero-valued (plain)\"\"\"\n _descr = Pdescr\n\nclass test_create_zeros_nested(create_zeros):\n \"\"\"Check the creation of heterogeneous arrays zero-valued (nested)\"\"\"\n _descr = Ndescr\n\n\nclass create_values(ScipyTestCase):\n \"\"\"Check the creation of heterogeneous arrays with values\"\"\"\n\n\n def check_tuple(self):\n \"\"\"Check creation from tuples\"\"\"\n h = array(self._buffer, dtype=self._descr)\n self.assert_(normalize_descr(self._descr) == h.dtype.descr)\n if self.multiple_rows:\n self.assert_(h.shape == (2,))\n else:\n self.assert_(h.shape == ())\n\n def check_list_of_tuple(self):\n \"\"\"Check creation from list of tuples\"\"\"\n h = array([self._buffer], dtype=self._descr)\n self.assert_(normalize_descr(self._descr) == h.dtype.descr)\n if self.multiple_rows:\n self.assert_(h.shape == (1,2))\n else:\n self.assert_(h.shape == (1,))\n\n def check_list_of_list_of_tuple(self):\n \"\"\"Check creation from list of list of tuples\"\"\"\n h = array([[self._buffer]], dtype=self._descr)\n self.assert_(normalize_descr(self._descr) == h.dtype.descr)\n if self.multiple_rows:\n self.assert_(h.shape == (1,1,2))\n else:\n self.assert_(h.shape == (1,1))\n\n\nclass test_create_values_plain_single(create_values):\n \"\"\"Check the creation of heterogeneous arrays (plain, single row)\"\"\"\n _descr = Pdescr\n multiple_rows = 0\n _buffer = PbufferT[0]\n\nclass test_create_values_plain_multiple(create_values):\n \"\"\"Check the creation of heterogeneous arrays (plain, multiple rows)\"\"\"\n _descr = Pdescr\n multiple_rows = 1\n _buffer = PbufferT\n\nclass test_create_values_nested_single(create_values):\n \"\"\"Check the creation of heterogeneous arrays (nested, single row)\"\"\"\n _descr = Ndescr\n multiple_rows = 0\n _buffer = NbufferT[0]\n\nclass test_create_values_nested_multiple(create_values):\n \"\"\"Check the creation of heterogeneous arrays (nested, multiple rows)\"\"\"\n _descr = Ndescr\n multiple_rows = 1\n _buffer = NbufferT\n\n\n############################################################\n# Reading tests\n############################################################\n\nclass read_values_plain(ScipyTestCase):\n \"\"\"Check the reading of values in heterogeneous arrays (plain)\"\"\"\n\n def check_access_fields(self):\n h = array(self._buffer, dtype=self._descr)\n if not self.multiple_rows:\n self.assert_(h.shape == ())\n assert_equal(h['x'], array(self._buffer[0], dtype='i4'))\n assert_equal(h['y'], array(self._buffer[1], dtype='f8'))\n assert_equal(h['z'], array(self._buffer[2], dtype='u1'))\n else:\n self.assert_(len(h) == 2)\n assert_equal(h['x'], array([self._buffer[0][0],\n self._buffer[1][0]], dtype='i4'))\n assert_equal(h['y'], array([self._buffer[0][1],\n self._buffer[1][1]], dtype='f8'))\n assert_equal(h['z'], array([self._buffer[0][2],\n self._buffer[1][2]], dtype='u1'))\n\n\nclass test_read_values_plain_single(read_values_plain):\n \"\"\"Check the creation of heterogeneous arrays (plain, single row)\"\"\"\n _descr = Pdescr\n multiple_rows = 0\n _buffer = PbufferT[0]\n\nclass test_read_values_plain_multiple(read_values_plain):\n \"\"\"Check the values of heterogeneous arrays (plain, multiple rows)\"\"\"\n _descr = Pdescr\n multiple_rows = 1\n _buffer = PbufferT\n\nclass read_values_nested(ScipyTestCase):\n \"\"\"Check the reading of values in heterogeneous arrays (nested)\"\"\"\n\n \n def check_access_top_fields(self):\n \"\"\"Check reading the top fields of a nested array\"\"\"\n h = array(self._buffer, dtype=self._descr)\n if not self.multiple_rows:\n self.assert_(h.shape == ())\n assert_equal(h['x'], array(self._buffer[0], dtype='i4'))\n assert_equal(h['y'], array(self._buffer[4], dtype='f8'))\n assert_equal(h['z'], array(self._buffer[5], dtype='u1'))\n else:\n self.assert_(len(h) == 2)\n assert_equal(h['x'], array([self._buffer[0][0],\n self._buffer[1][0]], dtype='i4'))\n assert_equal(h['y'], array([self._buffer[0][4],\n self._buffer[1][4]], dtype='f8'))\n assert_equal(h['z'], array([self._buffer[0][5],\n self._buffer[1][5]], dtype='u1'))\n\n\n def check_nested1_acessors(self):\n \"\"\"Check reading the nested fields of a nested array (1st level)\"\"\"\n h = array(self._buffer, dtype=self._descr)\n if not self.multiple_rows:\n assert_equal(h['Info']['value'],\n array(self._buffer[1][0], dtype='c16'))\n assert_equal(h['Info']['y2'],\n array(self._buffer[1][1], dtype='f8'))\n assert_equal(h['info']['Name'],\n array(self._buffer[3][0], dtype='U2'))\n assert_equal(h['info']['Value'],\n array(self._buffer[3][1], dtype='c16'))\n else:\n assert_equal(h['Info']['value'],\n array([self._buffer[0][1][0],\n self._buffer[1][1][0]],\n dtype='c16'))\n assert_equal(h['Info']['y2'],\n array([self._buffer[0][1][1],\n self._buffer[1][1][1]],\n dtype='f8'))\n assert_equal(h['info']['Name'],\n array([self._buffer[0][3][0],\n self._buffer[1][3][0]],\n dtype='U2'))\n assert_equal(h['info']['Value'],\n array([self._buffer[0][3][1],\n self._buffer[1][3][1]],\n dtype='c16'))\n\n def check_nested2_acessors(self):\n \"\"\"Check reading the nested fields of a nested array (2nd level)\"\"\"\n h = array(self._buffer, dtype=self._descr)\n if not self.multiple_rows:\n assert_equal(h['Info']['Info2']['value'],\n array(self._buffer[1][2][1], dtype='c16'))\n assert_equal(h['Info']['Info2']['z3'],\n array(self._buffer[1][2][3], dtype='u4'))\n else:\n assert_equal(h['Info']['Info2']['value'],\n array([self._buffer[0][1][2][1],\n self._buffer[1][1][2][1]],\n dtype='c16'))\n assert_equal(h['Info']['Info2']['z3'],\n array([self._buffer[0][1][2][3],\n self._buffer[1][1][2][3]],\n dtype='u4'))\n\n def check_nested1_descriptor(self):\n \"\"\"Check access nested descriptors of a nested array (1st level)\"\"\"\n h = array(self._buffer, dtype=self._descr)\n self.assert_(h.dtype['Info']['value'].name == 'complex128')\n self.assert_(h.dtype['Info']['y2'].name == 'float64')\n self.assert_(h.dtype['info']['Name'].name == 'unicode256')\n self.assert_(h.dtype['info']['Value'].name == 'complex128')\n\n def check_nested2_descriptor(self):\n \"\"\"Check access nested descriptors of a nested array (2nd level)\"\"\"\n h = array(self._buffer, dtype=self._descr)\n self.assert_(h.dtype['Info']['Info2']['value'].name == 'void256')\n self.assert_(h.dtype['Info']['Info2']['z3'].name == 'void64')\n\n\nclass test_read_values_nested_single(read_values_nested):\n \"\"\"Check the values of heterogeneous arrays (nested, single row)\"\"\"\n _descr = Ndescr\n multiple_rows = 0\n _buffer = NbufferT[0]\n\nclass test_read_values_nested_multiple(read_values_nested):\n \"\"\"Check the values of heterogeneous arrays (nested, multiple rows)\"\"\"\n _descr = Ndescr\n multiple_rows = 1\n _buffer = NbufferT\n\n\nif __name__ == \"__main__\":\n ScipyTest().run()\n", + "source_code_before": "import sys\nfrom numpy.testing import *\nset_package_path()\nfrom numpy import zeros, ones, array\nrestore_path()\n\n\n# This is the structure of the table used for plain objects:\n#\n# +-+-+-+\n# |x|y|z|\n# +-+-+-+\n\n# Structure of a plain array description:\nPdescr = [\n ('x', 'i4', (2,)),\n ('y', 'f8', (2, 2)),\n ('z', 'u1')]\n\n# A plain list of tuples with values for testing:\nPbufferT = [\n # x y z\n ([3,2], [[6.,4.],[6.,4.]], 8),\n ([4,3], [[7.,5.],[7.,5.]], 9),\n ]\n\n\n# This is the structure of the table used for nested objects (DON'T PANIC!):\n#\n# +-+---------------------------------+-----+----------+-+-+\n# |x|Info |color|info |y|z|\n# | +-----+--+----------------+----+--+ +----+-----+ | |\n# | |value|y2|Info2 |name|z2| |Name|Value| | |\n# | | | +----+-----+--+--+ | | | | | | |\n# | | | |name|value|y3|z3| | | | | | | |\n# +-+-----+--+----+-----+--+--+----+--+-----+----+-----+-+-+\n#\n\n# The corresponding nested array description:\nNdescr = [\n ('x', 'i4', (2,)),\n ('Info', [\n ('value', 'c16'),\n ('y2', 'f8'),\n ('Info2', [\n ('name', 'S2'),\n ('value', 'c16', (2,)),\n ('y3', 'f8', (2,)),\n ('z3', 'u4', (2,))]),\n ('name', 'S2'),\n ('z2', 'b1')]),\n ('color', 'S2'),\n ('info', [\n ('Name', 'S2'),\n ('Value', 'c16')]),\n ('y', 'f8', (2, 2)),\n ('z', 'u1')]\n\nNbufferT = [\n # x Info color info y z\n # value y2 Info2 name z2 Name Value\n # name value y3 z3\n ([3,2], (6j, 6., ('nn', [6j,4j], [6.,4.], [1,2]), 'NN', True), 'cc', ('NN', 6j), [[6.,4.],[6.,4.]], 8),\n ([4,3], (7j, 7., ('oo', [7j,5j], [7.,5.], [2,1]), 'OO', False), 'dd', ('OO', 7j), [[7.,5.],[7.,5.]], 9),\n ]\n\n\nbyteorder = {'little':'<', 'big':'>'}[sys.byteorder]\n\ndef normalize_descr(descr):\n \"Normalize a description adding the addient byteorder.\"\n\n out = []\n for item in descr:\n dtype = item[1]\n if isinstance(dtype, str):\n if dtype[0] not in ['|','<','>']:\n onebyte = dtype[1:] == \"1\"\n if onebyte or dtype[0] in ['S', 'V', 'b']:\n dtype = \"|\" + dtype\n else:\n dtype = byteorder + dtype\n if len(item) > 2 and item[2] > 1:\n nitem = (item[0], dtype, item[2])\n else:\n nitem = (item[0], dtype)\n out.append(nitem)\n elif isinstance(item[1], list):\n l = []\n for j in normalize_descr(item[1]):\n l.append(j)\n out.append((item[0], l))\n else:\n raise ValueError(\"Expected a str or list and got %s\" % \\\n (type(item)))\n return out\n\n\n############################################################\n# Creating tests\n############################################################\n\nclass create_zeros(ScipyTestCase):\n \"\"\"Check the creation of heterogeneous arrays zero-valued\"\"\"\n\n def check_zerosScalar(self):\n \"\"\"Check creation of multirow objects\"\"\"\n h = zeros((), dtype=self._descr)\n self.assert_(normalize_descr(self._descr) == h.dtype.descr)\n # A small check that data is ok\n assert_equal(h['z'], zeros((), dtype='u1'))\n\n def check_zerosSD(self):\n \"\"\"Check creation of multirow objects\"\"\"\n h = zeros((2,), dtype=self._descr)\n self.assert_(normalize_descr(self._descr) == h.dtype.descr)\n # A small check that data is ok\n assert_equal(h['z'], zeros((2,), dtype='u1'))\n\n def check_zerosMD(self):\n \"\"\"Check creation of multidimensional objects\"\"\"\n h = zeros((2,3), dtype=self._descr)\n self.assert_(normalize_descr(self._descr) == h.dtype.descr)\n # A small check that data is ok\n assert_equal(h['z'], zeros((2,3), dtype='u1'))\n\n\nclass test_create_zeros_plain(create_zeros):\n \"\"\"Check the creation of heterogeneous arrays zero-valued (plain)\"\"\"\n _descr = Pdescr\n\nclass test_create_zeros_nested(create_zeros):\n \"\"\"Check the creation of heterogeneous arrays zero-valued (nested)\"\"\"\n _descr = Ndescr\n\n\nclass create_values(ScipyTestCase):\n \"\"\"Check the creation of heterogeneous arrays with values\"\"\"\n\n\n def check_tuple(self):\n \"\"\"Check creation from tuples\"\"\"\n h = array(self._bufferT, dtype=self._descr)\n self.assert_(normalize_descr(self._descr) == h.dtype.descr)\n if self.multiple_rows:\n self.assert_(h.shape == (2,))\n else:\n self.assert_(h.shape == ())\n\n def check_list_of_tuple(self):\n \"\"\"Check creation from list of tuples\"\"\"\n h = array([self._bufferT], dtype=self._descr)\n self.assert_(normalize_descr(self._descr) == h.dtype.descr)\n if self.multiple_rows:\n self.assert_(h.shape == (1,2))\n else:\n self.assert_(h.shape == (1,))\n\n def check_list_of_list_of_tuple(self):\n \"\"\"Check creation from list of list of tuples\"\"\"\n h = array([[self._bufferT]], dtype=self._descr)\n self.assert_(normalize_descr(self._descr) == h.dtype.descr)\n if self.multiple_rows:\n self.assert_(h.shape == (1,1,2))\n else:\n self.assert_(h.shape == (1,1))\n\n\nclass test_create_values_plain_single(create_values):\n \"\"\"Check the creation of heterogeneous arrays (plain, single row)\"\"\"\n _descr = Pdescr\n multiple_rows = 0\n _bufferT = PbufferT[0]\n\nclass test_create_values_plain_multiple(create_values):\n \"\"\"Check the creation of heterogeneous arrays (plain, multiple rows)\"\"\"\n _descr = Pdescr\n multiple_rows = 1\n _bufferT = PbufferT\n\nclass test_create_values_nested_single(create_values):\n \"\"\"Check the creation of heterogeneous arrays (nested, single row)\"\"\"\n _descr = Ndescr\n multiple_rows = 0\n _bufferT = NbufferT[0]\n\nclass test_create_values_nested_multiple(create_values):\n \"\"\"Check the creation of heterogeneous arrays (nested, multiple rows)\"\"\"\n _descr = Ndescr\n multiple_rows = 1\n _bufferT = NbufferT\n\n\n############################################################\n# Reading tests\n############################################################\n\nclass read_values_plain(ScipyTestCase):\n \"\"\"Check the reading of values in heterogeneous arrays (plain)\"\"\"\n\n def is_correct(self):\n if self.multiple_rows:\n assert_equal(self.h['x'], array(self._buffer[0][0], dtype='i4'))\n assert_equal(self.h['y'], array(self._buffer[0][1], dtype='f8'))\n assert_equal(self.h['z'], array(self._buffer[0][2], dtype='u1'))\n else:\n assert_equal(self.h['x'], array([self._buffer[0][0],\n self._buffer[1][0]], dtype='i4'))\n assert_equal(self.h['y'], array([self._buffer[0][1],\n self._buffer[1][1]], dtype='f8'))\n assert_equal(self.h['z'], array([self._buffer[0][2],\n self._buffer[1][2]], dtype='u1'))\n\n\n def check_read_full_tuples(self):\n \"\"\"Check reading from objects created from tuples\"\"\"\n self._buffer = self._bufferT\n self.h = array(self._buffer, dtype=self._descr)\n\n\nclass test_read_values_plain_single(read_values_plain):\n \"\"\"Check the creation of heterogeneous arrays (plain, single row)\"\"\"\n _descr = Pdescr\n multiple_rows = 0\n _bufferT = PbufferT[0]\n\nclass test_read_values_plain_multiple(read_values_plain):\n \"\"\"Check the values of heterogeneous arrays (plain, multiple rows)\"\"\"\n _descr = Pdescr\n multiple_rows = 1\n _bufferT = PbufferT\n\nclass read_values_nested(read_values_plain):\n \"\"\"Check the reading of values in heterogeneous arrays (nested)\"\"\"\n\n \n # Uncomment this when numpy will eventually support lists as inputs.\n def _check_read_full_list(self):\n \"\"\"Check reading from objects created from list\"\"\"\n h = array(self._bufferT, dtype=self._descr)\n # Add here more code to check this...\n\n def check_read_full_tuple(self):\n \"\"\"Check reading from objects created from tuples\"\"\"\n h = array(self._bufferT, dtype=self._descr)\n # Add here more code to check this...\n\n# The next test classes are not finished yet...\nclass _test_read_values_nested_single(read_values_nested):\n \"\"\"Check the values of heterogeneous arrays (nested, single row)\"\"\"\n _descr = Ndescr\n multiple_rows = 0\n _bufferT = NbufferT[0]\n\nclass _test_read_values_nested_multiple(read_values_nested):\n \"\"\"Check the values of heterogeneous arrays (nested, multiple rows)\"\"\"\n _descr = Ndescr\n multiple_rows = 1\n _bufferT = NbufferT\n\n\nif __name__ == \"__main__\":\n ScipyTest().run()\n", + "methods": [ + { + "name": "normalize_descr", + "long_name": "normalize_descr( descr )", + "filename": "test_numerictypes.py", + "nloc": 26, + "complexity": 10, + "token_count": 191, + "parameters": [ + "descr" + ], + "start_line": 69, + "end_line": 95, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 27, + "top_nesting_level": 0 + }, + { + "name": "check_zeros0D", + "long_name": "check_zeros0D( self )", + "filename": "test_numerictypes.py", + "nloc": 7, + "complexity": 1, + "token_count": 119, + "parameters": [ + "self" + ], + "start_line": 105, + "end_line": 113, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 9, + "top_nesting_level": 1 + }, + { + "name": "check_zerosSD", + "long_name": "check_zerosSD( self )", + "filename": "test_numerictypes.py", + "nloc": 7, + "complexity": 1, + "token_count": 108, + "parameters": [ + "self" + ], + "start_line": 115, + "end_line": 123, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 9, + "top_nesting_level": 1 + }, + { + "name": "check_zerosMD", + "long_name": "check_zerosMD( self )", + "filename": "test_numerictypes.py", + "nloc": 7, + "complexity": 1, + "token_count": 106, + "parameters": [ + "self" + ], + "start_line": 125, + "end_line": 133, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 9, + "top_nesting_level": 1 + }, + { + "name": "check_tuple", + "long_name": "check_tuple( self )", + "filename": "test_numerictypes.py", + "nloc": 7, + "complexity": 2, + "token_count": 68, + "parameters": [ + "self" + ], + "start_line": 149, + "end_line": 156, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 8, + "top_nesting_level": 1 + }, + { + "name": "check_list_of_tuple", + "long_name": "check_list_of_tuple( self )", + "filename": "test_numerictypes.py", + "nloc": 7, + "complexity": 2, + "token_count": 73, + "parameters": [ + "self" + ], + "start_line": 158, + "end_line": 165, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 8, + "top_nesting_level": 1 + }, + { + "name": "check_list_of_list_of_tuple", + "long_name": "check_list_of_list_of_tuple( self )", + "filename": "test_numerictypes.py", + "nloc": 7, + "complexity": 2, + "token_count": 78, + "parameters": [ + "self" + ], + "start_line": 167, + "end_line": 174, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 8, + "top_nesting_level": 1 + }, + { + "name": "check_access_fields", + "long_name": "check_access_fields( self )", + "filename": "test_numerictypes.py", + "nloc": 15, + "complexity": 2, + "token_count": 220, + "parameters": [ + "self" + ], + "start_line": 209, + "end_line": 223, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 15, + "top_nesting_level": 1 + }, + { + "name": "check_access_top_fields", + "long_name": "check_access_top_fields( self )", + "filename": "test_numerictypes.py", + "nloc": 15, + "complexity": 2, + "token_count": 221, + "parameters": [ + "self" + ], + "start_line": 242, + "end_line": 257, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 16, + "top_nesting_level": 1 + }, + { + "name": "check_nested1_acessors", + "long_name": "check_nested1_acessors( self )", + "filename": "test_numerictypes.py", + "nloc": 28, + "complexity": 2, + "token_count": 316, + "parameters": [ + "self" + ], + "start_line": 260, + "end_line": 288, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 29, + "top_nesting_level": 1 + }, + { + "name": "check_nested2_acessors", + "long_name": "check_nested2_acessors( self )", + "filename": "test_numerictypes.py", + "nloc": 16, + "complexity": 2, + "token_count": 202, + "parameters": [ + "self" + ], + "start_line": 290, + "end_line": 306, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 17, + "top_nesting_level": 1 + }, + { + "name": "check_nested1_descriptor", + "long_name": "check_nested1_descriptor( self )", + "filename": "test_numerictypes.py", + "nloc": 6, + "complexity": 1, + "token_count": 92, + "parameters": [ + "self" + ], + "start_line": 308, + "end_line": 314, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 7, + "top_nesting_level": 1 + }, + { + "name": "check_nested2_descriptor", + "long_name": "check_nested2_descriptor( self )", + "filename": "test_numerictypes.py", + "nloc": 4, + "complexity": 1, + "token_count": 62, + "parameters": [ + "self" + ], + "start_line": 316, + "end_line": 320, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 5, + "top_nesting_level": 1 + } + ], + "methods_before": [ + { + "name": "normalize_descr", + "long_name": "normalize_descr( descr )", + "filename": "test_numerictypes.py", + "nloc": 26, + "complexity": 10, + "token_count": 191, + "parameters": [ + "descr" + ], + "start_line": 70, + "end_line": 96, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 27, + "top_nesting_level": 0 + }, + { + "name": "check_zerosScalar", + "long_name": "check_zerosScalar( self )", + "filename": "test_numerictypes.py", + "nloc": 4, + "complexity": 1, + "token_count": 53, + "parameters": [ + "self" + ], + "start_line": 106, + "end_line": 111, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 6, + "top_nesting_level": 1 + }, + { + "name": "check_zerosSD", + "long_name": "check_zerosSD( self )", + "filename": "test_numerictypes.py", + "nloc": 4, + "complexity": 1, + "token_count": 57, + "parameters": [ + "self" + ], + "start_line": 113, + "end_line": 118, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 6, + "top_nesting_level": 1 + }, + { + "name": "check_zerosMD", + "long_name": "check_zerosMD( self )", + "filename": "test_numerictypes.py", + "nloc": 4, + "complexity": 1, + "token_count": 59, + "parameters": [ + "self" + ], + "start_line": 120, + "end_line": 125, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 6, + "top_nesting_level": 1 + }, + { + "name": "check_tuple", + "long_name": "check_tuple( self )", + "filename": "test_numerictypes.py", + "nloc": 7, + "complexity": 2, + "token_count": 68, + "parameters": [ + "self" + ], + "start_line": 141, + "end_line": 148, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 8, + "top_nesting_level": 1 + }, + { + "name": "check_list_of_tuple", + "long_name": "check_list_of_tuple( self )", + "filename": "test_numerictypes.py", + "nloc": 7, + "complexity": 2, + "token_count": 73, + "parameters": [ + "self" + ], + "start_line": 150, + "end_line": 157, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 8, + "top_nesting_level": 1 + }, + { + "name": "check_list_of_list_of_tuple", + "long_name": "check_list_of_list_of_tuple( self )", + "filename": "test_numerictypes.py", + "nloc": 7, + "complexity": 2, + "token_count": 78, + "parameters": [ + "self" + ], + "start_line": 159, + "end_line": 166, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 8, + "top_nesting_level": 1 + }, + { + "name": "is_correct", + "long_name": "is_correct( self )", + "filename": "test_numerictypes.py", + "nloc": 12, + "complexity": 2, + "token_count": 204, + "parameters": [ + "self" + ], + "start_line": 201, + "end_line": 212, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 12, + "top_nesting_level": 1 + }, + { + "name": "check_read_full_tuples", + "long_name": "check_read_full_tuples( self )", + "filename": "test_numerictypes.py", + "nloc": 3, + "complexity": 1, + "token_count": 29, + "parameters": [ + "self" + ], + "start_line": 215, + "end_line": 218, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 1 + }, + { + "name": "_check_read_full_list", + "long_name": "_check_read_full_list( self )", + "filename": "test_numerictypes.py", + "nloc": 2, + "complexity": 1, + "token_count": 20, + "parameters": [ + "self" + ], + "start_line": 238, + "end_line": 240, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "check_read_full_tuple", + "long_name": "check_read_full_tuple( self )", + "filename": "test_numerictypes.py", + "nloc": 2, + "complexity": 1, + "token_count": 20, + "parameters": [ + "self" + ], + "start_line": 243, + "end_line": 245, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + } + ], + "changed_methods": [ + { + "name": "check_list_of_list_of_tuple", + "long_name": "check_list_of_list_of_tuple( self )", + "filename": "test_numerictypes.py", + "nloc": 7, + "complexity": 2, + "token_count": 78, + "parameters": [ + "self" + ], + "start_line": 167, + "end_line": 174, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 8, + "top_nesting_level": 1 + }, + { + "name": "check_nested1_acessors", + "long_name": "check_nested1_acessors( self )", + "filename": "test_numerictypes.py", + "nloc": 28, + "complexity": 2, + "token_count": 316, + "parameters": [ + "self" + ], + "start_line": 260, + "end_line": 288, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 29, + "top_nesting_level": 1 + }, + { + "name": "check_access_top_fields", + "long_name": "check_access_top_fields( self )", + "filename": "test_numerictypes.py", + "nloc": 15, + "complexity": 2, + "token_count": 221, + "parameters": [ + "self" + ], + "start_line": 242, + "end_line": 257, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 16, + "top_nesting_level": 1 + }, + { + "name": "check_zerosScalar", + "long_name": "check_zerosScalar( self )", + "filename": "test_numerictypes.py", + "nloc": 4, + "complexity": 1, + "token_count": 53, + "parameters": [ + "self" + ], + "start_line": 106, + "end_line": 111, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 6, + "top_nesting_level": 1 + }, + { + "name": "is_correct", + "long_name": "is_correct( self )", + "filename": "test_numerictypes.py", + "nloc": 12, + "complexity": 2, + "token_count": 204, + "parameters": [ + "self" + ], + "start_line": 201, + "end_line": 212, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 12, + "top_nesting_level": 1 + }, + { + "name": "check_tuple", + "long_name": "check_tuple( self )", + "filename": "test_numerictypes.py", + "nloc": 7, + "complexity": 2, + "token_count": 68, + "parameters": [ + "self" + ], + "start_line": 149, + "end_line": 156, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 8, + "top_nesting_level": 1 + }, + { + "name": "check_access_fields", + "long_name": "check_access_fields( self )", + "filename": "test_numerictypes.py", + "nloc": 15, + "complexity": 2, + "token_count": 220, + "parameters": [ + "self" + ], + "start_line": 209, + "end_line": 223, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 15, + "top_nesting_level": 1 + }, + { + "name": "check_zeros0D", + "long_name": "check_zeros0D( self )", + "filename": "test_numerictypes.py", + "nloc": 7, + "complexity": 1, + "token_count": 119, + "parameters": [ + "self" + ], + "start_line": 105, + "end_line": 113, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 9, + "top_nesting_level": 1 + }, + { + "name": "check_nested1_descriptor", + "long_name": "check_nested1_descriptor( self )", + "filename": "test_numerictypes.py", + "nloc": 6, + "complexity": 1, + "token_count": 92, + "parameters": [ + "self" + ], + "start_line": 308, + "end_line": 314, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 7, + "top_nesting_level": 1 + }, + { + "name": "check_nested2_acessors", + "long_name": "check_nested2_acessors( self )", + "filename": "test_numerictypes.py", + "nloc": 16, + "complexity": 2, + "token_count": 202, + "parameters": [ + "self" + ], + "start_line": 290, + "end_line": 306, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 17, + "top_nesting_level": 1 + }, + { + "name": "check_zerosSD", + "long_name": "check_zerosSD( self )", + "filename": "test_numerictypes.py", + "nloc": 7, + "complexity": 1, + "token_count": 108, + "parameters": [ + "self" + ], + "start_line": 115, + "end_line": 123, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 9, + "top_nesting_level": 1 + }, + { + "name": "normalize_descr", + "long_name": "normalize_descr( descr )", + "filename": "test_numerictypes.py", + "nloc": 26, + "complexity": 10, + "token_count": 191, + "parameters": [ + "descr" + ], + "start_line": 69, + "end_line": 95, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 27, + "top_nesting_level": 0 + }, + { + "name": "check_read_full_tuples", + "long_name": "check_read_full_tuples( self )", + "filename": "test_numerictypes.py", + "nloc": 3, + "complexity": 1, + "token_count": 29, + "parameters": [ + "self" + ], + "start_line": 215, + "end_line": 218, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 1 + }, + { + "name": "check_zerosMD", + "long_name": "check_zerosMD( self )", + "filename": "test_numerictypes.py", + "nloc": 7, + "complexity": 1, + "token_count": 106, + "parameters": [ + "self" + ], + "start_line": 125, + "end_line": 133, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 9, + "top_nesting_level": 1 + }, + { + "name": "check_list_of_tuple", + "long_name": "check_list_of_tuple( self )", + "filename": "test_numerictypes.py", + "nloc": 7, + "complexity": 2, + "token_count": 73, + "parameters": [ + "self" + ], + "start_line": 158, + "end_line": 165, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 8, + "top_nesting_level": 1 + }, + { + "name": "check_read_full_tuple", + "long_name": "check_read_full_tuple( self )", + "filename": "test_numerictypes.py", + "nloc": 2, + "complexity": 1, + "token_count": 20, + "parameters": [ + "self" + ], + "start_line": 243, + "end_line": 245, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "check_nested2_descriptor", + "long_name": "check_nested2_descriptor( self )", + "filename": "test_numerictypes.py", + "nloc": 4, + "complexity": 1, + "token_count": 62, + "parameters": [ + "self" + ], + "start_line": 316, + "end_line": 320, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 5, + "top_nesting_level": 1 + }, + { + "name": "_check_read_full_list", + "long_name": "_check_read_full_list( self )", + "filename": "test_numerictypes.py", + "nloc": 2, + "complexity": 1, + "token_count": 20, + "parameters": [ + "self" + ], + "start_line": 238, + "end_line": 240, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + } + ], + "nloc": 243, + "complexity": 29, + "token_count": 2472, + "diff_parsed": { + "added": [ + "import numpy", + " ('Name', 'U8'), # Try out 'U8' when interpretation of Unicode strings is more clear", + " \"Normalize a description adding the platform byteorder.\"", + "# Creation tests", + " def check_zeros0D(self):", + " \"\"\"Check creation of 0-dimensional objects\"\"\"", + " self.assert_(h.dtype.fields['x'][0].name[:4] == 'void')", + " self.assert_(h.dtype.fields['x'][0].char == 'V')", + " self.assert_(h.dtype.fields['x'][0].type == numpy.void)", + " \"\"\"Check creation of single-dimensional objects\"\"\"", + " self.assert_(h.dtype['y'].name[:4] == 'void')", + " self.assert_(h.dtype['y'].char == 'V')", + " self.assert_(h.dtype['y'].type == numpy.void)", + " \"\"\"Check creation of multi-dimensional objects\"\"\"", + " self.assert_(h.dtype['z'].name == 'uint8')", + " self.assert_(h.dtype['z'].char == 'B')", + " self.assert_(h.dtype['z'].type == numpy.uint8)", + " h = array(self._buffer, dtype=self._descr)", + " h = array([self._buffer], dtype=self._descr)", + " h = array([[self._buffer]], dtype=self._descr)", + " _buffer = PbufferT[0]", + " _buffer = PbufferT", + " _buffer = NbufferT[0]", + " _buffer = NbufferT", + " def check_access_fields(self):", + " h = array(self._buffer, dtype=self._descr)", + " if not self.multiple_rows:", + " self.assert_(h.shape == ())", + " assert_equal(h['x'], array(self._buffer[0], dtype='i4'))", + " assert_equal(h['y'], array(self._buffer[1], dtype='f8'))", + " assert_equal(h['z'], array(self._buffer[2], dtype='u1'))", + " self.assert_(len(h) == 2)", + " assert_equal(h['x'], array([self._buffer[0][0],", + " assert_equal(h['y'], array([self._buffer[0][1],", + " assert_equal(h['z'], array([self._buffer[0][2],", + " _buffer = PbufferT[0]", + " _buffer = PbufferT", + "class read_values_nested(ScipyTestCase):", + " def check_access_top_fields(self):", + " \"\"\"Check reading the top fields of a nested array\"\"\"", + " h = array(self._buffer, dtype=self._descr)", + " if not self.multiple_rows:", + " self.assert_(h.shape == ())", + " assert_equal(h['x'], array(self._buffer[0], dtype='i4'))", + " assert_equal(h['y'], array(self._buffer[4], dtype='f8'))", + " assert_equal(h['z'], array(self._buffer[5], dtype='u1'))", + " else:", + " self.assert_(len(h) == 2)", + " assert_equal(h['x'], array([self._buffer[0][0],", + " self._buffer[1][0]], dtype='i4'))", + " assert_equal(h['y'], array([self._buffer[0][4],", + " self._buffer[1][4]], dtype='f8'))", + " assert_equal(h['z'], array([self._buffer[0][5],", + " self._buffer[1][5]], dtype='u1'))", + "", + "", + " def check_nested1_acessors(self):", + " \"\"\"Check reading the nested fields of a nested array (1st level)\"\"\"", + " h = array(self._buffer, dtype=self._descr)", + " if not self.multiple_rows:", + " assert_equal(h['Info']['value'],", + " array(self._buffer[1][0], dtype='c16'))", + " assert_equal(h['Info']['y2'],", + " array(self._buffer[1][1], dtype='f8'))", + " assert_equal(h['info']['Name'],", + " array(self._buffer[3][0], dtype='U2'))", + " assert_equal(h['info']['Value'],", + " array(self._buffer[3][1], dtype='c16'))", + " else:", + " assert_equal(h['Info']['value'],", + " array([self._buffer[0][1][0],", + " self._buffer[1][1][0]],", + " dtype='c16'))", + " assert_equal(h['Info']['y2'],", + " array([self._buffer[0][1][1],", + " self._buffer[1][1][1]],", + " dtype='f8'))", + " assert_equal(h['info']['Name'],", + " array([self._buffer[0][3][0],", + " self._buffer[1][3][0]],", + " dtype='U2'))", + " assert_equal(h['info']['Value'],", + " array([self._buffer[0][3][1],", + " self._buffer[1][3][1]],", + " dtype='c16'))", + "", + " def check_nested2_acessors(self):", + " \"\"\"Check reading the nested fields of a nested array (2nd level)\"\"\"", + " h = array(self._buffer, dtype=self._descr)", + " if not self.multiple_rows:", + " assert_equal(h['Info']['Info2']['value'],", + " array(self._buffer[1][2][1], dtype='c16'))", + " assert_equal(h['Info']['Info2']['z3'],", + " array(self._buffer[1][2][3], dtype='u4'))", + " else:", + " assert_equal(h['Info']['Info2']['value'],", + " array([self._buffer[0][1][2][1],", + " self._buffer[1][1][2][1]],", + " dtype='c16'))", + " assert_equal(h['Info']['Info2']['z3'],", + " array([self._buffer[0][1][2][3],", + " self._buffer[1][1][2][3]],", + " dtype='u4'))", + "", + " def check_nested1_descriptor(self):", + " \"\"\"Check access nested descriptors of a nested array (1st level)\"\"\"", + " h = array(self._buffer, dtype=self._descr)", + " self.assert_(h.dtype['Info']['value'].name == 'complex128')", + " self.assert_(h.dtype['Info']['y2'].name == 'float64')", + " self.assert_(h.dtype['info']['Name'].name == 'unicode256')", + " self.assert_(h.dtype['info']['Value'].name == 'complex128')", + "", + " def check_nested2_descriptor(self):", + " \"\"\"Check access nested descriptors of a nested array (2nd level)\"\"\"", + " h = array(self._buffer, dtype=self._descr)", + " self.assert_(h.dtype['Info']['Info2']['value'].name == 'void256')", + " self.assert_(h.dtype['Info']['Info2']['z3'].name == 'void64')", + "", + "", + "class test_read_values_nested_single(read_values_nested):", + " _buffer = NbufferT[0]", + "class test_read_values_nested_multiple(read_values_nested):", + " _buffer = NbufferT" + ], + "deleted": [ + "set_package_path()", + "restore_path()", + " ('Name', 'S2'),", + " \"Normalize a description adding the addient byteorder.\"", + "# Creating tests", + " def check_zerosScalar(self):", + " \"\"\"Check creation of multirow objects\"\"\"", + " \"\"\"Check creation of multirow objects\"\"\"", + " \"\"\"Check creation of multidimensional objects\"\"\"", + " h = array(self._bufferT, dtype=self._descr)", + " h = array([self._bufferT], dtype=self._descr)", + " h = array([[self._bufferT]], dtype=self._descr)", + " _bufferT = PbufferT[0]", + " _bufferT = PbufferT", + " _bufferT = NbufferT[0]", + " _bufferT = NbufferT", + " def is_correct(self):", + " if self.multiple_rows:", + " assert_equal(self.h['x'], array(self._buffer[0][0], dtype='i4'))", + " assert_equal(self.h['y'], array(self._buffer[0][1], dtype='f8'))", + " assert_equal(self.h['z'], array(self._buffer[0][2], dtype='u1'))", + " assert_equal(self.h['x'], array([self._buffer[0][0],", + " assert_equal(self.h['y'], array([self._buffer[0][1],", + " assert_equal(self.h['z'], array([self._buffer[0][2],", + " def check_read_full_tuples(self):", + " \"\"\"Check reading from objects created from tuples\"\"\"", + " self._buffer = self._bufferT", + " self.h = array(self._buffer, dtype=self._descr)", + "", + "", + " _bufferT = PbufferT[0]", + " _bufferT = PbufferT", + "class read_values_nested(read_values_plain):", + " # Uncomment this when numpy will eventually support lists as inputs.", + " def _check_read_full_list(self):", + " \"\"\"Check reading from objects created from list\"\"\"", + " h = array(self._bufferT, dtype=self._descr)", + " # Add here more code to check this...", + "", + " def check_read_full_tuple(self):", + " \"\"\"Check reading from objects created from tuples\"\"\"", + " h = array(self._bufferT, dtype=self._descr)", + " # Add here more code to check this...", + "", + "# The next test classes are not finished yet...", + "class _test_read_values_nested_single(read_values_nested):", + " _bufferT = NbufferT[0]", + "class _test_read_values_nested_multiple(read_values_nested):", + " _bufferT = NbufferT" + ] + } + }, + { + "old_path": null, + "new_path": "numpy/core/tests/test_unicode.py", + "filename": "test_unicode.py", + "extension": "py", + "change_type": "ADD", + "diff": "@@ -0,0 +1,305 @@\n+import sys\n+from numpy.testing import *\n+from numpy.core import *\n+\n+# Guess the UCS length for this python interpreter\n+if len(buffer(u'u')) == 4:\n+ ucs4 = True\n+else:\n+ ucs4 = False\n+\n+# Value that can be represented in UCS2 interpreters\n+ucs2_value = u'\\uFFFF'\n+# Value that cannot be represented in UCS2 interpreters (but can in UCS4)\n+ucs4_value = u'\\U0010FFFF'\n+\n+\n+############################################################\n+# Creation tests\n+############################################################\n+\n+class create_zeros(ScipyTestCase):\n+ \"\"\"Check the creation of zero-valued arrays\"\"\"\n+\n+ def content_test(self, ua, ua_scalar, nbytes):\n+\n+ # Check the length of the unicode base type\n+ self.assert_(int(ua.dtype.str[2:]) == self.ulen)\n+ # Check the length of the data buffer\n+ self.assert_(len(ua.data) == nbytes)\n+ # Small check that data in array element is ok\n+ self.assert_(ua_scalar == u'\\x00'*self.ulen)\n+ # Encode to ascii and double check\n+ self.assert_(ua_scalar.encode('ascii') == '\\x00'*self.ulen)\n+ # Check buffer lengths for scalars\n+ if ucs4:\n+ self.assert_(len(buffer(ua_scalar)) == 4*self.ulen)\n+ else:\n+ self.assert_(len(buffer(ua_scalar)) == 2*self.ulen)\n+\n+ def check_zeros0D(self):\n+ \"\"\"Check creation of 0-dimensional objects\"\"\"\n+ ua = zeros((), dtype='U%s' % self.ulen)\n+ self.content_test(ua, ua[()], 4*self.ulen)\n+\n+ def check_zerosSD(self):\n+ \"\"\"Check creation of single-dimensional objects\"\"\"\n+ ua = zeros((2,), dtype='U%s' % self.ulen)\n+ self.content_test(ua, ua[0], 4*self.ulen*2)\n+ self.content_test(ua, ua[1], 4*self.ulen*2)\n+\n+ def check_zerosMD(self):\n+ \"\"\"Check creation of multi-dimensional objects\"\"\"\n+ ua = zeros((2,3,4), dtype='U%s' % self.ulen)\n+ self.content_test(ua, ua[0,0,0], 4*self.ulen*2*3*4)\n+ self.content_test(ua, ua[-1,-1,-1], 4*self.ulen*2*3*4)\n+\n+\n+class test_create_zeros_1(create_zeros):\n+ \"\"\"Check the creation of zero-valued arrays (size 1)\"\"\"\n+ ulen = 1\n+\n+class test_create_zeros_2(create_zeros):\n+ \"\"\"Check the creation of zero-valued arrays (size 2)\"\"\"\n+ ulen = 2\n+\n+class test_create_zeros_1009(create_zeros):\n+ \"\"\"Check the creation of zero-valued arrays (size 1009)\"\"\"\n+ ulen = 1009\n+\n+\n+class create_values(ScipyTestCase):\n+ \"\"\"Check the creation of unicode arrays with values\"\"\"\n+\n+ def content_test(self, ua, ua_scalar, nbytes):\n+\n+ # Check the length of the unicode base type\n+ self.assert_(int(ua.dtype.str[2:]) == self.ulen)\n+ # Check the length of the data buffer\n+ self.assert_(len(ua.data) == nbytes)\n+ # Small check that data in array element is ok\n+ self.assert_(ua_scalar == self.ucs_value*self.ulen)\n+ # Encode to UTF-8 and double check\n+ self.assert_(ua_scalar.encode('utf-8') == \\\n+ (self.ucs_value*self.ulen).encode('utf-8'))\n+ # Check buffer lengths for scalars\n+ if ucs4:\n+ self.assert_(len(buffer(ua_scalar)) == 4*self.ulen)\n+ else:\n+ if self.ucs_value == ucs4_value:\n+ # In UCS2, the \\U0010FFFF will be represented using a\n+ # surrogate *pair*\n+ self.assert_(len(buffer(ua_scalar)) == 2*2*self.ulen)\n+ else:\n+ # In UCS2, the \\uFFFF will be represented using a\n+ # regular 2-byte word\n+ self.assert_(len(buffer(ua_scalar)) == 2*self.ulen)\n+\n+ def check_values0D(self):\n+ \"\"\"Check creation of 0-dimensional objects with values\"\"\"\n+ ua = array(self.ucs_value*self.ulen, dtype='U%s' % self.ulen)\n+ self.content_test(ua, ua[()], 4*self.ulen)\n+\n+ def check_valuesSD(self):\n+ \"\"\"Check creation of single-dimensional objects with values\"\"\"\n+ ua = array([self.ucs_value*self.ulen]*2, dtype='U%s' % self.ulen)\n+ self.content_test(ua, ua[0], 4*self.ulen*2)\n+ self.content_test(ua, ua[1], 4*self.ulen*2)\n+\n+ def check_valuesMD(self):\n+ \"\"\"Check creation of multi-dimensional objects with values\"\"\"\n+ ua = array([[[self.ucs_value*self.ulen]*2]*3]*4, dtype='U%s' % self.ulen)\n+ self.content_test(ua, ua[0,0,0], 4*self.ulen*2*3*4)\n+ self.content_test(ua, ua[-1,-1,-1], 4*self.ulen*2*3*4)\n+\n+\n+class test_create_values_1_ucs2(create_values):\n+ \"\"\"Check the creation of valued arrays (size 1, UCS2 values)\"\"\"\n+ ulen = 1\n+ ucs_value = ucs2_value\n+\n+class test_create_values_1_ucs4(create_values):\n+ \"\"\"Check the creation of valued arrays (size 1, UCS4 values)\"\"\"\n+ ulen = 1\n+ ucs_value = ucs4_value\n+\n+class test_create_values_2_ucs2(create_values):\n+ \"\"\"Check the creation of valued arrays (size 2, UCS2 values)\"\"\"\n+ ulen = 2\n+ ucs_value = ucs2_value\n+\n+class test_create_values_2_ucs4(create_values):\n+ \"\"\"Check the creation of valued arrays (size 2, UCS4 values)\"\"\"\n+ ulen = 2\n+ ucs_value = ucs4_value\n+\n+class test_create_values_1009_ucs2(create_values):\n+ \"\"\"Check the creation of valued arrays (size 1009, UCS2 values)\"\"\"\n+ ulen = 1009\n+ ucs_value = ucs2_value\n+\n+class test_create_values_1009_ucs4(create_values):\n+ \"\"\"Check the creation of valued arrays (size 1009, UCS4 values)\"\"\"\n+ ulen = 1009\n+ ucs_value = ucs4_value\n+\n+\n+############################################################\n+# Assignment tests\n+############################################################\n+\n+class assign_values(ScipyTestCase):\n+ \"\"\"Check the assignment of unicode arrays with values\"\"\"\n+\n+ def content_test(self, ua, ua_scalar, nbytes):\n+\n+ # Check the length of the unicode base type\n+ self.assert_(int(ua.dtype.str[2:]) == self.ulen)\n+ # Check the length of the data buffer\n+ self.assert_(len(ua.data) == nbytes)\n+ # Small check that data in array element is ok\n+ self.assert_(ua_scalar == self.ucs_value*self.ulen)\n+ # Encode to UTF-8 and double check\n+ self.assert_(ua_scalar.encode('utf-8') == \\\n+ (self.ucs_value*self.ulen).encode('utf-8'))\n+ # Check buffer lengths for scalars\n+ if ucs4:\n+ self.assert_(len(buffer(ua_scalar)) == 4*self.ulen)\n+ else:\n+ if self.ucs_value == ucs4_value:\n+ # In UCS2, the \\U0010FFFF will be represented using a\n+ # surrogate *pair*\n+ self.assert_(len(buffer(ua_scalar)) == 2*2*self.ulen)\n+ else:\n+ # In UCS2, the \\uFFFF will be represented using a\n+ # regular 2-byte word\n+ self.assert_(len(buffer(ua_scalar)) == 2*self.ulen)\n+\n+ def check_values0D(self):\n+ \"\"\"Check assignment of 0-dimensional objects with values\"\"\"\n+ ua = zeros((), dtype='U%s' % self.ulen)\n+ ua[()] = self.ucs_value*self.ulen\n+ self.content_test(ua, ua[()], 4*self.ulen)\n+\n+ def check_valuesSD(self):\n+ \"\"\"Check assignment of single-dimensional objects with values\"\"\"\n+ ua = zeros((2,), dtype='U%s' % self.ulen)\n+ ua[0] = self.ucs_value*self.ulen\n+ self.content_test(ua, ua[0], 4*self.ulen*2) \n+ ua[1] = self.ucs_value*self.ulen\n+ self.content_test(ua, ua[1], 4*self.ulen*2)\n+\n+ def check_valuesMD(self):\n+ \"\"\"Check assignment of multi-dimensional objects with values\"\"\"\n+ ua = zeros((2,3,4), dtype='U%s' % self.ulen)\n+ ua[0,0,0] = self.ucs_value*self.ulen\n+ self.content_test(ua, ua[0,0,0], 4*self.ulen*2*3*4)\n+ ua[-1,-1,-1] = self.ucs_value*self.ulen\n+ self.content_test(ua, ua[-1,-1,-1], 4*self.ulen*2*3*4)\n+\n+\n+class test_assign_values_1_ucs2(assign_values):\n+ \"\"\"Check the assignment of valued arrays (size 1, UCS2 values)\"\"\"\n+ ulen = 1\n+ ucs_value = ucs2_value\n+\n+class test_assign_values_1_ucs4(assign_values):\n+ \"\"\"Check the assignment of valued arrays (size 1, UCS4 values)\"\"\"\n+ ulen = 1\n+ ucs_value = ucs4_value\n+\n+class test_assign_values_2_ucs2(assign_values):\n+ \"\"\"Check the assignment of valued arrays (size 2, UCS2 values)\"\"\"\n+ ulen = 2\n+ ucs_value = ucs2_value\n+\n+class test_assign_values_2_ucs4(assign_values):\n+ \"\"\"Check the assignment of valued arrays (size 2, UCS4 values)\"\"\"\n+ ulen = 2\n+ ucs_value = ucs4_value\n+\n+class test_assign_values_1009_ucs2(assign_values):\n+ \"\"\"Check the assignment of valued arrays (size 1009, UCS2 values)\"\"\"\n+ ulen = 1009\n+ ucs_value = ucs2_value\n+\n+class test_assign_values_1009_ucs4(assign_values):\n+ \"\"\"Check the assignment of valued arrays (size 1009, UCS4 values)\"\"\"\n+ ulen = 1009\n+ ucs_value = ucs4_value\n+\n+\n+############################################################\n+# Byteorder tests\n+############################################################\n+\n+class byteorder_values(ScipyTestCase):\n+ \"\"\"Check the byteorder of unicode arrays in round-trip conversions\"\"\"\n+\n+ def check_values0D(self):\n+ \"\"\"Check byteorder of 0-dimensional objects\"\"\"\n+ ua = array(self.ucs_value*self.ulen, dtype='U%s' % self.ulen)\n+ ua2 = ua.newbyteorder()\n+ # Scalars must be different\n+ # Problems here because it seems that ua.view() != ua (!)\n+ self.assert_(ua[()] != ua2[()])\n+ ua3 = ua2.newbyteorder()\n+ # Arrays must be equal after the round-trip\n+ assert_equal(ua, ua3)\n+\n+ def check_valuesSD(self):\n+ \"\"\"Check byteorder of single-dimensional objects\"\"\"\n+ ua = array([self.ucs_value*self.ulen]*2, dtype='U%s' % self.ulen)\n+ ua2 = ua.newbyteorder()\n+ # Scalars must be different\n+ self.assert_(ua[0] != ua2[0])\n+ self.assert_(ua[-1] != ua2[-1])\n+ ua3 = ua2.newbyteorder()\n+ # Arrays must be equal after the round-trip\n+ assert_equal(ua, ua3)\n+\n+ def check_valuesMD(self):\n+ \"\"\"Check byteorder of multi-dimensional objects\"\"\"\n+ ua = array([[[self.ucs_value*self.ulen]*2]*3]*4,\n+ dtype='U%s' % self.ulen)\n+ ua2 = ua.newbyteorder()\n+ # Scalars must be different\n+ self.assert_(ua[0,0,0] != ua2[0,0,0])\n+ self.assert_(ua[-1,-1,-1] != ua2[-1,-1,-1])\n+ ua3 = ua2.newbyteorder()\n+ # Arrays must be equal after the round-trip\n+ assert_equal(ua, ua3)\n+\n+class test_byteorder_1_ucs2(byteorder_values):\n+ \"\"\"Check the byteorder in unicode (size 1, UCS2 values)\"\"\"\n+ ulen = 1\n+ ucs_value = ucs2_value\n+\n+class test_byteorder_1_ucs4(byteorder_values):\n+ \"\"\"Check the byteorder in unicode (size 1, UCS4 values)\"\"\"\n+ ulen = 1\n+ ucs_value = ucs4_value\n+\n+class test_byteorder_2_ucs2(byteorder_values):\n+ \"\"\"Check the byteorder in unicode (size 2, UCS2 values)\"\"\"\n+ ulen = 2\n+ ucs_value = ucs2_value\n+\n+class test_byteorder_2_ucs4(byteorder_values):\n+ \"\"\"Check the byteorder in unicode (size 2, UCS4 values)\"\"\"\n+ ulen = 2\n+ ucs_value = ucs4_value\n+\n+class test_byteorder_1009_ucs2(byteorder_values):\n+ \"\"\"Check the byteorder in unicode (size 1009, UCS2 values)\"\"\"\n+ ulen = 1009\n+ ucs_value = ucs2_value\n+\n+class test_byteorder_1009_ucs4(byteorder_values):\n+ \"\"\"Check the byteorder in unicode (size 1009, UCS4 values)\"\"\"\n+ ulen = 1009\n+ ucs_value = ucs4_value\n+\n+\n+if __name__ == \"__main__\":\n+ ScipyTest().run()\n", + "added_lines": 305, + "deleted_lines": 0, + "source_code": "import sys\nfrom numpy.testing import *\nfrom numpy.core import *\n\n# Guess the UCS length for this python interpreter\nif len(buffer(u'u')) == 4:\n ucs4 = True\nelse:\n ucs4 = False\n\n# Value that can be represented in UCS2 interpreters\nucs2_value = u'\\uFFFF'\n# Value that cannot be represented in UCS2 interpreters (but can in UCS4)\nucs4_value = u'\\U0010FFFF'\n\n\n############################################################\n# Creation tests\n############################################################\n\nclass create_zeros(ScipyTestCase):\n \"\"\"Check the creation of zero-valued arrays\"\"\"\n\n def content_test(self, ua, ua_scalar, nbytes):\n\n # Check the length of the unicode base type\n self.assert_(int(ua.dtype.str[2:]) == self.ulen)\n # Check the length of the data buffer\n self.assert_(len(ua.data) == nbytes)\n # Small check that data in array element is ok\n self.assert_(ua_scalar == u'\\x00'*self.ulen)\n # Encode to ascii and double check\n self.assert_(ua_scalar.encode('ascii') == '\\x00'*self.ulen)\n # Check buffer lengths for scalars\n if ucs4:\n self.assert_(len(buffer(ua_scalar)) == 4*self.ulen)\n else:\n self.assert_(len(buffer(ua_scalar)) == 2*self.ulen)\n\n def check_zeros0D(self):\n \"\"\"Check creation of 0-dimensional objects\"\"\"\n ua = zeros((), dtype='U%s' % self.ulen)\n self.content_test(ua, ua[()], 4*self.ulen)\n\n def check_zerosSD(self):\n \"\"\"Check creation of single-dimensional objects\"\"\"\n ua = zeros((2,), dtype='U%s' % self.ulen)\n self.content_test(ua, ua[0], 4*self.ulen*2)\n self.content_test(ua, ua[1], 4*self.ulen*2)\n\n def check_zerosMD(self):\n \"\"\"Check creation of multi-dimensional objects\"\"\"\n ua = zeros((2,3,4), dtype='U%s' % self.ulen)\n self.content_test(ua, ua[0,0,0], 4*self.ulen*2*3*4)\n self.content_test(ua, ua[-1,-1,-1], 4*self.ulen*2*3*4)\n\n\nclass test_create_zeros_1(create_zeros):\n \"\"\"Check the creation of zero-valued arrays (size 1)\"\"\"\n ulen = 1\n\nclass test_create_zeros_2(create_zeros):\n \"\"\"Check the creation of zero-valued arrays (size 2)\"\"\"\n ulen = 2\n\nclass test_create_zeros_1009(create_zeros):\n \"\"\"Check the creation of zero-valued arrays (size 1009)\"\"\"\n ulen = 1009\n\n\nclass create_values(ScipyTestCase):\n \"\"\"Check the creation of unicode arrays with values\"\"\"\n\n def content_test(self, ua, ua_scalar, nbytes):\n\n # Check the length of the unicode base type\n self.assert_(int(ua.dtype.str[2:]) == self.ulen)\n # Check the length of the data buffer\n self.assert_(len(ua.data) == nbytes)\n # Small check that data in array element is ok\n self.assert_(ua_scalar == self.ucs_value*self.ulen)\n # Encode to UTF-8 and double check\n self.assert_(ua_scalar.encode('utf-8') == \\\n (self.ucs_value*self.ulen).encode('utf-8'))\n # Check buffer lengths for scalars\n if ucs4:\n self.assert_(len(buffer(ua_scalar)) == 4*self.ulen)\n else:\n if self.ucs_value == ucs4_value:\n # In UCS2, the \\U0010FFFF will be represented using a\n # surrogate *pair*\n self.assert_(len(buffer(ua_scalar)) == 2*2*self.ulen)\n else:\n # In UCS2, the \\uFFFF will be represented using a\n # regular 2-byte word\n self.assert_(len(buffer(ua_scalar)) == 2*self.ulen)\n\n def check_values0D(self):\n \"\"\"Check creation of 0-dimensional objects with values\"\"\"\n ua = array(self.ucs_value*self.ulen, dtype='U%s' % self.ulen)\n self.content_test(ua, ua[()], 4*self.ulen)\n\n def check_valuesSD(self):\n \"\"\"Check creation of single-dimensional objects with values\"\"\"\n ua = array([self.ucs_value*self.ulen]*2, dtype='U%s' % self.ulen)\n self.content_test(ua, ua[0], 4*self.ulen*2)\n self.content_test(ua, ua[1], 4*self.ulen*2)\n\n def check_valuesMD(self):\n \"\"\"Check creation of multi-dimensional objects with values\"\"\"\n ua = array([[[self.ucs_value*self.ulen]*2]*3]*4, dtype='U%s' % self.ulen)\n self.content_test(ua, ua[0,0,0], 4*self.ulen*2*3*4)\n self.content_test(ua, ua[-1,-1,-1], 4*self.ulen*2*3*4)\n\n\nclass test_create_values_1_ucs2(create_values):\n \"\"\"Check the creation of valued arrays (size 1, UCS2 values)\"\"\"\n ulen = 1\n ucs_value = ucs2_value\n\nclass test_create_values_1_ucs4(create_values):\n \"\"\"Check the creation of valued arrays (size 1, UCS4 values)\"\"\"\n ulen = 1\n ucs_value = ucs4_value\n\nclass test_create_values_2_ucs2(create_values):\n \"\"\"Check the creation of valued arrays (size 2, UCS2 values)\"\"\"\n ulen = 2\n ucs_value = ucs2_value\n\nclass test_create_values_2_ucs4(create_values):\n \"\"\"Check the creation of valued arrays (size 2, UCS4 values)\"\"\"\n ulen = 2\n ucs_value = ucs4_value\n\nclass test_create_values_1009_ucs2(create_values):\n \"\"\"Check the creation of valued arrays (size 1009, UCS2 values)\"\"\"\n ulen = 1009\n ucs_value = ucs2_value\n\nclass test_create_values_1009_ucs4(create_values):\n \"\"\"Check the creation of valued arrays (size 1009, UCS4 values)\"\"\"\n ulen = 1009\n ucs_value = ucs4_value\n\n\n############################################################\n# Assignment tests\n############################################################\n\nclass assign_values(ScipyTestCase):\n \"\"\"Check the assignment of unicode arrays with values\"\"\"\n\n def content_test(self, ua, ua_scalar, nbytes):\n\n # Check the length of the unicode base type\n self.assert_(int(ua.dtype.str[2:]) == self.ulen)\n # Check the length of the data buffer\n self.assert_(len(ua.data) == nbytes)\n # Small check that data in array element is ok\n self.assert_(ua_scalar == self.ucs_value*self.ulen)\n # Encode to UTF-8 and double check\n self.assert_(ua_scalar.encode('utf-8') == \\\n (self.ucs_value*self.ulen).encode('utf-8'))\n # Check buffer lengths for scalars\n if ucs4:\n self.assert_(len(buffer(ua_scalar)) == 4*self.ulen)\n else:\n if self.ucs_value == ucs4_value:\n # In UCS2, the \\U0010FFFF will be represented using a\n # surrogate *pair*\n self.assert_(len(buffer(ua_scalar)) == 2*2*self.ulen)\n else:\n # In UCS2, the \\uFFFF will be represented using a\n # regular 2-byte word\n self.assert_(len(buffer(ua_scalar)) == 2*self.ulen)\n\n def check_values0D(self):\n \"\"\"Check assignment of 0-dimensional objects with values\"\"\"\n ua = zeros((), dtype='U%s' % self.ulen)\n ua[()] = self.ucs_value*self.ulen\n self.content_test(ua, ua[()], 4*self.ulen)\n\n def check_valuesSD(self):\n \"\"\"Check assignment of single-dimensional objects with values\"\"\"\n ua = zeros((2,), dtype='U%s' % self.ulen)\n ua[0] = self.ucs_value*self.ulen\n self.content_test(ua, ua[0], 4*self.ulen*2) \n ua[1] = self.ucs_value*self.ulen\n self.content_test(ua, ua[1], 4*self.ulen*2)\n\n def check_valuesMD(self):\n \"\"\"Check assignment of multi-dimensional objects with values\"\"\"\n ua = zeros((2,3,4), dtype='U%s' % self.ulen)\n ua[0,0,0] = self.ucs_value*self.ulen\n self.content_test(ua, ua[0,0,0], 4*self.ulen*2*3*4)\n ua[-1,-1,-1] = self.ucs_value*self.ulen\n self.content_test(ua, ua[-1,-1,-1], 4*self.ulen*2*3*4)\n\n\nclass test_assign_values_1_ucs2(assign_values):\n \"\"\"Check the assignment of valued arrays (size 1, UCS2 values)\"\"\"\n ulen = 1\n ucs_value = ucs2_value\n\nclass test_assign_values_1_ucs4(assign_values):\n \"\"\"Check the assignment of valued arrays (size 1, UCS4 values)\"\"\"\n ulen = 1\n ucs_value = ucs4_value\n\nclass test_assign_values_2_ucs2(assign_values):\n \"\"\"Check the assignment of valued arrays (size 2, UCS2 values)\"\"\"\n ulen = 2\n ucs_value = ucs2_value\n\nclass test_assign_values_2_ucs4(assign_values):\n \"\"\"Check the assignment of valued arrays (size 2, UCS4 values)\"\"\"\n ulen = 2\n ucs_value = ucs4_value\n\nclass test_assign_values_1009_ucs2(assign_values):\n \"\"\"Check the assignment of valued arrays (size 1009, UCS2 values)\"\"\"\n ulen = 1009\n ucs_value = ucs2_value\n\nclass test_assign_values_1009_ucs4(assign_values):\n \"\"\"Check the assignment of valued arrays (size 1009, UCS4 values)\"\"\"\n ulen = 1009\n ucs_value = ucs4_value\n\n\n############################################################\n# Byteorder tests\n############################################################\n\nclass byteorder_values(ScipyTestCase):\n \"\"\"Check the byteorder of unicode arrays in round-trip conversions\"\"\"\n\n def check_values0D(self):\n \"\"\"Check byteorder of 0-dimensional objects\"\"\"\n ua = array(self.ucs_value*self.ulen, dtype='U%s' % self.ulen)\n ua2 = ua.newbyteorder()\n # Scalars must be different\n # Problems here because it seems that ua.view() != ua (!)\n self.assert_(ua[()] != ua2[()])\n ua3 = ua2.newbyteorder()\n # Arrays must be equal after the round-trip\n assert_equal(ua, ua3)\n\n def check_valuesSD(self):\n \"\"\"Check byteorder of single-dimensional objects\"\"\"\n ua = array([self.ucs_value*self.ulen]*2, dtype='U%s' % self.ulen)\n ua2 = ua.newbyteorder()\n # Scalars must be different\n self.assert_(ua[0] != ua2[0])\n self.assert_(ua[-1] != ua2[-1])\n ua3 = ua2.newbyteorder()\n # Arrays must be equal after the round-trip\n assert_equal(ua, ua3)\n\n def check_valuesMD(self):\n \"\"\"Check byteorder of multi-dimensional objects\"\"\"\n ua = array([[[self.ucs_value*self.ulen]*2]*3]*4,\n dtype='U%s' % self.ulen)\n ua2 = ua.newbyteorder()\n # Scalars must be different\n self.assert_(ua[0,0,0] != ua2[0,0,0])\n self.assert_(ua[-1,-1,-1] != ua2[-1,-1,-1])\n ua3 = ua2.newbyteorder()\n # Arrays must be equal after the round-trip\n assert_equal(ua, ua3)\n\nclass test_byteorder_1_ucs2(byteorder_values):\n \"\"\"Check the byteorder in unicode (size 1, UCS2 values)\"\"\"\n ulen = 1\n ucs_value = ucs2_value\n\nclass test_byteorder_1_ucs4(byteorder_values):\n \"\"\"Check the byteorder in unicode (size 1, UCS4 values)\"\"\"\n ulen = 1\n ucs_value = ucs4_value\n\nclass test_byteorder_2_ucs2(byteorder_values):\n \"\"\"Check the byteorder in unicode (size 2, UCS2 values)\"\"\"\n ulen = 2\n ucs_value = ucs2_value\n\nclass test_byteorder_2_ucs4(byteorder_values):\n \"\"\"Check the byteorder in unicode (size 2, UCS4 values)\"\"\"\n ulen = 2\n ucs_value = ucs4_value\n\nclass test_byteorder_1009_ucs2(byteorder_values):\n \"\"\"Check the byteorder in unicode (size 1009, UCS2 values)\"\"\"\n ulen = 1009\n ucs_value = ucs2_value\n\nclass test_byteorder_1009_ucs4(byteorder_values):\n \"\"\"Check the byteorder in unicode (size 1009, UCS4 values)\"\"\"\n ulen = 1009\n ucs_value = ucs4_value\n\n\nif __name__ == \"__main__\":\n ScipyTest().run()\n", + "source_code_before": null, + "methods": [ + { + "name": "content_test", + "long_name": "content_test( self , ua , ua_scalar , nbytes )", + "filename": "test_unicode.py", + "nloc": 9, + "complexity": 2, + "token_count": 116, + "parameters": [ + "self", + "ua", + "ua_scalar", + "nbytes" + ], + "start_line": 24, + "end_line": 38, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 15, + "top_nesting_level": 1 + }, + { + "name": "check_zeros0D", + "long_name": "check_zeros0D( self )", + "filename": "test_unicode.py", + "nloc": 3, + "complexity": 1, + "token_count": 39, + "parameters": [ + "self" + ], + "start_line": 40, + "end_line": 43, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 1 + }, + { + "name": "check_zerosSD", + "long_name": "check_zerosSD( self )", + "filename": "test_unicode.py", + "nloc": 4, + "complexity": 1, + "token_count": 61, + "parameters": [ + "self" + ], + "start_line": 45, + "end_line": 49, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 5, + "top_nesting_level": 1 + }, + { + "name": "check_zerosMD", + "long_name": "check_zerosMD( self )", + "filename": "test_unicode.py", + "nloc": 4, + "complexity": 1, + "token_count": 83, + "parameters": [ + "self" + ], + "start_line": 51, + "end_line": 55, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 5, + "top_nesting_level": 1 + }, + { + "name": "content_test", + "long_name": "content_test( self , ua , ua_scalar , nbytes )", + "filename": "test_unicode.py", + "nloc": 13, + "complexity": 3, + "token_count": 156, + "parameters": [ + "self", + "ua", + "ua_scalar", + "nbytes" + ], + "start_line": 74, + "end_line": 96, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 23, + "top_nesting_level": 1 + }, + { + "name": "check_values0D", + "long_name": "check_values0D( self )", + "filename": "test_unicode.py", + "nloc": 3, + "complexity": 1, + "token_count": 44, + "parameters": [ + "self" + ], + "start_line": 98, + "end_line": 101, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 1 + }, + { + "name": "check_valuesSD", + "long_name": "check_valuesSD( self )", + "filename": "test_unicode.py", + "nloc": 4, + "complexity": 1, + "token_count": 68, + "parameters": [ + "self" + ], + "start_line": 103, + "end_line": 107, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 5, + "top_nesting_level": 1 + }, + { + "name": "check_valuesMD", + "long_name": "check_valuesMD( self )", + "filename": "test_unicode.py", + "nloc": 4, + "complexity": 1, + "token_count": 95, + "parameters": [ + "self" + ], + "start_line": 109, + "end_line": 113, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 5, + "top_nesting_level": 1 + }, + { + "name": "content_test", + "long_name": "content_test( self , ua , ua_scalar , nbytes )", + "filename": "test_unicode.py", + "nloc": 13, + "complexity": 3, + "token_count": 156, + "parameters": [ + "self", + "ua", + "ua_scalar", + "nbytes" + ], + "start_line": 154, + "end_line": 176, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 23, + "top_nesting_level": 1 + }, + { + "name": "check_values0D", + "long_name": "check_values0D( self )", + "filename": "test_unicode.py", + "nloc": 4, + "complexity": 1, + "token_count": 52, + "parameters": [ + "self" + ], + "start_line": 178, + "end_line": 182, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 5, + "top_nesting_level": 1 + }, + { + "name": "check_valuesSD", + "long_name": "check_valuesSD( self )", + "filename": "test_unicode.py", + "nloc": 6, + "complexity": 1, + "token_count": 85, + "parameters": [ + "self" + ], + "start_line": 184, + "end_line": 190, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 7, + "top_nesting_level": 1 + }, + { + "name": "check_valuesMD", + "long_name": "check_valuesMD( self )", + "filename": "test_unicode.py", + "nloc": 6, + "complexity": 1, + "token_count": 118, + "parameters": [ + "self" + ], + "start_line": 192, + "end_line": 198, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 7, + "top_nesting_level": 1 + }, + { + "name": "check_values0D", + "long_name": "check_values0D( self )", + "filename": "test_unicode.py", + "nloc": 6, + "complexity": 1, + "token_count": 62, + "parameters": [ + "self" + ], + "start_line": 239, + "end_line": 248, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 10, + "top_nesting_level": 1 + }, + { + "name": "check_valuesSD", + "long_name": "check_valuesSD( self )", + "filename": "test_unicode.py", + "nloc": 7, + "complexity": 1, + "token_count": 80, + "parameters": [ + "self" + ], + "start_line": 250, + "end_line": 259, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 10, + "top_nesting_level": 1 + }, + { + "name": "check_valuesMD", + "long_name": "check_valuesMD( self )", + "filename": "test_unicode.py", + "nloc": 8, + "complexity": 1, + "token_count": 108, + "parameters": [ + "self" + ], + "start_line": 261, + "end_line": 271, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 11, + "top_nesting_level": 1 + } + ], + "methods_before": [], + "changed_methods": [ + { + "name": "check_valuesMD", + "long_name": "check_valuesMD( self )", + "filename": "test_unicode.py", + "nloc": 4, + "complexity": 1, + "token_count": 95, + "parameters": [ + "self" + ], + "start_line": 109, + "end_line": 113, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 5, + "top_nesting_level": 1 + }, + { + "name": "check_zerosSD", + "long_name": "check_zerosSD( self )", + "filename": "test_unicode.py", + "nloc": 4, + "complexity": 1, + "token_count": 61, + "parameters": [ + "self" + ], + "start_line": 45, + "end_line": 49, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 5, + "top_nesting_level": 1 + }, + { + "name": "content_test", + "long_name": "content_test( self , ua , ua_scalar , nbytes )", + "filename": "test_unicode.py", + "nloc": 9, + "complexity": 2, + "token_count": 116, + "parameters": [ + "self", + "ua", + "ua_scalar", + "nbytes" + ], + "start_line": 24, + "end_line": 38, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 15, + "top_nesting_level": 1 + }, + { + "name": "check_zeros0D", + "long_name": "check_zeros0D( self )", + "filename": "test_unicode.py", + "nloc": 3, + "complexity": 1, + "token_count": 39, + "parameters": [ + "self" + ], + "start_line": 40, + "end_line": 43, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 1 + }, + { + "name": "check_zerosMD", + "long_name": "check_zerosMD( self )", + "filename": "test_unicode.py", + "nloc": 4, + "complexity": 1, + "token_count": 83, + "parameters": [ + "self" + ], + "start_line": 51, + "end_line": 55, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 5, + "top_nesting_level": 1 + }, + { + "name": "check_valuesSD", + "long_name": "check_valuesSD( self )", + "filename": "test_unicode.py", + "nloc": 4, + "complexity": 1, + "token_count": 68, + "parameters": [ + "self" + ], + "start_line": 103, + "end_line": 107, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 5, + "top_nesting_level": 1 + }, + { + "name": "check_values0D", + "long_name": "check_values0D( self )", + "filename": "test_unicode.py", + "nloc": 3, + "complexity": 1, + "token_count": 44, + "parameters": [ + "self" + ], + "start_line": 98, + "end_line": 101, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 1 + } + ], + "nloc": 194, + "complexity": 20, + "token_count": 1684, + "diff_parsed": { + "added": [ + "import sys", + "from numpy.testing import *", + "from numpy.core import *", + "", + "# Guess the UCS length for this python interpreter", + "if len(buffer(u'u')) == 4:", + " ucs4 = True", + "else:", + " ucs4 = False", + "", + "# Value that can be represented in UCS2 interpreters", + "ucs2_value = u'\\uFFFF'", + "# Value that cannot be represented in UCS2 interpreters (but can in UCS4)", + "ucs4_value = u'\\U0010FFFF'", + "", + "", + "############################################################", + "# Creation tests", + "############################################################", + "", + "class create_zeros(ScipyTestCase):", + " \"\"\"Check the creation of zero-valued arrays\"\"\"", + "", + " def content_test(self, ua, ua_scalar, nbytes):", + "", + " # Check the length of the unicode base type", + " self.assert_(int(ua.dtype.str[2:]) == self.ulen)", + " # Check the length of the data buffer", + " self.assert_(len(ua.data) == nbytes)", + " # Small check that data in array element is ok", + " self.assert_(ua_scalar == u'\\x00'*self.ulen)", + " # Encode to ascii and double check", + " self.assert_(ua_scalar.encode('ascii') == '\\x00'*self.ulen)", + " # Check buffer lengths for scalars", + " if ucs4:", + " self.assert_(len(buffer(ua_scalar)) == 4*self.ulen)", + " else:", + " self.assert_(len(buffer(ua_scalar)) == 2*self.ulen)", + "", + " def check_zeros0D(self):", + " \"\"\"Check creation of 0-dimensional objects\"\"\"", + " ua = zeros((), dtype='U%s' % self.ulen)", + " self.content_test(ua, ua[()], 4*self.ulen)", + "", + " def check_zerosSD(self):", + " \"\"\"Check creation of single-dimensional objects\"\"\"", + " ua = zeros((2,), dtype='U%s' % self.ulen)", + " self.content_test(ua, ua[0], 4*self.ulen*2)", + " self.content_test(ua, ua[1], 4*self.ulen*2)", + "", + " def check_zerosMD(self):", + " \"\"\"Check creation of multi-dimensional objects\"\"\"", + " ua = zeros((2,3,4), dtype='U%s' % self.ulen)", + " self.content_test(ua, ua[0,0,0], 4*self.ulen*2*3*4)", + " self.content_test(ua, ua[-1,-1,-1], 4*self.ulen*2*3*4)", + "", + "", + "class test_create_zeros_1(create_zeros):", + " \"\"\"Check the creation of zero-valued arrays (size 1)\"\"\"", + " ulen = 1", + "", + "class test_create_zeros_2(create_zeros):", + " \"\"\"Check the creation of zero-valued arrays (size 2)\"\"\"", + " ulen = 2", + "", + "class test_create_zeros_1009(create_zeros):", + " \"\"\"Check the creation of zero-valued arrays (size 1009)\"\"\"", + " ulen = 1009", + "", + "", + "class create_values(ScipyTestCase):", + " \"\"\"Check the creation of unicode arrays with values\"\"\"", + "", + " def content_test(self, ua, ua_scalar, nbytes):", + "", + " # Check the length of the unicode base type", + " self.assert_(int(ua.dtype.str[2:]) == self.ulen)", + " # Check the length of the data buffer", + " self.assert_(len(ua.data) == nbytes)", + " # Small check that data in array element is ok", + " self.assert_(ua_scalar == self.ucs_value*self.ulen)", + " # Encode to UTF-8 and double check", + " self.assert_(ua_scalar.encode('utf-8') == \\", + " (self.ucs_value*self.ulen).encode('utf-8'))", + " # Check buffer lengths for scalars", + " if ucs4:", + " self.assert_(len(buffer(ua_scalar)) == 4*self.ulen)", + " else:", + " if self.ucs_value == ucs4_value:", + " # In UCS2, the \\U0010FFFF will be represented using a", + " # surrogate *pair*", + " self.assert_(len(buffer(ua_scalar)) == 2*2*self.ulen)", + " else:", + " # In UCS2, the \\uFFFF will be represented using a", + " # regular 2-byte word", + " self.assert_(len(buffer(ua_scalar)) == 2*self.ulen)", + "", + " def check_values0D(self):", + " \"\"\"Check creation of 0-dimensional objects with values\"\"\"", + " ua = array(self.ucs_value*self.ulen, dtype='U%s' % self.ulen)", + " self.content_test(ua, ua[()], 4*self.ulen)", + "", + " def check_valuesSD(self):", + " \"\"\"Check creation of single-dimensional objects with values\"\"\"", + " ua = array([self.ucs_value*self.ulen]*2, dtype='U%s' % self.ulen)", + " self.content_test(ua, ua[0], 4*self.ulen*2)", + " self.content_test(ua, ua[1], 4*self.ulen*2)", + "", + " def check_valuesMD(self):", + " \"\"\"Check creation of multi-dimensional objects with values\"\"\"", + " ua = array([[[self.ucs_value*self.ulen]*2]*3]*4, dtype='U%s' % self.ulen)", + " self.content_test(ua, ua[0,0,0], 4*self.ulen*2*3*4)", + " self.content_test(ua, ua[-1,-1,-1], 4*self.ulen*2*3*4)", + "", + "", + "class test_create_values_1_ucs2(create_values):", + " \"\"\"Check the creation of valued arrays (size 1, UCS2 values)\"\"\"", + " ulen = 1", + " ucs_value = ucs2_value", + "", + "class test_create_values_1_ucs4(create_values):", + " \"\"\"Check the creation of valued arrays (size 1, UCS4 values)\"\"\"", + " ulen = 1", + " ucs_value = ucs4_value", + "", + "class test_create_values_2_ucs2(create_values):", + " \"\"\"Check the creation of valued arrays (size 2, UCS2 values)\"\"\"", + " ulen = 2", + " ucs_value = ucs2_value", + "", + "class test_create_values_2_ucs4(create_values):", + " \"\"\"Check the creation of valued arrays (size 2, UCS4 values)\"\"\"", + " ulen = 2", + " ucs_value = ucs4_value", + "", + "class test_create_values_1009_ucs2(create_values):", + " \"\"\"Check the creation of valued arrays (size 1009, UCS2 values)\"\"\"", + " ulen = 1009", + " ucs_value = ucs2_value", + "", + "class test_create_values_1009_ucs4(create_values):", + " \"\"\"Check the creation of valued arrays (size 1009, UCS4 values)\"\"\"", + " ulen = 1009", + " ucs_value = ucs4_value", + "", + "", + "############################################################", + "# Assignment tests", + "############################################################", + "", + "class assign_values(ScipyTestCase):", + " \"\"\"Check the assignment of unicode arrays with values\"\"\"", + "", + " def content_test(self, ua, ua_scalar, nbytes):", + "", + " # Check the length of the unicode base type", + " self.assert_(int(ua.dtype.str[2:]) == self.ulen)", + " # Check the length of the data buffer", + " self.assert_(len(ua.data) == nbytes)", + " # Small check that data in array element is ok", + " self.assert_(ua_scalar == self.ucs_value*self.ulen)", + " # Encode to UTF-8 and double check", + " self.assert_(ua_scalar.encode('utf-8') == \\", + " (self.ucs_value*self.ulen).encode('utf-8'))", + " # Check buffer lengths for scalars", + " if ucs4:", + " self.assert_(len(buffer(ua_scalar)) == 4*self.ulen)", + " else:", + " if self.ucs_value == ucs4_value:", + " # In UCS2, the \\U0010FFFF will be represented using a", + " # surrogate *pair*", + " self.assert_(len(buffer(ua_scalar)) == 2*2*self.ulen)", + " else:", + " # In UCS2, the \\uFFFF will be represented using a", + " # regular 2-byte word", + " self.assert_(len(buffer(ua_scalar)) == 2*self.ulen)", + "", + " def check_values0D(self):", + " \"\"\"Check assignment of 0-dimensional objects with values\"\"\"", + " ua = zeros((), dtype='U%s' % self.ulen)", + " ua[()] = self.ucs_value*self.ulen", + " self.content_test(ua, ua[()], 4*self.ulen)", + "", + " def check_valuesSD(self):", + " \"\"\"Check assignment of single-dimensional objects with values\"\"\"", + " ua = zeros((2,), dtype='U%s' % self.ulen)", + " ua[0] = self.ucs_value*self.ulen", + " self.content_test(ua, ua[0], 4*self.ulen*2)", + " ua[1] = self.ucs_value*self.ulen", + " self.content_test(ua, ua[1], 4*self.ulen*2)", + "", + " def check_valuesMD(self):", + " \"\"\"Check assignment of multi-dimensional objects with values\"\"\"", + " ua = zeros((2,3,4), dtype='U%s' % self.ulen)", + " ua[0,0,0] = self.ucs_value*self.ulen", + " self.content_test(ua, ua[0,0,0], 4*self.ulen*2*3*4)", + " ua[-1,-1,-1] = self.ucs_value*self.ulen", + " self.content_test(ua, ua[-1,-1,-1], 4*self.ulen*2*3*4)", + "", + "", + "class test_assign_values_1_ucs2(assign_values):", + " \"\"\"Check the assignment of valued arrays (size 1, UCS2 values)\"\"\"", + " ulen = 1", + " ucs_value = ucs2_value", + "", + "class test_assign_values_1_ucs4(assign_values):", + " \"\"\"Check the assignment of valued arrays (size 1, UCS4 values)\"\"\"", + " ulen = 1", + " ucs_value = ucs4_value", + "", + "class test_assign_values_2_ucs2(assign_values):", + " \"\"\"Check the assignment of valued arrays (size 2, UCS2 values)\"\"\"", + " ulen = 2", + " ucs_value = ucs2_value", + "", + "class test_assign_values_2_ucs4(assign_values):", + " \"\"\"Check the assignment of valued arrays (size 2, UCS4 values)\"\"\"", + " ulen = 2", + " ucs_value = ucs4_value", + "", + "class test_assign_values_1009_ucs2(assign_values):", + " \"\"\"Check the assignment of valued arrays (size 1009, UCS2 values)\"\"\"", + " ulen = 1009", + " ucs_value = ucs2_value", + "", + "class test_assign_values_1009_ucs4(assign_values):", + " \"\"\"Check the assignment of valued arrays (size 1009, UCS4 values)\"\"\"", + " ulen = 1009", + " ucs_value = ucs4_value", + "", + "", + "############################################################", + "# Byteorder tests", + "############################################################", + "", + "class byteorder_values(ScipyTestCase):", + " \"\"\"Check the byteorder of unicode arrays in round-trip conversions\"\"\"", + "", + " def check_values0D(self):", + " \"\"\"Check byteorder of 0-dimensional objects\"\"\"", + " ua = array(self.ucs_value*self.ulen, dtype='U%s' % self.ulen)", + " ua2 = ua.newbyteorder()", + " # Scalars must be different", + " # Problems here because it seems that ua.view() != ua (!)", + " self.assert_(ua[()] != ua2[()])", + " ua3 = ua2.newbyteorder()", + " # Arrays must be equal after the round-trip", + " assert_equal(ua, ua3)", + "", + " def check_valuesSD(self):", + " \"\"\"Check byteorder of single-dimensional objects\"\"\"", + " ua = array([self.ucs_value*self.ulen]*2, dtype='U%s' % self.ulen)", + " ua2 = ua.newbyteorder()", + " # Scalars must be different", + " self.assert_(ua[0] != ua2[0])", + " self.assert_(ua[-1] != ua2[-1])", + " ua3 = ua2.newbyteorder()", + " # Arrays must be equal after the round-trip", + " assert_equal(ua, ua3)", + "", + " def check_valuesMD(self):", + " \"\"\"Check byteorder of multi-dimensional objects\"\"\"", + " ua = array([[[self.ucs_value*self.ulen]*2]*3]*4,", + " dtype='U%s' % self.ulen)", + " ua2 = ua.newbyteorder()", + " # Scalars must be different", + " self.assert_(ua[0,0,0] != ua2[0,0,0])", + " self.assert_(ua[-1,-1,-1] != ua2[-1,-1,-1])", + " ua3 = ua2.newbyteorder()", + " # Arrays must be equal after the round-trip", + " assert_equal(ua, ua3)", + "", + "class test_byteorder_1_ucs2(byteorder_values):", + " \"\"\"Check the byteorder in unicode (size 1, UCS2 values)\"\"\"", + " ulen = 1", + " ucs_value = ucs2_value", + "", + "class test_byteorder_1_ucs4(byteorder_values):", + " \"\"\"Check the byteorder in unicode (size 1, UCS4 values)\"\"\"", + " ulen = 1", + " ucs_value = ucs4_value", + "", + "class test_byteorder_2_ucs2(byteorder_values):", + " \"\"\"Check the byteorder in unicode (size 2, UCS2 values)\"\"\"", + " ulen = 2", + " ucs_value = ucs2_value", + "", + "class test_byteorder_2_ucs4(byteorder_values):", + " \"\"\"Check the byteorder in unicode (size 2, UCS4 values)\"\"\"", + " ulen = 2", + " ucs_value = ucs4_value", + "", + "class test_byteorder_1009_ucs2(byteorder_values):", + " \"\"\"Check the byteorder in unicode (size 1009, UCS2 values)\"\"\"", + " ulen = 1009", + " ucs_value = ucs2_value", + "", + "class test_byteorder_1009_ucs4(byteorder_values):", + " \"\"\"Check the byteorder in unicode (size 1009, UCS4 values)\"\"\"", + " ulen = 1009", + " ucs_value = ucs4_value", + "", + "", + "if __name__ == \"__main__\":", + " ScipyTest().run()" + ], + "deleted": [] + } + } + ] + }, + { + "hash": "70a40679af0eb4e2613606b0f19ba32e3ece67dc", + "msg": "Add a square() ufunc, and optimize power(x, ) for ints and reals.", + "author": { + "name": "cookedm", + "email": "cookedm@localhost" + }, + "committer": { + "name": "cookedm", + "email": "cookedm@localhost" + }, + "author_date": "2006-02-14T23:11:03+00:00", + "author_timezone": 0, + "committer_date": "2006-02-14T23:11:03+00:00", + "committer_timezone": 0, + "branches": [ + "main" + ], + "in_main_branch": true, + "merge": false, + "parents": [ + "6b93ba8d5761b2a2c84c8375b80d2bd1e2c9cfd3" + ], + "project_name": "repo_copy", + "project_path": "/tmp/tmpdjwupkfu/repo_copy", + "deletions": 2, + "insertions": 111, + "lines": 113, + "files": 2, + "dmm_unit_size": null, + "dmm_unit_complexity": null, + "dmm_unit_interfacing": null, + "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": "@@ -79,8 +79,9 @@\n (2,1), Zero,\n \"computes (C-like) x1 % x2 elementwise.\"\n ],\n-'power' : [nobool,noint,\n- (\"pow,\"*6,\n+'square' : [nobool,'O', (\"Py_square\",), (1,1), None, \"squares x\"],\n+'power' : [nobool,cmplxO,\n+ (\"pow,\"*3,\n \"PyNumber_Power\"),\n (2,1), One,\n \"computes x1**x2 elementwise.\"\n", + "added_lines": 3, + "deleted_lines": 2, + "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'square' : [nobool,'O', (\"Py_square\",), (1,1), None, \"squares x\"],\n'power' : [nobool,cmplxO,\n (\"pow,\"*3,\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'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", + "methods": [ + { + "name": "indent", + "long_name": "indent( st , spaces )", + "filename": "generate_umath.py", + "nloc": 5, + "complexity": 1, + "token_count": 44, + "parameters": [ + "st", + "spaces" + ], + "start_line": 327, + "end_line": 332, + "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": 377, + "end_line": 442, + "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": 444, + "end_line": 457, + "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": 460, + "end_line": 480, + "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": 483, + "end_line": 506, + "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": 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 + } + ], + "changed_methods": [], + "nloc": 466, + "complexity": 24, + "token_count": 2763, + "diff_parsed": { + "added": [ + "'square' : [nobool,'O', (\"Py_square\",), (1,1), None, \"squares x\"],", + "'power' : [nobool,cmplxO,", + " (\"pow,\"*3," + ], + "deleted": [ + "'power' : [nobool,noint,", + " (\"pow,\"*6," + ] + } + }, + { + "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": "@@ -1216,6 +1216,51 @@ static void\n }\n /**end repeat**/\n \n+/**begin repeat\n+#TYP=BYTE,UBYTE,SHORT,USHORT,INT,UINT,LONG,ULONG,LONGLONG,ULONGLONG,FLOAT,DOUBLE,LONGDOUBLE#\n+#typ=char, ubyte, short, ushort, int, uint, long, ulong, longlong, ulonglong, float, double, longdouble#\n+*/\n+static void\n+@TYP@_square(char **args, intp *dimensions, intp *steps, void *data)\n+{\n+ intp i, is1 = steps[0], os = steps[1], n = dimensions[0];\n+ char *i1 = args[0], *op = args[1];\n+\n+ for (i = 0; i < n; i++, i1 += is1, op += os) {\n+ @typ@ x = *((@typ@ *)i1);\n+ *((@typ@ *)op) = x*x;\n+ }\n+}\n+/**end repeat**/\n+\n+/**begin repeat\n+#TYP=CFLOAT,CDOUBLE,CLONGDOUBLE#\n+#typ=float, double, longdouble#\n+*/\n+static void\n+@TYP@_square(char **args, intp *dimensions, intp *steps, void *data)\n+{\n+ intp i, is1 = steps[0], os = steps[1], n = dimensions[0];\n+ char *i1 = args[0], *op = args[1];\n+ c@typ@ *x, *y;\n+ @typ@ xr, xi;\n+\n+ for (i = 0; i < n; i++, i1 += is1, op += os) {\n+ x = (c@typ@ *)i1;\n+ y = (c@typ@ *)op;\n+ xr = x->real;\n+ xi = x->imag;\n+ y->real = xr*xr - xi*xi;\n+ y->imag = 2*xr*xi;\n+ }\n+}\n+/**end repeat**/\n+\n+static PyObject *\n+Py_square(PyObject *o)\n+{\n+ return PyNumber_Multiply(o, o);\n+}\n \n /**begin repeat\n \n@@ -1243,6 +1288,69 @@ static void\n }\n /**end repeat**/\n \n+/**begin repeat\n+#TYP=FLOAT,DOUBLE,LONGDOUBLE#\n+#typ=float,double,longdouble#\n+#powfunc=powf,pow,powl#\n+#sqrtfunc=sqrtf,sqrt,sqrtl#\n+*/\n+static void\n+@TYP@_power(char **args, intp *dimensions, intp *steps, void *func)\n+{\n+ register intp i, is1=steps[0],is2=steps[1];\n+ register intp os=steps[2], n=dimensions[0];\n+ char *i1=args[0], *i2=args[1], *op=args[2];\n+ @typ@ x, y, v;\n+\n+ if (is2 == 0) {\n+ y = *((@typ@ *)i2);\n+ if (y == 0.0) {\n+ for (i = 0; i < n; i++, i1+=is1, op+=os) {\n+ *((@typ@ *)op) = 1.0;\n+ }\n+ } else if (y == 1.0) {\n+ for (i = 0; i < n; i++, i1+=is1, op+=os) {\n+ x = *((@typ@ *)i1);\n+ *((@typ@ *)op) = x;\n+ }\n+ } else if (y == 2.0) {\n+ for (i = 0; i < n; i++, i1+=is1, op+=os) {\n+ @typ@ s = *((@typ@ *)i1);\n+ *((@typ@ *)op) = s*s;\n+ }\n+ } else if (y == 3.0) {\n+ for (i = 0; i < n; i++, i1+=is1, op+=os) {\n+ x = *((@typ@ *)i1);\n+ *((@typ@ *)op) = x*x*x;\n+ }\n+ } else if (y == 4.0) {\n+ for (i = 0; i < n; i++, i1+=is1, op+=os) {\n+ x = *((@typ@ *)i1);\n+ v = x*x;\n+ *((@typ@ *)op) = v*v;\n+ }\n+ } else if (y == 0.5) {\n+ for (i = 0; i < n; i++, i1+=is1, op+=os) {\n+ x = *((@typ@ *)i1);\n+ *((@typ@ *)op) = @sqrtfunc@(x);\n+ }\n+ } else {\n+ for (i = 0; i < n; i++, i1+=is1, op+=os) {\n+ x = *((@typ@ *)i1);\n+ *((@typ@ *)op) = @powfunc@(x, y);\n+ }\n+ }\n+ } else {\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\n#ifdef log1pf\n#undef log1pf\n#endif\n#ifdef logf\n#undef logf\n#endif\n#ifdef sqrtf\n#undef sqrtf\n#endif\nfloat log1pf(float);\nfloat logf(float);\nfloat sqrtf(float);\n#ifdef acoshf\n#undef acoshf\n#endif\nstatic float acoshf(float x)\n{\n\treturn 2*logf(sqrtf((x+1.0)/2)+sqrtf((x-1.0)/2));\n}\n\n#ifdef asinhf\n#undef asinhf\n#endif\nstatic float asinhf(float xx)\n{\n\tfloat x, d;\n\tint sign;\n\tif (xx < 0.0) {\n\t\tsign = -1;\n\t\tx = -xx;\n\t}\n\telse {\n\t\tsign = 1;\n\t\tx = xx;\n\t}\n\tif (x > 1e5) {\n\t\td = x;\n\t} else {\n\t\td = sqrtf(x*x + 1);\n\t}\n\treturn sign*log1pf(x*(1.0 + x/(d+1)));\n}\n\n#ifdef atanhf\n#undef atanhf\n#endif\nstatic float atanhf(float x)\n{\n\treturn 0.5*log1pf(2.0*x/(1.0-x));\n}\n#else\n#ifdef acoshf\n#undef acoshf\n#endif\nstatic float acoshf(float x)\n{\n return (float)acosh((double)(x));\n}\n\n#ifdef asinhf\n#undef asinhf\n#endif\nstatic float asinhf(float x)\n{\n return (float)asinh((double)(x));\n}\n\n#ifdef atanhf\n#undef atanhf\n#endif\nstatic float atanhf(float x)\n{\n return (float)atanh((double)(x));\n}\n#endif\n#endif\n\n\n#if !defined(HAVE_INVERSE_HYPERBOLIC_LONGDOUBLE)\n#ifdef HAVE_LONGDOUBLE_FUNCS\n#ifdef logl\n#undef logl\n#endif\n#ifdef sqrtl\n#undef sqrtl\n#endif\n#ifdef log1pl\n#undef log1pl\n#endif\nlongdouble logl(longdouble);\nlongdouble sqrtl(longdouble);\nlongdouble log1pl(longdouble);\n#ifdef acoshl\n#undef acoshl\n#endif\nstatic longdouble acoshl(longdouble x)\n{\n\treturn 2*logl(sqrtl((x+1.0)/2)+sqrtl((x-1.0)/2));\n}\n\n#ifdef asinhl\n#undef asinhl\n#endif\nstatic longdouble asinhl(longdouble xx)\n{\n\tlongdouble x, d;\n\tint sign;\n\tif (xx < 0.0) {\n\t\tsign = -1;\n\t\tx = -xx;\n\t}\n\telse {\n\t\tsign = 1;\n\t\tx = xx;\n\t}\n\tif (x > 1e17) {\n\t\td = x;\n\t} else {\n\t\td = sqrtl(x*x + 1);\n\t}\n\treturn sign*log1pl(x*(1.0 + x/(d+1)));\n}\n\n#ifdef atanhl\n#undef atanhl\n#endif\nstatic longdouble atanhl(longdouble x)\n{\n\treturn 0.5*log1pl(2.0*x/(1.0-x));\n}\n\n#else\n\n#ifdef acoshl\n#undef acoshl\n#endif\nstatic longdouble acoshl(longdouble x)\n{\n return (longdouble)acosh((double)(x));\n}\n\n#ifdef asinhl\n#undef asinhl\n#endif\nstatic longdouble asinhl(longdouble x)\n{\n return (longdouble)asinh((double)(x));\n}\n\n#ifdef atanhl\n#undef atanhl\n#endif\nstatic longdouble atanhl(longdouble x)\n{\n return (longdouble)atanh((double)(x));\n}\n\n#endif\n#endif\n\n\n#ifdef HAVE_HYPOT\n#if !defined(NeXT) && !defined(_MSC_VER)\nextern double hypot(double, double);\n#endif\n#else\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#ifdef @kind@@c@\n#undef @kind@@c@\n#endif\n@typ@ @kind@@c@(@typ@ x) {\n\treturn (@typ@) @kind@((double)x);\n}\n#endif\n/**end repeat**/\n\n/**begin repeat\n\n#kind=(atan2,hypot,pow,fmod)*2#\n#typ=longdouble*4, float*4#\n#c=l*4,f*4#\n#TYPE=LONGDOUBLE*4,FLOAT*4#\n*/\n#ifndef HAVE_@TYPE@_FUNCS\n#ifdef @kind@@c@\n#undef @kind@@c@\n#endif\n@typ@ @kind@@c@(@typ@ x, @typ@ y) {\n\treturn (@typ@) @kind@((double)x, (double) y);\n}\n#endif\n/**end repeat**/\n\n/**begin repeat\n#kind=modf*2#\n#typ=longdouble, float#\n#c=l,f#\n#TYPE=LONGDOUBLE, FLOAT#\n*/\n#ifndef HAVE_@TYPE@_FUNCS\n#ifdef modf@c@\n#undef modf@c@\n#endif\n@typ@ modf@c@(@typ@ x, @typ@ *iptr) {\n double nx, niptr, y;\n nx = (double) x;\n y = modf(nx, &niptr);\n *iptr = (@typ@) niptr;\n return (@typ@) y;\n}\n#endif\n/**end repeat**/\n\n\n\n#ifndef HAVE_LOG1P\ndouble log1p(double x)\n{\n\tdouble u = 1. + x;\n\tif (u == 1.0) {\n\t\treturn x;\n\t} else {\n\t\treturn log(u) * x / (u-1.);\n\t}\n}\n#endif\n\n#if !defined(HAVE_LOG1P) || !defined(HAVE_LONGDOUBLE_FUNCS)\n#ifdef log1pl\n#undef log1pl\n#endif\nlongdouble log1pl(longdouble x)\n{\n\tlongdouble u = 1. + x;\n\tif (u == 1.0) {\n\t\treturn x;\n\t} else {\n\t\treturn logl(u) * x / (u-1.);\n\t}\n}\n#endif\n\n#if !defined(HAVE_LOG1P) || !defined(HAVE_FLOAT_FUNCS)\n#ifdef log1pf\n#undef log1pf\n#endif\nfloat log1pf(float x)\n{\n\tfloat u = 1. + x;\n\tif (u == 1.0) {\n\t\treturn x;\n\t} else {\n\t\treturn logf(u) * x / (u-1.);\n\t}\n}\n#endif\n\n#ifndef HAVE_EXPM1\nstatic double expm1(double x)\n{\n\tdouble u = exp(x);\n\tif (u == 1.0) {\n\t\treturn x;\n\t} else if (u-1.0 == -1.0) {\n\t\treturn -1;\n\t} else {\n\t\treturn (u-1.0) * x/log(u);\n\t}\n}\n#endif\n\n#if !defined(HAVE_EXPM1) || !defined(HAVE_LONGDOUBLE_FUNCS)\n#ifdef expml1\n#undef expml1\n#endif\nstatic longdouble expm1l(longdouble x)\n{\n\tlongdouble u = expl(x);\n\tif (u == 1.0) {\n\t\treturn x;\n\t} else if (u-1.0 == -1.0) {\n\t\treturn -1;\n\t} else {\n\t\treturn (u-1.0) * x/logl(u);\n\t}\n}\n#endif\n\n#if !defined(HAVE_EXPM1) || !defined(HAVE_FLOAT_FUNCS)\n#ifdef expm1f\n#undef expm1f\n#endif\nstatic float expm1f(float x)\n{\n\tfloat u = expf(x);\n\tif (u == 1.0) {\n\t\treturn x;\n\t} else if (u-1.0 == -1.0) {\n\t\treturn -1;\n\t} else {\n\t\treturn (u-1.0) * x/logf(u);\n\t}\n}\n#endif\n\n\n\n\n/* Don't pass structures between functions (only pointers) because how\n structures are passed is compiler dependent and could cause\n segfaults if ufuncobject.c is compiled with a different compiler\n than an extension that makes use of the UFUNC API\n*/\n\n/**begin repeat\n\n#typ=float, double, longdouble#\n#c=f,,l#\n*/\n\n/* constants */\nstatic c@typ@ nc_1@c@ = {1., 0.};\nstatic c@typ@ nc_half@c@ = {0.5, 0.};\nstatic c@typ@ nc_i@c@ = {0., 1.};\nstatic c@typ@ nc_i2@c@ = {0., 0.5};\n/*\nstatic c@typ@ nc_mi@c@ = {0., -1.};\nstatic c@typ@ nc_pi2@c@ = {M_PI/2., 0.};\n*/\n\nstatic void\nnc_sum@c@(c@typ@ *a, c@typ@ *b, c@typ@ *r)\n{\n\tr->real = a->real + b->real;\n\tr->imag = a->imag + b->imag;\n\treturn;\n}\n\nstatic void\nnc_diff@c@(c@typ@ *a, c@typ@ *b, c@typ@ *r)\n{\n\tr->real = a->real - b->real;\n\tr->imag = a->imag - b->imag;\n\treturn;\n}\n\nstatic void\nnc_neg@c@(c@typ@ *a, c@typ@ *r)\n{\n\tr->real = -a->real;\n\tr->imag = -a->imag;\n\treturn;\n}\n\nstatic void\nnc_prod@c@(c@typ@ *a, c@typ@ *b, c@typ@ *r)\n{\n\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; ireal;\n xi = x->imag;\n y->real = xr*xr - xi*xi;\n y->imag = 2*xr*xi;\n }\n}\n/**end repeat**/\n\nstatic PyObject *\nPy_square(PyObject *o)\n{\n return PyNumber_Multiply(o, o);\n}\n\n/**begin repeat\n\n#TYP=BYTE,UBYTE,SHORT,USHORT,INT,UINT,LONG,ULONG,LONGLONG,ULONGLONG#\n#typ=char, ubyte, short, ushort, int, uint, long, ulong, longlong, ulonglong#\n#btyp=float*4, double*6#\n*/\nstatic void\n@TYP@_power(char **args, intp *dimensions, intp *steps, void *func)\n{\n\tregister intp i, is1=steps[0],is2=steps[1];\n\tregister intp os=steps[2], n=dimensions[0];\n\tchar *i1=args[0], *i2=args[1], *op=args[2];\n\t@btyp@ x, y, v;\n @typ@ z;\n\n\tfor(i=0; i, >=, <, <=, ==, !=, &&, ||, &, |, ^#\n**/\nstatic void\nBOOL_@kind@(char **args, intp *dimensions, intp *steps, void *func)\n{\n\tregister intp i;\n\tintp is1=steps[0],is2=steps[1],os=steps[2], n=dimensions[0];\n\tchar *i1=args[0], *i2=args[1], *op=args[2];\n\tBool in1, in2;\n\tfor(i=0; i*13, >=*13, <*13, <=*13#\n#typ=(byte, ubyte, short, ushort, int, uint, long, ulong, longlong, ulonglong, float, double, longdouble)*4#\n#kind= greater*13, greater_equal*13, less*13, less_equal*13#\n*/\n\nstatic void\n@TYPE@_@kind@(char **args, intp *dimensions, intp *steps, void *func)\n{\n\tregister intp i;\n\tintp is1=steps[0],is2=steps[1],os=steps[2], n=dimensions[0];\n\tchar *i1=args[0], *i2=args[1], *op=args[2];\n\tfor(i=0; i*3, >=*3, <*3, <=*3#\n#typ=(cfloat, cdouble, clongdouble)*4#\n#kind= greater*3, greater_equal*3, less*3, less_equal*3#\n*/\n\nstatic void\n@TYPE@_@kind@(char **args, intp *dimensions, intp *steps, void *func)\n{\n\tregister intp i;\n\tintp is1=steps[0],is2=steps[1],os=steps[2], n=dimensions[0];\n\tchar *i1=args[0], *i2=args[1], *op=args[2];\n\tfor(i=0; ireal == ((@typ@ *)i2)->real)\n\t\t\t*((Bool *)op)=((@typ@ *)i1)->imag @OP@ \\\n\t\t\t\t((@typ@ *)i2)->imag;\n\t\telse\n\t\t\t*((Bool *)op)=((@typ@ *)i1)->real @OP@ \\\n\t\t\t\t((@typ@ *)i2)->real;\n\t}\n}\n/**end repeat**/\n\n\n/**begin repeat\n#TYPE=(BYTE,UBYTE,SHORT,USHORT,INT,UINT,LONG,ULONG,LONGLONG,ULONGLONG,FLOAT,DOUBLE,LONGDOUBLE)*4#\n#typ=(byte, ubyte, short, ushort, int, uint, long, ulong, longlong, ulonglong, float, double, longdouble)*4#\n#OP= ==*13, !=*13, &&*13, ||*13#\n#kind=equal*13, not_equal*13, logical_and*13, logical_or*13#\n*/\nstatic void\n@TYPE@_@kind@(char **args, intp *dimensions, intp *steps, void *func)\n{\n\tregister intp i;\n\tintp is1=steps[0],is2=steps[1],os=steps[2], n=dimensions[0];\n\tchar *i1=args[0], *i2=args[1], *op=args[2];\n\tfor(i=0; i 0 ? 1 : ((x) < 0 ? -1 : 0))\n#define _SIGN2(x) ((x) == 0 ? 0 : 1)\n#define _SIGNC(x) (((x).real > 0) ? 1 : ((x).real < 0 ? -1 : ((x).imag > 0 ? 1 : ((x).imag < 0) ? -1 : 0)))\n/**begin repeat\n#TYPE=BYTE,SHORT,INT,LONG,LONGLONG,FLOAT,DOUBLE,LONGDOUBLE,UBYTE,USHORT,UINT,ULONG,ULONGLONG#\n#typ=byte,short,int,long,longlong,float,double,longdouble,ubyte,ushort,uint,ulong,ulonglong#\n#func=_SIGN1*8,_SIGN2*5#\n */\nstatic void\n@TYPE@_sign(char **args, intp *dimensions, intp *steps, void *func)\n{\n\tregister intp i;\n\tintp is1=steps[0],os=steps[1], n=dimensions[0];\n\tchar *i1=args[0], *op=args[1];\n @typ@ t1;\n\tfor(i=0; ireal ||\t\\\n\t\t\t\t ((@typ@ *)i1)->imag);\n\t}\n}\n/**end repeat**/\n\n\n\n\n/**begin repeat\n#TYPE=BYTE,SHORT,INT,LONG,LONGLONG#\n#typ=byte, short, int, long, longlong#\n#ftyp=float*2,double*2,longdouble*1#\n#c=f*2,,,l*1#\n*/\nstatic void\n@TYPE@_remainder(char **args, intp *dimensions, intp *steps, void *func)\n{\n\tregister intp i;\n\tintp is1=steps[0],is2=steps[1],os=steps[2], n=dimensions[0];\n\tchar *i1=args[0], *i2=args[1], *op=args[2];\n\tregister @typ@ ix,iy, tmp;\n\tfor(i=0; i 0) == (iy > 0)) {\n\t\t\t*((@typ@ *)op) = ix % iy;\n\t\t}\n\t\telse { /* handle mixed case the way Python does */\n\t\t\ttmp = ix % iy;\n\t\t\tif (tmp) tmp += iy;\n\t\t\t*((@typ@ *)op)= tmp;\n\t\t}\n\t}\n}\n/**end repeat**/\n\n/**begin repeat\n#TYPE=UBYTE,USHORT,UINT,ULONG,ULONGLONG#\n#typ=ubyte, ushort, uint, ulong, ulonglong#\n*/\nstatic void\n@TYPE@_remainder(char **args, intp *dimensions, intp *steps, void *func)\n{\n\tregister intp i;\n\tintp is1=steps[0],is2=steps[1],os=steps[2], n=dimensions[0];\n\tchar *i1=args[0], *i2=args[1], *op=args[2];\n\tregister @typ@ ix,iy;\n\tfor(i=0; i>*10#\n#kind=bitwise_and*10, bitwise_or*10, bitwise_xor*10, left_shift*10, right_shift*10#\n\n*/\nstatic void\n@TYPE@_@kind@(char **args, intp *dimensions, intp *steps, void *func)\n{\n\tregister intp i;\n\tintp is1=steps[0],is2=steps[1],os=steps[2], n=dimensions[0];\n\tregister char *i1=args[0], *i2=args[1], *op=args[2];\n\tif (is1 == 0) {\n\t\tregister @typ@ t1 = *((@typ@ *)i1);\n\t\tfor (i=0; ireal || ((@typ@ *)i1)->imag;\n\t\tp2 = ((@typ@ *)i2)->real || ((@typ@ *)i2)->imag;\n\t\t*((Bool *)op)= (p1 || p2) && !(p1 && p2);\n\t}\n}\n/**end repeat**/\n\n\n\n/**begin repeat\n\n#TYPE=(BOOL,BYTE,UBYTE,SHORT,USHORT,INT,UINT,LONG,ULONG,LONGLONG,ULONGLONG,FLOAT,DOUBLE,LONGDOUBLE)*2#\n#OP= >*14, <*14#\n#typ=(Bool, byte, ubyte, short, ushort, int, uint, long, ulong, longlong, ulonglong, float, double, longdouble)*2#\n#kind= maximum*14, minimum*14#\n*/\nstatic void\n@TYPE@_@kind@(char **args, intp *dimensions, intp *steps, void *func)\n{\n\tregister intp i;\n\tintp is1=steps[0],is2=steps[1],os=steps[2], n=dimensions[0];\n\tchar *i1=args[0], *i2=args[1], *op=args[2];\n\tfor(i=0; i*3, <*3#\n#typ=(cfloat, cdouble, clongdouble)*2#\n#kind= maximum*3, minimum*3#\n*/\nstatic void\n@TYPE@_@kind@(char **args, intp *dimensions, intp *steps, void *func)\n{\n\tregister intp i;\n\tintp is1=steps[0],is2=steps[1],os=steps[2], n=dimensions[0];\n\tchar *i1=args[0], *i2=args[1], *op=args[2];\n @typ@ *i1c, *i2c;\n\tfor(i=0; ireal @OP@ i2c->real) || \\\n ((i1c->real==i2c->real) && (i1c->imag @OP@ i2c->imag)))\n 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\n#ifdef log1pf\n#undef log1pf\n#endif\n#ifdef logf\n#undef logf\n#endif\n#ifdef sqrtf\n#undef sqrtf\n#endif\nfloat log1pf(float);\nfloat logf(float);\nfloat sqrtf(float);\n#ifdef acoshf\n#undef acoshf\n#endif\nstatic float acoshf(float x)\n{\n\treturn 2*logf(sqrtf((x+1.0)/2)+sqrtf((x-1.0)/2));\n}\n\n#ifdef asinhf\n#undef asinhf\n#endif\nstatic float asinhf(float xx)\n{\n\tfloat x, d;\n\tint sign;\n\tif (xx < 0.0) {\n\t\tsign = -1;\n\t\tx = -xx;\n\t}\n\telse {\n\t\tsign = 1;\n\t\tx = xx;\n\t}\n\tif (x > 1e5) {\n\t\td = x;\n\t} else {\n\t\td = sqrtf(x*x + 1);\n\t}\n\treturn sign*log1pf(x*(1.0 + x/(d+1)));\n}\n\n#ifdef atanhf\n#undef atanhf\n#endif\nstatic float atanhf(float x)\n{\n\treturn 0.5*log1pf(2.0*x/(1.0-x));\n}\n#else\n#ifdef acoshf\n#undef acoshf\n#endif\nstatic float acoshf(float x)\n{\n return (float)acosh((double)(x));\n}\n\n#ifdef asinhf\n#undef asinhf\n#endif\nstatic float asinhf(float x)\n{\n return (float)asinh((double)(x));\n}\n\n#ifdef atanhf\n#undef atanhf\n#endif\nstatic float atanhf(float x)\n{\n return (float)atanh((double)(x));\n}\n#endif\n#endif\n\n\n#if !defined(HAVE_INVERSE_HYPERBOLIC_LONGDOUBLE)\n#ifdef HAVE_LONGDOUBLE_FUNCS\n#ifdef logl\n#undef logl\n#endif\n#ifdef sqrtl\n#undef sqrtl\n#endif\n#ifdef log1pl\n#undef log1pl\n#endif\nlongdouble logl(longdouble);\nlongdouble sqrtl(longdouble);\nlongdouble log1pl(longdouble);\n#ifdef acoshl\n#undef acoshl\n#endif\nstatic longdouble acoshl(longdouble x)\n{\n\treturn 2*logl(sqrtl((x+1.0)/2)+sqrtl((x-1.0)/2));\n}\n\n#ifdef asinhl\n#undef asinhl\n#endif\nstatic longdouble asinhl(longdouble xx)\n{\n\tlongdouble x, d;\n\tint sign;\n\tif (xx < 0.0) {\n\t\tsign = -1;\n\t\tx = -xx;\n\t}\n\telse {\n\t\tsign = 1;\n\t\tx = xx;\n\t}\n\tif (x > 1e17) {\n\t\td = x;\n\t} else {\n\t\td = sqrtl(x*x + 1);\n\t}\n\treturn sign*log1pl(x*(1.0 + x/(d+1)));\n}\n\n#ifdef atanhl\n#undef atanhl\n#endif\nstatic longdouble atanhl(longdouble x)\n{\n\treturn 0.5*log1pl(2.0*x/(1.0-x));\n}\n\n#else\n\n#ifdef acoshl\n#undef acoshl\n#endif\nstatic longdouble acoshl(longdouble x)\n{\n return (longdouble)acosh((double)(x));\n}\n\n#ifdef asinhl\n#undef asinhl\n#endif\nstatic longdouble asinhl(longdouble x)\n{\n return (longdouble)asinh((double)(x));\n}\n\n#ifdef atanhl\n#undef atanhl\n#endif\nstatic longdouble atanhl(longdouble x)\n{\n return (longdouble)atanh((double)(x));\n}\n\n#endif\n#endif\n\n\n#ifdef HAVE_HYPOT\n#if !defined(NeXT) && !defined(_MSC_VER)\nextern double hypot(double, double);\n#endif\n#else\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#ifdef @kind@@c@\n#undef @kind@@c@\n#endif\n@typ@ @kind@@c@(@typ@ x) {\n\treturn (@typ@) @kind@((double)x);\n}\n#endif\n/**end repeat**/\n\n/**begin repeat\n\n#kind=(atan2,hypot,pow,fmod)*2#\n#typ=longdouble*4, float*4#\n#c=l*4,f*4#\n#TYPE=LONGDOUBLE*4,FLOAT*4#\n*/\n#ifndef HAVE_@TYPE@_FUNCS\n#ifdef @kind@@c@\n#undef @kind@@c@\n#endif\n@typ@ @kind@@c@(@typ@ x, @typ@ y) {\n\treturn (@typ@) @kind@((double)x, (double) y);\n}\n#endif\n/**end repeat**/\n\n/**begin repeat\n#kind=modf*2#\n#typ=longdouble, float#\n#c=l,f#\n#TYPE=LONGDOUBLE, FLOAT#\n*/\n#ifndef HAVE_@TYPE@_FUNCS\n#ifdef modf@c@\n#undef modf@c@\n#endif\n@typ@ modf@c@(@typ@ x, @typ@ *iptr) {\n double nx, niptr, y;\n nx = (double) x;\n y = modf(nx, &niptr);\n *iptr = (@typ@) niptr;\n return (@typ@) y;\n}\n#endif\n/**end repeat**/\n\n\n\n#ifndef HAVE_LOG1P\ndouble log1p(double x)\n{\n\tdouble u = 1. + x;\n\tif (u == 1.0) {\n\t\treturn x;\n\t} else {\n\t\treturn log(u) * x / (u-1.);\n\t}\n}\n#endif\n\n#if !defined(HAVE_LOG1P) || !defined(HAVE_LONGDOUBLE_FUNCS)\n#ifdef log1pl\n#undef log1pl\n#endif\nlongdouble log1pl(longdouble x)\n{\n\tlongdouble u = 1. + x;\n\tif (u == 1.0) {\n\t\treturn x;\n\t} else {\n\t\treturn logl(u) * x / (u-1.);\n\t}\n}\n#endif\n\n#if !defined(HAVE_LOG1P) || !defined(HAVE_FLOAT_FUNCS)\n#ifdef log1pf\n#undef log1pf\n#endif\nfloat log1pf(float x)\n{\n\tfloat u = 1. + x;\n\tif (u == 1.0) {\n\t\treturn x;\n\t} else {\n\t\treturn logf(u) * x / (u-1.);\n\t}\n}\n#endif\n\n#ifndef HAVE_EXPM1\nstatic double expm1(double x)\n{\n\tdouble u = exp(x);\n\tif (u == 1.0) {\n\t\treturn x;\n\t} else if (u-1.0 == -1.0) {\n\t\treturn -1;\n\t} else {\n\t\treturn (u-1.0) * x/log(u);\n\t}\n}\n#endif\n\n#if !defined(HAVE_EXPM1) || !defined(HAVE_LONGDOUBLE_FUNCS)\n#ifdef expml1\n#undef expml1\n#endif\nstatic longdouble expm1l(longdouble x)\n{\n\tlongdouble u = expl(x);\n\tif (u == 1.0) {\n\t\treturn x;\n\t} else if (u-1.0 == -1.0) {\n\t\treturn -1;\n\t} else {\n\t\treturn (u-1.0) * x/logl(u);\n\t}\n}\n#endif\n\n#if !defined(HAVE_EXPM1) || !defined(HAVE_FLOAT_FUNCS)\n#ifdef expm1f\n#undef expm1f\n#endif\nstatic float expm1f(float x)\n{\n\tfloat u = expf(x);\n\tif (u == 1.0) {\n\t\treturn x;\n\t} else if (u-1.0 == -1.0) {\n\t\treturn -1;\n\t} else {\n\t\treturn (u-1.0) * x/logf(u);\n\t}\n}\n#endif\n\n\n\n\n/* Don't pass structures between functions (only pointers) because how\n structures are passed is compiler dependent and could cause\n segfaults if ufuncobject.c is compiled with a different compiler\n than an extension that makes use of the UFUNC API\n*/\n\n/**begin repeat\n\n#typ=float, double, longdouble#\n#c=f,,l#\n*/\n\n/* constants */\nstatic c@typ@ nc_1@c@ = {1., 0.};\nstatic c@typ@ nc_half@c@ = {0.5, 0.};\nstatic c@typ@ nc_i@c@ = {0., 1.};\nstatic c@typ@ nc_i2@c@ = {0., 0.5};\n/*\nstatic c@typ@ nc_mi@c@ = {0., -1.};\nstatic c@typ@ nc_pi2@c@ = {M_PI/2., 0.};\n*/\n\nstatic void\nnc_sum@c@(c@typ@ *a, c@typ@ *b, c@typ@ *r)\n{\n\tr->real = a->real + b->real;\n\tr->imag = a->imag + b->imag;\n\treturn;\n}\n\nstatic void\nnc_diff@c@(c@typ@ *a, c@typ@ *b, c@typ@ *r)\n{\n\tr->real = a->real - b->real;\n\tr->imag = a->imag - b->imag;\n\treturn;\n}\n\nstatic void\nnc_neg@c@(c@typ@ *a, c@typ@ *r)\n{\n\tr->real = -a->real;\n\tr->imag = -a->imag;\n\treturn;\n}\n\nstatic void\nnc_prod@c@(c@typ@ *a, c@typ@ *b, c@typ@ *r)\n{\n\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=bitwise_and*10, bitwise_or*10, bitwise_xor*10, left_shift*10, right_shift*10#\n\n*/\nstatic void\n@TYPE@_@kind@(char **args, intp *dimensions, intp *steps, void *func)\n{\n\tregister intp i;\n\tintp is1=steps[0],is2=steps[1],os=steps[2], n=dimensions[0];\n\tregister char *i1=args[0], *i2=args[1], *op=args[2];\n\tif (is1 == 0) {\n\t\tregister @typ@ t1 = *((@typ@ *)i1);\n\t\tfor (i=0; ireal || ((@typ@ *)i1)->imag;\n\t\tp2 = ((@typ@ *)i2)->real || ((@typ@ *)i2)->imag;\n\t\t*((Bool *)op)= (p1 || p2) && !(p1 && p2);\n\t}\n}\n/**end repeat**/\n\n\n\n/**begin repeat\n\n#TYPE=(BOOL,BYTE,UBYTE,SHORT,USHORT,INT,UINT,LONG,ULONG,LONGLONG,ULONGLONG,FLOAT,DOUBLE,LONGDOUBLE)*2#\n#OP= >*14, <*14#\n#typ=(Bool, byte, ubyte, short, ushort, int, uint, long, ulong, longlong, ulonglong, float, double, longdouble)*2#\n#kind= maximum*14, minimum*14#\n*/\nstatic void\n@TYPE@_@kind@(char **args, intp *dimensions, intp *steps, void *func)\n{\n\tregister intp i;\n\tintp is1=steps[0],is2=steps[1],os=steps[2], n=dimensions[0];\n\tchar *i1=args[0], *i2=args[1], *op=args[2];\n\tfor(i=0; i*3, <*3#\n#typ=(cfloat, cdouble, clongdouble)*2#\n#kind= maximum*3, minimum*3#\n*/\nstatic void\n@TYPE@_@kind@(char **args, intp *dimensions, intp *steps, void *func)\n{\n\tregister intp i;\n\tintp is1=steps[0],is2=steps[1],os=steps[2], n=dimensions[0];\n\tchar *i1=args[0], *i2=args[1], *op=args[2];\n @typ@ *i1c, *i2c;\n\tfor(i=0; ireal @OP@ i2c->real) || \\\n ((i1c->real==i2c->real) && (i1c->imag @OP@ i2c->imag)))\n 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;", + " xi = x->imag;", + " y->real = xr*xr - xi*xi;", + " y->imag = 2*xr*xi;", + " }", + "}", + "/**end repeat**/", + "", + "static PyObject *", + "Py_square(PyObject *o)", + "{", + " return PyNumber_Multiply(o, o);", + "}", + "/**begin repeat", + "#TYP=FLOAT,DOUBLE,LONGDOUBLE#", + "#typ=float,double,longdouble#", + "#powfunc=powf,pow,powl#", + "#sqrtfunc=sqrtf,sqrt,sqrtl#", + "*/", + "static void", + "@TYP@_power(char **args, intp *dimensions, intp *steps, void *func)", + "{", + " register intp i, is1=steps[0],is2=steps[1];", + " register intp os=steps[2], n=dimensions[0];", + " char *i1=args[0], *i2=args[1], *op=args[2];", + " @typ@ x, y, v;", + "", + " if (is2 == 0) {", + " y = *((@typ@ *)i2);", + " if (y == 0.0) {", + " for (i = 0; i < n; i++, i1+=is1, op+=os) {", + " *((@typ@ *)op) = 1.0;", + " }", + " } else if (y == 1.0) {", + " for (i = 0; i < n; i++, i1+=is1, op+=os) {", + " x = *((@typ@ *)i1);", + " *((@typ@ *)op) = x;", + " }", + " } else if (y == 2.0) {", + " for (i = 0; i < n; i++, i1+=is1, op+=os) {", + " @typ@ s = *((@typ@ *)i1);", + " *((@typ@ *)op) = s*s;", + " }", + " } else if (y == 3.0) {", + " for (i = 0; i < n; i++, i1+=is1, op+=os) {", + " x = *((@typ@ *)i1);", + " *((@typ@ *)op) = x*x*x;", + " }", + " } else if (y == 4.0) {", + " for (i = 0; i < n; i++, i1+=is1, op+=os) {", + " x = *((@typ@ *)i1);", + " v = x*x;", + " *((@typ@ *)op) = v*v;", + " }", + " } else if (y == 0.5) {", + " for (i = 0; i < n; i++, i1+=is1, op+=os) {", + " x = *((@typ@ *)i1);", + " *((@typ@ *)op) = @sqrtfunc@(x);", + " }", + " } else {", + " for (i = 0; i < n; i++, i1+=is1, op+=os) {", + " x = *((@typ@ *)i1);", + " *((@typ@ *)op) = @powfunc@(x, y);", + " }", + " }", + " } else {", + " for(i=0; i\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, \"dtype\");\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 void *\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 (void *)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, \"dtype\",\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)) == 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\tif (mps[i]->ob_type != subtype) {\n\t\t\tprior2 = PyArray_GetPriority((PyObject *)(mps[i]), 0.0);\n\t\t\tif (prior2 > prior1) {\n\t\t\t\tprior1 = prior2;\n\t\t\t\tsubtype = mps[i]->ob_type;\n\t\t\t\tret = mps[i];\n\t\t\t}\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; idescr->elsize;\n\tbyteorder = arr->descr->byteorder;\n\tptr = arr->data;\n\tif (elsize > 1 && \\\n\t (byteorder == PyArray_LITTLE ||\t\\\n\t (byteorder == PyArray_NATIVE &&\n\t PyArray_ISNBO(PyArray_LITTLE))))\n\t\tptr += elsize-1;\n\t\n\treturn ((*ptr & bitmask) != 0);\t\n}\n\n\n/*OBJECT_API*/\nstatic char\nPyArray_ScalarKind(int typenum, PyArrayObject **arr) \n{\n\tif (PyTypeNum_ISSIGNED(typenum)) {\n\t\tif (arr && _signbit_set(*arr)) return UFUNC_INTNEG_SCALAR;\n\t\telse return UFUNC_INTPOS_SCALAR;\n\t}\n\tif (PyTypeNum_ISFLOAT(typenum)) return UFUNC_FLOAT_SCALAR;\n\tif (PyTypeNum_ISUNSIGNED(typenum)) return UFUNC_INTPOS_SCALAR;\n\tif (PyTypeNum_ISCOMPLEX(typenum)) return UFUNC_COMPLEX_SCALAR;\n\tif (PyTypeNum_ISBOOL(typenum)) return UFUNC_BOOL_SCALAR;\n\n\treturn UFUNC_OBJECT_SCALAR;\n}\n\n\n/*OBJECT_API*/\nstatic int \nPyArray_CanCoerceScalar(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\n/* This needs to change to allow scalars of a different \"kind\" to alter the input type\n */\n\n/*OBJECT_API*/\nstatic PyArrayObject **\nPyArray_ConvertToCommonType(PyObject *op, int *retn)\n{\n\tint i, n, allscalars=0; \n\tPyArrayObject **mps=NULL;\n\tPyObject *otmp;\n\tPyArray_Descr *intype=NULL, *stype=NULL;\n\tPyArray_Descr *newtype=NULL;\n\tchar scalarkind;\n\n\t\n\t*retn = n = PySequence_Length(op);\n\tif (PyErr_Occurred()) {*retn = 0; return NULL;}\n\t\n\tmps = (PyArrayObject **)PyDataMem_NEW(n*sizeof(PyArrayObject *));\n\tif (mps == NULL) {\n\t\t*retn = 0;\n\t\treturn (void*)PyErr_NoMemory();\n\t}\n\t\n\tfor(i=0; itype_num, NULL);\n\t\t\tif (intype && !PyArray_CanCoerceScalar(newtype->type_num,\n\t\t\t\t\t\t\t intype->type_num, \n\t\t\t\t\t\t\t scalarkind)) {\n\t\t\t\tPy_XDECREF(intype);\n\t\t\t\tintype = stype;\n\t\t\t}\n\t\t\tmps[i] = (PyArrayObject *)Py_None;\n\t\t\tPy_INCREF(Py_None);\n\t\t}\n\t\tPy_XDECREF(otmp);\n\t}\n\tif (intype==NULL) { /* all scalars */\n\t\tallscalars = 1;\n\t\tintype = stype;\n\t\tPy_INCREF(intype);\n\t\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, NULL);\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 Make a new empty array, of the passed size, of a type that takes the\n priority of ap1 and ap2 into account.\n */\nstatic PyArrayObject *\nnew_array_for_sum(PyArrayObject *ap1, PyArrayObject *ap2,\n\t\t int nd, intp dimensions[], int typenum)\n{\n\tPyArrayObject *ret;\n\tPyTypeObject *subtype;\n\tdouble prior1, prior2;\n\t/* Need to choose an output array that can hold a sum \n\t -- use priority to determine which subtype.\n\t */\n\tif (ap2->ob_type != ap1->ob_type) {\n\t\tprior2 = PyArray_GetPriority((PyObject *)ap2, 0.0);\n\t\tprior1 = PyArray_GetPriority((PyObject *)ap1, 0.0);\n\n\t\tsubtype = (prior2 > prior1 ? ap2->ob_type : ap1->ob_type);\n\t} else {\n\t\tprior1 = prior2 = 0.0;\n\t\tsubtype = ap1->ob_type;\n\t}\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\treturn ret;\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\tPyArrayIterObject *it1, *it2;\n\tintp i, j, l;\n\tint typenum, nd;\n\tintp is1, is2, os;\n\tchar *op;\n\tintp dimensions[MAX_DIMS];\n\tPyArray_DotFunc *dot;\n\tPyArray_Descr *typec;\n\t\n\ttypenum = PyArray_ObjectType(op1, 0); \n\ttypenum = PyArray_ObjectType(op2, typenum);\n\n\ttypec = PyArray_DescrFromType(typenum);\n\tPy_INCREF(typec);\n\tap1 = (PyArrayObject *)PyArray_FromAny(op1, typec, 0, 0, \n\t\t\t\t\t BEHAVED_FLAGS, NULL);\n\tif (ap1 == NULL) {Py_DECREF(typec); return NULL;}\n\tap2 = (PyArrayObject *)PyArray_FromAny(op2, typec, 0, 0,\n\t\t\t\t\t BEHAVED_FLAGS, NULL);\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\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\tret = new_array_for_sum(ap1, ap2, nd, dimensions, typenum);\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\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\tit1 = (PyArrayIterObject *)\\\n\t\tPyArray_IterAllButAxis((PyObject *)ap1, ap1->nd-1);\n\tit2 = (PyArrayIterObject *)\\\n\t\tPyArray_IterAllButAxis((PyObject *)ap2, ap2->nd-1);\n\n\twhile(1) {\n\t\twhile(it2->index < it2->size) {\n\t\t\tdot(it1->dataptr, is1, it2->dataptr, is2, op, l, ret);\n\t\t\top += os;\n\t\t\tPyArray_ITER_NEXT(it2);\n\t\t}\n\t\tPyArray_ITER_NEXT(it1);\n\t\tif (it1->index >= it1->size) break;\n\t\tPyArray_ITER_RESET(it2);\n\t}\n\tPy_DECREF(it1);\n\tPy_DECREF(it2);\n\n\tif (PyErr_Occurred()) goto fail;\n\t\t\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/* just like inner product but does the swapaxes stuff on the fly */\n/*MULTIARRAY_API\n Numeric.matrixproduct(a,v)\n*/\nstatic PyObject *\nPyArray_MatrixProduct(PyObject *op1, PyObject *op2) \n{\n\tPyArrayObject *ap1, *ap2, *ret=NULL;\n\tPyArrayIterObject *it1, *it2;\n\tintp i, j, l;\n\tint typenum, nd;\n\tintp is1, is2, os;\n\tchar *op;\n\tintp dimensions[MAX_DIMS];\n\tPyArray_DotFunc *dot;\n\tintp matchDim;\n\tPyArray_Descr *typec;\n\n\ttypenum = PyArray_ObjectType(op1, 0); \n\ttypenum = PyArray_ObjectType(op2, typenum);\t\n\t\n\ttypec = PyArray_DescrFromType(typenum);\n\tPy_INCREF(typec);\n\tap1 = (PyArrayObject *)PyArray_FromAny(op1, typec, 0, 0, \n\t\t\t\t\t BEHAVED_FLAGS, NULL);\n\tif (ap1 == NULL) {Py_DECREF(typec); return NULL;}\n\tap2 = (PyArrayObject *)PyArray_FromAny(op2, typec, 0, 0,\n\t\t\t\t\t BEHAVED_FLAGS, NULL);\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\tif (ap2->nd > 1) {\n\t\tmatchDim = ap2->nd - 2;\n\t}\n\telse {\n\t\tmatchDim = 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\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; istrides[ap1->nd-1]; is2 = ap2->strides[matchDim];\n\n /* Choose which subtype to return */\n\tret = new_array_for_sum(ap1, ap2, nd, dimensions, typenum);\n\tif (ret == NULL) goto fail;\n\n\t/* Ensure that multiarray.dot([],[]) -> 0 */\n\tmemset(PyArray_DATA(ret), 0, PyArray_ITEMSIZE(ret));\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\top = ret->data; os = ret->descr->elsize;\n\n\tit1 = (PyArrayIterObject *)\\\n\t\tPyArray_IterAllButAxis((PyObject *)ap1, ap1->nd-1);\n\tit2 = (PyArrayIterObject *)\\\n\t\tPyArray_IterAllButAxis((PyObject *)ap2, matchDim);\n\n\twhile(1) {\n\t\twhile(it2->index < it2->size) {\n\t\t\tdot(it1->dataptr, is1, it2->dataptr, is2, op, l, ret);\n\t\t\top += os;\n\t\t\tPyArray_ITER_NEXT(it2);\n\t\t}\n\t\tPyArray_ITER_NEXT(it1);\n\t\tif (it1->index >= it1->size) break;\n\t\tPyArray_ITER_RESET(it2);\n\t}\n\tPy_DECREF(it1);\n\tPy_DECREF(it2);\n\tif (PyErr_Occurred()) goto fail; /* only for OBJECT arrays */\n\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/*MULTIARRAY_API\n Fast Copy and Transpose\n*/\nstatic PyObject *\nPyArray_CopyAndTranspose(PyObject *op) \n{\n\tPyObject *ret, *arr;\n\tint nd;\n\tintp dims[2];\n\tintp i,j;\n\tint elsize, str2;\n\tchar *iptr;\n\tchar *optr;\n\n\t/* make sure it is well-behaved */\n\tarr = PyArray_FromAny(op, NULL, 0, 0, CARRAY_FLAGS, NULL);\n\tnd = PyArray_NDIM(arr);\n\tif (nd == 1) { /* we will give in to old behavior */\n\t\tret = PyArray_Copy((PyArrayObject *)arr);\n\t\tPy_DECREF(arr);\n\t\treturn ret;\t\t\n\t}\n\telse if (nd != 2) {\n\t\tPy_DECREF(arr);\n\t\tPyErr_SetString(PyExc_ValueError, \n\t\t\t\t\"only 2-d arrays are allowed\");\n\t\treturn NULL;\n\t}\n\n\t/* Now construct output array */\n\tdims[0] = PyArray_DIM(arr,1);\n\tdims[1] = PyArray_DIM(arr,0);\n\telsize = PyArray_ITEMSIZE(arr);\n\t\n\tPy_INCREF(PyArray_DESCR(arr));\n\tret = PyArray_NewFromDescr(arr->ob_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\tret = new_array_for_sum(ap1, ap2, 1, &length, typenum);\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 Py_INCREF(self->descr); \n\tvalues = (PyArrayObject *)PyArray_FromAny(values0, self->descr, 0, 0, \n\t\t\t\t\t\t DEFAULT_FLAGS | FORCECAST, NULL); \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, NULL);\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\tif (type->type_num == PyArray_UNICODE)\n\t\t\ttype->elsize = itemsize << 2; \n\t\telse\n\t\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\tif (type->hasobject) newdescr->hasobject = 1;\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 int hasobject=0;\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; ihasobject)\n hasobject = 1;\n\t\ttup = PyTuple_New(2);\n\t\tPyTuple_SET_ITEM(tup, 0, (PyObject *)conv);\n\t\tPyTuple_SET_ITEM(tup, 1, PyInt_FromLong((long) totalsize));\n\t\ttotalsize += conv->elsize;\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 new->hasobject=hasobject;\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 int hasobject=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; ihasobject)\n\t\t\thasobject=1;\t\t\t\n\t\tPyTuple_SET_ITEM(tup, 0, (PyObject *)conv);\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\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\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 new->hasobject=hasobject;\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 int hasobject=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\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\tPyTuple_SET_ITEM(tup, 1, PyInt_FromLong(totalsize));\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\tif (PyDict_GetItem(fields, name) != NULL) {\n\t\t\tPyErr_SetString(PyExc_ValueError,\n\t\t\t\t\t\"name already used as a name or title\");\n\t\t\tret = PY_FAIL;\n\t\t}\n\t\tPyDict_SetItem(fields, name, tup);\n\t\tPy_DECREF(name);\n\t\tif (len == 3) {\n\t\t\tif (PyDict_GetItem(fields, item) != NULL) {\n\t\t\t\tPyErr_SetString(PyExc_ValueError, \n\t\t\t\t\t\t\"title already used as a name or \" \\\n\t\t\t\t\t\t\" title.\");\n\t\t\t\tret=PY_FAIL;\n\t\t\t}\n\t\t\telse {\n\t\t\t\tPyDict_SetItem(fields, item, tup);\n\t\t\t}\n\t\t}\n\t\tPy_DECREF(tup);\n\t\tif ((ret == PY_FAIL) || (newdescr->elsize == 0)) goto fail;\n if (!hasobject && newdescr->hasobject)\n hasobject = 1;\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 new->hasobject=hasobject;\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 == '|' || (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\tint i;\n\t\t\telsize = atoi(type+1);\n\t\t\t/* check for commas present */\n\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\nstatic PyObject *\n_prepend_ones(PyArrayObject *arr, int nd, int ndmin)\n{\n\tintp newdims[MAX_DIMS];\n\tintp newstrides[MAX_DIMS];\n\tint i,k,num;\n\tPyObject *ret;\n\n\tnum = ndmin-nd;\n\tfor (i=0; idescr->elsize;\n\t}\n\tfor (i=num;idimensions[k];\n\t\tnewstrides[i] = arr->strides[k];\n\t}\n\tPy_INCREF(arr->descr);\n\tret = PyArray_NewFromDescr(arr->ob_type, arr->descr, ndmin,\n\t\t\t\t newdims, newstrides, arr->data, arr->flags,\n\t\t\t\t (PyObject *)arr);\n\t/* steals a reference to arr --- so don't increment\n\t here */\n\tPyArray_BASE(ret) = (PyObject *)arr;\n\treturn ret;\n}\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,ndmin=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\"\\\n\t\"The ndmin argument specifies how many dimensions the returned\\n\"\\\n\t\"array should have as a minimum. 1's will be pre-pended to the\\n\"\\\n\t\"shape as needed to meet this requirement.\";\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\t\t\t \"ndmin\", NULL};\n Bool subok=FALSE;\n\tBool copy=TRUE;\n\tint ndmin=0, nd;\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&i\", 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\t\t\t\t&ndmin)) \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\tret = op;\n\t\t\t\tgoto finish;\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\tgoto finish;\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\tret = op;\n\t\t\t\tgoto finish;\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\tgoto finish;\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_CheckFromAny(op, type, 0, 0, flags, NULL)) == NULL) \n\t\treturn NULL;\n\n finish:\n\n\tif ((nd=PyArray_NDIM(ret)) >= ndmin) return ret;\n\t/* create a new array from the same data with ones in the shape */\n\t/* steals a reference to ret */\n\treturn _prepend_ones((PyArrayObject *)ret, nd, ndmin);\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(dtype,obj) will return a new scalar array of the given type initialized with obj. Mainly for pickle support. The dtype must be a valid data-type descriptor. If dtype 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[] = {\"dtype\",\"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}; /* XXX ? */\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\nstatic int\n_skip_sep(char **ptr, char *sep)\n{\n\tchar *a;\n\tint n;\n\tn = strlen(sep);\n\ta = *ptr;\n\twhile(*a != '\\0' && (strncmp(a, sep, n) != 0))\n\t\ta++;\n\tif (*a == '\\0') return -1;\n\t*ptr = a+strlen(sep);\n\treturn 0;\n}\n\n/* steals a reference to dtype -- accepts NULL */\n/*OBJECT_API*/\nstatic PyObject *\nPyArray_FromString(char *data, intp slen, PyArray_Descr *dtype, \n\t\t intp n, char *sep)\n{\n\tint itemsize;\n\tPyArrayObject *ret;\n\tBool binary;\n\n\tif (dtype == NULL)\n\t\tdtype=PyArray_DescrFromType(PyArray_LONG);\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\n\tbinary = ((sep == NULL) || (strlen(sep) == 0));\t\n\n\tif (binary) {\n\t\tif (dtype == &OBJECT_Descr) {\n\t\t\tPyErr_SetString(PyExc_ValueError, \n\t\t\t\t\t\"Cannot create an object array from\"\\\n\t\t\t\t\t\" a binary string\");\n\t\t\tPy_DECREF(dtype);\n\t\t\treturn NULL;\n\t\t}\t\t\n\t\tif (n < 0 ) {\n\t\t\tif (slen % itemsize != 0) {\n\t\t\t\tPyErr_SetString(PyExc_ValueError, \n\t\t\t\t\t\t\"string size must be a \"\\\n\t\t\t\t\t\t\"multiple of element size\");\n\t\t\t\tPy_DECREF(dtype);\n\t\t\t\treturn NULL;\n\t\t\t}\n\t\t\tn = slen/itemsize;\n\t\t} else {\n\t\t\tif (slen < n*itemsize) {\n\t\t\t\tPyErr_SetString(PyExc_ValueError, \n\t\t\t\t\t\t\"string is smaller than \" \\\n\t\t\t\t\t\t\"requested size\");\n\t\t\t\tPy_DECREF(dtype);\n\t\t\t\treturn NULL;\n\t\t\t}\n\t\t}\n\t\n\t\tif ((ret = (PyArrayObject *)\\\n\t\t PyArray_NewFromDescr(&PyArray_Type, dtype,\n\t\t\t\t\t 1, &n, NULL, NULL,\n\t\t\t\t\t 0, NULL)) == NULL)\n\t\t\treturn NULL;\t\t\n\t\tmemcpy(ret->data, data, n*dtype->elsize);\n\t\treturn (PyObject *)ret;\n\t}\n\telse { /* read from character-based string */\n\t\tchar *ptr;\t\t\n\t\tPyArray_FromStrFunc *fromstr;\n\t\tchar *dptr;\n\t\tintp nread=0;\n\t\tintp index;\n\n\t\tfromstr = dtype->f->fromstr;\n\t\tif (fromstr == 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 strings for given \"\t\\\n\t\t\t\t\t\"array type\");\n\t\t\tPy_DECREF(dtype);\n\t\t\treturn NULL;\n\t\t}\n\n\t\tif (n!=-1) {\n\t\t\tret = (PyArrayObject *) \\\n\t\t\t\tPyArray_NewFromDescr(&PyArray_Type,\n\t\t\t\t\t\t dtype, 1, &n, NULL,\n\t\t\t\t\t\t NULL, 0, NULL);\n\t\t\tif (ret == NULL) return NULL;\n\t\t\tptr = data;\n\t\t\tdptr = ret->data;\n\t\t\tfor (index=0; index < n; index++) {\n\t\t\t\tif (fromstr(ptr, dptr, &ptr, ret) < 0)\n\t\t\t\t\tbreak;\n\t\t\t\tnread += 1;\n\t\t\t\tdptr += dtype->elsize;\n\t\t\t\tif (_skip_sep(&ptr, sep) < 0) \n\t\t\t\t\tbreak;\n\t\t\t}\n\t\t\tif (nread < n) {\n\t\t\t\tfprintf(stderr, \"%ld items requested but \"\\\n\t\t\t\t\t\"only %ld read\\n\", \n\t\t\t\t\t(long) n, (long) nread);\n\t\t\t\tret->data = \\\n\t\t\t\t\tPyDataMem_RENEW(ret->data, \n\t\t\t\t\t\t\tnread *\t\t\\\n\t\t\t\t\t\t\tret->descr->elsize);\n\t\t\t\tPyArray_DIM(ret,0) = nread;\n\t\t\t}\n\t\t}\n\t\telse {\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\t\t\tchar *end;\n\t\t\tint val;\n\n\t\t\tret = (PyArrayObject *)\\\n\t\t\t\tPyArray_NewFromDescr(&PyArray_Type, \n\t\t\t\t\t\t dtype,\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 (ret==NULL) return NULL;\n\t\t\ttotalbytes = bytes = size * dtype->elsize;\n\t\t\tdptr = ret->data;\n\t\t\tptr = data;\n\t\t\tend = data+slen;\n\t\t\twhile (ptr < end) {\n\t\t\t\tval = fromstr(ptr, dptr, &ptr, ret);\n\t\t\t\tif (val < 0) break;\n\t\t\t\tnread += 1;\n\t\t\t\tval = _skip_sep(&ptr, sep);\n\t\t\t\tif (val < 0) break;\n\t\t\t\tthisbuf += 1;\n\t\t\t\tdptr += dtype->elsize;\n\t\t\t\tif (thisbuf == size) {\n\t\t\t\t\ttotalbytes += bytes;\n\t\t\t\t\tret->data = PyDataMem_RENEW(ret->data, \n\t\t\t\t\t\t\t\t totalbytes);\n\t\t\t\t\tdptr = ret->data + \\\n\t\t\t\t\t\t(totalbytes - bytes);\n\t\t\t\t\tthisbuf = 0;\n\t\t\t\t}\n\t\t\t}\n\t\t\tret->data = PyDataMem_RENEW(ret->data, \n\t\t\t\t\t\t nread*ret->descr->elsize);\n\t\t\tPyArray_DIM(ret,0) = nread;\n#undef _FILEBUFNUM\n\t\t}\n\t}\n\treturn (PyObject *)ret;\n}\n\nstatic char doc_fromString[] = \"fromstring(string, dtype=int, count=-1, sep='') 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. If sep is not empty then the string is interpreted in ASCII mode and converted to the desired number type using sep as the separator between elements (extra whitespace is ignored).\";\n\nstatic PyObject *\narray_fromString(PyObject *ignored, PyObject *args, PyObject *keywds)\n{\n\tchar *data;\n\tlonglong nin=-1;\n\tchar *sep=NULL;\n\tint s;\n\tstatic char *kwlist[] = {\"string\", \"dtype\", \"count\", \"sep\", NULL};\n\tPyArray_Descr *descr=NULL;\n\n\tif (!PyArg_ParseTupleAndKeywords(args, keywds, \"s#|O&Ls\", 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, &sep)) {\n\t\treturn NULL;\n\t}\n\n\treturn PyArray_FromString(data, (intp)s, descr, (intp)nin, sep);\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\tPy_DECREF(typecode);\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\tPy_DECREF(typecode);\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\tPy_DECREF(typecode);\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 platform-independent method of persistence. But it can be \\n\"\\\n\t\" useful to 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_BYTES(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_BYTES(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[] = \n\"arange([start,] stop[, step,], dtype=None)\\n\\n\"\n\"For integer arguments, just like range() except it returns an array whose type can\\n\"\n\"be specified by the keyword argument dtype.\\n\\n\"\n\"If dtype is not specified, the type of the result is deduced from the type of the\\n\"\n\"arguments.\\n\\n\"\n\"For floating point arguments, the length of the result is ceil((stop - start)/step).\\n\"\n\"This rule may result in the last element of the result be greater than stop.\";\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_DescrConverter2,\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/*MULTIARRAY_API\n GetNDArrayCVersion\n*/\nstatic unsigned int\nPyArray_GetNDArrayCVersion(void)\n{\n\treturn (unsigned int)NDARRAY_VERSION;\n}\n\nstatic char \ndoc__get_ndarray_c_version[] = \"_get_ndarray_c_version() gets the compile time NDARRAY_VERSION number\";\n\nstatic PyObject *\narray__get_ndarray_c_version(PyObject *dummy, PyObject *args, PyObject *kwds) \n{\n\tstatic char *kwlist[] = {NULL};\n\tif(!PyArg_ParseTupleAndKeywords(args, kwds, \"\", kwlist )) return NULL;\n\t\n\treturn PyInt_FromLong( (long) PyArray_GetNDArrayCVersion() );\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, NULL);\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{\"_get_ndarray_c_version\", (PyCFunction)array__get_ndarray_c_version, \n\t METH_VARARGS|METH_KEYWORDS, doc__get_ndarray_c_version},\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, \"dtype\", (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\tif (!PyErr_Occurred()) {\n\t\tPyErr_SetString(PyExc_RuntimeError, \n\t\t\t\t\"cannot load multiarray module.\");\n\t}\n\treturn;\n}\n\n", + "source_code_before": "\n/*\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 extensively for numpy 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, \"dtype\");\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 void *\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 (void *)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, \"dtype\",\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)) == 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\tif (mps[i]->ob_type != subtype) {\n\t\t\tprior2 = PyArray_GetPriority((PyObject *)(mps[i]), 0.0);\n\t\t\tif (prior2 > prior1) {\n\t\t\t\tprior1 = prior2;\n\t\t\t\tsubtype = mps[i]->ob_type;\n\t\t\t\tret = mps[i];\n\t\t\t}\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; idescr->elsize;\n\tbyteorder = arr->descr->byteorder;\n\tptr = arr->data;\n\tif (elsize > 1 && \\\n\t (byteorder == PyArray_LITTLE ||\t\\\n\t (byteorder == PyArray_NATIVE &&\n\t PyArray_ISNBO(PyArray_LITTLE))))\n\t\tptr += elsize-1;\n\t\n\treturn ((*ptr & bitmask) != 0);\t\n}\n\n\n/*OBJECT_API*/\nstatic char\nPyArray_ScalarKind(int typenum, PyArrayObject **arr) \n{\n\tif (PyTypeNum_ISSIGNED(typenum)) {\n\t\tif (arr && _signbit_set(*arr)) return UFUNC_INTNEG_SCALAR;\n\t\telse return UFUNC_INTPOS_SCALAR;\n\t}\n\tif (PyTypeNum_ISFLOAT(typenum)) return UFUNC_FLOAT_SCALAR;\n\tif (PyTypeNum_ISUNSIGNED(typenum)) return UFUNC_INTPOS_SCALAR;\n\tif (PyTypeNum_ISCOMPLEX(typenum)) return UFUNC_COMPLEX_SCALAR;\n\tif (PyTypeNum_ISBOOL(typenum)) return UFUNC_BOOL_SCALAR;\n\n\treturn UFUNC_OBJECT_SCALAR;\n}\n\n\n/*OBJECT_API*/\nstatic int \nPyArray_CanCoerceScalar(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\n/* This needs to change to allow scalars of a different \"kind\" to alter the input type\n */\n\n/*OBJECT_API*/\nstatic PyArrayObject **\nPyArray_ConvertToCommonType(PyObject *op, int *retn)\n{\n\tint i, n, allscalars=0; \n\tPyArrayObject **mps=NULL;\n\tPyObject *otmp;\n\tPyArray_Descr *intype=NULL, *stype=NULL;\n\tPyArray_Descr *newtype=NULL;\n\tchar scalarkind;\n\n\t\n\t*retn = n = PySequence_Length(op);\n\tif (PyErr_Occurred()) {*retn = 0; return NULL;}\n\t\n\tmps = (PyArrayObject **)PyDataMem_NEW(n*sizeof(PyArrayObject *));\n\tif (mps == NULL) {\n\t\t*retn = 0;\n\t\treturn (void*)PyErr_NoMemory();\n\t}\n\t\n\tfor(i=0; itype_num, NULL);\n\t\t\tif (intype && !PyArray_CanCoerceScalar(newtype->type_num,\n\t\t\t\t\t\t\t intype->type_num, \n\t\t\t\t\t\t\t scalarkind)) {\n\t\t\t\tPy_XDECREF(intype);\n\t\t\t\tintype = stype;\n\t\t\t}\n\t\t\tmps[i] = (PyArrayObject *)Py_None;\n\t\t\tPy_INCREF(Py_None);\n\t\t}\n\t\tPy_XDECREF(otmp);\n\t}\n\tif (intype==NULL) { /* all scalars */\n\t\tallscalars = 1;\n\t\tintype = stype;\n\t\tPy_INCREF(intype);\n\t\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, NULL);\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 Make a new empty array, of the passed size, of a type that takes the\n priority of ap1 and ap2 into account.\n */\nstatic PyArrayObject *\nnew_array_for_sum(PyArrayObject *ap1, PyArrayObject *ap2,\n\t\t int nd, intp dimensions[], int typenum)\n{\n\tPyArrayObject *ret;\n\tPyTypeObject *subtype;\n\tdouble prior1, prior2;\n\t/* Need to choose an output array that can hold a sum \n\t -- use priority to determine which subtype.\n\t */\n\tif (ap2->ob_type != ap1->ob_type) {\n\t\tprior2 = PyArray_GetPriority((PyObject *)ap2, 0.0);\n\t\tprior1 = PyArray_GetPriority((PyObject *)ap1, 0.0);\n\n\t\tsubtype = (prior2 > prior1 ? ap2->ob_type : ap1->ob_type);\n\t} else {\n\t\tprior1 = prior2 = 0.0;\n\t\tsubtype = ap1->ob_type;\n\t}\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\treturn ret;\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\tPyArrayIterObject *it1, *it2;\n\tintp i, j, l;\n\tint typenum, nd;\n\tintp is1, is2, os;\n\tchar *op;\n\tintp dimensions[MAX_DIMS];\n\tPyArray_DotFunc *dot;\n\tPyArray_Descr *typec;\n\t\n\ttypenum = PyArray_ObjectType(op1, 0); \n\ttypenum = PyArray_ObjectType(op2, typenum);\n\n\ttypec = PyArray_DescrFromType(typenum);\n\tPy_INCREF(typec);\n\tap1 = (PyArrayObject *)PyArray_FromAny(op1, typec, 0, 0, \n\t\t\t\t\t BEHAVED_FLAGS, NULL);\n\tif (ap1 == NULL) {Py_DECREF(typec); return NULL;}\n\tap2 = (PyArrayObject *)PyArray_FromAny(op2, typec, 0, 0,\n\t\t\t\t\t BEHAVED_FLAGS, NULL);\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\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\tret = new_array_for_sum(ap1, ap2, nd, dimensions, typenum);\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\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\tit1 = (PyArrayIterObject *)\\\n\t\tPyArray_IterAllButAxis((PyObject *)ap1, ap1->nd-1);\n\tit2 = (PyArrayIterObject *)\\\n\t\tPyArray_IterAllButAxis((PyObject *)ap2, ap2->nd-1);\n\n\twhile(1) {\n\t\twhile(it2->index < it2->size) {\n\t\t\tdot(it1->dataptr, is1, it2->dataptr, is2, op, l, ret);\n\t\t\top += os;\n\t\t\tPyArray_ITER_NEXT(it2);\n\t\t}\n\t\tPyArray_ITER_NEXT(it1);\n\t\tif (it1->index >= it1->size) break;\n\t\tPyArray_ITER_RESET(it2);\n\t}\n\tPy_DECREF(it1);\n\tPy_DECREF(it2);\n\n\tif (PyErr_Occurred()) goto fail;\n\t\t\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/* just like inner product but does the swapaxes stuff on the fly */\n/*MULTIARRAY_API\n Numeric.matrixproduct(a,v)\n*/\nstatic PyObject *\nPyArray_MatrixProduct(PyObject *op1, PyObject *op2) \n{\n\tPyArrayObject *ap1, *ap2, *ret=NULL;\n\tPyArrayIterObject *it1, *it2;\n\tintp i, j, l;\n\tint typenum, nd;\n\tintp is1, is2, os;\n\tchar *op;\n\tintp dimensions[MAX_DIMS];\n\tPyArray_DotFunc *dot;\n\tintp matchDim;\n\tPyArray_Descr *typec;\n\n\ttypenum = PyArray_ObjectType(op1, 0); \n\ttypenum = PyArray_ObjectType(op2, typenum);\t\n\t\n\ttypec = PyArray_DescrFromType(typenum);\n\tPy_INCREF(typec);\n\tap1 = (PyArrayObject *)PyArray_FromAny(op1, typec, 0, 0, \n\t\t\t\t\t BEHAVED_FLAGS, NULL);\n\tif (ap1 == NULL) {Py_DECREF(typec); return NULL;}\n\tap2 = (PyArrayObject *)PyArray_FromAny(op2, typec, 0, 0,\n\t\t\t\t\t BEHAVED_FLAGS, NULL);\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\tif (ap2->nd > 1) {\n\t\tmatchDim = ap2->nd - 2;\n\t}\n\telse {\n\t\tmatchDim = 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\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; istrides[ap1->nd-1]; is2 = ap2->strides[matchDim];\n\n /* Choose which subtype to return */\n\tret = new_array_for_sum(ap1, ap2, nd, dimensions, typenum);\n\tif (ret == NULL) goto fail;\n\n\t/* Ensure that multiarray.dot([],[]) -> 0 */\n\tmemset(PyArray_DATA(ret), 0, PyArray_ITEMSIZE(ret));\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\top = ret->data; os = ret->descr->elsize;\n\n\tit1 = (PyArrayIterObject *)\\\n\t\tPyArray_IterAllButAxis((PyObject *)ap1, ap1->nd-1);\n\tit2 = (PyArrayIterObject *)\\\n\t\tPyArray_IterAllButAxis((PyObject *)ap2, matchDim);\n\n\twhile(1) {\n\t\twhile(it2->index < it2->size) {\n\t\t\tdot(it1->dataptr, is1, it2->dataptr, is2, op, l, ret);\n\t\t\top += os;\n\t\t\tPyArray_ITER_NEXT(it2);\n\t\t}\n\t\tPyArray_ITER_NEXT(it1);\n\t\tif (it1->index >= it1->size) break;\n\t\tPyArray_ITER_RESET(it2);\n\t}\n\tPy_DECREF(it1);\n\tPy_DECREF(it2);\n\tif (PyErr_Occurred()) goto fail; /* only for OBJECT arrays */\n\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/*MULTIARRAY_API\n Fast Copy and Transpose\n*/\nstatic PyObject *\nPyArray_CopyAndTranspose(PyObject *op) \n{\n\tPyObject *ret, *arr;\n\tint nd;\n\tintp dims[2];\n\tintp i,j;\n\tint elsize, str2;\n\tchar *iptr;\n\tchar *optr;\n\n\t/* make sure it is well-behaved */\n\tarr = PyArray_FromAny(op, NULL, 0, 0, CARRAY_FLAGS, NULL);\n\tnd = PyArray_NDIM(arr);\n\tif (nd == 1) { /* we will give in to old behavior */\n\t\tret = PyArray_Copy((PyArrayObject *)arr);\n\t\tPy_DECREF(arr);\n\t\treturn ret;\t\t\n\t}\n\telse if (nd != 2) {\n\t\tPy_DECREF(arr);\n\t\tPyErr_SetString(PyExc_ValueError, \n\t\t\t\t\"only 2-d arrays are allowed\");\n\t\treturn NULL;\n\t}\n\n\t/* Now construct output array */\n\tdims[0] = PyArray_DIM(arr,1);\n\tdims[1] = PyArray_DIM(arr,0);\n\telsize = PyArray_ITEMSIZE(arr);\n\t\n\tPy_INCREF(PyArray_DESCR(arr));\n\tret = PyArray_NewFromDescr(arr->ob_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\tret = new_array_for_sum(ap1, ap2, 1, &length, typenum);\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 Py_INCREF(self->descr); \n\tvalues = (PyArrayObject *)PyArray_FromAny(values0, self->descr, 0, 0, \n\t\t\t\t\t\t DEFAULT_FLAGS | FORCECAST, NULL); \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, NULL);\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\tif (type->type_num == PyArray_UNICODE)\n\t\t\ttype->elsize = itemsize << 2; \n\t\telse\n\t\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\tif (type->hasobject) newdescr->hasobject = 1;\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 int hasobject=0;\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; ihasobject)\n hasobject = 1;\n\t\ttup = PyTuple_New(2);\n\t\tPyTuple_SET_ITEM(tup, 0, (PyObject *)conv);\n\t\tPyTuple_SET_ITEM(tup, 1, PyInt_FromLong((long) totalsize));\n\t\ttotalsize += conv->elsize;\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 new->hasobject=hasobject;\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 int hasobject=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; ihasobject)\n\t\t\thasobject=1;\t\t\t\n\t\tPyTuple_SET_ITEM(tup, 0, (PyObject *)conv);\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\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\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 new->hasobject=hasobject;\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 int hasobject=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\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\tPyTuple_SET_ITEM(tup, 1, PyInt_FromLong(totalsize));\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\tif (PyDict_GetItem(fields, name) != NULL) {\n\t\t\tPyErr_SetString(PyExc_ValueError,\n\t\t\t\t\t\"name already used as a name or title\");\n\t\t\tret = PY_FAIL;\n\t\t}\n\t\tPyDict_SetItem(fields, name, tup);\n\t\tPy_DECREF(name);\n\t\tif (len == 3) {\n\t\t\tif (PyDict_GetItem(fields, item) != NULL) {\n\t\t\t\tPyErr_SetString(PyExc_ValueError, \n\t\t\t\t\t\t\"title already used as a name or \" \\\n\t\t\t\t\t\t\" title.\");\n\t\t\t\tret=PY_FAIL;\n\t\t\t}\n\t\t\telse {\n\t\t\t\tPyDict_SetItem(fields, item, tup);\n\t\t\t}\n\t\t}\n\t\tPy_DECREF(tup);\n\t\tif ((ret == PY_FAIL) || (newdescr->elsize == 0)) goto fail;\n if (!hasobject && newdescr->hasobject)\n hasobject = 1;\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 new->hasobject=hasobject;\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 == '|' || (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\tint i;\n\t\t\telsize = atoi(type+1);\n\t\t\t/* check for commas present */\n\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\nstatic PyObject *\n_prepend_ones(PyArrayObject *arr, int nd, int ndmin)\n{\n\tintp newdims[MAX_DIMS];\n\tintp newstrides[MAX_DIMS];\n\tint i,k,num;\n\tPyObject *ret;\n\n\tnum = ndmin-nd;\n\tfor (i=0; idescr->elsize;\n\t}\n\tfor (i=num;idimensions[k];\n\t\tnewstrides[i] = arr->strides[k];\n\t}\n\tPy_INCREF(arr->descr);\n\tret = PyArray_NewFromDescr(arr->ob_type, arr->descr, ndmin,\n\t\t\t\t newdims, newstrides, arr->data, arr->flags,\n\t\t\t\t (PyObject *)arr);\n\t/* steals a reference to arr --- so don't increment\n\t here */\n\tPyArray_BASE(ret) = (PyObject *)arr;\n\treturn ret;\n}\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,ndmin=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\"\\\n\t\"The ndmin argument specifies how many dimensions the returned\\n\"\\\n\t\"array should have as a minimum. 1's will be pre-pended to the\\n\"\\\n\t\"shape as needed to meet this requirement.\";\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\t\t\t \"ndmin\", NULL};\n Bool subok=FALSE;\n\tBool copy=TRUE;\n\tint ndmin=0, nd;\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&i\", 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\t\t\t\t&ndmin)) \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\tret = op;\n\t\t\t\tgoto finish;\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\tgoto finish;\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\tret = op;\n\t\t\t\tgoto finish;\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\tgoto finish;\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_CheckFromAny(op, type, 0, 0, flags, NULL)) == NULL) \n\t\treturn NULL;\n\n finish:\n\n\tif ((nd=PyArray_NDIM(ret)) >= ndmin) return ret;\n\t/* create a new array from the same data with ones in the shape */\n\t/* steals a reference to ret */\n\treturn _prepend_ones((PyArrayObject *)ret, nd, ndmin);\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(dtype,obj) will return a new scalar array of the given type initialized with obj. Mainly for pickle support. The dtype must be a valid data-type descriptor. If dtype 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[] = {\"dtype\",\"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}; /* XXX ? */\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\nstatic int\n_skip_sep(char **ptr, char *sep)\n{\n\tchar *a;\n\tint n;\n\tn = strlen(sep);\n\ta = *ptr;\n\twhile(*a != '\\0' && (strncmp(a, sep, n) != 0))\n\t\ta++;\n\tif (*a == '\\0') return -1;\n\t*ptr = a+strlen(sep);\n\treturn 0;\n}\n\n/* steals a reference to dtype -- accepts NULL */\n/*OBJECT_API*/\nstatic PyObject *\nPyArray_FromString(char *data, intp slen, PyArray_Descr *dtype, \n\t\t intp n, char *sep)\n{\n\tint itemsize;\n\tPyArrayObject *ret;\n\tBool binary;\n\n\tif (dtype == NULL)\n\t\tdtype=PyArray_DescrFromType(PyArray_LONG);\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\n\tbinary = ((sep == NULL) || (strlen(sep) == 0));\t\n\n\tif (binary) {\n\t\tif (dtype == &OBJECT_Descr) {\n\t\t\tPyErr_SetString(PyExc_ValueError, \n\t\t\t\t\t\"Cannot create an object array from\"\\\n\t\t\t\t\t\" a binary string\");\n\t\t\tPy_DECREF(dtype);\n\t\t\treturn NULL;\n\t\t}\t\t\n\t\tif (n < 0 ) {\n\t\t\tif (slen % itemsize != 0) {\n\t\t\t\tPyErr_SetString(PyExc_ValueError, \n\t\t\t\t\t\t\"string size must be a \"\\\n\t\t\t\t\t\t\"multiple of element size\");\n\t\t\t\tPy_DECREF(dtype);\n\t\t\t\treturn NULL;\n\t\t\t}\n\t\t\tn = slen/itemsize;\n\t\t} else {\n\t\t\tif (slen < n*itemsize) {\n\t\t\t\tPyErr_SetString(PyExc_ValueError, \n\t\t\t\t\t\t\"string is smaller than \" \\\n\t\t\t\t\t\t\"requested size\");\n\t\t\t\tPy_DECREF(dtype);\n\t\t\t\treturn NULL;\n\t\t\t}\n\t\t}\n\t\n\t\tif ((ret = (PyArrayObject *)\\\n\t\t PyArray_NewFromDescr(&PyArray_Type, dtype,\n\t\t\t\t\t 1, &n, NULL, NULL,\n\t\t\t\t\t 0, NULL)) == NULL)\n\t\t\treturn NULL;\t\t\n\t\tmemcpy(ret->data, data, n*dtype->elsize);\n\t\treturn (PyObject *)ret;\n\t}\n\telse { /* read from character-based string */\n\t\tchar *ptr;\t\t\n\t\tPyArray_FromStrFunc *fromstr;\n\t\tchar *dptr;\n\t\tintp nread=0;\n\t\tintp index;\n\n\t\tfromstr = dtype->f->fromstr;\n\t\tif (fromstr == 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 strings for given \"\t\\\n\t\t\t\t\t\"array type\");\n\t\t\tPy_DECREF(dtype);\n\t\t\treturn NULL;\n\t\t}\n\n\t\tif (n!=-1) {\n\t\t\tret = (PyArrayObject *) \\\n\t\t\t\tPyArray_NewFromDescr(&PyArray_Type,\n\t\t\t\t\t\t dtype, 1, &n, NULL,\n\t\t\t\t\t\t NULL, 0, NULL);\n\t\t\tif (ret == NULL) return NULL;\n\t\t\tptr = data;\n\t\t\tdptr = ret->data;\n\t\t\tfor (index=0; index < n; index++) {\n\t\t\t\tif (fromstr(ptr, dptr, &ptr, ret) < 0)\n\t\t\t\t\tbreak;\n\t\t\t\tnread += 1;\n\t\t\t\tdptr += dtype->elsize;\n\t\t\t\tif (_skip_sep(&ptr, sep) < 0) \n\t\t\t\t\tbreak;\n\t\t\t}\n\t\t\tif (nread < n) {\n\t\t\t\tfprintf(stderr, \"%ld items requested but \"\\\n\t\t\t\t\t\"only %ld read\\n\", \n\t\t\t\t\t(long) n, (long) nread);\n\t\t\t\tret->data = \\\n\t\t\t\t\tPyDataMem_RENEW(ret->data, \n\t\t\t\t\t\t\tnread *\t\t\\\n\t\t\t\t\t\t\tret->descr->elsize);\n\t\t\t\tPyArray_DIM(ret,0) = nread;\n\t\t\t}\n\t\t}\n\t\telse {\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\t\t\tchar *end;\n\t\t\tint val;\n\n\t\t\tret = (PyArrayObject *)\\\n\t\t\t\tPyArray_NewFromDescr(&PyArray_Type, \n\t\t\t\t\t\t dtype,\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 (ret==NULL) return NULL;\n\t\t\ttotalbytes = bytes = size * dtype->elsize;\n\t\t\tdptr = ret->data;\n\t\t\tptr = data;\n\t\t\tend = data+slen;\n\t\t\twhile (ptr < end) {\n\t\t\t\tval = fromstr(ptr, dptr, &ptr, ret);\n\t\t\t\tif (val < 0) break;\n\t\t\t\tnread += 1;\n\t\t\t\tval = _skip_sep(&ptr, sep);\n\t\t\t\tif (val < 0) break;\n\t\t\t\tthisbuf += 1;\n\t\t\t\tdptr += dtype->elsize;\n\t\t\t\tif (thisbuf == size) {\n\t\t\t\t\ttotalbytes += bytes;\n\t\t\t\t\tret->data = PyDataMem_RENEW(ret->data, \n\t\t\t\t\t\t\t\t totalbytes);\n\t\t\t\t\tdptr = ret->data + \\\n\t\t\t\t\t\t(totalbytes - bytes);\n\t\t\t\t\tthisbuf = 0;\n\t\t\t\t}\n\t\t\t}\n\t\t\tret->data = PyDataMem_RENEW(ret->data, \n\t\t\t\t\t\t nread*ret->descr->elsize);\n\t\t\tPyArray_DIM(ret,0) = nread;\n#undef _FILEBUFNUM\n\t\t}\n\t}\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\tchar *sep=NULL;\n\tint s;\n\tstatic char *kwlist[] = {\"string\", \"dtype\", \"count\", \"sep\", NULL};\n\tPyArray_Descr *descr=NULL;\n\n\tif (!PyArg_ParseTupleAndKeywords(args, keywds, \"s#|O&Ls\", 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, &sep)) {\n\t\treturn NULL;\n\t}\n\n\treturn PyArray_FromString(data, (intp)s, descr, (intp)nin, sep);\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\tPy_DECREF(typecode);\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\tPy_DECREF(typecode);\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\tPy_DECREF(typecode);\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 platform-independent method of persistence. But it can be \\n\"\\\n\t\" useful to 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_BYTES(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_BYTES(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[] = \n\"arange([start,] stop[, step,], dtype=None)\\n\\n\"\n\"For integer arguments, just like range() except it returns an array whose type can\\n\"\n\"be specified by the keyword argument dtype.\\n\\n\"\n\"If dtype is not specified, the type of the result is deduced from the type of the\\n\"\n\"arguments.\\n\\n\"\n\"For floating point arguments, the length of the result is ceil((stop - start)/step).\\n\"\n\"This rule may result in the last element of the result be greater than stop.\";\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_DescrConverter2,\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/*MULTIARRAY_API\n GetNDArrayCVersion\n*/\nstatic unsigned int\nPyArray_GetNDArrayCVersion(void)\n{\n\treturn (unsigned int)NDARRAY_VERSION;\n}\n\nstatic char \ndoc__get_ndarray_c_version[] = \"_get_ndarray_c_version() gets the compile time NDARRAY_VERSION number\";\n\nstatic PyObject *\narray__get_ndarray_c_version(PyObject *dummy, PyObject *args, PyObject *kwds) \n{\n\tstatic char *kwlist[] = {NULL};\n\tif(!PyArg_ParseTupleAndKeywords(args, kwds, \"\", kwlist )) return NULL;\n\t\n\treturn PyInt_FromLong( (long) PyArray_GetNDArrayCVersion() );\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, NULL);\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{\"_get_ndarray_c_version\", (PyCFunction)array__get_ndarray_c_version, \n\t METH_VARARGS|METH_KEYWORDS, doc__get_ndarray_c_version},\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, \"dtype\", (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\tif (!PyErr_Occurred()) {\n\t\tPyErr_SetString(PyExc_RuntimeError, \n\t\t\t\t\"cannot load multiarray module.\");\n\t}\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": 35, + "end_line": 50, + "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": 75, + "end_line": 80, + "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": 86, + "end_line": 91, + "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": 65, + "parameters": [ + "obj", + "ind" + ], + "start_line": 97, + "end_line": 105, + "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": 111, + "end_line": 123, + "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": 129, + "end_line": 136, + "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": 143, + "end_line": 173, + "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": 179, + "end_line": 196, + "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": 202, + "end_line": 237, + "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": 248, + "end_line": 257, + "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": 260, + "end_line": 286, + "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": 297, + "end_line": 384, + "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": 393, + "end_line": 428, + "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": 435, + "end_line": 456, + "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": 463, + "end_line": 522, + "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": 529, + "end_line": 539, + "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": 545, + "end_line": 555, + "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": 561, + "end_line": 571, + "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": 577, + "end_line": 588, + "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": 594, + "end_line": 605, + "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": 611, + "end_line": 622, + "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": 102, + "parameters": [ + "self", + "condition", + "axis" + ], + "start_line": 629, + "end_line": 649, + "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": 655, + "end_line": 714, + "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": 720, + "end_line": 750, + "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": 756, + "end_line": 792, + "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": 798, + "end_line": 808, + "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": 776, + "parameters": [ + "self", + "offset", + "axis1", + "axis2" + ], + "start_line": 814, + "end_line": 933, + "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": 402, + "parameters": [ + "op", + "ptr", + "dims", + "nd", + "typedescr" + ], + "start_line": 949, + "end_line": 1000, + "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": 1008, + "end_line": 1018, + "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": 1024, + "end_line": 1036, + "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": 1044, + "end_line": 1055, + "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": 1059, + "end_line": 1087, + "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": 94, + "complexity": 21, + "token_count": 630, + "parameters": [ + "op", + "axis" + ], + "start_line": 1099, + "end_line": 1205, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 107, + "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": 1211, + "end_line": 1252, + "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": 1258, + "end_line": 1311, + "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": 1317, + "end_line": 1412, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 96, + "top_nesting_level": 0 + }, + { + "name": "_signbit_set", + "long_name": "_signbit_set( PyArrayObject * arr)", + "filename": "multiarraymodule.c", + "nloc": 16, + "complexity": 5, + "token_count": 89, + "parameters": [ + "arr" + ], + "start_line": 1416, + "end_line": 1433, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 18, + "top_nesting_level": 0 + }, + { + "name": "PyArray_ScalarKind", + "long_name": "PyArray_ScalarKind( int typenum , PyArrayObject ** arr)", + "filename": "multiarraymodule.c", + "nloc": 12, + "complexity": 8, + "token_count": 80, + "parameters": [ + "typenum", + "arr" + ], + "start_line": 1438, + "end_line": 1450, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 13, + "top_nesting_level": 0 + }, + { + "name": "PyArray_CanCoerceScalar", + "long_name": "PyArray_CanCoerceScalar( char thistype , char neededtype , char scalar)", + "filename": "multiarraymodule.c", + "nloc": 21, + "complexity": 9, + "token_count": 101, + "parameters": [ + "thistype", + "neededtype", + "scalar" + ], + "start_line": 1455, + "end_line": 1476, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 22, + "top_nesting_level": 0 + }, + { + "name": "PyArray_ConvertToCommonType", + "long_name": "PyArray_ConvertToCommonType( PyObject * op , int * retn)", + "filename": "multiarraymodule.c", + "nloc": 73, + "complexity": 15, + "token_count": 482, + "parameters": [ + "op", + "retn" + ], + "start_line": 1484, + "end_line": 1563, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 80, + "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": 1570, + "end_line": 1651, + "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": 1654, + "end_line": 1661, + "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": 1672, + "end_line": 1726, + "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": 1729, + "end_line": 1807, + "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": 1815, + "end_line": 1818, + "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": 355, + "parameters": [ + "op", + "axis", + "which" + ], + "start_line": 1873, + "end_line": 1939, + "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": 1945, + "end_line": 1953, + "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": 1959, + "end_line": 2039, + "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": 2051, + "end_line": 2195, + "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": 2199, + "end_line": 2234, + "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": 2240, + "end_line": 2285, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 46, + "top_nesting_level": 0 + }, + { + "name": "new_array_for_sum", + "long_name": "new_array_for_sum( PyArrayObject * ap1 , PyArrayObject * ap2 , int nd , intp dimensions [ ] , int typenum)", + "filename": "multiarraymodule.c", + "nloc": 20, + "complexity": 4, + "token_count": 147, + "parameters": [ + "ap1", + "ap2", + "nd", + "typenum" + ], + "start_line": 2292, + "end_line": 2316, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 25, + "top_nesting_level": 0 + }, + { + "name": "PyArray_InnerProduct", + "long_name": "PyArray_InnerProduct( PyObject * op1 , PyObject * op2)", + "filename": "multiarraymodule.c", + "nloc": 79, + "complexity": 15, + "token_count": 624, + "parameters": [ + "op1", + "op2" + ], + "start_line": 2325, + "end_line": 2423, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 99, + "top_nesting_level": 0 + }, + { + "name": "PyArray_MatrixProduct", + "long_name": "PyArray_MatrixProduct( PyObject * op1 , PyObject * op2)", + "filename": "multiarraymodule.c", + "nloc": 89, + "complexity": 17, + "token_count": 680, + "parameters": [ + "op1", + "op2" + ], + "start_line": 2431, + "end_line": 2542, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 112, + "top_nesting_level": 0 + }, + { + "name": "PyArray_CopyAndTranspose", + "long_name": "PyArray_CopyAndTranspose( PyObject * op)", + "filename": "multiarraymodule.c", + "nloc": 47, + "complexity": 6, + "token_count": 286, + "parameters": [ + "op" + ], + "start_line": 2548, + "end_line": 2602, + "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": 86, + "complexity": 13, + "token_count": 601, + "parameters": [ + "op1", + "op2", + "mode" + ], + "start_line": 2608, + "end_line": 2705, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 98, + "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": 2712, + "end_line": 2736, + "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": 2742, + "end_line": 2753, + "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": 2759, + "end_line": 2770, + "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": 2776, + "end_line": 2799, + "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": 2806, + "end_line": 2863, + "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": 2870, + "end_line": 2945, + "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": 64, + "complexity": 15, + "token_count": 479, + "parameters": [ + "self", + "values0", + "indices0" + ], + "start_line": 2951, + "end_line": 3021, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 71, + "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": 3027, + "end_line": 3098, + "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": 68, + "parameters": [ + "object", + "address" + ], + "start_line": 3114, + "end_line": 3126, + "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": 3132, + "end_line": 3140, + "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": 3147, + "end_line": 3262, + "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": 3280, + "end_line": 3305, + "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": 3320, + "end_line": 3356, + "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": 3374, + "end_line": 3407, + "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": 65, + "complexity": 16, + "token_count": 399, + "parameters": [ + "obj" + ], + "start_line": 3410, + "end_line": 3487, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 78, + "top_nesting_level": 0 + }, + { + "name": "_convert_from_array_descr", + "long_name": "_convert_from_array_descr( PyObject * obj)", + "filename": "multiarraymodule.c", + "nloc": 69, + "complexity": 14, + "token_count": 442, + "parameters": [ + "obj" + ], + "start_line": 3495, + "end_line": 3566, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 72, + "top_nesting_level": 0 + }, + { + "name": "_convert_from_list", + "long_name": "_convert_from_list( PyObject * obj , int align , int try_descr)", + "filename": "multiarraymodule.c", + "nloc": 70, + "complexity": 13, + "token_count": 428, + "parameters": [ + "obj", + "align", + "try_descr" + ], + "start_line": 3577, + "end_line": 3648, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 72, + "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": 3661, + "end_line": 3677, + "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": 3714, + "end_line": 3719, + "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": 112, + "complexity": 29, + "token_count": 720, + "parameters": [ + "obj", + "align" + ], + "start_line": 3722, + "end_line": 3843, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 122, + "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": 3861, + "end_line": 3868, + "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": 141, + "complexity": 55, + "token_count": 886, + "parameters": [ + "obj", + "at" + ], + "start_line": 3885, + "end_line": 4065, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 181, + "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": 4071, + "end_line": 4103, + "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": 4109, + "end_line": 4135, + "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": 4144, + "end_line": 4163, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 20, + "top_nesting_level": 0 + }, + { + "name": "_prepend_ones", + "long_name": "_prepend_ones( PyArrayObject * arr , int nd , int ndmin)", + "filename": "multiarraymodule.c", + "nloc": 23, + "complexity": 3, + "token_count": 175, + "parameters": [ + "arr", + "nd", + "ndmin" + ], + "start_line": 4168, + "end_line": 4193, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 26, + "top_nesting_level": 0 + }, + { + "name": "_array_fromobject", + "long_name": "_array_fromobject( PyObject * ignored , PyObject * args , PyObject * kws)", + "filename": "multiarraymodule.c", + "nloc": 66, + "complexity": 16, + "token_count": 380, + "parameters": [ + "ignored", + "args", + "kws" + ], + "start_line": 4215, + "end_line": 4290, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 76, + "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": 4298, + "end_line": 4313, + "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": 4319, + "end_line": 4343, + "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": 4348, + "end_line": 4406, + "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": 4415, + "end_line": 4439, + "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": 4445, + "end_line": 4469, + "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": 4476, + "end_line": 4485, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 10, + "top_nesting_level": 0 + }, + { + "name": "_skip_sep", + "long_name": "_skip_sep( char ** ptr , char * sep)", + "filename": "multiarraymodule.c", + "nloc": 12, + "complexity": 4, + "token_count": 78, + "parameters": [ + "ptr", + "sep" + ], + "start_line": 4488, + "end_line": 4499, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 12, + "top_nesting_level": 0 + }, + { + "name": "PyArray_FromString", + "long_name": "PyArray_FromString( char * data , intp slen , PyArray_Descr * dtype , intp n , char * sep)", + "filename": "multiarraymodule.c", + "nloc": 133, + "complexity": 22, + "token_count": 711, + "parameters": [ + "data", + "slen", + "dtype", + "n", + "sep" + ], + "start_line": 4504, + "end_line": 4646, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 143, + "top_nesting_level": 0 + }, + { + "name": "array_fromString", + "long_name": "array_fromString( PyObject * ignored , PyObject * args , PyObject * keywds)", + "filename": "multiarraymodule.c", + "nloc": 16, + "complexity": 2, + "token_count": 116, + "parameters": [ + "ignored", + "args", + "keywds" + ], + "start_line": 4651, + "end_line": 4668, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 18, + "top_nesting_level": 0 + }, + { + "name": "PyArray_FromFile", + "long_name": "PyArray_FromFile( FILE * fp , PyArray_Descr * typecode , intp num , char * sep)", + "filename": "multiarraymodule.c", + "nloc": 114, + "complexity": 22, + "token_count": 664, + "parameters": [ + "fp", + "typecode", + "num", + "sep" + ], + "start_line": 4682, + "end_line": 4810, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 129, + "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": 4828, + "end_line": 4866, + "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": 4870, + "end_line": 4963, + "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": 4979, + "end_line": 4996, + "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": 5002, + "end_line": 5013, + "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": 5020, + "end_line": 5026, + "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": 5033, + "end_line": 5039, + "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": 5043, + "end_line": 5049, + "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": 5053, + "end_line": 5062, + "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": 5069, + "end_line": 5120, + "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": 5126, + "end_line": 5158, + "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": 5165, + "end_line": 5249, + "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": 5262, + "end_line": 5274, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 13, + "top_nesting_level": 0 + }, + { + "name": "PyArray_GetNDArrayCVersion", + "long_name": "PyArray_GetNDArrayCVersion()", + "filename": "multiarraymodule.c", + "nloc": 4, + "complexity": 1, + "token_count": 13, + "parameters": [], + "start_line": 5280, + "end_line": 5283, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 0 + }, + { + "name": "array__get_ndarray_c_version", + "long_name": "array__get_ndarray_c_version( PyObject * dummy , PyObject * args , PyObject * kwds)", + "filename": "multiarraymodule.c", + "nloc": 6, + "complexity": 2, + "token_count": 55, + "parameters": [ + "dummy", + "args", + "kwds" + ], + "start_line": 5289, + "end_line": 5295, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 7, + "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": 5301, + "end_line": 5317, + "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": 5323, + "end_line": 5340, + "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": 233, + "parameters": [ + "condition", + "x", + "y" + ], + "start_line": 5347, + "end_line": 5387, + "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": 5395, + "end_line": 5403, + "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": 5415, + "end_line": 5425, + "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": 5434, + "end_line": 5445, + "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": 5452, + "end_line": 5475, + "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": 5482, + "end_line": 5490, + "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": 5499, + "end_line": 5517, + "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": 5583, + "end_line": 5696, + "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": 5701, + "end_line": 5725, + "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": 64, + "complexity": 15, + "token_count": 435, + "parameters": [], + "start_line": 5730, + "end_line": 5822, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 93, + "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": 35, + "end_line": 50, + "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": 75, + "end_line": 80, + "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": 86, + "end_line": 91, + "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": 65, + "parameters": [ + "obj", + "ind" + ], + "start_line": 97, + "end_line": 105, + "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": 111, + "end_line": 123, + "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": 129, + "end_line": 136, + "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": 143, + "end_line": 173, + "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": 179, + "end_line": 196, + "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": 202, + "end_line": 237, + "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": 248, + "end_line": 257, + "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": 260, + "end_line": 286, + "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": 297, + "end_line": 384, + "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": 393, + "end_line": 428, + "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": 435, + "end_line": 456, + "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": 463, + "end_line": 522, + "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": 529, + "end_line": 539, + "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": 545, + "end_line": 555, + "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": 561, + "end_line": 571, + "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": 577, + "end_line": 588, + "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": 594, + "end_line": 605, + "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": 611, + "end_line": 622, + "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": 102, + "parameters": [ + "self", + "condition", + "axis" + ], + "start_line": 629, + "end_line": 649, + "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": 655, + "end_line": 714, + "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": 720, + "end_line": 750, + "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": 756, + "end_line": 792, + "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": 798, + "end_line": 808, + "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": 776, + "parameters": [ + "self", + "offset", + "axis1", + "axis2" + ], + "start_line": 814, + "end_line": 933, + "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": 402, + "parameters": [ + "op", + "ptr", + "dims", + "nd", + "typedescr" + ], + "start_line": 949, + "end_line": 1000, + "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": 1008, + "end_line": 1018, + "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": 1024, + "end_line": 1036, + "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": 1044, + "end_line": 1055, + "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": 1059, + "end_line": 1087, + "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": 94, + "complexity": 21, + "token_count": 630, + "parameters": [ + "op", + "axis" + ], + "start_line": 1099, + "end_line": 1205, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 107, + "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": 1211, + "end_line": 1252, + "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": 1258, + "end_line": 1311, + "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": 1317, + "end_line": 1412, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 96, + "top_nesting_level": 0 + }, + { + "name": "_signbit_set", + "long_name": "_signbit_set( PyArrayObject * arr)", + "filename": "multiarraymodule.c", + "nloc": 16, + "complexity": 5, + "token_count": 89, + "parameters": [ + "arr" + ], + "start_line": 1416, + "end_line": 1433, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 18, + "top_nesting_level": 0 + }, + { + "name": "PyArray_ScalarKind", + "long_name": "PyArray_ScalarKind( int typenum , PyArrayObject ** arr)", + "filename": "multiarraymodule.c", + "nloc": 12, + "complexity": 8, + "token_count": 80, + "parameters": [ + "typenum", + "arr" + ], + "start_line": 1438, + "end_line": 1450, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 13, + "top_nesting_level": 0 + }, + { + "name": "PyArray_CanCoerceScalar", + "long_name": "PyArray_CanCoerceScalar( char thistype , char neededtype , char scalar)", + "filename": "multiarraymodule.c", + "nloc": 21, + "complexity": 9, + "token_count": 101, + "parameters": [ + "thistype", + "neededtype", + "scalar" + ], + "start_line": 1455, + "end_line": 1476, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 22, + "top_nesting_level": 0 + }, + { + "name": "PyArray_ConvertToCommonType", + "long_name": "PyArray_ConvertToCommonType( PyObject * op , int * retn)", + "filename": "multiarraymodule.c", + "nloc": 73, + "complexity": 15, + "token_count": 482, + "parameters": [ + "op", + "retn" + ], + "start_line": 1484, + "end_line": 1563, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 80, + "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": 1570, + "end_line": 1651, + "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": 1654, + "end_line": 1661, + "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": 1672, + "end_line": 1726, + "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": 1729, + "end_line": 1807, + "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": 1815, + "end_line": 1818, + "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": 355, + "parameters": [ + "op", + "axis", + "which" + ], + "start_line": 1873, + "end_line": 1939, + "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": 1945, + "end_line": 1953, + "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": 1959, + "end_line": 2039, + "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": 2051, + "end_line": 2195, + "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": 2199, + "end_line": 2234, + "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": 2240, + "end_line": 2285, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 46, + "top_nesting_level": 0 + }, + { + "name": "new_array_for_sum", + "long_name": "new_array_for_sum( PyArrayObject * ap1 , PyArrayObject * ap2 , int nd , intp dimensions [ ] , int typenum)", + "filename": "multiarraymodule.c", + "nloc": 20, + "complexity": 4, + "token_count": 147, + "parameters": [ + "ap1", + "ap2", + "nd", + "typenum" + ], + "start_line": 2292, + "end_line": 2316, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 25, + "top_nesting_level": 0 + }, + { + "name": "PyArray_InnerProduct", + "long_name": "PyArray_InnerProduct( PyObject * op1 , PyObject * op2)", + "filename": "multiarraymodule.c", + "nloc": 79, + "complexity": 15, + "token_count": 624, + "parameters": [ + "op1", + "op2" + ], + "start_line": 2325, + "end_line": 2423, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 99, + "top_nesting_level": 0 + }, + { + "name": "PyArray_MatrixProduct", + "long_name": "PyArray_MatrixProduct( PyObject * op1 , PyObject * op2)", + "filename": "multiarraymodule.c", + "nloc": 89, + "complexity": 17, + "token_count": 680, + "parameters": [ + "op1", + "op2" + ], + "start_line": 2431, + "end_line": 2542, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 112, + "top_nesting_level": 0 + }, + { + "name": "PyArray_CopyAndTranspose", + "long_name": "PyArray_CopyAndTranspose( PyObject * op)", + "filename": "multiarraymodule.c", + "nloc": 47, + "complexity": 6, + "token_count": 286, + "parameters": [ + "op" + ], + "start_line": 2548, + "end_line": 2602, + "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": 86, + "complexity": 13, + "token_count": 601, + "parameters": [ + "op1", + "op2", + "mode" + ], + "start_line": 2608, + "end_line": 2705, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 98, + "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": 2712, + "end_line": 2736, + "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": 2742, + "end_line": 2753, + "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": 2759, + "end_line": 2770, + "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": 2776, + "end_line": 2799, + "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": 2806, + "end_line": 2863, + "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": 2870, + "end_line": 2945, + "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": 64, + "complexity": 15, + "token_count": 479, + "parameters": [ + "self", + "values0", + "indices0" + ], + "start_line": 2951, + "end_line": 3021, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 71, + "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": 3027, + "end_line": 3098, + "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": 68, + "parameters": [ + "object", + "address" + ], + "start_line": 3114, + "end_line": 3126, + "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": 3132, + "end_line": 3140, + "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": 3147, + "end_line": 3262, + "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": 3280, + "end_line": 3305, + "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": 3320, + "end_line": 3356, + "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": 3374, + "end_line": 3407, + "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": 65, + "complexity": 16, + "token_count": 399, + "parameters": [ + "obj" + ], + "start_line": 3410, + "end_line": 3487, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 78, + "top_nesting_level": 0 + }, + { + "name": "_convert_from_array_descr", + "long_name": "_convert_from_array_descr( PyObject * obj)", + "filename": "multiarraymodule.c", + "nloc": 69, + "complexity": 14, + "token_count": 442, + "parameters": [ + "obj" + ], + "start_line": 3495, + "end_line": 3566, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 72, + "top_nesting_level": 0 + }, + { + "name": "_convert_from_list", + "long_name": "_convert_from_list( PyObject * obj , int align , int try_descr)", + "filename": "multiarraymodule.c", + "nloc": 70, + "complexity": 13, + "token_count": 428, + "parameters": [ + "obj", + "align", + "try_descr" + ], + "start_line": 3577, + "end_line": 3648, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 72, + "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": 3661, + "end_line": 3677, + "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": 3714, + "end_line": 3719, + "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": 112, + "complexity": 29, + "token_count": 720, + "parameters": [ + "obj", + "align" + ], + "start_line": 3722, + "end_line": 3843, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 122, + "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": 3861, + "end_line": 3868, + "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": 141, + "complexity": 55, + "token_count": 886, + "parameters": [ + "obj", + "at" + ], + "start_line": 3885, + "end_line": 4065, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 181, + "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": 4071, + "end_line": 4103, + "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": 4109, + "end_line": 4135, + "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": 4144, + "end_line": 4163, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 20, + "top_nesting_level": 0 + }, + { + "name": "_prepend_ones", + "long_name": "_prepend_ones( PyArrayObject * arr , int nd , int ndmin)", + "filename": "multiarraymodule.c", + "nloc": 23, + "complexity": 3, + "token_count": 175, + "parameters": [ + "arr", + "nd", + "ndmin" + ], + "start_line": 4168, + "end_line": 4193, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 26, + "top_nesting_level": 0 + }, + { + "name": "_array_fromobject", + "long_name": "_array_fromobject( PyObject * ignored , PyObject * args , PyObject * kws)", + "filename": "multiarraymodule.c", + "nloc": 66, + "complexity": 16, + "token_count": 380, + "parameters": [ + "ignored", + "args", + "kws" + ], + "start_line": 4215, + "end_line": 4290, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 76, + "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": 4298, + "end_line": 4313, + "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": 4319, + "end_line": 4343, + "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": 4348, + "end_line": 4406, + "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": 4415, + "end_line": 4439, + "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": 4445, + "end_line": 4469, + "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": 4476, + "end_line": 4485, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 10, + "top_nesting_level": 0 + }, + { + "name": "_skip_sep", + "long_name": "_skip_sep( char ** ptr , char * sep)", + "filename": "multiarraymodule.c", + "nloc": 12, + "complexity": 4, + "token_count": 78, + "parameters": [ + "ptr", + "sep" + ], + "start_line": 4488, + "end_line": 4499, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 12, + "top_nesting_level": 0 + }, + { + "name": "PyArray_FromString", + "long_name": "PyArray_FromString( char * data , intp slen , PyArray_Descr * dtype , intp n , char * sep)", + "filename": "multiarraymodule.c", + "nloc": 133, + "complexity": 22, + "token_count": 711, + "parameters": [ + "data", + "slen", + "dtype", + "n", + "sep" + ], + "start_line": 4504, + "end_line": 4646, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 143, + "top_nesting_level": 0 + }, + { + "name": "array_fromString", + "long_name": "array_fromString( PyObject * ignored , PyObject * args , PyObject * keywds)", + "filename": "multiarraymodule.c", + "nloc": 16, + "complexity": 2, + "token_count": 116, + "parameters": [ + "ignored", + "args", + "keywds" + ], + "start_line": 4651, + "end_line": 4668, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 18, + "top_nesting_level": 0 + }, + { + "name": "PyArray_FromFile", + "long_name": "PyArray_FromFile( FILE * fp , PyArray_Descr * typecode , intp num , char * sep)", + "filename": "multiarraymodule.c", + "nloc": 114, + "complexity": 22, + "token_count": 664, + "parameters": [ + "fp", + "typecode", + "num", + "sep" + ], + "start_line": 4682, + "end_line": 4810, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 129, + "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": 4828, + "end_line": 4866, + "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": 4870, + "end_line": 4963, + "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": 4979, + "end_line": 4996, + "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": 5002, + "end_line": 5013, + "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": 5020, + "end_line": 5026, + "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": 5033, + "end_line": 5039, + "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": 5043, + "end_line": 5049, + "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": 5053, + "end_line": 5062, + "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": 5069, + "end_line": 5120, + "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": 5126, + "end_line": 5158, + "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": 5165, + "end_line": 5249, + "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": 5262, + "end_line": 5274, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 13, + "top_nesting_level": 0 + }, + { + "name": "PyArray_GetNDArrayCVersion", + "long_name": "PyArray_GetNDArrayCVersion()", + "filename": "multiarraymodule.c", + "nloc": 4, + "complexity": 1, + "token_count": 13, + "parameters": [], + "start_line": 5280, + "end_line": 5283, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 0 + }, + { + "name": "array__get_ndarray_c_version", + "long_name": "array__get_ndarray_c_version( PyObject * dummy , PyObject * args , PyObject * kwds)", + "filename": "multiarraymodule.c", + "nloc": 6, + "complexity": 2, + "token_count": 55, + "parameters": [ + "dummy", + "args", + "kwds" + ], + "start_line": 5289, + "end_line": 5295, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 7, + "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": 5301, + "end_line": 5317, + "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": 5323, + "end_line": 5340, + "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": 233, + "parameters": [ + "condition", + "x", + "y" + ], + "start_line": 5347, + "end_line": 5387, + "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": 5395, + "end_line": 5403, + "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": 5415, + "end_line": 5425, + "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": 5434, + "end_line": 5445, + "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": 5452, + "end_line": 5475, + "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": 5482, + "end_line": 5490, + "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": 5499, + "end_line": 5517, + "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": 5583, + "end_line": 5696, + "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": 5701, + "end_line": 5725, + "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": 64, + "complexity": 15, + "token_count": 435, + "parameters": [], + "start_line": 5730, + "end_line": 5822, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 93, + "top_nesting_level": 0 + } + ], + "changed_methods": [], + "nloc": 4413, + "complexity": 968, + "token_count": 28570, + "diff_parsed": { + "added": [ + "static char doc_fromString[] = \"fromstring(string, dtype=int, count=-1, sep='') 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. If sep is not empty then the string is interpreted in ASCII mode and converted to the desired number type using sep as the separator between elements (extra whitespace is ignored).\";" + ], + "deleted": [ + "static 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.\";" + ] + } + } + ] + } +] \ No newline at end of file